Skip to contentSkip to conversation

KVM test: Create a verify_kernel_crash() VM method v3

PATCH New Lucas Meneghel Rodrigues 1 participant 2 messages Mar 18, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 KVM test: Create a verify_kernel_crash() VM method v3

A method to verify guest kernel panics can be very useful for a number of tests. Adapted from a function present on virtio_console test, create VM.verify_kernel_crash() and use it on unattended_install.

Changes from v1:
* According to mgoldish's comments, instead of using
read_nonblocking() and read_until_last_line_matches(), use simply get_output(), and only throw an exception at the time we have a full trace.

Changes from v3:
* Reimplementing the method on a less moronic fashion.

---
 client/tests/kvm/kvm_vm.py |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
client/tests/kvm/kvm_vm.py +23 -0
index 43ae79c..8114670 100755
@@ -105,6 +105,15 @@ class VMDeadError(VMError):
                 (self.status, self.output))
 
 
+class VMDeadKernelCrashError(VMError):
+    def __init__(self, kernel_crash):
+        VMError.__init__(self, kernel_crash)
+        self.kernel_crash = kernel_crash
+
+    def __str__(self):
+        return ("VM is dead due to a kernel crash:\n%s" % self.kernel_crash)
+
+
 class VMAddressError(VMError):
     pass
 
@@ -1158,6 +1167,20 @@ class VM:
         return not self.process or not self.process.is_alive()
 
 
+    def verify_kernel_crash(self):
+        """
+        Find kernel crash message on the VM serial console.
+
+        @raise: VMDeadKernelCrashError, in case a kernel crash message was
+                found.
+        """
+        data = self.serial_console.get_output()
+        match = re.search(r"BUG:.*---\[ end trace .* \]---", data,
+                          re.DOTALL|re.MULTILINE)
+        if match is not None:
+            raise VMDeadKernelCrashError(match.group(0))
+
+
     def get_params(self):
         """
         Return the VM's params dict. Most modified params take effect only
Signature · 1 line
1.7.4
#1 lore raw

PATCH 2/2 KVM test: Use verify_kernel_crash() on unattended install

With this we can fail the test much earlier if a guest kernel panic happens, instead of waiting for the full timeout to complete.

---
 client/tests/kvm/tests/unattended_install.py |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
client/tests/kvm/tests/unattended_install.py +1 -0
index 7c6d845..4868053 100644
@@ -16,6 +16,7 @@ def run_unattended_install(test, params, env):
     """
     vm = env.get_vm(params["main_vm"])
     vm.verify_alive()
+    vm.verify_kernel_crash()
 
     install_timeout = int(params.get("timeout", 3000))
     post_install_delay = int(params.get("post_install_delay", 0))
Signature · 1 line
1.7.4