Skip to contentSkip to conversation

Introducing the concept of non fatal failures in KVM autotest

PATCH In review Lucas Meneghel Rodrigues 2 participants 6 messages Apr 8, 2011 KVM

lore
Share & tools
lore
#0 lore raw

cover Introducing the concept of non fatal failures in KVM autotest

In order to fix make it possible to throw test errors in certain special conditions, yet executing dependent tests,introduced a new public job API and modified kvm_utils.run_tests logic.

Also modified preprocessing code to provide a feature asked for a long time:
make tests with dependencies failed to execute, but to throw a TestNA exception, so our developers are not fooled with a high PASS rate on a job that had a central dependency (such as KVM build) failed.

More info on the commit messages. John, I would like you to review only the first patch, as it touches a very visible autotest API, so it is high risk.

Lucas Meneghel Rodrigues (4):
client job: Introduce a run_test_detail method
KVM test: Fail a test right away if 'dependency_fail = yes' is on
params
KVM test: Refine image_check function
KVM test: Modify kvm_utils.run_tests to include non fatal failures

 client/bin/job.py                     |   54 ++++++++++++++++++++++++++++++--
 client/tests/kvm/kvm_preprocessing.py |    6 +++-
 client/tests/kvm/kvm_utils.py         |   17 ++++++++--
 client/tests/kvm/kvm_vm.py            |   19 ++++++++++--
 4 files changed, 84 insertions(+), 12 deletions(-)
Signature · 1 line
1.7.4.2
#1 lore raw

PATCH 1/4 client job: Introduce a run_test_detail method

For the KVM test, we have for a long time a system of 'test dependencies': If a dependency test, such as guest installation has failed, it is not possible to run subsequent tests for obvious reasons. There are minor failures though, that don't necessarily block other tests, such as some specific types of image problems found on a guest after the routine check.

However, job.run_test() returns a boolean, making it not possible to fail a test, so we are not ignoring problems, and at the same time, execute dependent tests, because the failure was deemed to be non-fatal. Therefore, introduce and additional method, job.run_test_detail(), that returns the test status (see all possible statuses on client/common_lib/error.py), rather than a boolean. With this finer grained control, we can implement the kvm subtest dependency system in a better way.

Strategy: refactor the run_test method into _run_test_base and creating the 2 implementations, run_test, and run_test_detail in terms of _run_test_base.

Risk: High (touches a very very visible test writer API) Tests executed: run_test continues to work, run_test_detail provides the correct return codes and change does not break job_unittest.

---
 client/bin/job.py |   54 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 50 insertions(+), 4 deletions(-)
client/bin/job.py +50 -4
index 97412c0..9effcdb 100644
@@ -539,10 +539,9 @@ class base_client_job(base_job.base_job):
             raise error.UnhandledTestError(e)
 
 
-    @_run_test_complete_on_exit
-    def run_test(self, url, *args, **dargs):
+    def _run_test_base(self, url, *args, **dargs):
         """
-        Summon a test object and run it.
+        Prepares arguments and run functions to run_test and run_test_detail.
 
         @param url A url that identifies the test to run.
         @param tag An optional keyword argument that will be added to the
@@ -550,7 +549,11 @@ class base_client_job(base_job.base_job):
         @param subdir_tag An optional keyword argument that will be added
             to the subdir name.
 
-        @returns True if the test passes, False otherwise.
+        @returns:
+                subdir: Test subdirectory
+                testname: Test name
+                group_func: Actual test run function
+                timeout: Test timeout
         """
         group, testname = self.pkgmgr.get_package_name(url, 'test')
         testname, subdir, tag = self._build_tagged_test_name(testname, dargs)
@@ -573,6 +576,25 @@ class base_client_job(base_job.base_job):
             else:
                 self.record('GOOD', subdir, testname, 'completed successfully')
 
+        return (subdir, testname, group_func, timeout)
+
+
+    @_run_test_complete_on_exit
+    def run_test(self, url, *args, **dargs):
+        """
+        Summon a test object and run it.
+
+        @param url A url that identifies the test to run.
+        @param tag An optional keyword argument that will be added to the
+            test and subdir name.
+        @param subdir_tag An optional keyword argument that will be added
+            to the subdir name.
+
+        @returns True if the test passes, False otherwise.
+        """
+        (subdir, testname, group_func, timeout) = self._run_test_base(url,
+                                                                      *args,
+                                                                      **dargs)
         try:
             self._rungroup(subdir, testname, group_func, timeout)
             return True
@@ -585,6 +607,30 @@ class base_client_job(base_job.base_job):
         # UnhandledTestError that is caught above.
 
 
+    @_run_test_complete_on_exit
+    def run_test_detail(self, url, *args, **dargs):
+        """
+        Summon a test object and run it, returning test status.
+
+        @param url A url that identifies the test to run.
+        @param tag An optional keyword argument that will be added to the
+            test and subdir name.
+        @param subdir_tag An optional keyword argument that will be added
+            to the subdir name.
+
+        @returns Test status
+        @see: client/common_lib/error.py, exit_status
+        """
+        (subdir, testname, group_func, timeout) = self._run_test_base(url,
+                                                                      *args,
+                                                                      **dargs)
+        try:
+            self._rungroup(subdir, testname, group_func, timeout)
+            return 'GOOD'
+        except error.TestBaseException, detail:
+            return detail.exit_status
+
+
     def _rungroup(self, subdir, testname, function, timeout, *args, **dargs):
         """\
         subdir:
Signature · 1 line
1.7.4.2
#2 lore raw

PATCH 2/4 KVM test: Fail a test right away if 'dependency_fail = yes' is on params

In reply to Lucas Meneghel Rodrigues

When the KVM config file parser generates the list of tests, it will generate a full list of dicts, each dict maps to a test to be executed. However, due to the design of our dependency system, we skip running tests that had a dependency failure.

While fair, this also masks the fact that the tests that were not executed are indeed failures (test couldn't run because a dependency failed). So test jobs that had very serious problem (say, kvm build failed so every other test failed in sequence), will yield fairly reasonable PASS rates, that can fool developers.

So, here's what we are going to do to solve this:

* When a dependency fails, when it comes to execute a dependency
test, don't just skip it. Execute it in a way that it will always throw a TestNA exception.

In order to do that:

* Introduce an extra parameter 'dependency_fail = yes' on the
dependent test 'params' dict.
* Make test preprocessing code to fail the test right away with
TestNA whenever params[dependency_fail] is 'yes'.

---
 client/tests/kvm/kvm_preprocessing.py |    6 +++++-
 client/tests/kvm/kvm_utils.py         |    6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
client/tests/kvm/kvm_preprocessing.py +5 -1
index 515e3a5..47c29d4 100644
@@ -193,8 +193,12 @@ def preprocess(test, params, env):
     @param params: A dict containing all VM and image parameters.
     @param env: The environment (a dict-like object).
     """
-    error.context("preprocessing")
+    # If a dependency test prior to this test has failed, then let's 'run' this
+    # test, but fail it right away as TestNA.
+    if params("dependency_failed") == 'yes':
+        raise error.TestNA("Test dependency failed")
 
+    error.context("preprocessing")
     # Start tcpdump if it isn't already running
     if "address_cache" not in env:
         env["address_cache"] = {}
client/tests/kvm/kvm_utils.py +5 -1
index 5ecbd4a..ff9ee17 100644
@@ -1173,7 +1173,11 @@ def run_tests(parser, job):
             if not current_status:
                 failed = True
         else:
-            current_status = False
+            # We will force the test to fail as TestNA during preprocessing
+            dict['dependency_failed'] = 'yes'
+            current_status = job.run_test("kvm", params=dict, tag=test_tag,
+                                          iterations=test_iterations,
+                                          profile_only= bool(profilers) or None)
         status_dict[dict.get("name")] = current_status
 
     return not failed
Signature · 1 line
1.7.4.2
#3 lore raw

PATCH 3/4 KVM test: Refine image_check function

In reply to Lucas Meneghel Rodrigues

With the accumulated experience running the KVM test to perform quality control on our KVM branches, we noticed that qemu-img check might return exit code != 0, but not all failures mean some data integrity problem happend.

After checking qemu-img check code, we found out that:

Exit code 1: Check error. Problem on the check itself, most of the time harmless, however there is some risk of data corruption.

Exit code 2: Data corruption error. This means for sure that disk corruption happened. Bad, bad.

Exit code 3: Leaked clusters error. This means some leaked clusters were found on the image, which is not a data corruption condition, it only means that some space is going to be lost on that image.

So, refine the logic of the image_check function, executing qemu-img check and verifying its exit code

Exit code 1: Raise error.TestWarn
Exit code 2: Raise VMImageError
Exit code 3: Raise error.TestWarn

This change, together with the new logic of the KVM run_tests() utility function, will make it possible to still fail tests in cases 1) and 3), but letting the dependencies to be executed.

---
 client/tests/kvm/kvm_vm.py |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
client/tests/kvm/kvm_vm.py +16 -3
index 8114670..445ba6b 100755
@@ -294,10 +294,23 @@ def check_image(params, root_dir):
             except error.CmdError:
                 logging.error("Error getting info from image %s",
                               image_filename)
-            try:
-                utils.system("%s check %s" % (qemu_img_cmd, image_filename))
-            except error.CmdError:
+
+            cmd_result = utils.run("%s check %s" %
+                                   (qemu_img_cmd, image_filename),
+                                   ignore_status=True)
+            # Error check, large chances of a non-fatal problem.
+            # There are chances that bad data was skipped though
+            if cmd_result.exit_status == 1:
+                raise error.TestWarn("qemu-img check error. Some bad data in "
+                                     "the image may have gone unnoticed")
+            # Exit status 2 is data corruption for sure, so fail the test
+            elif cmd_result.exit_status == 2:
                 raise VMImageCheckError(image_filename)
+            # Leaked clusters, they are known to be harmless to data integrity
+            elif cmd_result.exit_status == 3:
+                raise error.TestWarn("Leaked clusters were noticed during "
+                                     "image check. No data integrity problem "
+                                     "was found though.")
 
     else:
         if not os.path.exists(image_filename):
Signature · 1 line
1.7.4.2
#5 lore raw

PATCH 4/4 KVM test: Modify kvm_utils.run_tests to include non fatal failures

In reply to Lucas Meneghel Rodrigues

So now if a error.TestWarn is thrown, dependent tests can run just fine.

---
 client/tests/kvm/kvm_utils.py |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
client/tests/kvm/kvm_utils.py +10 -5
index ff9ee17..8b908ff 100644
@@ -1150,7 +1150,10 @@ def run_tests(parser, job):
             for test_name in status_dict.keys():
                 if not dep in test_name:
                     continue
-                if not status_dict[test_name]:
+                # So the only really non-fatal state is WARN,
+                # All the others make it not safe to proceed with dependency
+                # execution
+                if status_dict[test_name] not in ['GOOD', 'WARN']:
                     dependencies_satisfied = False
                     break
         if dependencies_satisfied:
@@ -1163,8 +1166,9 @@ def run_tests(parser, job):
 
             # We need only one execution, profiled, hence we're passing
             # the profile_only parameter to job.run_test().
-            current_status = job.run_test("kvm", params=dict, tag=test_tag,
-                                          iterations=test_iterations,
+            current_status = job.run_test_detail("kvm", params=dict,
+                                                 tag=test_tag,
+                                                 iterations=test_iterations,
                                           profile_only= bool(profilers) or None)
 
             for profiler in profilers:
@@ -1175,8 +1179,9 @@ def run_tests(parser, job):
         else:
             # We will force the test to fail as TestNA during preprocessing
             dict['dependency_failed'] = 'yes'
-            current_status = job.run_test("kvm", params=dict, tag=test_tag,
-                                          iterations=test_iterations,
+            current_status = job.run_test_detail("kvm", params=dict,
+                                                 tag=test_tag,
+                                                 iterations=test_iterations,
                                           profile_only= bool(profilers) or None)
         status_dict[dict.get("name")] = current_status
 
Signature · 1 line
1.7.4.2
#4 lore raw

Re: [Autotest] [PATCH 3/4] KVM test: Refine image_check function

In reply to Lucas Meneghel Rodrigues
Quoted 46 lines · Lucas Meneghel Rodrigues

With the accumulated experience running the KVM test to perform quality control on our KVM branches, we noticed that qemu-img check might return exit code != 0, but not all failures mean some data integrity problem happend.

After checking qemu-img check code, we found out that:

Exit code 1: Check error. Problem on the check itself, most of the time harmless, however there is some risk of data corruption.

Exit code 2: Data corruption error. This means for sure that disk corruption happened. Bad, bad.

Exit code 3: Leaked clusters error. This means some leaked clusters were found on the image, which is not a data corruption condition, it only means that some space is going to be lost on that image.

So, refine the logic of the image_check function, executing qemu-img check and verifying its exit code

Exit code 1: Raise error.TestWarn
Exit code 2: Raise VMImageError
Exit code 3: Raise error.TestWarn

This change, together with the new logic of the KVM run_tests() utility function, will make it possible to still fail tests in cases 1) and 3), but letting the dependencies to be executed.

---
 client/tests/kvm/kvm_vm.py |   19 ++++++++++++++++---

 1 files changed, 16 insertions(+), 3 deletions(-)
client/tests/kvm/kvm_vm.py +0 -0
index 8114670..445ba6b 100755
@@ -294,10 +294,23 @@ def check_image(params, root_dir):

            except error.CmdError:
                logging.error("Error getting info from image %s", image_filename)
-            try:
-                utils.system("%s check %s" % (qemu_img_cmd, image_filename))

Quoted 8 lines

-            except error.CmdError:
+
+            cmd_result = utils.run("%s check %s" %
+                                   (qemu_img_cmd, image_filename),
+                                   ignore_status=True)
+            # Error check, large chances of a non-fatal problem.
+            # There are chances that bad data was skipped though
+            if cmd_result.exit_status == 1:

^ I think here I could've printed the stdout and stderr of the qemu-img check command to help debugging things. Another option is to pass the appropriate run params to make stdout and stderr to be printed to logs. However, if we do that we'll have not overly useful and generally enormous 'leaked cluster' messages on case 3.

Quoted 4 lines

+                raise error.TestWarn("qemu-img check error. Some bad data in "
+                                     "the image may have gone unnoticed")
+            # Exit status 2 is data corruption for sure, so fail the test
+            elif cmd_result.exit_status == 2:

^ Same here. I'm commenting on my own patches so I remember to make those improvements :)

Quoted 17 lines

                raise VMImageCheckError(image_filename)
+            # Leaked clusters, they are known to be harmless to data integrity
+            elif cmd_result.exit_status == 3:
+                raise error.TestWarn("Leaked clusters were noticed during "
+                                     "image check. No data integrity problem "
+                                     "was found though.")

    else:
        if not os.path.exists(image_filename):
--
1.7.4.2

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Signature · 1 line
Lucas