KVM test: shutdown test: allow shutting down using system_powerdown

In addition to using the shutdown command/program, allow using the
system_powerdown monitor command.  The behavior is controlled using the
shutdown_method parameter, which may equal either "shell" or "system_powerdown".

If shutdown_method equals "system_powerdown", the test sleeps a given amount of
time (controlled by the parameter sleep_before_powerdown) and then sends the
system_powerdown monitor command.

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



git-svn-id: http://test.kernel.org/svn/autotest/trunk@3691 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/tests/kvm/kvm_tests.py b/client/tests/kvm/kvm_tests.py
index 801b84e..863b863 100644
--- a/client/tests/kvm/kvm_tests.py
+++ b/client/tests/kvm/kvm_tests.py
@@ -73,8 +73,9 @@
     """
     KVM shutdown test:
     1) Log into a guest
-    2) Send a shutdown command to the guest
-    3) Wait until it's down
+    2) Send a shutdown command to the guest, or issue a system_powerdown
+       monitor command (depending on the value of shutdown_method)
+    3) Wait until the guest is down
 
     @param test: kvm test object
     @param params: Dictionary with the test parameters
@@ -95,15 +96,24 @@
     try:
         logging.info("Logged in")
 
-        # Send the VM's shutdown command
-        session.sendline(vm.get_params().get("shutdown_command"))
-
-        logging.info("Shutdown command sent; waiting for guest to go down...")
+        if params.get("shutdown_method") == "shell":
+            # Send a shutdown command to the guest's shell
+            session.sendline(vm.get_params().get("shutdown_command"))
+            logging.info("Shutdown command sent; waiting for guest to go "
+                         "down...")
+        elif params.get("shutdown_method") == "system_powerdown":
+            # Sleep for a while -- give the guest a chance to finish booting
+            time.sleep(float(params.get("sleep_before_powerdown", 10)))
+            # Send a system_powerdown monitor command
+            vm.send_monitor_cmd("system_powerdown")
+            logging.info("system_powerdown monitor command sent; waiting for "
+                         "guest to go down...")
 
         if not kvm_utils.wait_for(vm.is_dead, 240, 0, 1):
             raise error.TestFail("Guest refuses to go down")
 
         logging.info("Guest is down")
+
     finally:
         session.close()