KVM test: kvm_vm.py: add status and output to VMDeadError
PATCH 1/4 KVM test: kvm_vm.py: add status and output to VMDeadError
Signed-off-by Michael Goldish <[email protected]>
--- client/tests/kvm/kvm_vm.py | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
client/tests/kvm/kvm_vm.py +10 -2
@@ -86,7 +86,14 @@ class VMKVMInitError(VMPostCreateError): class VMDeadError(VMError): - pass + def __init__(self, status, output): + VMError.__init__(self, status, output) + self.status = status + self.output = output + + def __str__(self): + return ("VM process is dead (status: %s, output: %r)" % + (self.status, self.output)) class VMAddressError(VMError):
@@ -1016,7 +1023,8 @@ class VM: @raise: Various monitor exceptions if the monitor is unresponsive """ if self.is_dead(): - raise VMDeadError("VM is dead") + raise VMDeadError(self.process.get_status(), + self.process.get_output()) if self.monitors: self.monitor.verify_responsive()
Signature · 1 line
1.7.3.4
PATCH 2/4 KVM test: kvm_utils.Thread.join(): allow suppressing the exception
If suppress_exception is True, the exception raised in the thread will not be re-raised.
Signed-off-by Michael Goldish <[email protected]>
--- client/tests/kvm/kvm_utils.py | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-)
client/tests/kvm/kvm_utils.py +9 -7
@@ -1188,22 +1188,24 @@ class Thread(threading.Thread): del self._target, self._args, self._kwargs - def join(self, timeout=None): + def join(self, timeout=None, suppress_exception=False): """ Join the thread. If target raised an exception, re-raise it. Otherwise, return the value returned by target. @param timeout: Timeout value to pass to threading.Thread.join(). + @param suppress_exception: If True, don't re-raise the exception. """ threading.Thread.join(self, timeout) try: if self._e: - # Because the exception was raised in another thread, we need - # to explicitly insert the current context into it - s = error.exception_context(self._e[1]) - s = error.join_contexts(error.get_context(), s) - error.set_exception_context(self._e[1], s) - raise self._e[0], self._e[1], self._e[2] + if not suppress_exception: + # Because the exception was raised in another thread, we + # need to explicitly insert the current context into it + s = error.exception_context(self._e[1]) + s = error.join_contexts(error.get_context(), s) + error.set_exception_context(self._e[1], s) + raise self._e[0], self._e[1], self._e[2] else: return self._retval finally:
Signature · 1 line
1.7.3.4
PATCH 3/4 KVM test: don't re-raise a background exception if something went wrong in the main thread
In reply to Michael GoldishSigned-off-by Michael Goldish <[email protected]>
--- .../kvm/tests/migration_with_file_transfer.py | 7 ++++++- client/tests/kvm/tests/migration_with_reboot.py | 7 ++++++- client/tests/kvm/tests/vmstop.py | 5 +---- 3 files changed, 13 insertions(+), 6 deletions(-)
client/tests/kvm/tests/migration_with_file_transfer.py +6 -1
@@ -46,7 +46,12 @@ def run_migration_with_file_transfer(test, params, env): logging.info("File transfer not ended, starting a round of " "migration...") vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay) - finally: + except: + # If something bad happened in the main thread, ignore + # exceptions raised in the background thread + bg.join(suppress_exception=True) + raise + else: bg.join() error.context("transferring file to guest while migrating",
client/tests/kvm/tests/migration_with_reboot.py +6 -1
@@ -35,7 +35,12 @@ def run_migration_with_reboot(test, params, env): try: while bg.is_alive(): vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay) - finally: + except: + # If something bad happened in the main thread, ignore exceptions + # raised in the background thread + bg.join(suppress_exception=True) + raise + else: session = bg.join() finally: session.close()
client/tests/kvm/tests/vmstop.py +1 -4
@@ -70,10 +70,7 @@ def run_vmstop(test, params, env): if md5_save1 != md5_save2: raise error.TestFail("The produced state files differ") finally: - try: - bg.join() - except: - pass + bg.join(suppress_exception=True) finally: session.close()
Signature · 1 line
1.7.3.4
PATCH 4/4 KVM test: VM.migrate(): make sure the VM is alive after migration
In reply to Michael GoldishAlso add a context() call to make the VMDeadError exception more descriptive.
Signed-off-by Michael Goldish <[email protected]>
--- client/tests/kvm/kvm_vm.py | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
client/tests/kvm/kvm_vm.py +5 -0
@@ -1499,6 +1499,11 @@ class VM: # and self is the destination VM that will remain alive. If this # is remote migration, self is a dead VM object. + error.context("after migration") + if local: + time.sleep(1) + self.verify_alive() + if local and stable_check: try: save1 = os.path.join(save_path, "src-" + clone.instance)
Signature · 1 line
1.7.3.4