def run(test, params, env): """ Vsock negative test 1. Boot guest with vhost-vsock-pci device 2. Download and compile vsock on both guest and host 3. Connect guest CID(on host) without listening port inside guest 3. Send data from guest 4. Receive data from host 5. Interrupt vsock process during transfering data on host :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ vm = env.get_vm(params["main_vm"]) session = vm.wait_for_login() vsock_test_tool = params["vsock_test_tool"] if vsock_test_tool == "nc_vsock": tool_bin = vsock_test.compile_nc_vsock(test, vm, session) if vsock_test_tool == "ncat": tool_bin = path.find_command("ncat") port = random.randrange(1, 6000) vsock_dev = params["vsocks"].split()[0] guest_cid = vm.devices.get(vsock_dev).get_param("guest-cid") if vsock_test_tool == "nc_vsock": conn_cmd = "%s %s %s" % (tool_bin, guest_cid, port) if vsock_test_tool == "ncat": conn_cmd = "%s --vsock %s %s" % (tool_bin, guest_cid, port) connected_str = "Connection reset by peer" error_context.context( "Connect vsock from host without" " listening on guest.", test.log.info) try: process.system_output(conn_cmd) except process.CmdError as e: if connected_str not in str(e.result): test.fail("The connection does not fail as expected.") else: test.fail("The connection success, while it is expected to fail.") finally: session.close() session = vm.wait_for_login() tmp_file = "/tmp/vsock_file_%s" % utils_misc.generate_random_string(6) rec_session = vsock_test.send_data_from_guest_to_host(session, tool_bin, guest_cid, tmp_file, file_size=10000) try: check_data_received(test, rec_session, tmp_file) kill_host_receive_process(test, rec_session) vsock_test.check_guest_vsock_conn_exit(test, session) finally: session.cmd_output("rm -f %s" % tmp_file) session.close() vm.verify_alive()
def run(test, params, env): """ Vsock migration test 1. Boot guest with vhost-vsock-pci device 2. Download and compile nc-vsock on both guest and host S1): 3. Start listening inside guest, nc-vsock -l $port 4. Connect guest CID from host, nc-vsock $guest_cid $port 5. Input character, e.g. 'Hello world' 6. Check if guest receive the content correctly 7. Reboot guest with differnt guest CID 8. Migration 9. Check guest session exited and close host session 10. repeat step 3 to 6 11. Send data from guest, nc-vsock -l $port < tmp_file 12. Receive data from host, nc-vsock $guest_cid $port 13. Do ping-pong migration 3 times :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ def ping_pong_migration(repeat_times): """ Do ping pong migration. """ mig_timeout = float(params.get("mig_timeout", "3600")) mig_protocol = params.get("migration_protocol", "tcp") mig_cancel_delay = int(params.get("mig_cancel") == "yes") * 2 inner_funcs = ast.literal_eval(params.get("migrate_inner_funcs", "[]")) capabilities = ast.literal_eval( params.get("migrate_capabilities", "{}")) for i in range(repeat_times): if i % 2 == 0: logging.info("Round %s ping...", str(i / 2)) else: logging.info("Round %s pong...", str(i / 2)) vm.migrate( mig_timeout, mig_protocol, mig_cancel_delay, migrate_capabilities=capabilities, mig_inner_funcs=inner_funcs, env=env, ) def input_character_vsock(): connected_str = r"Connection from cid*" nc_vsock_listen(nc_vsock_bin, port, session) host_vsock_session = nc_vsock_connect(nc_vsock_bin, guest_cid, port) send_data = "Hello world" check_received_data(test, session, connected_str) error_context.context('Input "Hello world" to vsock.', logging.info) host_vsock_session.sendline(send_data) check_received_data(test, session, send_data) return host_vsock_session vm = env.get_vm(params["main_vm"]) session = vm.wait_for_login() nc_vsock_bin = compile_nc_vsock(test, vm, session) vsock_dev = params["vsocks"].split()[0] guest_cid = vm.devices.get(vsock_dev).get_param("guest-cid") port = random.randrange(1, 6000) host_vsock_session = input_character_vsock() guest_cid = int(vm.devices.get(vsock_dev).get_param("guest-cid")) + 1 vm.devices.get(vsock_dev).set_param("guest-cid", guest_cid) session.close() # reboot with different guest-cid vm.reboot() # do migration ping_pong_migration(1) session = vm.wait_for_login() if session.cmd_output("ss --vsock | grep %s" % port): test.fail( "nc-vsock listening process inside guest does not exit after migrate" ) host_vsock_session.close() # send data from guest to host tmp_file = "/tmp/vsock_file_%s" % utils_misc.generate_random_string(6) rec_session = send_data_from_guest_to_host(session, nc_vsock_bin, guest_cid, tmp_file) utils_misc.wait_for(lambda: not rec_session.is_alive(), timeout=20) cmd_chksum = "md5sum %s" % tmp_file md5_origin = session.cmd_output(cmd_chksum).split()[0] md5_received = process.system_output(cmd_chksum).split()[0].decode() host_vsock_session = input_character_vsock() ping_pong_migration(3) cmd_rm = "rm -rf %s*" % nc_vsock_bin if tmp_file: cmd_rm += "; rm -rf %s" % tmp_file session.cmd_output_safe(cmd_rm) process.system(cmd_rm, ignore_status=True) if md5_received != md5_origin: test.fail("Data transfer not integrated, the original md5 value" " is %s, while the md5 value received on host is %s" % (md5_origin, md5_received))
def run(test, params, env): """ Hotplug/unhotplug virtio-vsock device 1. Boot guest without virtio-vsock-pci device 2. Hotplug virtio-vsock device 3. Check device inside guest(lspci/dmesg) 4. Transfer data from guest to host 5. Unplug virtio-vsock device 6. Cancel the vsock process on host 7. Reboot guest :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ linux_modules.load_module('vhost_vsock') vm = env.get_vm(params['main_vm']) session = vm.wait_for_login() guest_cid = utils_vsock.get_guest_cid(3) vsock_id = 'hotplugged_vsock' vsock_params = {'id': vsock_id, 'guest-cid': guest_cid} vsock_test_tool = params["vsock_test_tool"] if '-mmio:' in params.get('machine_type'): dev_vsock = qdevices.QDevice('vhost-vsock-device', vsock_params) elif params.get('machine_type').startswith("s390"): vsock_params['devno'] = params.get('devno') dev_vsock = qdevices.QDevice("vhost-vsock-ccw", vsock_params) else: dev_vsock = qdevices.QDevice('vhost-vsock-pci', vsock_params) vm.devices.simple_hotplug(dev_vsock, vm.monitor) error_context.context( 'Check vsock device exist in guest lspci and ' 'dmesg output.', logging.info) addr_pattern = params['addr_pattern'] device_pattern = params['device_pattern'] check_vsock_cmd = params.get('check_vsock_cmd', 'lspci') time.sleep(10) lspci_output = session.cmd_output(check_vsock_cmd) device_str = re.findall(r'%s\s%s' % (addr_pattern, device_pattern), lspci_output) if params.get('dmesg_check') == 'yes': if not device_str: test.fail('check_vsock_cmd failed, no device "%s"' % device_pattern) else: address = re.findall(addr_pattern, device_str[0])[0] chk_dmesg_cmd = 'dmesg' output = re.findall(address, session.cmd_output(chk_dmesg_cmd)) if not output: test.fail('dmesg failed, no info related to %s' % address) else: error_msg = '' for o in output: if re.search(r'fail|error', o, re.I): error_msg += '%s' % o break if error_msg: test.fail("dmesg check failed: %s" % error_msg) # Transfer data from guest to host try: if vsock_test_tool == "nc_vsock": tool_bin = vsock_test.compile_nc_vsock(test, vm, session) if vsock_test_tool == "ncat": tool_bin = path.find_command("ncat") tmp_file = "/tmp/vsock_file_%s" % utils_misc.generate_random_string(6) rec_session = vsock_test.send_data_from_guest_to_host(session, tool_bin, guest_cid, tmp_file, file_size=10000) vsock_negative_test.check_data_received(test, rec_session, tmp_file) vm.devices.simple_unplug(dev_vsock, vm.monitor) vsock_negative_test.kill_host_receive_process(test, rec_session) vsock_test.check_guest_vsock_conn_exit(test, session) finally: session.cmd_output("rm -f %s" % tmp_file) session.close() vm.reboot()