Skip to contentSkip to conversation

kvm_autotest: dynamically load tests

PATCH In review David Huff 3 participants 8 messages Apr 28, 2009 – May 27, 2009 KVM

lore
Share & tools
lore

David Huff

author
#0 lore raw

looking for comments/feedback....

These relatively simple changes to kvm_runtest_2 will allow for the addition of new tests without having modifying kvm_runtest "code."

One would just add a newtest.py file and update the config file. This will simplify test development and make it easier to deploying new tests in an existing environment.

The patch looks for tests that are not statically defined in kvm_runtest_2.py in ./kvm-autotest/client/tests/kvm_runtest_2/kvm_tests/'testname'.py and dynamically loads a module with a corresponding method run_'testname' where testname is defined by the "type" parameter in the config file.

author
#1 lore raw

PATCH 1/1 Modified kvm_runtest_2.py to look for tests in kvm_tests/

This will allow for adding of additional tests with out modifying the "code."

One would just add the testname.py file to the test_dir and edit the comfig file.

---
 client/tests/kvm_runtest_2/kvm_runtest_2.py |   32 +++++++++++++++++++-------
 1 files changed, 23 insertions(+), 9 deletions(-)
client/tests/kvm_runtest_2/kvm_runtest_2.py +23 -9
index fda7282..b6477f5 100644
@@ -2,6 +2,7 @@
 
 import sys
 import os
+import inspect
 import time
 import shelve
 import random
@@ -21,26 +22,26 @@ class test_routine:
 class kvm_runtest_2(test.test):
     version = 1
 
+
     def setup(self):
         pass
 
     def initialize(self):
-        # Define the test routines corresponding to different values of the 'type' field
+        # directory where to look for tests
+        self.test_dir = os.path.join(self.bindir, "kvm_tests")
+        
+        # pre-defined the test routines corresponding to different values of the 'type' field
         self.test_routines = {
-                # type                       module name            routine
+                # type                       module name            routine name
                 "steps":        test_routine("kvm_guest_wizard",    "run_steps"),
                 "stepmaker":    test_routine("stepmaker",           "run_stepmaker"),
-                "boot":         test_routine("kvm_tests",           "run_boot"),
-                "migration":    test_routine("kvm_tests",           "run_migration"),
-                "yum_update":   test_routine("kvm_tests",           "run_yum_update"),
-                "autotest":     test_routine("kvm_tests",           "run_autotest"),
                 "kvm_install":  test_routine("kvm_install",         "run_kvm_install"),
-                "linux_s3":     test_routine("kvm_tests",           "run_linux_s3"),
                 }
-
+        
         # Make it possible to import modules from the test's bindir
         sys.path.append(self.bindir)
-
+        sys.path.append(self.test_dir)
+        
     def run_once(self, params):
         import kvm_log
         import kvm_utils
@@ -74,6 +75,12 @@ class kvm_runtest_2(test.test):
                 type = params.get("type")
                 routine_obj = self.test_routines.get(type)
                 # If type could not be found in self.test_routines...
+                # look for test in kvm_tests directory, where type = 'testname' 
+                # defined in file 'testname'.py and test routine method run_'testname'
+                if os.path.isfile(os.path.join(self.test_dir,type+".py")):
+                    module_name = type
+                    routine_name = "run_"+module_name
+                    routine_obj =  test_routine(moudule_name,routine_name)
                 if not routine_obj:
                     message = "Unsupported test type: %s" % type
                     kvm_log.error(message)
@@ -83,6 +90,13 @@ class kvm_runtest_2(test.test):
                     # Dynamically import the module
                     module = __import__(routine_obj.module_name)
                     # Get the needed routine
+                    try:
+                        inspect.isfunction(eval("module."+routine_obj.routine_name))
+                    except Exception, e:
+                        kvm_log.error("Test failed: %s" % e)
+                        kvm_log.error("could not load:%s" % eval("module."+routine_obj.routine_name))
+                        raise
+                    
                     routine_obj.routine = eval("module." + routine_obj.routine_name)
 
                 # Preprocess
Signature · 1 line
1.6.0.6
#2 lore raw

Re: [PATCH] Modified kvm_runtest_2.py to look for tests in kvm_tests/

Quoted 56 lines · David Huff

This will allow for adding of additional tests with out modifying the "code."

One would just add the testname.py file to the test_dir and edit the comfig file.

---
 client/tests/kvm_runtest_2/kvm_runtest_2.py |   32 +++++++++++++++++++-------
 1 files changed, 23 insertions(+), 9 deletions(-)
client/tests/kvm_runtest_2/kvm_runtest_2.py +10 -9
index fda7282..b6477f5 100644
@@ -2,6 +2,7 @@
 
 import sys
 import os
+import inspect
 import time
 import shelve
 import random
@@ -21,26 +22,26 @@ class test_routine:
 class kvm_runtest_2(test.test):
     version = 1
 
+
     def setup(self):
         pass
 
     def initialize(self):
-        # Define the test routines corresponding to different values of the 'type' field
+        # directory where to look for tests
+        self.test_dir = os.path.join(self.bindir, "kvm_tests")
+        
+        # pre-defined the test routines corresponding to different values of the 'type' field
         self.test_routines = {
-                # type                       module name            routine
+                # type                       module name            routine name
                 "steps":        test_routine("kvm_guest_wizard",    "run_steps"),
                 "stepmaker":    test_routine("stepmaker",           "run_stepmaker"),
-                "boot":         test_routine("kvm_tests",           "run_boot"),
-                "migration":    test_routine("kvm_tests",           "run_migration"),
-                "yum_update":   test_routine("kvm_tests",           "run_yum_update"),
-                "autotest":     test_routine("kvm_tests",           "run_autotest"),
                 "kvm_install":  test_routine("kvm_install",         "run_kvm_install"),
-                "linux_s3":     test_routine("kvm_tests",           "run_linux_s3"),
                 }
-
+        
         # Make it possible to import modules from the test's bindir
         sys.path.append(self.bindir)
-
+        sys.path.append(self.test_dir)
+        
     def run_once(self, params):
         import kvm_log
         import kvm_utils

client/tests/kvm_runtest_2/kvm_runtest_2.py class kvm_runtest_2(test.test): · line 76

Quoted 2 lines
client/tests/kvm_runtest_2/kvm_runtest_2.py +0 -0
@@ -74,6 +75,12 @@ class kvm_runtest_2(test.test):
                 type = params.get("type")
                 routine_obj = self.test_routines.get(type)

If routine_obj exists, use it, instead of dynamically load according to type.

client/tests/kvm_runtest_2/kvm_runtest_2.py class kvm_runtest_2(test.test): · line 83

Quoted 7 lines
client/tests/kvm_runtest_2/kvm_runtest_2.py +6 -0
                 # If type could not be found in self.test_routines...
+                # look for test in kvm_tests directory, where type = 'testname' 
+                # defined in file 'testname'.py and test routine method run_'testname'
+                if os.path.isfile(os.path.join(self.test_dir,type+".py")):
+                    module_name = type
+                    routine_name = "run_"+module_name
+                    routine_obj =  test_routine(moudule_name,routine_name)

1. Nit: Please leave a space after comma.
2. Typo moudule_name.

client/tests/kvm_runtest_2/kvm_runtest_2.py class kvm_runtest_2(test.test): · line 94

Quoted 9 lines
client/tests/kvm_runtest_2/kvm_runtest_2.py +2 -0
                 if not routine_obj:
                     message = "Unsupported test type: %s" % type
                     kvm_log.error(message)
@@ -83,6 +90,13 @@ class kvm_runtest_2(test.test):
                     # Dynamically import the module
                     module = __import__(routine_obj.module_name)
                     # Get the needed routine
+                    try:
+                        inspect.isfunction(eval("module."+routine_obj.routine_name))

1. Nit: f = eval("module."+routine_obj.routine_name) inspect.isfunction(f)
...
routing_obj.routing = f

2. If you call inspect.isfunction(), check its return-value. It can return false. ( If you do not call inspect it would fail later when routine_obj.routine is called ).

Regards,
Uri.

author
#3 lore raw

PATCH 1/1 Added "stock" or existing test to ./kvm_tests/

In reply to David Huff

autotest.py, boot.py, linux_s3.py, migration.py, yum_update.py

---
 client/tests/kvm_runtest_2/kvm_tests/autotest.py   |  145 ++++++++++++++++++++
 client/tests/kvm_runtest_2/kvm_tests/boot.py       |   45 ++++++
 client/tests/kvm_runtest_2/kvm_tests/linux_s3.py   |   53 +++++++
 client/tests/kvm_runtest_2/kvm_tests/migration.py  |  132 ++++++++++++++++++
 client/tests/kvm_runtest_2/kvm_tests/yum_update.py |   53 +++++++
 5 files changed, 428 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm_runtest_2/kvm_tests/autotest.py
 create mode 100644 client/tests/kvm_runtest_2/kvm_tests/boot.py
 create mode 100644 client/tests/kvm_runtest_2/kvm_tests/linux_s3.py
 create mode 100644 client/tests/kvm_runtest_2/kvm_tests/migration.py
 create mode 100644 client/tests/kvm_runtest_2/kvm_tests/yum_update.py
client/tests/kvm_runtest_2/kvm_tests/autotest.py new file +145 -0
new file mode 100644
index 0000000..7497596
@@ -0,0 +1,145 @@
+import time
+import os
+
+#from autotest_lib.client.common_lib import utils, error
+
+#import kvm_log
+#import kvm_utils
+#import ppm_utils
+#import scan_results
+
+
+def run_autotest(test, params, env):
+    vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
+    if not vm:
+        raise error.TestError, "VM object not found in environment"
+    if not vm.is_alive():
+        raise error.TestError, "VM seems to be dead; Test requires a living VM"
+
+    kvm_log.info("Logging into guest...")
+
+    session = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
+    if not session:
+        raise error.TestFail, "Could not log into guest"
+
+    kvm_log.info("Logged in")
+
+    # Collect some info
+    test_name = params.get("test_name")
+    test_timeout = int(params.get("test_timeout", 300))
+    test_control_file = params.get("test_control_file", "control")
+    tarred_autotest_path = "/tmp/autotest.tar.bz2"
+    tarred_test_path = "/tmp/%s.tar.bz2" % test_name
+
+    # tar the contents of bindir/autotest
+    cmd = "cd %s; tar cvjf %s autotest/*"
+    cmd += " --exclude=autotest/tests"
+    cmd += " --exclude=autotest/results"
+    cmd += " --exclude=autotest/tmp"
+    cmd += " --exclude=autotest/control"
+    cmd += " --exclude=*.pyc"
+    cmd += " --exclude=*.svn"
+    cmd += " --exclude=*.git"
+    kvm_utils.run_bg(cmd % (test.bindir, tarred_autotest_path), timeout=30)
+
+    # tar the contents of bindir/autotest/tests/<test_name>
+    cmd = "cd %s; tar cvjf %s %s/*"
+    cmd += " --exclude=*.pyc"
+    cmd += " --exclude=*.svn"
+    cmd += " --exclude=*.git"
+    kvm_utils.run_bg(cmd % (os.path.join(test.bindir, "autotest", "tests"), tarred_test_path, test_name), timeout=30)
+
+    # Check if we need to copy autotest.tar.bz2
+    copy = False
+    output = session.get_command_output("ls -l autotest.tar.bz2")
+    if "such file" in output:
+        copy = True
+    else:
+        size = int(output.split()[4])
+        if size != os.path.getsize(tarred_autotest_path):
+            copy = True
+    # Perform the copy
+    if copy:
+        kvm_log.info("Copying autotest.tar.bz2 to guest (file is missing or has a different size)...")
+        if not vm.scp_to_remote(tarred_autotest_path, ""):
+            raise error.TestFail, "Could not copy autotest.tar.bz2 to guest"
+
+    # Check if we need to copy <test_name>.tar.bz2
+    copy = False
+    output = session.get_command_output("ls -l %s.tar.bz2" % test_name)
+    if "such file" in output:
+        copy = True
+    else:
+        size = int(output.split()[4])
+        if size != os.path.getsize(tarred_test_path):
+            copy = True
+    # Perform the copy
+    if copy:
+        kvm_log.info("Copying %s.tar.bz2 to guest (file is missing or has a different size)..." % test_name)
+        if not vm.scp_to_remote(tarred_test_path, ""):
+            raise error.TestFail, "Could not copy %s.tar.bz2 to guest" % test_name
+
+    # Extract autotest.tar.bz2
+    kvm_log.info("Extracting autotest.tar.bz2...")
+    status = session.get_command_status("tar xvfj autotest.tar.bz2")
+    if status != 0:
+        raise error.TestFail, "Could not extract autotest.tar.bz2"
+
+    # mkdir autotest/tests
+    session.sendline("mkdir autotest/tests")
+
+    # Extract <test_name>.tar.bz2 into autotest/tests
+    kvm_log.info("Extracting %s.tar.bz2..." % test_name)
+    status = session.get_command_status("tar xvfj %s.tar.bz2 -C autotest/tests" % test_name)
+    if status != 0:
+        raise error.TestFail, "Could not extract %s.tar.bz2" % test_name
+
+    # Run the test
+    kvm_log.info("Running test '%s'..." % test_name)
+    session.sendline("cd autotest/tests/%s" % test_name)
+    session.sendline("rm -f ./%s.state" % test_control_file)
+    session.read_up_to_prompt()
+    session.sendline("../../bin/autotest ./%s" % test_control_file)
+    kvm_log.info("---------------- Test output ----------------")
+    match, output = session.read_up_to_prompt(timeout=test_timeout, print_func=kvm_log.info)
+    kvm_log.info("---------------- End of test output ----------------")
+    if not match:
+        raise error.TestFail, "Timeout elapsed while waiting for test to complete"
+
+    session.close()
+
+    # Parse test results
+    result_list = scan_results.parse_results(output)
+
+    # Report test results and check for FAIL/ERROR status
+    kvm_log.info("Results (test, status, duration, info):")
+    status_error = False
+    status_fail = False
+    if result_list == []:
+        status_fail = True
+        message_fail = "Test '%s' did not produce any recognizable results" % test_name
+    for result in result_list:
+        kvm_log.info(str(result))
+        if result[1] == "FAIL":
+            status_fail = True
+            message_fail = "Test '%s' ended with FAIL (info: '%s')" % (result[0], result[3])
+        if result[1] == "ERROR":
+            status_error = True
+            message_error = "Test '%s' ended with ERROR (info: '%s')" % (result[0], result[3])
+        if result[1] == "ABORT":
+            status_error = True
+            message_error = "Test '%s' ended with ABORT (info: '%s')" % (result[0], result[3])
+
+    # Copy test results to the local bindir/guest_results
+    kvm_log.info("Copying results back from guest...")
+    guest_results_dir = os.path.join(test.outputdir, "guest_results")
+    if not os.path.exists(guest_results_dir):
+        os.mkdir(guest_results_dir)
+    if not vm.scp_from_remote("autotest/results/default/*", guest_results_dir):
+        kvm_log.error("Could not copy results back from guest")
+
+    # Fail the test if necessary
+    if status_fail:
+        raise error.TestFail, message_fail
+    elif status_error:
+        raise error.TestError, message_error
client/tests/kvm_runtest_2/kvm_tests/boot.py new file +45 -0

45 lines not on this page · raw message

client/tests/kvm_runtest_2/kvm_tests/linux_s3.py new file +53 -0

54 lines not on this page · raw message

client/tests/kvm_runtest_2/kvm_tests/migration.py new file +132 -0

132 lines not on this page · raw message

client/tests/kvm_runtest_2/kvm_tests/yum_update.py new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
1.6.0.6
author
#4 lore raw

PATCH 1/1 removed old kvm_test.py, tests now in seprate subdir

In reply to David Huff
---
 client/tests/kvm_runtest_2/kvm_tests.py |  396 -------------------------------
 1 files changed, 0 insertions(+), 396 deletions(-)
 delete mode 100644 client/tests/kvm_runtest_2/kvm_tests.py
client/tests/kvm_runtest_2/kvm_tests.py deleted +0 -396
deleted file mode 100644
index 950115d..0000000
@@ -1,396 +0,0 @@
-import time
-import os
-
-from autotest_lib.client.common_lib import utils, error
-
-import kvm_log
-import kvm_utils
-import ppm_utils
-import scan_results
-
-
-def run_boot(test, params, env):
-    vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
-    if not vm:
-        raise error.TestError, "VM object not found in environment"
-    if not vm.is_alive():
-        raise error.TestError, "VM seems to be dead; Test requires a living VM"
-
-    kvm_log.info("Waiting for guest to be up...")
-
-    session = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
-    if not session:
-        raise error.TestFail, "Could not log into guest"
-
-    kvm_log.info("Logged in")
-
-    if params.get("reboot") == "yes":
-        # Send the VM's reboot command
-        session.sendline(vm.get_params().get("cmd_reboot"))
-        kvm_log.info("Reboot command sent; waiting for guest to go down...")
-
-        if not kvm_utils.wait_for(lambda: not session.is_responsive(), 120, 0, 1):
-            raise error.TestFail, "Guest refuses to go down"
-
-        session.close()
-
-        kvm_log.info("Guest is down; waiting for it to go up again...")
-
-        session = kvm_utils.wait_for(vm.ssh_login, 120, 0, 2)
-        if not session:
-            raise error.TestFail, "Could not log into guest after reboot"
-
-        kvm_log.info("Guest is up again")
-
-    session.close()
-
-
-def run_migration(test, params, env):
-    src_vm_name = params.get("migration_src")
-    vm = kvm_utils.env_get_vm(env, src_vm_name)
-    if not vm:
-        raise error.TestError, "VM '%s' not found in environment" % src_vm_name
-    if not vm.is_alive():
-        raise error.TestError, "VM '%s' seems to be dead; Test requires a living VM" % src_vm_name
-
-    dest_vm_name = params.get("migration_dst")
-    dest_vm = kvm_utils.env_get_vm(env, dest_vm_name)
-    if not dest_vm:
-        raise error.TestError, "VM '%s' not found in environment" % dest_vm_name
-    if not dest_vm.is_alive():
-        raise error.TestError, "VM '%s' seems to be dead; Test requires a living VM" % dest_vm_name
-
-    pre_scrdump_filename = os.path.join(test.debugdir, "migration_pre.ppm")
-    post_scrdump_filename = os.path.join(test.debugdir, "migration_post.ppm")
-
-    # See if migration is supported
-    s, o = vm.send_monitor_cmd("help info")
-    if not "info migrate" in o:
-        raise error.TestError, "Migration is not supported"
-
-    # Log into guest and get the output of migration_test_command
-    kvm_log.info("Waiting for guest to be up...")
-
-    session = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
-    if not session:
-        raise error.TestFail, "Could not log into guest"
-
-    kvm_log.info("Logged in")
-
-    reference_output = session.get_command_output(params.get("migration_test_command"))
-    session.close()
-
-    # Define the migration command
-    cmd = "migrate -d tcp:localhost:%d" % dest_vm.migration_port
-    kvm_log.debug("Migration command: %s" % cmd)
-
-    # Migrate
-    s, o = vm.send_monitor_cmd(cmd)
-    if s:
-        kvm_log.error("Migration command failed (command: %r, output: %r)" % (cmd, o))
-        raise error.TestFail, "Migration command failed"
-
-    # Define some helper functions
-    def mig_finished():
-        s, o = vm.send_monitor_cmd("info migrate")
-        if s:
-            return False
-        if "Migration status: active" in o:
-            return False
-        return True
-
-    def mig_succeeded():
-        s, o = vm.send_monitor_cmd("info migrate")
-        if s == 0 and "Migration status: completed" in o:
-            return True
-        return False
-
-    def mig_failed():
-        s, o = vm.send_monitor_cmd("info migrate")
-        if s == 0 and "Migration status: failed" in o:
-            return True
-        return False
-
-    # Wait for migration to finish
-    if not kvm_utils.wait_for(mig_finished, 90, 2, 2, "Waiting for migration to finish..."):
-        raise error.TestFail, "Timeout elapsed while waiting for migration to finish"
-
-    # Report migration status
-    if mig_succeeded():
-        kvm_log.info("Migration finished successfully")
-    else:
-        if mig_failed():
-            message = "Migration failed"
-        else:
-            message = "Migration ended with unknown status"
-        raise error.TestFail, message
-
-    # Get 'post' screendump
-    dest_vm.send_monitor_cmd("screendump %s" % post_scrdump_filename)
-
-    # Get 'pre' screendump
-    vm.send_monitor_cmd("screendump %s" % pre_scrdump_filename)
-
-    # Kill the source VM
-    vm.send_monitor_cmd("quit", block=False)
-
-    # Compare 'pre' and 'post' screendumps
-    # Should work, but disabled for now
-    #(pre_w, pre_h, pre_data) = ppm_utils.image_read_from_ppm_file(pre_scrdump_filename)
-    #(post_w, post_h, post_data) = ppm_utils.image_read_from_ppm_file(post_scrdump_filename)
-    #if pre_w != post_w or pre_h != post_h or ppm_utils.image_fuzzy_compare(pre_w, pre_h, pre_data, post_data) < 0.99:
-    #    message = "Pre- and post-migration screendumps are too different"
-    #    kvm_log.error(message + "\n(see info at %s)" % test.debugdir)
-    #    raise error.TestFail, message
-
-    # Hack: it seems that the first attempt to communicate with the SSH port following migration
-    # always fails (or succeeds after a very long time). So just connect to the port once so the
-    # following call to ssh_login succeeds.
-    dest_vm.is_sshd_running(timeout=0.0)
-
-    # Log into guest and get the output of migration_test_command
-    kvm_log.info("Logging into guest after migration...")
-
-    session = dest_vm.ssh_login()
-    if not session:
-        raise error.TestFail, "Could not log into guest after migration"
-
-    kvm_log.info("Logged in after migration")
-
-    output = session.get_command_output(params.get("migration_test_command"))
-    session.close()
-
-    # Compare output to reference output
-    if output != reference_output:
-        kvm_log.info("Command output before migration differs from command output after migration")
-        kvm_log.info("Command: %s" % params.get("migration_test_command"))
-        kvm_log.info("Output before:" + kvm_utils.format_str_for_message(reference_output))
-        kvm_log.info("Output after:" + kvm_utils.format_str_for_message(output))
-        raise error.TestFail, "Command produced different output before and after migration"
-
-
-def run_autotest(test, params, env):
-    vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
-    if not vm:
-        raise error.TestError, "VM object not found in environment"
-    if not vm.is_alive():
-        raise error.TestError, "VM seems to be dead; Test requires a living VM"
-
-    kvm_log.info("Logging into guest...")
-
-    session = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
-    if not session:
-        raise error.TestFail, "Could not log into guest"
-
-    kvm_log.info("Logged in")
-
-    # Collect some info
-    test_name = params.get("test_name")
-    test_timeout = int(params.get("test_timeout", 300))
-    test_control_file = params.get("test_control_file", "control")
-    tarred_autotest_path = "/tmp/autotest.tar.bz2"
-    tarred_test_path = "/tmp/%s.tar.bz2" % test_name
-
-    # tar the contents of bindir/autotest
-    cmd = "cd %s; tar cvjf %s autotest/*"
-    cmd += " --exclude=autotest/tests"
-    cmd += " --exclude=autotest/results"
-    cmd += " --exclude=autotest/tmp"
-    cmd += " --exclude=autotest/control"
-    cmd += " --exclude=*.pyc"
-    cmd += " --exclude=*.svn"
-    cmd += " --exclude=*.git"
-    kvm_utils.run_bg(cmd % (test.bindir, tarred_autotest_path), timeout=30)
-
-    # tar the contents of bindir/autotest/tests/<test_name>
-    cmd = "cd %s; tar cvjf %s %s/*"
-    cmd += " --exclude=*.pyc"
-    cmd += " --exclude=*.svn"
-    cmd += " --exclude=*.git"
-    kvm_utils.run_bg(cmd % (os.path.join(test.bindir, "autotest", "tests"), tarred_test_path, test_name), timeout=30)
-
-    # Check if we need to copy autotest.tar.bz2
-    copy = False
-    output = session.get_command_output("ls -l autotest.tar.bz2")
-    if "such file" in output:
-        copy = True
-    else:
-        size = int(output.split()[4])
-        if size != os.path.getsize(tarred_autotest_path):
-            copy = True
-    # Perform the copy
-    if copy:
-        kvm_log.info("Copying autotest.tar.bz2 to guest (file is missing or has a different size)...")
-        if not vm.scp_to_remote(tarred_autotest_path, ""):
-            raise error.TestFail, "Could not copy autotest.tar.bz2 to guest"
-
-    # Check if we need to copy <test_name>.tar.bz2
-    copy = False
-    output = session.get_command_output("ls -l %s.tar.bz2" % test_name)
-    if "such file" in output:
-        copy = True
-    else:
-        size = int(output.split()[4])
-        if size != os.path.getsize(tarred_test_path):
-            copy = True
-    # Perform the copy
-    if copy:
-        kvm_log.info("Copying %s.tar.bz2 to guest (file is missing or has a different size)..." % test_name)
-        if not vm.scp_to_remote(tarred_test_path, ""):
-            raise error.TestFail, "Could not copy %s.tar.bz2 to guest" % test_name
-
-    # Extract autotest.tar.bz2
-    kvm_log.info("Extracting autotest.tar.bz2...")
-    status = session.get_command_status("tar xvfj autotest.tar.bz2")
-    if status != 0:
-        raise error.TestFail, "Could not extract autotest.tar.bz2"
-
-    # mkdir autotest/tests
-    session.sendline("mkdir autotest/tests")
-
-    # Extract <test_name>.tar.bz2 into autotest/tests
-    kvm_log.info("Extracting %s.tar.bz2..." % test_name)
-    status = session.get_command_status("tar xvfj %s.tar.bz2 -C autotest/tests" % test_name)
-    if status != 0:
-        raise error.TestFail, "Could not extract %s.tar.bz2" % test_name
-
-    # Run the test
-    kvm_log.info("Running test '%s'..." % test_name)
-    session.sendline("cd autotest/tests/%s" % test_name)
-    session.sendline("rm -f ./%s.state" % test_control_file)
-    session.read_up_to_prompt()
-    session.sendline("../../bin/autotest ./%s" % test_control_file)
-    kvm_log.info("---------------- Test output ----------------")
-    match, output = session.read_up_to_prompt(timeout=test_timeout, print_func=kvm_log.info)
-    kvm_log.info("---------------- End of test output ----------------")
-    if not match:
-        raise error.TestFail, "Timeout elapsed while waiting for test to complete"
-
-    session.close()
-
-    # Parse test results
-    result_list = scan_results.parse_results(output)
-
-    # Report test results and check for FAIL/ERROR status
-    kvm_log.info("Results (test, status, duration, info):")
-    status_error = False
-    status_fail = False
-    if result_list == []:
-        status_fail = True
-        message_fail = "Test '%s' did not produce any recognizable results" % test_name
-    for result in result_list:
-        kvm_log.info(str(result))
-        if result[1] == "FAIL":
-            status_fail = True
-            message_fail = "Test '%s' ended with FAIL (info: '%s')" % (result[0], result[3])
-        if result[1] == "ERROR":
-            status_error = True
-            message_error = "Test '%s' ended with ERROR (info: '%s')" % (result[0], result[3])
-        if result[1] == "ABORT":
-            status_error = True
-            message_error = "Test '%s' ended with ABORT (info: '%s')" % (result[0], result[3])
-
-    # Copy test results to the local bindir/guest_results
-    kvm_log.info("Copying results back from guest...")
-    guest_results_dir = os.path.join(test.outputdir, "guest_results")
-    if not os.path.exists(guest_results_dir):
-        os.mkdir(guest_results_dir)
-    if not vm.scp_from_remote("autotest/results/default/*", guest_results_dir):
-        kvm_log.error("Could not copy results back from guest")
-
-    # Fail the test if necessary
-    if status_fail:
-        raise error.TestFail, message_fail
-    elif status_error:
-        raise error.TestError, message_error
-
-
-
-# I'm not sure if we need these...
-
-def internal_yum_update(session, command, prompt, timeout):
-    session.sendline(command)
-    end_time = time.time() + timeout
-    while time.time() < end_time:
-        (match, text) = session.read_until_last_line_matches(["[Ii]s this [Oo][Kk]", prompt], timeout=timeout)
-        if match == 0:
-            kvm_log.info("Got 'Is this ok'; sending 'y'")
-            session.sendline("y")
-        elif match == 1:
-            kvm_log.info("Got shell prompt")
-            return True
-        else:
-            kvm_log.info("Timeout or process exited")
-            return False
-
-
-def run_yum_update(test, params, env):
-    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("Logging into guest...")
-
-    session = kvm_utils.wait_for(vm.ssh_login, 120, 0, 2)
-    if not session:
-        message = "Could not log into guest"
-        kvm_log.error(message)
-        raise error.TestFail, message
-
-    kvm_log.info("Logged in")
-
-    internal_yum_update(session, "yum update", params.get("ssh_prompt"), 600)
-    internal_yum_update(session, "yum update kernel", params.get("ssh_prompt"), 600)
-
-    session.close()
-
-
-def run_linux_s3(test, params, env):
-    vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
-    if not vm:
-        raise error.TestError, "VM object not found in environment"
-    if not vm.is_alive():
-        raise error.TestError, "VM seems to be dead; Test requires a living VM"
-
-    kvm_log.info("Waiting for guest to be up...")
-
-    session = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
-    if not session:
-        raise error.TestFail, "Could not log into guest"
-
-    kvm_log.info("Logged in")
-    kvm_log.info("Checking that VM supports S3")
-
-    status = session.get_command_status("grep -q mem /sys/power/state")
-    if status == None:
-        kvm_log.error("Failed to check if S3 exists")
-    elif status != 0:
-        raise error.TestFail, "Guest does not support S3"
-
-    kvm_log.info("Waiting for a while for X to start")
-    time.sleep(10)
-
-    src_tty = session.get_command_output("fgconsole").strip()
-    kvm_log.info("Current virtual terminal is %s" % src_tty)
-    if src_tty not in map(str, range(1,10)):
-	raise error.TestFail, "Got a strange current vt (%s)" % src_tty
-
-    dst_tty = "1"
-    if src_tty == "1":
-        dst_tty = "2"
-
-    kvm_log.info("Putting VM into S3")
-    command = "chvt %s && echo mem > /sys/power/state && chvt %s" % (dst_tty, src_tty)
-    status = session.get_command_status(command, timeout=120)
-    if status != 0:
-        raise error.TestFail, "Suspend to mem failed"
-
-    kvm_log.info("VM resumed after S3")
-
-    session.close()
Signature · 1 line
1.6.0.6
#5 lore raw
In reply to David Huff
Quoted 7 lines · David Huff

looking for comments/feedback....

These relatively simple changes to kvm_runtest_2 will allow for the addition of new tests without having modifying kvm_runtest "code."

One would just add a newtest.py file and update the config file. This will simplify test development and make it easier to deploying new tests in an existing environment.

The patch looks for tests that are not statically defined in kvm_runtest_2.py in ./kvm-autotest/client/tests/kvm_runtest_2/kvm_tests/'testname'.py and dynamically loads a module with a corresponding method run_'testname' where testname is defined by the "type" parameter in the config file.

Hi David,

I'm not sure this patch-set makes development much easier, as it only saves adding one line (entry) in test_routines table, but is less flexible (e.g. force file-name and function-name of test routines).

Moving the test to a separate kvm_tests directory can be done without dynamic load of the tests.

I don't have strong feelings about it though.

What others think ?

Thanks,
Uri.

author
#6 lore raw
Quoted 9 lines · Uri Lublin

Hi David,

I'm not sure this patch-set makes development much easier, as it only saves adding one line (entry) in test_routines table, but is less flexible (e.g. force file-name and function-name of test routines).

Moving the test to a separate kvm_tests directory can be done without dynamic load of the tests.

Quoted 6 lines

I don't have strong feelings about it though.

What others think ?

Thanks,
Uri.

Uri,

Thanks for the feedback, Lucas and I had a brief discussion about this last week so I just wanted to repost what I already had just as a starting point for a discussion on this topic, I know my patches are rough.

Our thinking is that it would be nice to be able to drop new tests in to a kvm_test dir, modify the config file, and not have to "update" the kvm_auottest or autotest binarys.

However I would also like to hear others opinions on this...

-D

#7 lore raw
Quoted 24 lines · David Huff
Quoted 9 lines · Uri Lublin

Hi David,

I'm not sure this patch-set makes development much easier, as it only saves adding one line (entry) in test_routines table, but is less flexible (e.g. force file-name and function-name of test routines).

Moving the test to a separate kvm_tests directory can be done without dynamic load of the tests.

Quoted 6 lines

I don't have strong feelings about it though.

What others think ?

Thanks,
    Uri.

Uri,

Thanks for the feedback, Lucas and I had a brief discussion about this last week so I just wanted to repost what I already had just as a starting point for a discussion on this topic, I know my patches are rough.

Quoted 5 lines

Our thinking is that it would be nice to be able to drop new tests in to a kvm_test dir, modify the config file, and not have to "update" the kvm_auottest or autotest binarys.

However I would also like to hear others opinions on this...

This looks nice to me. As the number of tests increase with time the code will still be modular and independent of testcases. Also one can very quickly add a set of new testcases to execute locally. This will keep the kvm_tests.py short.
We can think the other way too. What are the issues with the new approach other than what Uri pointed out?

Quoted 7 lines

-D
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Sudhir Kumar