OLD | NEW |
1 import sys, os, time, logging, imp | 1 import os, logging, imp |
2 from autotest_lib.client.bin import test | 2 from autotest_lib.client.bin import test |
3 from autotest_lib.client.common_lib import error | 3 from autotest_lib.client.common_lib import error |
4 import kvm_utils, kvm_preprocessing | 4 import kvm_utils, kvm_preprocessing |
5 | 5 |
6 | 6 |
7 class kvm(test.test): | 7 class kvm(test.test): |
8 """ | 8 """ |
9 Suite of KVM virtualization functional tests. | 9 Suite of KVM virtualization functional tests. |
10 Contains tests for testing both KVM kernel code and userspace code. | 10 Contains tests for testing both KVM kernel code and userspace code. |
11 | 11 |
12 @copyright: Red Hat 2008-2009 | 12 @copyright: Red Hat 2008-2009 |
13 @author: Uri Lublin (uril@redhat.com) | 13 @author: Uri Lublin (uril@redhat.com) |
14 @author: Dror Russo (drusso@redhat.com) | 14 @author: Dror Russo (drusso@redhat.com) |
15 @author: Michael Goldish (mgoldish@redhat.com) | 15 @author: Michael Goldish (mgoldish@redhat.com) |
16 @author: David Huff (dhuff@redhat.com) | 16 @author: David Huff (dhuff@redhat.com) |
17 @author: Alexey Eromenko (aeromenk@redhat.com) | 17 @author: Alexey Eromenko (aeromenk@redhat.com) |
18 @author: Mike Burns (mburns@redhat.com) | 18 @author: Mike Burns (mburns@redhat.com) |
19 | 19 |
20 @see: http://www.linux-kvm.org/page/KVM-Autotest/Client_Install | 20 @see: http://www.linux-kvm.org/page/KVM-Autotest/Client_Install |
21 (Online doc - Getting started with KVM testing) | 21 (Online doc - Getting started with KVM testing) |
22 """ | 22 """ |
23 version = 1 | 23 version = 1 |
24 env_version = 0 | 24 env_version = 1 |
25 | 25 |
26 def run_once(self, params): | 26 def run_once(self, params): |
| 27 # Convert params to a Params object |
| 28 params = kvm_utils.Params(params) |
| 29 |
27 # Report the parameters we've received and write them as keyvals | 30 # Report the parameters we've received and write them as keyvals |
28 logging.debug("Test parameters:") | 31 logging.debug("Test parameters:") |
29 keys = params.keys() | 32 keys = params.keys() |
30 keys.sort() | 33 keys.sort() |
31 for key in keys: | 34 for key in keys: |
32 logging.debug(" %s = %s", key, params[key]) | 35 logging.debug(" %s = %s", key, params[key]) |
33 self.write_test_keyval({key: params[key]}) | 36 self.write_test_keyval({key: params[key]}) |
34 | 37 |
35 # Set the log file dir for the logging mechanism used by kvm_subprocess | 38 # Set the log file dir for the logging mechanism used by kvm_subprocess |
36 # (this must be done before unpickling env) | 39 # (this must be done before unpickling env) |
37 kvm_utils.set_log_file_dir(self.debugdir) | 40 kvm_utils.set_log_file_dir(self.debugdir) |
38 | 41 |
39 # Open the environment file | 42 # Open the environment file |
40 logging.info("Unpickling env. You may see some harmless error " | 43 logging.info("Unpickling env. You may see some harmless error " |
41 "messages.") | 44 "messages.") |
42 env_filename = os.path.join(self.bindir, params.get("env", "env")) | 45 env_filename = os.path.join(self.bindir, params.get("env", "env")) |
43 env = kvm_utils.load_env(env_filename, self.env_version) | 46 env = kvm_utils.Env(env_filename, self.env_version) |
44 logging.debug("Contents of environment: %s", env) | |
45 | 47 |
46 test_passed = False | 48 test_passed = False |
47 | 49 |
48 try: | 50 try: |
49 try: | 51 try: |
50 try: | 52 try: |
51 # Get the test routine corresponding to the specified | 53 # Get the test routine corresponding to the specified |
52 # test type | 54 # test type |
53 t_type = params.get("type") | 55 t_type = params.get("type") |
54 # Verify if we have the correspondent source file for it | 56 # Verify if we have the correspondent source file for it |
55 subtest_dir = os.path.join(self.bindir, "tests") | 57 subtest_dir = os.path.join(self.bindir, "tests") |
56 module_path = os.path.join(subtest_dir, "%s.py" % t_type) | 58 module_path = os.path.join(subtest_dir, "%s.py" % t_type) |
57 if not os.path.isfile(module_path): | 59 if not os.path.isfile(module_path): |
58 raise error.TestError("No %s.py test file found" % | 60 raise error.TestError("No %s.py test file found" % |
59 t_type) | 61 t_type) |
60 # Load the test module | 62 # Load the test module |
61 f, p, d = imp.find_module(t_type, [subtest_dir]) | 63 f, p, d = imp.find_module(t_type, [subtest_dir]) |
62 test_module = imp.load_module(t_type, f, p, d) | 64 test_module = imp.load_module(t_type, f, p, d) |
63 f.close() | 65 f.close() |
64 | 66 |
65 # Preprocess | 67 # Preprocess |
66 try: | 68 try: |
67 kvm_preprocessing.preprocess(self, params, env) | 69 kvm_preprocessing.preprocess(self, params, env) |
68 finally: | 70 finally: |
69 kvm_utils.dump_env(env, env_filename) | 71 env.save() |
70 # Run the test function | 72 # Run the test function |
71 run_func = getattr(test_module, "run_%s" % t_type) | 73 run_func = getattr(test_module, "run_%s" % t_type) |
72 try: | 74 try: |
73 run_func(self, params, env) | 75 run_func(self, params, env) |
74 finally: | 76 finally: |
75 kvm_utils.dump_env(env, env_filename) | 77 env.save() |
76 test_passed = True | 78 test_passed = True |
77 | 79 |
78 except Exception, e: | 80 except Exception, e: |
79 logging.error("Test failed: %s: %s", | 81 logging.error("Test failed: %s: %s", |
80 e.__class__.__name__, e) | 82 e.__class__.__name__, e) |
81 try: | 83 try: |
82 kvm_preprocessing.postprocess_on_error( | 84 kvm_preprocessing.postprocess_on_error( |
83 self, params, env) | 85 self, params, env) |
84 finally: | 86 finally: |
85 kvm_utils.dump_env(env, env_filename) | 87 env.save() |
86 raise | 88 raise |
87 | 89 |
88 finally: | 90 finally: |
89 # Postprocess | 91 # Postprocess |
90 try: | 92 try: |
91 try: | 93 try: |
92 kvm_preprocessing.postprocess(self, params, env) | 94 kvm_preprocessing.postprocess(self, params, env) |
93 except Exception, e: | 95 except Exception, e: |
94 if test_passed: | 96 if test_passed: |
95 raise | 97 raise |
96 logging.error("Exception raised during " | 98 logging.error("Exception raised during " |
97 "postprocessing: %s", e) | 99 "postprocessing: %s", e) |
98 finally: | 100 finally: |
99 kvm_utils.dump_env(env, env_filename) | 101 env.save() |
100 logging.debug("Contents of environment: %s", env) | |
101 | 102 |
102 except Exception, e: | 103 except Exception, e: |
103 if params.get("abort_on_error") != "yes": | 104 if params.get("abort_on_error") != "yes": |
104 raise | 105 raise |
105 # Abort on error | 106 # Abort on error |
106 logging.info("Aborting job (%s)", e) | 107 logging.info("Aborting job (%s)", e) |
107 for vm in kvm_utils.env_get_all_vms(env): | 108 for vm in env.get_all_vms(): |
108 if vm.is_dead(): | 109 if vm.is_dead(): |
109 continue | 110 continue |
110 logging.info("VM '%s' is alive.", vm.name) | 111 logging.info("VM '%s' is alive.", vm.name) |
111 for m in vm.monitors: | 112 for m in vm.monitors: |
112 logging.info("'%s' has a %s monitor unix socket at: %s", | 113 logging.info("'%s' has a %s monitor unix socket at: %s", |
113 vm.name, m.protocol, m.filename) | 114 vm.name, m.protocol, m.filename) |
114 logging.info("The command line used to start '%s' was:\n%s", | 115 logging.info("The command line used to start '%s' was:\n%s", |
115 vm.name, vm.make_qemu_command()) | 116 vm.name, vm.make_qemu_command()) |
116 raise error.JobError("Abort requested (%s)" % e) | 117 raise error.JobError("Abort requested (%s)" % e) |
OLD | NEW |