KVM test: boot test: add option to reboot using system_reset

The boot test now behaves as follows:
- Normally it just waits for the guest to go up and logs into it.
- If reboot_method is specified and equals "shell", the guest is sent a reboot
  shell command, and the test waits until the guest comes back up.
- If reboot method is specified and equals "system_reset", the VM is sent a
  system_reset monitor command, and the test waits until the guest comes back
  up.
  Before sending the system_reset command the test sleeps for a given duration.
  The duration is controlled by the parameter 'sleep_before_reset'.

Signed-off-by: Michael Goldish <mgoldish@redhat.com>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@3690 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/tests/kvm/kvm_tests.py b/client/tests/kvm/kvm_tests.py
index c2bfb8a..801b84e 100644
--- a/client/tests/kvm/kvm_tests.py
+++ b/client/tests/kvm/kvm_tests.py
@@ -13,9 +13,9 @@
     """
     KVM reboot test:
     1) Log into a guest
-    2) Send a reboot command to the guest
-    3) Wait until it's up.
-    4) Log into the guest to verify it's up again.
+    2) Send a reboot command or a system_reset monitor command (optional)
+    3) Wait until the guest is up again
+    4) Log into the guest to verify it's up again
 
     @param test: kvm test object
     @param params: Dictionary with the test parameters
@@ -33,13 +33,24 @@
     if not session:
         raise error.TestFail("Could not log into guest")
 
-    logging.info("Logged in")
+    try:
+        logging.info("Logged in")
 
-    if params.get("reboot") == "yes":
-        # Send the VM's reboot command
-        session.sendline(vm.get_params().get("reboot_command"))
-        logging.info("Reboot command sent; waiting for guest to go down...")
+        if params.get("reboot_method") == "shell":
+            # Send a reboot command to the guest's shell
+            session.sendline(vm.get_params().get("reboot_command"))
+            logging.info("Reboot command sent; waiting for guest to go "
+                         "down...")
+        elif params.get("reboot_method") == "system_reset":
+            # Sleep for a while -- give the guest a chance to finish booting
+            time.sleep(float(params.get("sleep_before_reset", 10)))
+            # Send a system_reset monitor command
+            vm.send_monitor_cmd("system_reset")
+            logging.info("system_reset monitor command sent; waiting for "
+                         "guest to go down...")
+        else: return
 
+        # Wait for the session to become unresponsive
         if not kvm_utils.wait_for(lambda: not session.is_responsive(),
                                   120, 0, 1):
             raise error.TestFail("Guest refuses to go down")
@@ -54,7 +65,8 @@
 
         logging.info("Guest is up again")
 
-    session.close()
+    finally:
+        session.close()
 
 
 def run_shutdown(test, params, env):