Skip to contentSkip to conversation

KVM test: kvm_vm.py: add status and output to VMDeadError

PATCH New Michael Goldish 1 participant 4 messages Jan 11, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 KVM test: kvm_vm.py: add status and output to VMDeadError

---
 client/tests/kvm/kvm_vm.py |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
client/tests/kvm/kvm_vm.py +10 -2
index 0403569..a69a191 100755
@@ -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
#1 lore raw

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.

---
 client/tests/kvm/kvm_utils.py |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)
client/tests/kvm/kvm_utils.py +9 -7
index 8e6cef1..d55594c 100644
@@ -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
#2 lore raw

PATCH 3/4 KVM test: don't re-raise a background exception if something went wrong in the main thread

In reply to Michael Goldish
---
 .../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
index 4064b4a..734fe35 100644
@@ -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
index 671f1ef..0688282 100644
@@ -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
index 4d47471..1dd6dcf 100644
@@ -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
#3 lore raw

PATCH 4/4 KVM test: VM.migrate(): make sure the VM is alive after migration

In reply to Michael Goldish

Also add a context() call to make the VMDeadError exception more descriptive.

---
 client/tests/kvm/kvm_vm.py |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
client/tests/kvm/kvm_vm.py +5 -0
index a69a191..18d10ef 100755
@@ -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