OLD | NEW |
1 """ | 1 """ |
2 High-level KVM test utility functions. | 2 High-level KVM test utility functions. |
3 | 3 |
4 This module is meant to reduce code size by performing common test procedures. | 4 This module is meant to reduce code size by performing common test procedures. |
5 Generally, code here should look like test code. | 5 Generally, code here should look like test code. |
6 More specifically: | 6 More specifically: |
7 - Functions in this module should raise exceptions if things go wrong | 7 - Functions in this module should raise exceptions if things go wrong |
8 (unlike functions in kvm_utils.py and kvm_vm.py which report failure via | 8 (unlike functions in kvm_utils.py and kvm_vm.py which report failure via |
9 their returned values). | 9 their returned values). |
10 - Functions in this module may use logging.info(), in addition to | 10 - Functions in this module may use logging.info(), in addition to |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 previous commands). | 252 previous commands). |
253 | 253 |
254 @param session: A shell session. | 254 @param session: A shell session. |
255 @param time_command: Command to issue to get the current guest time. | 255 @param time_command: Command to issue to get the current guest time. |
256 @param time_filter_re: Regex filter to apply on the output of | 256 @param time_filter_re: Regex filter to apply on the output of |
257 time_command in order to get the current time. | 257 time_command in order to get the current time. |
258 @param time_format: Format string to pass to time.strptime() with the | 258 @param time_format: Format string to pass to time.strptime() with the |
259 result of the regex filter. | 259 result of the regex filter. |
260 @return: A tuple containing the host time and guest time. | 260 @return: A tuple containing the host time and guest time. |
261 """ | 261 """ |
262 if len(re.findall("ntpdate|w32tm", time_command)) == 0: | 262 host_time = time.time() |
263 host_time = time.time() | 263 session.sendline(time_command) |
264 session.sendline(time_command) | 264 (match, s) = session.read_up_to_prompt() |
265 (match, s) = session.read_up_to_prompt() | 265 if not match: |
266 if not match: | 266 raise error.TestError("Could not get guest time") |
267 raise error.TestError("Could not get guest time") | |
268 | 267 |
269 try: | 268 try: |
270 s = re.findall(time_filter_re, s)[0] | 269 s = re.findall(time_filter_re, s)[0] |
271 except IndexError: | 270 except IndexError: |
272 logging.debug("The time string from guest is:\n%s" % s) | 271 logging.debug("The time string from guest is:\n%s" % s) |
273 raise error.TestError("The time string from guest is unexpected.") | 272 raise error.TestError("The time string from guest is unexpected.") |
274 except Exception, e: | 273 except Exception, e: |
275 logging.debug("(time_filter_re, time_string): (%s, %s)" % | 274 logging.debug("(time_filter_re, time_string): (%s, %s)" % |
276 (time_filter_re, s)) | 275 (time_filter_re, s)) |
277 raise e | 276 raise e |
278 | 277 |
279 guest_time = time.mktime(time.strptime(s, time_format)) | 278 guest_time = time.mktime(time.strptime(s, time_format)) |
280 else: | |
281 s , o = session.get_command_status_output(time_command) | |
282 if s != 0: | |
283 raise error.TestError("Could not get guest time") | |
284 if re.match('ntpdate', time_command): | |
285 offset = re.findall('offset (.*) sec',o)[0] | |
286 host_main, host_mantissa = re.findall(time_filter_re, o)[0] | |
287 host_time = time.mktime(time.strptime(host_main, time_format)) \ | |
288 + float("0.%s" % host_mantissa) | |
289 guest_time = host_time + float(offset) | |
290 else: | |
291 guest_time = re.findall(time_filter_re, o)[0] | |
292 offset = re.findall("o:(.*)s", o)[0] | |
293 if re.match('PM', guest_time): | |
294 hour = re.findall('\d+ (\d+):', guest_time)[0] | |
295 hour = str(int(hour) + 12) | |
296 guest_time = re.sub('\d+\s\d+:', "\d+\s%s:" % hour, | |
297 guest_time)[:-3] | |
298 else: | |
299 guest_time = guest_time[:-3] | |
300 guest_time = time.mktime(time.strptime(guest_time, time_format)) | |
301 host_time = guest_time - float(offset) | |
302 | |
303 return (host_time, guest_time) | 279 return (host_time, guest_time) |
304 | 280 |
305 | 281 |
306 def get_memory_info(lvms): | 282 def get_memory_info(lvms): |
307 """ | 283 """ |
308 Get memory information from host and guests in format: | 284 Get memory information from host and guests in format: |
309 Host: memfree = XXXM; Guests memsh = {XXX,XXX,...} | 285 Host: memfree = XXXM; Guests memsh = {XXX,XXX,...} |
310 | 286 |
311 @params lvms: List of VM objects | 287 @params lvms: List of VM objects |
312 @return: String with memory info report | 288 @return: String with memory info report |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 raise error.TestFail("Autotest control file run did not produce any " | 474 raise error.TestFail("Autotest control file run did not produce any " |
499 "recognizable results") | 475 "recognizable results") |
500 if bad_results: | 476 if bad_results: |
501 if len(bad_results) == 1: | 477 if len(bad_results) == 1: |
502 e_msg = ("Test %s failed during control file execution" % | 478 e_msg = ("Test %s failed during control file execution" % |
503 bad_results[0]) | 479 bad_results[0]) |
504 else: | 480 else: |
505 e_msg = ("Tests %s failed during control file execution" % | 481 e_msg = ("Tests %s failed during control file execution" % |
506 " ".join(bad_results)) | 482 " ".join(bad_results)) |
507 raise error.TestFail(e_msg) | 483 raise error.TestFail(e_msg) |
OLD | NEW |