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

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

Issue 6246035: Merge remote branch 'cros/upstream' into master (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/autotest.git@master
Patch Set: patch Created 9 years, 10 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
OLDNEW
1 import re, string, logging 1 import re, string, logging
2 from autotest_lib.client.common_lib import error 2 from autotest_lib.client.common_lib import error
3 import kvm_test_utils, kvm_utils, kvm_monitor 3 import kvm_monitor
4 4
5 5
6 def run_physical_resources_check(test, params, env): 6 def run_physical_resources_check(test, params, env):
7 """ 7 """
8 Check physical resources assigned to KVM virtual machines: 8 Check physical resources assigned to KVM virtual machines:
9 1) Log into the guest 9 1) Log into the guest
10 2) Verify whether cpu counts ,memory size, nics' model, 10 2) Verify whether cpu counts ,memory size, nics' model,
11 count and drives' format & count, drive_serial, UUID 11 count and drives' format & count, drive_serial, UUID
12 reported by the guest OS matches what has been assigned 12 reported by the guest OS matches what has been assigned
13 to the VM (qemu command line) 13 to the VM (qemu command line)
14 3) Verify all MAC addresses for guest NICs 14 3) Verify all MAC addresses for guest NICs
15 15
16 @param test: kvm test object 16 @param test: kvm test object
17 @param params: Dictionary with the test parameters 17 @param params: Dictionary with the test parameters
18 @param env: Dictionary with test environment. 18 @param env: Dictionary with test environment.
19 """ 19 """
20 vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) 20 vm = env.get_vm(params["main_vm"])
21 vm.verify_alive()
21 timeout = int(params.get("login_timeout", 360)) 22 timeout = int(params.get("login_timeout", 360))
22 session = kvm_test_utils.wait_for_login(vm, timeout=timeout) 23 session = vm.wait_for_login(timeout=timeout)
23 24
24 logging.info("Starting physical resources check test") 25 logging.info("Starting physical resources check test")
25 logging.info("Values assigned to VM are the values we expect " 26 logging.info("Values assigned to VM are the values we expect "
26 "to see reported by the Operating System") 27 "to see reported by the Operating System")
27 # Define a failure counter, as we want to check all physical 28 # Define a failure counter, as we want to check all physical
28 # resources to know which checks passed and which ones failed 29 # resources to know which checks passed and which ones failed
29 n_fail = 0 30 n_fail = 0
30 31
31 # Check cpu count 32 # Check cpu count
32 logging.info("CPU count check") 33 logging.info("CPU count check")
33 expected_cpu_nr = int(params.get("smp")) 34 expected_cpu_nr = int(params.get("smp"))
34 actual_cpu_nr = vm.get_cpu_count() 35 actual_cpu_nr = vm.get_cpu_count()
35 if expected_cpu_nr != actual_cpu_nr: 36 if expected_cpu_nr != actual_cpu_nr:
36 n_fail += 1 37 n_fail += 1
37 logging.error("CPU count mismatch:") 38 logging.error("CPU count mismatch:")
38 logging.error(" Assigned to VM: %s" % expected_cpu_nr) 39 logging.error(" Assigned to VM: %s", expected_cpu_nr)
39 logging.error(" Reported by OS: %s" % actual_cpu_nr) 40 logging.error(" Reported by OS: %s", actual_cpu_nr)
40 41
41 # Check memory size 42 # Check memory size
42 logging.info("Memory size check") 43 logging.info("Memory size check")
43 expected_mem = int(params.get("mem")) 44 expected_mem = int(params.get("mem"))
44 actual_mem = vm.get_memory_size() 45 actual_mem = vm.get_memory_size()
45 if actual_mem != expected_mem: 46 if actual_mem != expected_mem:
46 n_fail += 1 47 n_fail += 1
47 logging.error("Memory size mismatch:") 48 logging.error("Memory size mismatch:")
48 logging.error(" Assigned to VM: %s" % expected_mem) 49 logging.error(" Assigned to VM: %s", expected_mem)
49 logging.error(" Reported by OS: %s" % actual_mem) 50 logging.error(" Reported by OS: %s", actual_mem)
50 51
51 # Define a function for checking number of hard drivers & NICs 52 # Define a function for checking number of hard drivers & NICs
52 def check_num(devices, info_cmd, check_str): 53 def check_num(devices, info_cmd, check_str):
53 f_fail = 0 54 f_fail = 0
54 expected_num = kvm_utils.get_sub_dict_names(params, devices).__len__() 55 expected_num = params.objects(devices).__len__()
56 o = ""
55 try: 57 try:
56 o = vm.monitor.info(info_cmd) 58 o = vm.monitor.info(info_cmd)
57 except kvm_monitor.MonitorError, e: 59 except kvm_monitor.MonitorError, e:
58 f_fail += 1 60 f_fail += 1
59 logging.error(e) 61 logging.error(e)
60 logging.error("info/query monitor command failed (%s)", info_cmd) 62 logging.error("info/query monitor command failed (%s)", info_cmd)
61 63
62 actual_num = string.count(o, check_str) 64 actual_num = string.count(o, check_str)
63 if expected_num != actual_num: 65 if expected_num != actual_num:
64 f_fail += 1 66 f_fail += 1
65 logging.error("%s number mismatch:") 67 logging.error("%s number mismatch:")
66 logging.error(" Assigned to VM: %d" % expected_num) 68 logging.error(" Assigned to VM: %d", expected_num)
67 logging.error(" Reported by OS: %d" % actual_num) 69 logging.error(" Reported by OS: %d", actual_num)
68 return expected_num, f_fail 70 return expected_num, f_fail
69 71
70 logging.info("Hard drive count check") 72 logging.info("Hard drive count check")
71 drives_num, f_fail = check_num("images", "block", "type=hd") 73 n_fail += check_num("images", "block", "type=hd")[1]
72 n_fail += f_fail
73 74
74 logging.info("NIC count check") 75 logging.info("NIC count check")
75 nics_num, f_fail = check_num("nics", "network", "model=") 76 n_fail += check_num("nics", "network", "model=")[1]
76 n_fail += f_fail
77 77
78 # Define a function for checking hard drives & NICs' model 78 # Define a function for checking hard drives & NICs' model
79 def chk_fmt_model(device, fmt_model, info_cmd, str): 79 def chk_fmt_model(device, fmt_model, info_cmd, regexp):
80 f_fail = 0 80 f_fail = 0
81 devices = kvm_utils.get_sub_dict_names(params, device) 81 devices = params.objects(device)
82 for chk_device in devices: 82 for chk_device in devices:
83 expected = kvm_utils.get_sub_dict(params, chk_device).get(fmt_model) 83 expected = params.object_params(chk_device).get(fmt_model)
84 if not expected: 84 if not expected:
85 expected = "rtl8139" 85 expected = "rtl8139"
86 o = ""
86 try: 87 try:
87 o = vm.monitor.info(info_cmd) 88 o = vm.monitor.info(info_cmd)
88 except kvm_monitor.MonitorError, e: 89 except kvm_monitor.MonitorError, e:
89 f_fail += 1 90 f_fail += 1
90 logging.error(e) 91 logging.error(e)
91 logging.error("info/query monitor command failed (%s)", 92 logging.error("info/query monitor command failed (%s)",
92 info_cmd) 93 info_cmd)
93 94
94 device_found = re.findall(str, o) 95 device_found = re.findall(regexp, o)
95 logging.debug("Found devices: %s" % device_found) 96 logging.debug("Found devices: %s", device_found)
96 found = False 97 found = False
97 for fm in device_found: 98 for fm in device_found:
98 if expected in fm: 99 if expected in fm:
99 found = True 100 found = True
100 101
101 if not found: 102 if not found:
102 f_fail += 1 103 f_fail += 1
103 logging.error("%s model mismatch:") 104 logging.error("%s model mismatch:")
104 logging.error(" Assigned to VM: %s" % expected) 105 logging.error(" Assigned to VM: %s", expected)
105 logging.error(" Reported by OS: %s" % device_found) 106 logging.error(" Reported by OS: %s", device_found)
106 return f_fail 107 return f_fail
107 108
108 logging.info("NICs model check") 109 logging.info("NICs model check")
109 f_fail = chk_fmt_model("nics", "nic_model", "network", "model=(.*),") 110 f_fail = chk_fmt_model("nics", "nic_model", "network", "model=(.*),")
110 n_fail += f_fail 111 n_fail += f_fail
111 112
112 logging.info("Drive format check") 113 logging.info("Drive format check")
113 f_fail = chk_fmt_model("images", "drive_format", "block", "(.*)\: type=hd") 114 f_fail = chk_fmt_model("images", "drive_format", "block", "(.*)\: type=hd")
114 n_fail += f_fail 115 n_fail += f_fail
115 116
116 logging.info("Network card MAC check") 117 logging.info("Network card MAC check")
118 o = ""
117 try: 119 try:
118 o = vm.monitor.info("network") 120 o = vm.monitor.info("network")
119 except kvm_monitor.MonitorError, e: 121 except kvm_monitor.MonitorError, e:
120 n_fail += 1 122 n_fail += 1
121 logging.error(e) 123 logging.error(e)
122 logging.error("info/query monitor command failed (network)") 124 logging.error("info/query monitor command failed (network)")
123 found_mac_addresses = re.findall("macaddr=(\S+)", o) 125 found_mac_addresses = re.findall("macaddr=(\S+)", o)
124 logging.debug("Found MAC adresses: %s" % found_mac_addresses) 126 logging.debug("Found MAC adresses: %s", found_mac_addresses)
125 127
126 num_nics = len(kvm_utils.get_sub_dict_names(params, "nics")) 128 num_nics = len(params.objects("nics"))
127 for nic_index in range(num_nics): 129 for nic_index in range(num_nics):
128 mac = vm.get_mac_address(nic_index) 130 mac = vm.get_mac_address(nic_index)
129 if not string.lower(mac) in found_mac_addresses: 131 if not string.lower(mac) in found_mac_addresses:
130 n_fail += 1 132 n_fail += 1
131 logging.error("MAC address mismatch:") 133 logging.error("MAC address mismatch:")
132 logging.error(" Assigned to VM (not found): %s" % mac) 134 logging.error(" Assigned to VM (not found): %s", mac)
133 135
134 # Define a function to verify UUID & Serial number 136 # Define a function to verify UUID & Serial number
135 def verify_device(expect, name, verify_cmd): 137 def verify_device(expect, name, verify_cmd):
136 f_fail = 0 138 f_fail = 0
137 if verify_cmd: 139 if verify_cmd:
138 actual = session.get_command_output(verify_cmd) 140 actual = session.cmd_output(verify_cmd)
139 if not string.upper(expect) in actual: 141 if not string.upper(expect) in actual:
140 f_fail += 1 142 f_fail += 1
141 logging.error("%s mismatch:") 143 logging.error("%s mismatch:")
142 logging.error(" Assigned to VM: %s" % string.upper(expect)) 144 logging.error(" Assigned to VM: %s", string.upper(expect))
143 logging.error(" Reported by OS: %s" % actual) 145 logging.error(" Reported by OS: %s", actual)
144 return f_fail 146 return f_fail
145 147
146 logging.info("UUID check") 148 logging.info("UUID check")
147 if vm.get_uuid(): 149 if vm.get_uuid():
148 f_fail = verify_device(vm.get_uuid(), "UUID", 150 f_fail = verify_device(vm.get_uuid(), "UUID",
149 params.get("catch_uuid_cmd")) 151 params.get("catch_uuid_cmd"))
150 n_fail += f_fail 152 n_fail += f_fail
151 153
152 logging.info("Hard Disk serial number check") 154 logging.info("Hard Disk serial number check")
153 catch_serial_cmd = params.get("catch_serial_cmd") 155 catch_serial_cmd = params.get("catch_serial_cmd")
154 f_fail = verify_device(params.get("drive_serial"), "Serial", 156 f_fail = verify_device(params.get("drive_serial"), "Serial",
155 catch_serial_cmd) 157 catch_serial_cmd)
156 n_fail += f_fail 158 n_fail += f_fail
157 159
158 if n_fail != 0: 160 if n_fail != 0:
159 raise error.TestFail("Physical resources check test reported %s " 161 raise error.TestFail("Physical resources check test reported %s "
160 "failures. Please verify the test logs." % n_fail) 162 "failures. Please verify the test logs." % n_fail)
161 163
162 session.close() 164 session.close()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698