OLD | NEW |
1 """ | 1 """ |
2 virtio_console test | 2 virtio_console test |
3 | 3 |
4 @copyright: 2010 Red Hat, Inc. | 4 @copyright: 2010 Red Hat, Inc. |
5 """ | 5 """ |
6 import array, logging, os, random, re, select, shutil, socket, sys, tempfile | 6 import array, logging, os, random, re, select, shutil, socket, sys, tempfile |
7 import threading, time, traceback | 7 import threading, time, traceback |
8 from collections import deque | 8 from collections import deque |
9 from threading import Thread | 9 from threading import Thread |
10 | 10 |
11 from autotest_lib.client.common_lib import error | 11 from autotest_lib.client.common_lib import error |
12 from autotest_lib.client.bin import utils | 12 from autotest_lib.client.bin import utils |
13 import kvm_subprocess, kvm_test_utils, kvm_utils | 13 from autotest_lib.client.virt import virt_utils, virt_test_utils, kvm_monitor |
14 import kvm_preprocessing, kvm_monitor | 14 from autotest_lib.client.virt import virt_env_process, aexpect |
15 | 15 |
16 | 16 |
17 def run_virtio_console(test, params, env): | 17 def run_virtio_console(test, params, env): |
18 """ | 18 """ |
19 KVM virtio_console test | 19 KVM virtio_console test |
20 | 20 |
21 1) Starts VMs with the specified number of virtio console devices | 21 1) Starts VMs with the specified number of virtio console devices |
22 2) Start smoke test | 22 2) Start smoke test |
23 3) Start loopback test | 23 3) Start loopback test |
24 4) Start performance test | 24 4) Start performance test |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 self.quiet = quiet | 296 self.quiet = quiet |
297 | 297 |
298 | 298 |
299 def run(self): | 299 def run(self): |
300 logging.debug("ThSend %s: run", self.getName()) | 300 logging.debug("ThSend %s: run", self.getName()) |
301 try: | 301 try: |
302 while not self.exitevent.isSet(): | 302 while not self.exitevent.isSet(): |
303 self.idx += self.port.send(self.data) | 303 self.idx += self.port.send(self.data) |
304 logging.debug("ThSend %s: exit(%d)", self.getName(), | 304 logging.debug("ThSend %s: exit(%d)", self.getName(), |
305 self.idx) | 305 self.idx) |
306 except Exception as ints: | 306 except Exception, ints: |
307 if not self.quiet: | 307 if not self.quiet: |
308 raise ints | 308 raise ints |
309 logging.debug(ints) | 309 logging.debug(ints) |
310 | 310 |
311 | 311 |
312 class ThSendCheck(Thread): | 312 class ThSendCheck(Thread): |
313 """ | 313 """ |
314 Random data sender thread. | 314 Random data sender thread. |
315 """ | 315 """ |
316 def __init__(self, port, event, queues, blocklen=1024): | 316 def __init__(self, port, event, queues, blocklen=1024): |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 logging.debug("ThRecv %s: run", self.getName()) | 409 logging.debug("ThRecv %s: run", self.getName()) |
410 try: | 410 try: |
411 while not self.exitevent.isSet(): | 411 while not self.exitevent.isSet(): |
412 # TODO: Workaround, it didn't work with select :-/ | 412 # TODO: Workaround, it didn't work with select :-/ |
413 try: | 413 try: |
414 self.idx += len(self.port.recv(self.blocklen)) | 414 self.idx += len(self.port.recv(self.blocklen)) |
415 except socket.timeout: | 415 except socket.timeout: |
416 pass | 416 pass |
417 self.port.settimeout(self._port_timeout) | 417 self.port.settimeout(self._port_timeout) |
418 logging.debug("ThRecv %s: exit(%d)", self.getName(), self.idx) | 418 logging.debug("ThRecv %s: exit(%d)", self.getName(), self.idx) |
419 except Exception as ints: | 419 except Exception, ints: |
420 if not self.quiet: | 420 if not self.quiet: |
421 raise ints | 421 raise ints |
422 logging.debug(ints) | 422 logging.debug(ints) |
423 | 423 |
424 | 424 |
425 class ThRecvCheck(Thread): | 425 class ThRecvCheck(Thread): |
426 """ | 426 """ |
427 Random data receiver/checker thread. | 427 Random data receiver/checker thread. |
428 """ | 428 """ |
429 def __init__(self, port, buffer, event, blocklen=1024, sendlen=0): | 429 def __init__(self, port, buffer, event, blocklen=1024, sendlen=0): |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 @return: Tuple (match index, data, kernel_crash) | 627 @return: Tuple (match index, data, kernel_crash) |
628 """ | 628 """ |
629 logging.debug("Executing '%s' on virtio_console_guest.py loop," + | 629 logging.debug("Executing '%s' on virtio_console_guest.py loop," + |
630 " vm: %s, timeout: %s", command, vm[0].name, timeout) | 630 " vm: %s, timeout: %s", command, vm[0].name, timeout) |
631 vm[1].sendline(command) | 631 vm[1].sendline(command) |
632 try: | 632 try: |
633 (match, data) = vm[1].read_until_last_line_matches(["PASS:", | 633 (match, data) = vm[1].read_until_last_line_matches(["PASS:", |
634 "FAIL:"], | 634 "FAIL:"], |
635 timeout) | 635 timeout) |
636 | 636 |
637 except (kvm_subprocess.ExpectError), e: | 637 except aexpect.ExpectError, e: |
638 match = None | 638 match = None |
639 data = "Cmd process timeout. Data in console: " + e.output | 639 data = "Cmd process timeout. Data in console: " + e.output |
640 | 640 |
641 kcrash_data = _search_kernel_crashlog(vm[3]) | 641 kcrash_data = _search_kernel_crashlog(vm[3]) |
642 if kcrash_data is not None: | 642 if kcrash_data is not None: |
643 logging.error(kcrash_data) | 643 logging.error(kcrash_data) |
644 vm[4] = True | 644 vm[4] = True |
645 | 645 |
646 return (match, data) | 646 return (match, data) |
647 | 647 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 kcrash = False | 765 kcrash = False |
766 | 766 |
767 return [vm, session, tmp_dir, sserial, kcrash], [consoles, serialports] | 767 return [vm, session, tmp_dir, sserial, kcrash], [consoles, serialports] |
768 | 768 |
769 | 769 |
770 def _restore_vm(): | 770 def _restore_vm(): |
771 """ | 771 """ |
772 Restore old virtual machine when VM is destroyed. | 772 Restore old virtual machine when VM is destroyed. |
773 """ | 773 """ |
774 logging.debug("Booting guest %s", params.get("main_vm")) | 774 logging.debug("Booting guest %s", params.get("main_vm")) |
775 kvm_preprocessing.preprocess_vm(test, params, env, | 775 virt_env_process.preprocess_vm(test, params, env, |
776 params.get("main_vm")) | 776 params.get("main_vm")) |
777 | 777 |
778 vm = env.get_vm(params.get("main_vm")) | 778 vm = env.get_vm(params.get("main_vm")) |
779 | 779 |
780 kernel_bug = None | 780 kernel_bug = None |
781 try: | 781 try: |
782 session = kvm_test_utils.wait_for_login(vm, 0, | 782 session = virt_test_utils.wait_for_login(vm, 0, |
783 float(params.get("boot_timeout", 100)), | 783 float(params.get("boot_timeout", 100)), |
784 0, 2) | 784 0, 2) |
785 except (error.TestFail): | 785 except (error.TestFail): |
786 kernel_bug = _search_kernel_crashlog(vm.serial_console, 10) | 786 kernel_bug = _search_kernel_crashlog(vm.serial_console, 10) |
787 if kernel_bug is not None: | 787 if kernel_bug is not None: |
788 logging.error(kernel_bug) | 788 logging.error(kernel_bug) |
789 raise | 789 raise |
790 | 790 |
791 kernel_bug = _search_kernel_crashlog(vm.serial_console, 10) | 791 kernel_bug = _search_kernel_crashlog(vm.serial_console, 10) |
792 if kernel_bug is not None: | 792 if kernel_bug is not None: |
793 logging.error(kernel_bug) | 793 logging.error(kernel_bug) |
794 | 794 |
795 sserial = kvm_test_utils.wait_for_login(vm, 0, | 795 sserial = virt_test_utils.wait_for_login(vm, 0, |
796 float(params.get("boot_timeout", 20)), | 796 float(params.get("boot_timeout", 20)), |
797 0, 2, serial=True) | 797 0, 2, serial=True) |
798 return [vm, session, sserial] | 798 return [vm, session, sserial] |
799 | 799 |
800 | 800 |
801 def topen(vm, port): | 801 def topen(vm, port): |
802 """ | 802 """ |
803 Open virtioconsole port. | 803 Open virtioconsole port. |
804 | 804 |
805 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session]. | 805 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session]. |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 Test maximum count of ports in guest machine. | 1189 Test maximum count of ports in guest machine. |
1190 | 1190 |
1191 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session]. | 1191 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session]. |
1192 @param consoles: Consoles which should be close before rmmod. | 1192 @param consoles: Consoles which should be close before rmmod. |
1193 """ | 1193 """ |
1194 logging.debug("Count of serial ports: 30") | 1194 logging.debug("Count of serial ports: 30") |
1195 vm[0].destroy(gracefully = False) | 1195 vm[0].destroy(gracefully = False) |
1196 (vm, consoles) = _vm_create(0, 30, False) | 1196 (vm, consoles) = _vm_create(0, 30, False) |
1197 try: | 1197 try: |
1198 init_guest(vm, consoles) | 1198 init_guest(vm, consoles) |
1199 except error.TestFail as ints: | 1199 except error.TestFail, ints: |
1200 logging.info("Count of serial ports: 30") | 1200 logging.info("Count of serial ports: 30") |
1201 raise ints | 1201 raise ints |
1202 clean_reload_vm(vm, consoles, expected=True) | 1202 clean_reload_vm(vm, consoles, expected=True) |
1203 | 1203 |
1204 | 1204 |
1205 def tmax_console_ports(vm, consoles): | 1205 def tmax_console_ports(vm, consoles): |
1206 """ | 1206 """ |
1207 Test maximum count of ports in guest machine. | 1207 Test maximum count of ports in guest machine. |
1208 | 1208 |
1209 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session]. | 1209 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session]. |
1210 @param consoles: Consoles which should be close before rmmod. | 1210 @param consoles: Consoles which should be close before rmmod. |
1211 """ | 1211 """ |
1212 logging.debug("Count of console ports: 30") | 1212 logging.debug("Count of console ports: 30") |
1213 vm[0].destroy(gracefully = False) | 1213 vm[0].destroy(gracefully = False) |
1214 (vm, consoles) = _vm_create(30, 0, False) | 1214 (vm, consoles) = _vm_create(30, 0, False) |
1215 try: | 1215 try: |
1216 init_guest(vm, consoles) | 1216 init_guest(vm, consoles) |
1217 except error.TestFail as ints: | 1217 except error.TestFail, ints: |
1218 logging.info("Count of console ports: 30") | 1218 logging.info("Count of console ports: 30") |
1219 raise ints | 1219 raise ints |
1220 clean_reload_vm(vm, consoles, expected=True) | 1220 clean_reload_vm(vm, consoles, expected=True) |
1221 | 1221 |
1222 | 1222 |
1223 def tmax_mix_serial_conosle_port(vm, consoles): | 1223 def tmax_mix_serial_conosle_port(vm, consoles): |
1224 """ | 1224 """ |
1225 Test maximim count of ports in guest machine. | 1225 Test maximim count of ports in guest machine. |
1226 | 1226 |
1227 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session]. | 1227 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session]. |
1228 @param consoles: Consoles which should be close before rmmod. | 1228 @param consoles: Consoles which should be close before rmmod. |
1229 """ | 1229 """ |
1230 logging.debug("Count of ports (serial+console): 30") | 1230 logging.debug("Count of ports (serial+console): 30") |
1231 vm[0].destroy(gracefully = False) | 1231 vm[0].destroy(gracefully = False) |
1232 (vm, consoles) = _vm_create(15, 15, False) | 1232 (vm, consoles) = _vm_create(15, 15, False) |
1233 try: | 1233 try: |
1234 init_guest(vm, consoles) | 1234 init_guest(vm, consoles) |
1235 except error.TestFail as ints: | 1235 except error.TestFail, ints: |
1236 logging.info("Count of ports (serial+console): 30") | 1236 logging.info("Count of ports (serial+console): 30") |
1237 raise ints | 1237 raise ints |
1238 clean_reload_vm(vm, consoles, expected=True) | 1238 clean_reload_vm(vm, consoles, expected=True) |
1239 | 1239 |
1240 | 1240 |
1241 def tshutdown(vm, consoles): | 1241 def tshutdown(vm, consoles): |
1242 """ | 1242 """ |
1243 Try to gently shutdown the machine. Virtio_console shouldn't block this. | 1243 Try to gently shutdown the machine. Virtio_console shouldn't block this. |
1244 | 1244 |
1245 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session]. | 1245 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session]. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 tmp = "%d data sent; " % threads[0].idx | 1333 tmp = "%d data sent; " % threads[0].idx |
1334 for thread in threads[1:]: | 1334 for thread in threads[1:]: |
1335 tmp += "%d, " % thread.idx | 1335 tmp += "%d, " % thread.idx |
1336 logging.debug("test_loopback: %s data received and verified", | 1336 logging.debug("test_loopback: %s data received and verified", |
1337 tmp[:-2]) | 1337 tmp[:-2]) |
1338 i+=1 | 1338 i+=1 |
1339 time.sleep(2) | 1339 time.sleep(2) |
1340 | 1340 |
1341 | 1341 |
1342 for j in range(parms[1]): | 1342 for j in range(parms[1]): |
1343 vm[0] = kvm_test_utils.migrate(vm[0], env, 3600, "exec", 0, | 1343 vm[0] = virt_test_utils.migrate(vm[0], env, 3600, "exec", 0, |
1344 offline) | 1344 offline) |
1345 if not vm[1]: | 1345 if not vm[1]: |
1346 raise error.TestFail("Could not log into guest after migration") | 1346 raise error.TestFail("Could not log into guest after migration") |
1347 vm[1] = kvm_test_utils.wait_for_login(vm[0], 0, | 1347 vm[1] = virt_test_utils.wait_for_login(vm[0], 0, |
1348 float(params.get("boot_timeout", 100)), | 1348 float(params.get("boot_timeout", 100)), |
1349 0, 2) | 1349 0, 2) |
1350 # OS is sometime a bit dizzy. DL=30 | 1350 # OS is sometime a bit dizzy. DL=30 |
1351 _init_guest(vm, 30) | 1351 _init_guest(vm, 30) |
1352 | 1352 |
1353 i=0 | 1353 i=0 |
1354 while i < 6: | 1354 while i < 6: |
1355 tmp = "%d data sent; " % threads[0].idx | 1355 tmp = "%d data sent; " % threads[0].idx |
1356 for thread in threads[1:]: | 1356 for thread in threads[1:]: |
1357 tmp += "%d, " % thread.idx | 1357 tmp += "%d, " % thread.idx |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1896 kernel_bug = _search_kernel_crashlog(vm[0].serial_console, 10) | 1896 kernel_bug = _search_kernel_crashlog(vm[0].serial_console, 10) |
1897 if kernel_bug is not None: | 1897 if kernel_bug is not None: |
1898 logging.error(kernel_bug) | 1898 logging.error(kernel_bug) |
1899 raise error.TestFail("Kernel crash.") | 1899 raise error.TestFail("Kernel crash.") |
1900 | 1900 |
1901 if vm[4] == True: | 1901 if vm[4] == True: |
1902 raise error.TestFail("Kernel crash.") | 1902 raise error.TestFail("Kernel crash.") |
1903 match, tmp = _on_guest("guest_exit()", vm, 10) | 1903 match, tmp = _on_guest("guest_exit()", vm, 10) |
1904 if (match is None) or (match == 0): | 1904 if (match is None) or (match == 0): |
1905 vm[1].close() | 1905 vm[1].close() |
1906 vm[1] = kvm_test_utils.wait_for_login(vm[0], 0, | 1906 vm[1] = virt_test_utils.wait_for_login(vm[0], 0, |
1907 float(params.get("boot_timeout", 5)), | 1907 float(params.get("boot_timeout", 5)), |
1908 0, 10) | 1908 0, 10) |
1909 on_guest("killall -9 python " | 1909 on_guest("killall -9 python " |
1910 "&& echo -n PASS: python killed" | 1910 "&& echo -n PASS: python killed" |
1911 "|| echo -n PASS: python was already dead", | 1911 "|| echo -n PASS: python was already dead", |
1912 vm, 10) | 1912 vm, 10) |
1913 | 1913 |
1914 init_guest(vm, consoles) | 1914 init_guest(vm, consoles) |
1915 _clean_ports(vm, consoles) | 1915 _clean_ports(vm, consoles) |
1916 | 1916 |
1917 except (error.TestFail, kvm_subprocess.ExpectError, | 1917 except (error.TestFail, aexpect.ExpectError, |
1918 Exception), inst: | 1918 Exception), inst: |
1919 logging.error(inst) | 1919 logging.error(inst) |
1920 logging.error("Virtio-console driver is irreparably" | 1920 logging.error("Virtio-console driver is irreparably" |
1921 " blocked. Every comd end with sig KILL." | 1921 " blocked. Every comd end with sig KILL." |
1922 "Trying to reboot vm to continue testing...") | 1922 "Trying to reboot vm to continue testing...") |
1923 try: | 1923 try: |
1924 vm[0].destroy(gracefully = True) | 1924 vm[0].destroy(gracefully = True) |
1925 (vm[0], vm[1], vm[3]) = _restore_vm() | 1925 (vm[0], vm[1], vm[3]) = _restore_vm() |
1926 except (kvm_monitor.MonitorProtocolError): | 1926 except (kvm_monitor.MonitorProtocolError): |
1927 logging.error("Qemu is blocked. Monitor no longer " | 1927 logging.error("Qemu is blocked. Monitor no longer " |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2165 | 2165 |
2166 if subtest.is_failed(): | 2166 if subtest.is_failed(): |
2167 raise error.TestFail("%d out of %d virtio console tests failed" % | 2167 raise error.TestFail("%d out of %d virtio console tests failed" % |
2168 (subtest.failed, (subtest.passed+subtest.failed))) | 2168 (subtest.failed, (subtest.passed+subtest.failed))) |
2169 | 2169 |
2170 | 2170 |
2171 # CLEANUP | 2171 # CLEANUP |
2172 vm[1].close() | 2172 vm[1].close() |
2173 vm[0].destroy(gracefully=False) | 2173 vm[0].destroy(gracefully=False) |
2174 shutil.rmtree(vm[2]) | 2174 shutil.rmtree(vm[2]) |
OLD | NEW |