Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: client/tests/kvm/kvm.py

Issue 6883246: Merge autotest upstream from @5318 ~ @5336 (Closed) Base URL: ssh://gitrw.chromium.org:9222/autotest.git@master
Patch Set: patch Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « client/tests/kvm/get_started.py ('k') | client/tests/kvm/migration_control.srv » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import os, 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 from autotest_lib.client.virt import virt_utils, virt_env_process
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 = 1 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 27 # Convert params to a Params object
28 params = kvm_utils.Params(params) 28 params = virt_utils.Params(params)
29 29
30 # If a dependency test prior to this test has failed, let's fail 30 # If a dependency test prior to this test has failed, let's fail
31 # it right away as TestNA. 31 # it right away as TestNA.
32 if params.get("dependency_failed") == 'yes': 32 if params.get("dependency_failed") == 'yes':
33 raise error.TestNAError("Test dependency failed") 33 raise error.TestNAError("Test dependency failed")
34 34
35 # Report the parameters we've received and write them as keyvals 35 # Report the parameters we've received and write them as keyvals
36 logging.debug("Test parameters:") 36 logging.debug("Test parameters:")
37 keys = params.keys() 37 keys = params.keys()
38 keys.sort() 38 keys.sort()
39 for key in keys: 39 for key in keys:
40 logging.debug(" %s = %s", key, params[key]) 40 logging.debug(" %s = %s", key, params[key])
41 self.write_test_keyval({key: params[key]}) 41 self.write_test_keyval({key: params[key]})
42 42
43 # Set the log file dir for the logging mechanism used by kvm_subprocess 43 # Set the log file dir for the logging mechanism used by kvm_subprocess
44 # (this must be done before unpickling env) 44 # (this must be done before unpickling env)
45 kvm_utils.set_log_file_dir(self.debugdir) 45 virt_utils.set_log_file_dir(self.debugdir)
46 46
47 # Open the environment file 47 # Open the environment file
48 logging.info("Unpickling env. You may see some harmless error " 48 logging.info("Unpickling env. You may see some harmless error "
49 "messages.") 49 "messages.")
50 env_filename = os.path.join(self.bindir, params.get("env", "env")) 50 env_filename = os.path.join(self.bindir, params.get("env", "env"))
51 env = kvm_utils.Env(env_filename, self.env_version) 51 env = virt_utils.Env(env_filename, self.env_version)
52 52
53 test_passed = False 53 test_passed = False
54 54
55 try: 55 try:
56 try: 56 try:
57 try: 57 try:
58 # Get the test routine corresponding to the specified 58 # Get the test routine corresponding to the specified
59 # test type 59 # test type
60 t_type = params.get("type") 60 t_type = params.get("type")
61 # Verify if we have the correspondent source file for it 61 # Verify if we have the correspondent source file for it
62 subtest_dir = os.path.join(self.bindir, "tests") 62 virt_dir = os.path.dirname(virt_utils.__file__)
63 module_path = os.path.join(subtest_dir, "%s.py" % t_type) 63 subtest_dir_virt = os.path.join(virt_dir, "tests")
64 if not os.path.isfile(module_path): 64 subtest_dir_kvm = os.path.join(self.bindir, "tests")
65 raise error.TestError("No %s.py test file found" % 65 subtest_dir = None
66 t_type) 66 for d in [subtest_dir_kvm, subtest_dir_virt]:
67 module_path = os.path.join(d, "%s.py" % t_type)
68 if os.path.isfile(module_path):
69 subtest_dir = d
70 break
71 if subtest_dir is None:
72 raise error.TestError("Could not find test file %s.py "
73 "on either %s or %s directory" %
74 subtest_dir_kvm, subtest_dir_virt)
67 # Load the test module 75 # Load the test module
68 f, p, d = imp.find_module(t_type, [subtest_dir]) 76 f, p, d = imp.find_module(t_type, [subtest_dir])
69 test_module = imp.load_module(t_type, f, p, d) 77 test_module = imp.load_module(t_type, f, p, d)
70 f.close() 78 f.close()
71 79
72 # Preprocess 80 # Preprocess
73 try: 81 try:
74 kvm_preprocessing.preprocess(self, params, env) 82 virt_env_process.preprocess(self, params, env)
75 finally: 83 finally:
76 env.save() 84 env.save()
77 # Run the test function 85 # Run the test function
78 run_func = getattr(test_module, "run_%s" % t_type) 86 run_func = getattr(test_module, "run_%s" % t_type)
79 try: 87 try:
80 run_func(self, params, env) 88 run_func(self, params, env)
81 finally: 89 finally:
82 env.save() 90 env.save()
83 test_passed = True 91 test_passed = True
84 92
85 except Exception, e: 93 except Exception, e:
86 logging.error("Test failed: %s: %s", 94 logging.error("Test failed: %s: %s",
87 e.__class__.__name__, e) 95 e.__class__.__name__, e)
88 try: 96 try:
89 kvm_preprocessing.postprocess_on_error( 97 virt_env_process.postprocess_on_error(
90 self, params, env) 98 self, params, env)
91 finally: 99 finally:
92 env.save() 100 env.save()
93 raise 101 raise
94 102
95 finally: 103 finally:
96 # Postprocess 104 # Postprocess
97 try: 105 try:
98 try: 106 try:
99 kvm_preprocessing.postprocess(self, params, env) 107 virt_env_process.postprocess(self, params, env)
100 except Exception, e: 108 except Exception, e:
101 if test_passed: 109 if test_passed:
102 raise 110 raise
103 logging.error("Exception raised during " 111 logging.error("Exception raised during "
104 "postprocessing: %s", e) 112 "postprocessing: %s", e)
105 finally: 113 finally:
106 env.save() 114 env.save()
107 115
108 except Exception, e: 116 except Exception, e:
109 if params.get("abort_on_error") != "yes": 117 if params.get("abort_on_error") != "yes":
110 raise 118 raise
111 # Abort on error 119 # Abort on error
112 logging.info("Aborting job (%s)", e) 120 logging.info("Aborting job (%s)", e)
113 for vm in env.get_all_vms(): 121 for vm in env.get_all_vms():
114 if vm.is_dead(): 122 if vm.is_dead():
115 continue 123 continue
116 logging.info("VM '%s' is alive.", vm.name) 124 logging.info("VM '%s' is alive.", vm.name)
117 for m in vm.monitors: 125 for m in vm.monitors:
118 logging.info("'%s' has a %s monitor unix socket at: %s", 126 logging.info("'%s' has a %s monitor unix socket at: %s",
119 vm.name, m.protocol, m.filename) 127 vm.name, m.protocol, m.filename)
120 logging.info("The command line used to start '%s' was:\n%s", 128 logging.info("The command line used to start '%s' was:\n%s",
121 vm.name, vm.make_qemu_command()) 129 vm.name, vm.make_qemu_command())
122 raise error.JobError("Abort requested (%s)" % e) 130 raise error.JobError("Abort requested (%s)" % e)
OLDNEW
« no previous file with comments | « client/tests/kvm/get_started.py ('k') | client/tests/kvm/migration_control.srv » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698