Introduce a background error queue to store exceptions happened during virt background tasks (such as aexpect instances and screendump thread). With this queue, it is possible to store exception information useful to fail tests at certain points. Examples: * We can detect qemu suffered a crash from inside the aexpect thread * We can detect screen inactivity on the screendump thread and fail the unattended install test without having to wait the entire timeout of the test The next patches will introduce that functionality. Implementation consists in a virt test attribute, background_error test, that is a Queue.Queue() (thread safe), background threads that want to make use of it need to catch the exception they want to propagate and store it in the queue using put(sys.exc_info). Then in every convenient situation to do so, subtests can call the test.verify_bg_errors() method (in the beginning or end of each test loop, where operations such as migrations are executed). Signed-off-by: Lucas Meneghel Rodrigues <lmr@xxxxxxxxxx> --- client/virt/virt_test.py | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) diff --git a/client/virt/virt_test.py b/client/virt/virt_test.py index e18081b..0ce43c4 100644 --- a/client/virt/virt_test.py +++ b/client/virt/virt_test.py @@ -1,4 +1,4 @@ -import os, sys, logging, imp +import os, sys, logging, imp, Queue from autotest_lib.client.bin import test from autotest_lib.client.common_lib import error @@ -22,6 +22,22 @@ class virt_test(test.test): if params.get("preserve_srcdir", "yes") == "yes": self.preserve_srcdir = True self.virtdir = os.path.dirname(sys.modules[__name__].__file__) + # Queue to store exceptions that happen in bg threads + self.background_errors = Queue.Queue() + + + def verify_background_errors(self): + """ + Verify if there are any errors that happened on background threads. + + @raise Exception: Any exception stored on the background_errors queue. + """ + try: + exc = self.background_errors.get(block=False) + except Queue.Empty: + pass + else: + raise exc[1], None, exc[2] def run_once(self, params): @@ -86,6 +102,7 @@ class virt_test(test.test): run_func = getattr(test_module, "run_%s" % t_type) try: run_func(self, params, env) + self.verify_background_errors() finally: env.save() test_passed = True -- 1.7.7 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html