diff mbox

[kvm-autotest] new test, saves and reloads a guest, from Red Hat QE

Message ID 1239046863-11939-2-git-send-email-dhuff@redhat.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

David Huff April 6, 2009, 7:41 p.m. UTC
---
 client/tests/kvm_runtest_2/kvm_runtest_2.py     |    1 +
 client/tests/kvm_runtest_2/kvm_tests.cfg.sample |    6 ++
 client/tests/kvm_runtest_2/kvm_tests.py         |   97 +++++++++++++++++++++++
 3 files changed, 104 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/client/tests/kvm_runtest_2/kvm_runtest_2.py b/client/tests/kvm_runtest_2/kvm_runtest_2.py
index c53877f..c83dce9 100644
--- a/client/tests/kvm_runtest_2/kvm_runtest_2.py
+++ b/client/tests/kvm_runtest_2/kvm_runtest_2.py
@@ -34,6 +34,7 @@  class kvm_runtest_2(test.test):
                 "migration":    test_routine("kvm_tests",           "run_migration"),
                 "yum_update":   test_routine("kvm_tests",           "run_yum_update"),
                 "autotest":     test_routine("kvm_tests",           "run_autotest"),
+                "saveload":     test_routine("kvm_tests",           "run_save_load"),
                 "kvm_install":  test_routine("kvm_install",         "run_kvm_install"),
                 "linux_s3":     test_routine("kvm_tests",           "run_linux_s3"),
                 }
diff --git a/client/tests/kvm_runtest_2/kvm_tests.cfg.sample b/client/tests/kvm_runtest_2/kvm_tests.cfg.sample
index 5619fa8..869398a 100644
--- a/client/tests/kvm_runtest_2/kvm_tests.cfg.sample
+++ b/client/tests/kvm_runtest_2/kvm_tests.cfg.sample
@@ -48,6 +48,12 @@  variants:
         reboot = yes
         extra_params += " -snapshot"
         kill_vm_on_error = yes
+        
+    - saveload:	install
+    	type = saveload
+		pre_command = "if [ -f kvm_save_test_file ] ; then rm -rf kvm_save_test_file; fi"
+		do_command  = "touch kvm_save_test_file
+		verify_command = "[ -f kvm_save_test_file ]"
 
     - migrate:      install setup
         type = migration
diff --git a/client/tests/kvm_runtest_2/kvm_tests.py b/client/tests/kvm_runtest_2/kvm_tests.py
index 0d19af6..463cc84 100644
--- a/client/tests/kvm_runtest_2/kvm_tests.py
+++ b/client/tests/kvm_runtest_2/kvm_tests.py
@@ -449,3 +449,100 @@  def run_linux_s3(test, params, env):
     kvm_log.info("VM resumed after S3")
 
     session.close()
+    
+def run_save_load(test, params, env):
+    # state testing, save and load vm state
+    vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
+    if not vm:
+        message = "VM object not found in environment"
+        kvm_log.error(message)
+        raise error.TestError, message
+    if not vm.is_alive():
+        message = "VM seems to be dead; Test requires a living VM"
+        kvm_log.error(message)
+        raise error.TestError, message
+
+    kvm_log.info("Waiting for guest to be up...")
+
+    pxssh = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
+    if not pxssh:
+        message = "Could not log into guest"
+        kvm_log.error(message)
+        raise error.TestFail, message
+
+    pre_command=params.get("pre_command")
+    do_command=params.get("do_command")
+    verify_command=params.get("verify_command")
+
+    # do preparation
+    kvm_log.info("Logged in")
+    kvm_log.info("Doing preparation ... %s" % pre_command)
+    if not pxssh.send_command(pre_command):
+        message = "%s failed" % pre_command
+        kvm_log.error(message)
+        raise error.TestFail, message
+    pxssh.close()
+    kvm_log.info("Logged out")
+
+    # save state
+    kvm_log.info("Saving VM state ...")
+    vm.send_monitor_cmd('savevm test1')
+    s, o = vm.send_monitor_cmd('info snapshots')
+    if not 'test1' in o:
+        message = "Saveing VM state error %s" % o
+        kvm_log.error(message)
+        raise error.TestFail, message
+    kvm_log.info(o)
+    kvm_log.info("VM state saved")
+
+    kvm_log.info("Destroying VM ...")
+    vm.destroy();
+    kvm_log.info("VM Destroyed")
+    
+    kvm_log.info("Booting VM...")
+    if not vm.create():
+        message = "Could no recreate VM instance"
+        kvm_log.error(message)
+        raise error.TestError, message
+    kvm_log.info("VM recreated")    
+
+    # do modification
+    pxssh = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
+    if not pxssh:
+        message = "Could not log into guest"
+        kvm_log.error(message)
+        raise error.TestFail, message
+    kvm_log.info("Logged in")
+    kvm_log.info("Doing modification %s" % do_command)
+    if not pxssh.send_command(do_command):
+        message = "%s failed" % do_command
+        kvm_log.error(message)
+        raise error.TestFail, message
+    pxssh.close()
+    kvm_log.info("Logged out")
+    
+    # load state
+    kvm_log.info("Loading VM state ...")
+    s, o = vm.send_monitor_cmd('loadvm test1')
+    kvm_log.info(o)
+    if "Error" in o:
+        message = "VM state load failed: %s" % o
+        kvm_log.error(message)
+        raise error.TestFail, message
+    kvm_log.info("VM state loaded")
+
+    # verify the status
+    pxssh = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
+    if not pxssh:
+        message = "Could not log into guest"
+        kvm_log.error(message)
+        raise error.TestFail, message
+    kvm_log.info("Verifying ... %s" % verify_command)
+    if pxssh.send_command(verify_command):
+        message = "Loaded state does not match previous saved one"
+        kvm_log.error(message)
+        raise error.TestFail, message
+
+    vm.send_command("delvm test1")
+    
+    pxssh.close()