def reboot(self, session=None, method="shell", nic_index=0, timeout=240): """ Reboot the VM and wait for it to come back up by trying to log in until timeout expires. @param session: A shell session object or None. @param method: Reboot method. Can be "shell" (send a shell reboot command). @param nic_index: Index of NIC to access in the VM, when logging in after rebooting. @param timeout: Time to wait for login to succeed (after rebooting). @return: A new shell session object. """ error.base_context("rebooting '%s'" % self.name, logging.info) error.context("before reboot") session = session or self.login() error.context() if method == "shell": session.sendline(self.params.get("reboot_command")) else: raise virt_vm.VMRebootError("Unknown reboot method: %s" % method) error.context("waiting for guest to go down", logging.info) if not utils_misc.wait_for(lambda: not session.is_responsive(timeout=30), 120, 0, 1): raise virt_vm.VMRebootError("Guest refuses to go down") session.close() error.context("logging in after reboot", logging.info) return self.wait_for_login(nic_index, timeout=timeout)
def run(test, params, env): """ KVM -no-shutdown flag test: 1. Boot a guest, with -no-shutdown flag on command line 2. Run 'system_powerdown' command in monitor 3. Wait for guest OS to shutdown down and issue power off to the VM 4. Run 'system_reset' qemu monitor command 5. Run 'cont' qemu monitor command 6. Wait for guest OS to boot up 7. Repeat step 2-6 for 5 times. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ timeout = int(params.get("login_timeout", 360)) repeat_times = int(params.get("repeat_times", 5)) error.base_context("Qemu -no-shutdown test") vm = env.get_vm(params["main_vm"]) vm.verify_alive() qemu_process_id = vm.get_pid() session = vm.wait_for_login(timeout=timeout) logging.info("The guest bootup successfully.") for i in xrange(repeat_times): error.context( "Round %s : Send monitor cmd system_powerdown." % str(i + 1), logging.info) # Send a system_powerdown monitor command vm.monitor.cmd("system_powerdown") # Wait for the session to become unresponsive and close it if not utils_misc.wait_for(lambda: not session.is_responsive(), timeout, 0, 1): raise error.TestFail("Oops, Guest refuses to go down!") if session: session.close() # Check the qemu id is not change if not utils_misc.wait_for(lambda: vm.is_alive(), 5, 0, 1): raise error.TestFail("VM not responsive after system_" "powerdown with -no-shutdown!") if vm.get_pid() != qemu_process_id: raise error.TestFail("Qemu pid changed after system_powerdown!") logging.info("Round %s -> System_powerdown successfully.", str(i + 1)) # Send monitor command system_reset and cont error.context( "Round %s : Send monitor command system_reset and cont." % str(i + 1), logging.info) vm.monitor.cmd("system_reset") vm.resume() session = vm.wait_for_login(timeout=timeout) logging.info("Round %s -> Guest is up successfully." % str(i + 1)) if vm.get_pid() != qemu_process_id: raise error.TestFail("Qemu pid changed after system_reset & cont!") if session: session.close()
def run(test, params, env): """ KVM shutdown test: 1) Log into a guest 2) Send a shutdown command to the guest, or issue a system_powerdown monitor command (depending on the value of shutdown_method) 3) Wait until the guest is down :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ timeout = int(params.get("login_timeout", 360)) shutdown_count = int(params.get("shutdown_count", 1)) shutdown_method = params.get("shutdown_method", "shell") sleep_time = float(params.get("sleep_before_powerdown", 10)) shutdown_command = params.get("shutdown_command") for i in xrange(shutdown_count): vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) error.base_context( "shutting down the VM %s/%s" % (i + 1, shutdown_count), logging.info) if params.get("setup_runlevel") == "yes": error.context("Setup the runlevel for guest", logging.info) expect_runlevel = params.get("expect_runlevel", "3") ori_runlevel = session.cmd("runlevel") ori_runlevel = re.findall("\d+", ori_runlevel)[-1] if ori_runlevel == expect_runlevel: logging.info("Guest runlevel is the same as expect.") else: session.cmd("init %s" % expect_runlevel) tmp_runlevel = session.cmd("runlevel") tmp_runlevel = re.findall("\d+", tmp_runlevel)[-1] if tmp_runlevel != expect_runlevel: logging.warn("Failed to setup runlevel for guest") if shutdown_method == "shell": # Send a shutdown command to the guest's shell session.sendline(shutdown_command) error.context("waiting VM to go down (shutdown shell cmd)", logging.info) elif shutdown_method == "system_powerdown": # Sleep for a while -- give the guest a chance to finish booting time.sleep(sleep_time) # Send a system_powerdown monitor command vm.monitor.cmd("system_powerdown") error.context( "waiting VM to go down " "(system_powerdown monitor cmd)", logging.info) if not utils_misc.wait_for(vm.is_dead, 360, 0, 1): raise error.TestFail("Guest refuses to go down") if i < shutdown_count - 1: session.close() env_process.preprocess_vm(test, params, env, params["main_vm"])
def run(test, params, env): """ KVM shutdown test: 1) Log into a guest 2) Send a shutdown command to the guest, or issue a system_powerdown monitor command (depending on the value of shutdown_method) 3) Wait until the guest is down :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ timeout = int(params.get("login_timeout", 360)) shutdown_count = int(params.get("shutdown_count", 1)) shutdown_method = params.get("shutdown_method", "shell") sleep_time = float(params.get("sleep_before_powerdown", 10)) shutdown_command = params.get("shutdown_command") for i in xrange(shutdown_count): vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) error.base_context("shutting down the VM %s/%s" % (i + 1, shutdown_count), logging.info) if params.get("setup_runlevel") == "yes": error.context("Setup the runlevel for guest", logging.info) expect_runlevel = params.get("expect_runlevel", "3") ori_runlevel = session.cmd("runlevel") ori_runlevel = re.findall("\d+", ori_runlevel)[-1] if ori_runlevel == expect_runlevel: logging.info("Guest runlevel is the same as expect.") else: session.cmd("init %s" % expect_runlevel) tmp_runlevel = session.cmd("runlevel") tmp_runlevel = re.findall("\d+", tmp_runlevel)[-1] if tmp_runlevel != expect_runlevel: logging.warn("Failed to setup runlevel for guest") if shutdown_method == "shell": # Send a shutdown command to the guest's shell session.sendline(shutdown_command) error.context("waiting VM to go down (shutdown shell cmd)", logging.info) elif shutdown_method == "system_powerdown": # Sleep for a while -- give the guest a chance to finish booting time.sleep(sleep_time) # Send a system_powerdown monitor command vm.monitor.cmd("system_powerdown") error.context("waiting VM to go down " "(system_powerdown monitor cmd)", logging.info) if not utils_misc.wait_for(vm.is_dead, 360, 0, 1): raise error.TestFail("Guest refuses to go down") if i < shutdown_count - 1: session.close() env_process.preprocess_vm(test, params, env, params["main_vm"])
def run(test, params, env): """ KVM -no-shutdown flag test: 1. Boot a guest, with -no-shutdown flag on command line 2. Run 'system_powerdown' command in monitor 3. Wait for guest OS to shutdown down and issue power off to the VM 4. Run 'system_reset' qemu monitor command 5. Run 'cont' qemu monitor command 6. Wait for guest OS to boot up 7. Repeat step 2-6 for 5 times. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ timeout = int(params.get("login_timeout", 360)) repeat_times = int(params.get("repeat_times", 5)) error.base_context("Qemu -no-shutdown test") vm = env.get_vm(params["main_vm"]) vm.verify_alive() qemu_process_id = vm.get_pid() session = vm.wait_for_login(timeout=timeout) logging.info("The guest bootup successfully.") for i in xrange(repeat_times): error.context("Round %s : Send monitor cmd system_powerdown." % str(i + 1), logging.info) # Send a system_powerdown monitor command vm.monitor.cmd("system_powerdown") # Wait for the session to become unresponsive and close it if not utils_misc.wait_for(lambda: not session.is_responsive(), timeout, 0, 1): raise error.TestFail("Oops, Guest refuses to go down!") if session: session.close() # Check the qemu id is not change if not utils_misc.wait_for(lambda: vm.is_alive(), 5, 0, 1): raise error.TestFail("VM not responsive after system_" "powerdown with -no-shutdown!") if vm.get_pid() != qemu_process_id: raise error.TestFail("Qemu pid changed after system_powerdown!") logging.info("Round %s -> System_powerdown successfully.", str(i + 1)) # Send monitor command system_reset and cont error.context("Round %s : Send monitor command system_reset and cont." % str(i + 1), logging.info) vm.monitor.cmd("system_reset") vm.resume() session = vm.wait_for_login(timeout=timeout) logging.info("Round %s -> Guest is up successfully." % str(i + 1)) if vm.get_pid() != qemu_process_id: raise error.TestFail("Qemu pid changed after system_reset & cont!") if session: session.close()
def run_vnc(test, params, env): """ Base test for vnc, mainly focus on handshaking during vnc connection setup. This case check following point: 1) VNC server support different rfb protocol version. Now it is 3.3, 3.7 and 3.8. 2) Connection could be setup with password enable. 3) Change and __com.redhat_set_password monitor command could work. This case will do following step: 1) Start VM with VNC password enable. 2) Handshaking after vnc password set by change. 3) Handshaking after vnc password set by __com.redhat_set_password. 4) Handshaking again after vnc password timeout. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environmen. """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() port = vm.get_vnc_port() default_cmd = "__com.redhat_set_password protocol=vnc," default_cmd += "password=%s,expiration=%s" change_passwd_cmd = params.get("change_passwd_cmd", default_cmd) rfb_version_list = params.get("rfb_version").strip().split() for rfb_version in rfb_version_list: error.base_context("Test with guest RFB version %s" % rfb_version) rand = random.SystemRandom() rand.seed() password = utils_misc.generate_random_string(rand.randint(1, 8)) logging.info("Set VNC password to: %s", password) timeout = rand.randint(10, 100) logging.info("VNC password timeout is: %s", timeout) vm.monitor.send_args_cmd(change_passwd_cmd % (password, timeout)) error.context("Connect to VNC server after setting password" " to '%s'" % password) vnc = VNC(port=port, rfb_version=rfb_version) status = vnc.hand_shake(password) vnc.initialize() vnc.close() if not status: raise error.TestFail("VNC Authentication failed.") logging.info("VNC Authentication pass") logging.info("Waiting for vnc password timeout.") time.sleep(timeout + 5) error.context("Connect to VNC server after password expires") vnc = VNC(port=port, rfb_version=rfb_version) status = vnc.hand_shake(password) vnc.close() if status: # Should not handshake succeffully. raise error.TestFail("VNC connected with Timeout password, The" " cmd of setting expire time doesn't work.")
def run(test, params, env): """ Base test for vnc, mainly focus on handshaking during vnc connection setup. This case check following point: 1) VNC server support different rfb protocol version. Now it is 3.3, 3.7 and 3.8. 2) Connection could be setup with password enable. 3) Change and __com.redhat_set_password monitor command could work. This case will do following step: 1) Start VM with VNC password enable. 2) Handshaking after vnc password set by change. 3) Handshaking after vnc password set by __com.redhat_set_password. 4) Handshaking again after vnc password timeout. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environmen. """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() port = vm.get_vnc_port() default_cmd = "__com.redhat_set_password protocol=vnc," default_cmd += "password=%s,expiration=%s" change_passwd_cmd = params.get("change_passwd_cmd", default_cmd) rfb_version_list = params.get("rfb_version").strip().split() for rfb_version in rfb_version_list: error.base_context("Test with guest RFB version %s" % rfb_version) rand = random.SystemRandom() rand.seed() password = utils_misc.generate_random_string(rand.randint(1, 8)) logging.info("Set VNC password to: %s", password) timeout = rand.randint(10, 100) logging.info("VNC password timeout is: %s", timeout) vm.monitor.send_args_cmd(change_passwd_cmd % (password, timeout)) error.context("Connect to VNC server after setting password" " to '%s'" % password) vnc = VNC(port=port, rfb_version=rfb_version) status = vnc.hand_shake(password) vnc.initialize() vnc.close() if not status: raise error.TestFail("VNC Authentication failed.") logging.info("VNC Authentication pass") logging.info("Waiting for vnc password timeout.") time.sleep(timeout + 5) error.context("Connect to VNC server after password expires") vnc = VNC(port=port, rfb_version=rfb_version) status = vnc.hand_shake(password) vnc.close() if status: # Should not handshake succeffully. raise error.TestFail("VNC connected with Timeout password, The" " cmd of setting expire time doesn't work.")
def run(test, params, env): """ Boots VMs until one of them becomes unresponsive, and records the maximum number of VMs successfully started: 1) boot the first vm 2) boot the second vm cloned from the first vm, check whether it boots up and all booted vms respond to shell commands 3) go on until cannot create VM anymore or cannot allocate memory for VM :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ error.base_context("waiting for the first guest to be up", logging.info) vm = env.get_vm(params["main_vm"]) vm.verify_alive() login_timeout = float(params.get("login_timeout", 240)) session = vm.wait_for_login(timeout=login_timeout) num = 2 sessions = [session] # Boot the VMs try: try: while num <= int(params.get("max_vms")): # Clone vm according to the first one error.base_context("booting guest #%d" % num, logging.info) vm_name = "vm%d" % num vm_params = vm.params.copy() curr_vm = vm.clone(vm_name, vm_params) env.register_vm(vm_name, curr_vm) env_process.preprocess_vm(test, vm_params, env, vm_name) params["vms"] += " " + vm_name session = curr_vm.wait_for_login(timeout=login_timeout) sessions.append(session) logging.info("Guest #%d booted up successfully", num) # Check whether all previous shell sessions are responsive for i, se in enumerate(sessions): error.context("checking responsiveness of guest" " #%d" % (i + 1), logging.debug) se.cmd(params.get("alive_test_cmd")) num += 1 except Exception, emsg: raise error.TestFail("Expect to boot up %s guests." "Failed to boot up #%d guest with " "error: %s." % (params["max_vms"], num, emsg)) finally: for se in sessions: se.close() logging.info("Total number booted: %d" % (num - 1))
def copy_images(): error.base_context("Copy image from NFS after installation failure") image_copy_on_error = params.get("image_copy_on_error", "no") if image_copy_on_error == "yes": logging.info("Running image_copy to copy pristine image from NFS.") try: error.context("Quit qemu-kvm before copying guest image") vm.monitor.quit() except Exception, e: logging.warn(e) from virttest import utils_test error.context("Copy image from NFS Server") utils_test.run_image_copy(test, params, env)
def run_numa_basic(test, params, env): """ Qemu numa basic test: 1) Get host numa topological structure 2) Start a guest and bind it on the cpus of one node 3) Check the memory status of qemu process. It should mainly use the memory in the same node. 4) Destroy the guest 5) Repeat step 2 ~ 4 on every node in host :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ error.context("Get host numa topological structure", logging.info) timeout = float(params.get("login_timeout", 240)) host_numa_node = utils_misc.NumaInfo() node_list = host_numa_node.online_nodes for node_id in node_list: error.base_context("Bind qemu process to numa node %s" % node_id, logging.info) vm = "vm_bind_to_%s" % node_id params['qemu_command_prefix'] = "numactl --cpunodebind=%s" % node_id utils_memory.drop_caches() env_process.preprocess_vm(test, params, env, vm) vm = env.get_vm(vm) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) session.close() error.context("Check the memory use status of qemu process", logging.info) memory_status, _ = utils_test.qemu.get_numa_status( host_numa_node, vm.get_pid()) node_used_most = 0 memory_sz_used_most = 0 for index in range(len(node_list)): if memory_sz_used_most < memory_status[index]: memory_sz_used_most = memory_status[index] node_used_most = node_list[index] logging.debug("Qemu used %s pages in node" " %s" % (memory_status[index], node_list[index])) if node_used_most != node_id: raise error.TestFail("Qemu still use memory from other node." " Expect: %s, used: %s" % (node_id, node_used_most)) error.context("Destroy guest.", logging.info) vm.destroy()
def run(test, params, env): """ Qemu numa basic test: 1) Get host numa topological structure 2) Start a guest and bind it on the cpus of one node 3) Check the memory status of qemu process. It should mainly use the memory in the same node. 4) Destroy the guest 5) Repeat step 2 ~ 4 on every node in host :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ error.context("Get host numa topological structure", logging.info) timeout = float(params.get("login_timeout", 240)) host_numa_node = utils_misc.NumaInfo() node_list = host_numa_node.online_nodes for node_id in node_list: error.base_context("Bind qemu process to numa node %s" % node_id, logging.info) vm = "vm_bind_to_%s" % node_id params['qemu_command_prefix'] = "numactl --cpunodebind=%s" % node_id utils_memory.drop_caches() env_process.preprocess_vm(test, params, env, vm) vm = env.get_vm(vm) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) session.close() error.context("Check the memory use status of qemu process", logging.info) memory_status, _ = utils_test.qemu.get_numa_status(host_numa_node, vm.get_pid()) node_used_most = 0 memory_sz_used_most = 0 for index in range(len(node_list)): if memory_sz_used_most < memory_status[index]: memory_sz_used_most = memory_status[index] node_used_most = node_list[index] logging.debug("Qemu used %s pages in node" " %s" % (memory_status[index], node_list[index])) if node_used_most != node_id: raise error.TestFail("Qemu still use memory from other node." " Expect: %s, used: %s" % (node_id, node_used_most)) error.context("Destroy guest.", logging.info) vm.destroy()
def run(test, params, env): """ KVM shutdown test: For a test with two VMs: client & guest 1) Log into the VMS(guests) that represent the client &guest 2) Send a shutdown command to the guest, or issue a system_powerdown monitor command (depending on the value of shutdown_method) 3) Wait until the guest is down :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ client_vm = env.get_vm(params["client_vm"]) client_vm.verify_alive() guest_vm = env.get_vm(params["guest_vm"]) guest_vm.verify_alive() timeout = int(params.get("login_timeout", 360)) # shutdown both of the sessions for vm in [client_vm, guest_vm]: vm_session = vm.wait_for_login(timeout=timeout, username="******", password="******") try: error.base_context("shutting down the VM") if params.get("shutdown_method") == "shell": # Send a shutdown command to the guest's shell vm_session.sendline(vm.get_params().get("shutdown_command")) error.context("waiting VM to go down (shutdown shell cmd)") elif params.get("shutdown_method") == "system_powerdown": # Sleep for a while -- give the guest a chance to finish # booting time.sleep(float(params.get("sleep_before_powerdown", 10))) # Send a system_powerdown monitor command vm.monitor.system_powerdown() error.context("waiting VM to go down " "(system_powerdown monitor cmd)") if not utils_misc.wait_for(vm.is_dead, 240, 0, 1): vm.destroy(gracefully=False, free_mac_addresses=True) raise error.TestFail("Guest refuses to go down") finally: vm_session.close()
def run_client_guest_shutdown(test, params, env): """ KVM shutdown test: For a test with two VMs: client & guest 1) Log into the VMS(guests) that represent the client &guest 2) Send a shutdown command to the guest, or issue a system_powerdown monitor command (depending on the value of shutdown_method) 3) Wait until the guest is down :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ client_vm = env.get_vm(params["client_vm"]) client_vm.verify_alive() guest_vm = env.get_vm(params["guest_vm"]) guest_vm.verify_alive() timeout = int(params.get("login_timeout", 360)) # shutdown both of the sessions for vm in [client_vm, guest_vm]: vm_session = vm.wait_for_login(timeout=timeout, username="******", password="******") try: error.base_context("shutting down the VM") if params.get("shutdown_method") == "shell": # Send a shutdown command to the guest's shell vm_session.sendline(vm.get_params().get("shutdown_command")) error.context("waiting VM to go down (shutdown shell cmd)") elif params.get("shutdown_method") == "system_powerdown": # Sleep for a while -- give the guest a chance to finish # booting time.sleep(float(params.get("sleep_before_powerdown", 10))) # Send a system_powerdown monitor command vm.monitor.cmd("system_powerdown") error.context("waiting VM to go down " "(system_powerdown monitor cmd)") if not utils_misc.wait_for(vm.is_dead, 240, 0, 1): vm.destroy(gracefully=False, free_mac_addresses=True) raise error.TestFail("Guest refuses to go down") finally: vm_session.close()
def gagent_check_fsfreeze(self, test, params, env): """ Test guest agent commands "guest-fsfreeze-freeze/status/thaw" Test steps: 1) Check the FS is thawed. 2) Freeze the FS. 3) Check the FS is frozen from both guest agent side and guest os side. 4) Thaw the FS. :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environmen. """ error.base_context("Check guest agent command 'guest-fsfreeze-freeze'", logging.info) error_context.context("Verify FS is thawed and freeze the FS.") try: expect_status = self.gagent.FSFREEZE_STATUS_THAWED self.gagent.verify_fsfreeze_status(expect_status) except guest_agent.VAgentFreezeStatusError: # Thaw guest FS if the fs status is incorrect. self.gagent.fsthaw(check_status=False) self._action_before_fsfreeze(test, params, env) self.gagent.fsfreeze() try: self._action_after_fsfreeze(test, params, env) # Next, thaw guest fs. self._action_before_fsthaw(test, params, env) error_context.context("Thaw the FS.") self.gagent.fsthaw() except Exception: # Thaw fs finally, avoid problem in following cases. try: self.gagent.fsthaw(check_status=False) except Exception, detail: # Ignore exception for this thaw action. logging.warn( "Finally failed to thaw guest fs," " detail: '%s'", detail) raise
def gagent_check_fsfreeze(self, test, params, env): """ Test guest agent commands "guest-fsfreeze-freeze/status/thaw" Test steps: 1) Check the FS is thawed. 2) Freeze the FS. 3) Check the FS is frozen from both guest agent side and guest os side. 4) Thaw the FS. :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environmen. """ error.base_context("Check guest agent command 'guest-fsfreeze-freeze'", logging.info) error.context("Verify FS is thawed and freeze the FS.") try: expect_status = self.gagent.FSFREEZE_STATUS_THAWED self.gagent.verify_fsfreeze_status(expect_status) except guest_agent.VAgentFreezeStatusError: # Thaw guest FS if the fs status is incorrect. self.gagent.fsthaw(check_status=False) self._action_before_fsfreeze(test, params, env) self.gagent.fsfreeze() try: self._action_after_fsfreeze(test, params, env) # Next, thaw guest fs. self._action_before_fsthaw(test, params, env) error.context("Thaw the FS.") self.gagent.fsthaw() except Exception: # Thaw fs finally, avoid problem in following cases. try: self.gagent.fsthaw(check_status=False) except Exception, detail: # Ignore exception for this thaw action. logging.warn("Finally failed to thaw guest fs," " detail: '%s'", detail) raise
def run_shutdown(test, params, env): """ KVM shutdown test: 1) Log into a guest 2) Send a shutdown command to the guest, or issue a system_powerdown monitor command (depending on the value of shutdown_method) 3) Wait until the guest is down @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"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) try: error.base_context("shutting down the VM", logging.info) if params.get("shutdown_method") == "shell": # Send a shutdown command to the guest's shell session.sendline(vm.get_params().get("shutdown_command")) error.context("waiting VM to go down (shutdown shell cmd)", logging.info) elif params.get("shutdown_method") == "system_powerdown": # Sleep for a while -- give the guest a chance to finish booting time.sleep(float(params.get("sleep_before_powerdown", 10))) # Send a system_powerdown monitor command vm.monitor.cmd("system_powerdown") error.context("waiting VM to go down " "(system_powerdown monitor cmd)", logging.info) if not utils_misc.wait_for(vm.is_dead, 240, 0, 1): raise error.TestFail("Guest refuses to go down") finally: session.close()
def run(test, params, env): """ Test 802.1Q vlan of NIC, config it by vconfig/ip command. 1) Create two VMs. 2) load 8021q module in guest. 3) Setup vlans by vconfig/ip in guest and using hard-coded ip address. 4) Enable arp_ignore for all ipv4 device in guest. 5) Repeat steps 2 - 4 in every guest. 6) Test by ping between same and different vlans of two VMs. 7) Test by flood ping between same vlan of two VMs. 8) Test by TCP data transfer between same vlan of two VMs. 9) Remove the named vlan-device. 10) Test maximal plumb/unplumb vlans. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def add_vlan(session, v_id, iface="eth0", cmd_type="ip"): """ Creates a vlan-device on iface by cmd that assigned by cmd_type now only support 'ip' and 'vconfig' """ vlan_if = '%s.%s' % (iface, v_id) txt = "Create vlan interface '%s' on %s" % (vlan_if, iface) error.context(txt, logging.info) if cmd_type == "vconfig": cmd = "vconfig add %s %s" % (iface, v_id) elif cmd_type == "ip": v_name = "%s.%s" % (iface, v_id) cmd = "ip link add link %s %s type vlan id %s " % (iface, v_name, v_id) else: err_msg = "Unexpected vlan operation command: %s, " % cmd_type err_msg += "only support 'ip' and 'vconfig' now" raise error.TestError(err_msg) session.cmd(cmd) def set_ip_vlan(session, v_id, vlan_ip, iface="eth0"): """ Set ip address of vlan interface """ iface = "%s.%s" % (iface, v_id) txt = "Assign IP '%s' to vlan interface '%s'" % (vlan_ip, iface) error.context(txt, logging.info) session.cmd("ifconfig %s %s" % (iface, vlan_ip)) def set_arp_ignore(session): """ Enable arp_ignore for all ipv4 device in guest """ error.context("Enable arp_ignore for all ipv4 device in guest", logging.info) ignore_cmd = "echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore" session.cmd(ignore_cmd) def rem_vlan(session, v_id, iface="eth0", cmd_type="ip"): """ Removes the named vlan interface(iface+v_id) """ v_iface = '%s.%s' % (iface, v_id) if cmd_type == "vconfig": rem_vlan_cmd = "vconfig rem %s" % v_iface elif cmd_type == "ip": rem_vlan_cmd = "ip link delete %s" % v_iface else: err_msg = "Unexpected vlan operation command: %s, " % cmd_type err_msg += "only support 'ip' and 'vconfig' now" raise error.TestError(err_msg) error.context("Remove vlan interface '%s'." % v_iface, logging.info) return session.cmd_status(rem_vlan_cmd) def nc_transfer(src, dst): """ Transfer file by netcat """ nc_port = utils_misc.find_free_port(1025, 5334, vm_ip[dst]) listen_cmd = params.get("listen_cmd") send_cmd = params.get("send_cmd") #listen in dst listen_cmd = listen_cmd % (nc_port, "receive") sessions[dst].sendline(listen_cmd) time.sleep(2) # send file from src to dst send_cmd = send_cmd % (vlan_ip[dst], str(nc_port), "file") sessions[src].cmd(send_cmd, timeout=60) try: sessions[dst].read_up_to_prompt(timeout=60) except aexpect.ExpectError: # kill server session_ctl[dst].cmd_output_safe("killall -9 nc") raise error.TestFail("Fail to receive file" " from vm%s to vm%s" % (src + 1, dst + 1)) # check MD5 message digest of receive file in dst output = sessions[dst].cmd_output("md5sum receive").strip() digest_receive = re.findall(r'(\w+)', output)[0] if digest_receive == digest_origin[src]: logging.info("File succeed received in vm %s", vlan_ip[dst]) else: logging.info("Digest_origin is %s", digest_origin[src]) logging.info("Digest_receive is %s", digest_receive) raise error.TestFail("File transferred differ from origin") sessions[dst].cmd("rm -f receive") def flood_ping(src, dst): """ Flood ping test # we must use a dedicated session because the aexpect # does not have the other method to interrupt the process in # the guest rather than close the session. """ txt = "Flood ping from %s interface %s to %s" % ( vms[src].name, ifname[src], vlan_ip[dst]) error.context(txt, logging.info) session_flood = vms[src].wait_for_login(timeout=60) utils_test.ping(vlan_ip[dst], flood=True, interface=ifname[src], session=session_flood, timeout=10) session_flood.close() vms = [] sessions = [] session_ctl = [] ifname = [] vm_ip = [] digest_origin = [] vlan_ip = ['', ''] ip_unit = ['1', '2'] subnet = params.get("subnet", "192.168") vlan_num = int(params.get("vlan_num", 5)) maximal = int(params.get("maximal", 4094)) file_size = params.get("file_size", 4096) cmd_type = params.get("cmd_type", "ip") login_timeout = int(params.get("login_timeout", 360)) vms.append(env.get_vm(params["main_vm"])) vms.append(env.get_vm("vm2")) for vm_ in vms: vm_.verify_alive() for vm_index, vm in enumerate(vms): error.base_context("Prepare test env on %s" % vm.name) session = vm.wait_for_login(timeout=login_timeout) if not session: err_msg = "Could not log into guest %s" % vm.name raise error.TestError(err_msg) sessions.append(session) logging.info("Logged in %s successful" % vm.name) session_ctl.append(vm.wait_for_login(timeout=login_timeout)) ifname.append(utils_net.get_linux_ifname(session, vm.get_mac_address())) # get guest ip vm_ip.append(vm.get_address()) # produce sized file in vm dd_cmd = "dd if=/dev/urandom of=file bs=1M count=%s" session.cmd(dd_cmd % file_size) # record MD5 message digest of file md5sum_output = session.cmd("md5sum file", timeout=60) digest_origin.append(re.findall(r'(\w+)', md5sum_output)[0]) # stop firewall in vm session.cmd_output_safe("iptables -F; service iptables stop; true") error.context("Load 8021q module in guest %s" % vm.name, logging.info) session.cmd_output_safe("modprobe 8021q") error.context("Setup vlan environment in guest %s" % vm.name, logging.info) for vlan_i in range(1, vlan_num + 1): add_vlan(session, vlan_i, ifname[vm_index], cmd_type) v_ip = "%s.%s.%s" % (subnet, vlan_i, ip_unit[vm_index]) set_ip_vlan(session, vlan_i, v_ip, ifname[vm_index]) set_arp_ignore(session) try: for vlan in range(1, vlan_num + 1): error.base_context("Test for vlan %s" % vlan, logging.info) error.context("Ping test between vlans", logging.info) interface = ifname[0] + '.' + str(vlan) for vm_index, vm in enumerate(vms): for vlan2 in range(1, vlan_num + 1): interface = ifname[vm_index] + '.' + str(vlan) dest = ".".join( (subnet, str(vlan2), ip_unit[(vm_index + 1) % 2])) status, output = utils_test.ping( dest, count=2, interface=interface, session=sessions[vm_index], timeout=30) if ((vlan == vlan2) ^ (status == 0)): err_msg = "%s ping %s unexpected, " % (interface, dest) err_msg += "error info: %s" % output raise error.TestFail(err_msg) error.context("Flood ping between vlans", logging.info) vlan_ip[0] = ".".join((subnet, str(vlan), ip_unit[0])) vlan_ip[1] = ".".join((subnet, str(vlan), ip_unit[1])) flood_ping(0, 1) flood_ping(1, 0) error.context("Transferring data between vlans by nc", logging.info) nc_transfer(0, 1) nc_transfer(1, 0) finally: # If client can not connect the nc server, need kill the server. for session in session_ctl: session.cmd_output_safe("killall -9 nc") error.base_context("Remove vlan") for vm_index, vm in enumerate(vms): for vlan in range(1, vlan_num + 1): status = rem_vlan(sessions[vm_index], vlan, ifname[vm_index], cmd_type) if status: logging.error("Remove vlan %s failed" % vlan) # Plumb/unplumb maximal number of vlan interfaces if params.get("do_maximal_test", "no") == "yes": bound = maximal + 1 try: error.base_context("Vlan scalability test") error.context("Testing the plumb of vlan interface", logging.info) for vlan_index in range(1, bound): add_vlan(sessions[0], vlan_index, ifname[0], cmd_type) vlan_added = vlan_index if vlan_added != maximal: raise error.TestFail("Maximal interface plumb test failed") finally: for vlan_index in range(1, vlan_added + 1): if rem_vlan(sessions[0], vlan_index, ifname[0], cmd_type): logging.error("Remove vlan %s failed" % vlan_index) error.base_context("Vlan negative test") error.context("Create vlan with ID %s in guest" % bound, logging.info) try: add_vlan(sessions[0], bound, ifname[0], cmd_type) raise error.TestFail("Maximal ID allow to vlan is %s" % maximal) except aexpect.ShellCmdError, detail: pattern = params["msg_pattern"] if not re.search(pattern, detail.output, re.M | re.I): raise
def run_qemu_nobody(test, params, env): """ Check smbios table : 1) Run the qemu command as nobody 2) check the process is same as the user's :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def get_user_ugid(username): """ return user uid and gid as a list """ user_uid = utils.system_output("id -u %s" % username).split() user_gid = utils.system_output("id -g %s" % username).split() return(user_uid, user_gid) def get_ugid_from_processid(pid): """ return a list[uid,euid,suid,fsuid,gid,egid,sgid,fsgid] of pid """ grep_ugid_cmd = "cat /proc/%s/status | grep -iE '^(U|G)id'" o = utils.system_output(grep_ugid_cmd % pid.strip()) ugid = re.findall("(\d+)", o) # real UID, effective UID, saved set UID, and file system UID if ugid: return ugid else: raise error.TestError("Could not find the correct UID for process %s" % pid) exec_username = params.get("user_runas", "nobody") error.base_context("Run QEMU %s test:" % exec_username) error.context("Get the user uid and gid,using 'id -u/g username'") (exec_uid, exec_gid) = get_user_ugid(exec_username) error.context("Run the qemu as user '%s'" % exec_username) logging.info("The user %s :uid='%s', gid='%s'" % (exec_username, exec_uid, exec_gid)) params["extra_params"] = " -runas %s" % exec_username params["start_vm"] = "yes" env_process.preprocess_vm(test, params, env, params.get("main_vm")) vm = env.get_vm(params["main_vm"]) failures = [] for pid in utils.get_children_pids(vm.get_shell_pid()): error.context("Get the process '%s' u/gid, using 'cat /proc/%s/status'" % (pid, pid), logging.info) qemu_ugid = get_ugid_from_processid(pid) logging.info("Process run as uid=%s,euid=%s,suid=%s,fsuid=%s" % tuple(qemu_ugid[0:4])) logging.info("Process run as gid=%s,egid=%s,sgid=%s,fsgid=%s" % tuple(qemu_ugid[4:])) error.context("Check if the user %s ugid is equal to the process %s" % (exec_username, pid)) # generate user uid, euid, suid, fsuid, gid, egid, sgid, fsgid user_ugid_extend = exec_uid * 4 + exec_gid * 4 if cmp(user_ugid_extend, qemu_ugid) != 0: e_msg = ("Process %s error, expect ugid is %s, real is %s" % (pid, user_ugid_extend, qemu_ugid)) failures.append(e_msg) if failures: raise error.TestFail("FAIL: Test reported %s failures:\n%s" % (len(failures), "\n".join(failures)))
def run_systemtap_tracing(test, params, env): """ TestStep: 1) Exec the stap script in host 2) Boot the guest, and do some operation(if needed). 3) Check the output of the stap params: @param test: kvm test object @param params: Dictionary with the test parameters @param env: Dictionary with test environment. """ def create_patterns_reg(trace_key): """ create a regular exp using the tracing key, the purpose is checking the systemtap output is accord with expected. """ pattern_reg = "" for tracing_key in trace_key.split(): pattern_reg += "%s=\d+," % tracing_key return pattern_reg.rstrip(",") error.base_context("Qemu_Tracing Test") error.context("Test start ...") probe_var_key = params.get("probe_var_key") checking_pattern_re = create_patterns_reg(probe_var_key) capdata_timeout = int(params.get("capdata_timeout", "360")) timeout = int(params.get("login_timeout", "360")) time_inter = int(params.get("time_inter", "1")) if params.get("extra_params"): params["extra_params"] = params.get("extra_params") env_process.preprocess_vm(test, params, env, params.get("main_vm")) vm = env.get_vm(params["main_vm"]) if params.get("cmds_exec"): for cmd in params.get("cmds_exec").split(","): if re.findall(":", cmd): cmd_type = cmd.split(":")[0] exec_cmds = cmd.split(":")[1] else: cmd_type = "bash" exec_cmds = cmd for cmd_exec in exec_cmds.split(";"): error.context("Execute %s cmd '%s'" % (cmd_type, cmd_exec) ,logging.info) if cmd_type == "monitor" : vm.monitor.send_args_cmd(cmd_exec) elif cmd_type == "bash" : guest_session = vm.wait_for_login(timeout = timeout) guest_session.cmd(cmd_exec) error.context("Get the output of stap script", logging.info) stap_log_file = utils_misc.get_path(test.profdir, "systemtap.log") start_time = time.time() while (time.time() - start_time) < capdata_timeout: if os.path.isfile(stap_log_file): fd = open(stap_log_file, 'r') data = fd.read() if (not data) or (not re.findall(checking_pattern_re, data)): time.sleep(time_inter) fd.close() continue elif data and re.findall(checking_pattern_re, data): logging.info("Capture the data successfully") logging.info("The capture data is like: %s" % re.findall(checking_pattern_re, data)[-1]) fd.close() break; else: time.sleep(time_inter) else: raise error.TestError("Timeout for capature the stap log data")
def run(test, params, env): """ QEMU flow caches stress test test 1) Make sure nf_conntrack is disabled in host and guest. If nf_conntrack is enabled in host, skip this case. 2) Boot guest with vhost=on/off. 3) Enable multi queues support in guest (optional). 4) After installation of netperf, run netserver in host. 5) Run netperf TCP_CRR protocal test in guest. 6) Transfer file between guest and host. 7) Check the md5 of copied file. This is a sample QEMU test, so people can get used to some of the test APIs. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ msg = "Make sure nf_conntrack is disabled in host and guest." error.context(msg, logging.info) if "nf_conntrack" in utils.system_output("lsmod"): err = "nf_conntrack load in host, skip this case" raise error.TestNAError(err) params["start_vm"] = "yes" error.context("Boot up guest", logging.info) env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) if "nf_conntrack" in session.cmd_output("lsmod"): msg = "Unload nf_conntrack module in guest." error.context(msg, logging.info) black_str = "#disable nf_conntrack\nblacklist nf_conntrack\n" \ "blacklist nf_conntrack_ipv6\nblacklist xt_conntrack\n" \ "blacklist nf_conntrack_ftp\nblacklist xt_state\n" \ "blacklist iptable_nat\nblacklist ipt_REDIRECT\n" \ "blacklist nf_nat\nblacklist nf_conntrack_ipv4" cmd = "echo -e '%s' >> /etc/modprobe.d/blacklist.conf" % black_str session.cmd(cmd) session = vm.reboot(session, timeout=timeout) if "nf_conntrack" in session.cmd_output("lsmod"): err = "Fail to unload nf_conntrack module in guest." error.TestError(err) netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"), params["netperf_link"]) md5sum = params.get("pkg_md5sum") win_netperf_link = params.get("win_netperf_link") if win_netperf_link: win_netperf_link = utils_misc.get_path( data_dir.get_deps_dir("netperf"), win_netperf_link) win_netperf_md5sum = params.get("win_netperf_md5sum") server_path = params.get("server_path", "/var/tmp/") client_path = params.get("client_path", "/var/tmp/") win_netperf_path = params.get("win_netperf_path", "c:\\") client_num = params.get("netperf_client_num", 520) netperf_timeout = int(params.get("netperf_timeout", 600)) netperf_client_ip = vm.get_address() host_ip = utils_net.get_host_ip_address(params) netperf_server_ip = params.get("netperf_server_ip", host_ip) username = params.get("username", "root") password = params.get("password", "123456") passwd = params.get("hostpasswd", "123456") client = params.get("shell_client", "ssh") port = params.get("shell_port", "22") compile_option_client = params.get("compile_option_client", "") compile_option_server = params.get("compile_option_server", "") if int(params.get("queues", 1)) > 1 and params.get("os_type") == "linux": error.context("Enable multi queues support in guest.", logging.info) guest_mac = vm.get_mac_address() ifname = utils_net.get_linux_ifname(session, guest_mac) cmd = "ethtool -L %s combined %s" % (ifname, params.get("queues")) status, out = session.cmd_status_output(cmd) msg = "Fail to enable multi queues support in guest." msg += "Command %s fail output: %s" % (cmd, out) error.TestError(msg) if params.get("os_type") == "linux": session.cmd("iptables -F", ignore_all_errors=True) g_client_link = netperf_link g_client_path = client_path g_md5sum = md5sum elif params.get("os_type") == "windows": g_client_link = win_netperf_link g_client_path = win_netperf_path g_md5sum = win_netperf_md5sum error.context("Setup netperf in guest and host", logging.info) netperf_client = utils_netperf.NetperfClient( netperf_client_ip, g_client_path, g_md5sum, g_client_link, username=username, password=password, compile_option=compile_option_client) netperf_server = utils_netperf.NetperfServer( netperf_server_ip, server_path, md5sum, netperf_link, client, port, password=passwd, compile_option=compile_option_server) try: error.base_context("Run netperf test between host and guest.") error.context("Start netserver in host.", logging.info) netperf_server.start() error.context("Start Netperf in guest for %ss." % netperf_timeout, logging.info) test_option = "-t TCP_CRR -l %s -- -b 10 -D" % netperf_timeout netperf_client.bg_start(netperf_server_ip, test_option, client_num) utils_misc.wait_for(lambda: not netperf_client.is_netperf_running(), timeout=netperf_timeout, first=590, step=2) utils_test.run_file_transfer(test, params, env) finally: netperf_server.stop() netperf_client.package.env_cleanup(True) if session: session.close()
def run(test, params, env): """ KVM migration test: 1) Start a guest. 2) Start netperf server in guest. 3) Start multi netperf clients in host. 4) Migrate the guest in local during netperf clients working. 5) Repeatedly migrate VM and wait until netperf clients stopped. :param test: QEMU test object. :param params: Dictionary with test parameters. :param env: Dictionary with the test environment. """ def dlink_preprcess(download_link): """ Preprocess the download link """ if not download_link: raise error.TestNAError("Can not get the netperf download_link") if not utils.is_url(download_link): download_link = utils_misc.get_path(data_dir.get_deps_dir(), download_link) return download_link login_timeout = int(params.get("login_timeout", 360)) 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 netperf_timeout = int(params.get("netperf_timeout", "300")) client_num = int(params.get("client_num", "100")) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) guest_address = vm.get_address() download_link = dlink_preprcess(params.get("netperf_download_link")) md5sum = params.get("pkg_md5sum") server_download_link = params.get("server_download_link", download_link) server_md5sum = params.get("server_md5sum", md5sum) server_download_link = dlink_preprcess(server_download_link) server_path = params.get("server_path", "/tmp/server.tar.bz2") client_path = params.get("client_path", "/tmp/client.tar.bz2") username = params.get("username", "root") password = params.get("password", "redhat") passwd = params.get("hostpasswd", "redhat") client = params.get("shell_client", "ssh") port = params.get("shell_port", "22") netperf_client = utils_netperf.NetperfClient("localhost", client_path, md5sum, download_link, password=passwd) netperf_server = utils_netperf.NetperfServer(guest_address, server_path, server_md5sum, server_download_link, client, port, username=username, password=password) try: if params.get("os_type") == "linux": session.cmd("iptables -F", ignore_all_errors=True) error.base_context("Run netperf test between host and guest") error.context("Start netserver in guest.", logging.info) netperf_server.start() error.context("Start Netperf on host", logging.info) test_option = "-l %s" % netperf_timeout netperf_client.bg_start(guest_address, test_option, client_num) m_count = 0 while netperf_client.is_test_running(): m_count += 1 error.context("Start migration iterations: %s " % m_count, logging.info) vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay, env=env) finally: netperf_server.stop() netperf_server.env_cleanup(True) netperf_client.env_cleanup(True) if session: session.close()
def run_qemu_nobody(test, params, env): """ Check smbios table : 1) Run the qemu command as nobody 2) check the process is same as the user's @param test: QEMU test object. @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ def get_user_ugid(username): """ return user uid and gid as a list """ user_uid = utils.system_output("id -u %s" % username).split() user_gid = utils.system_output("id -g %s" % username).split() return (user_uid, user_gid) def get_ugid_from_processid(pid): """ return a list[uid,euid,suid,fsuid,gid,egid,sgid,fsgid] of pid """ grep_ugid_cmd = "cat /proc/%s/status | grep -iE '^(U|G)id'" o = utils.system_output(grep_ugid_cmd % pid.strip()) ugid = re.findall("(\d+)", o) #real UID, effective UID, saved set UID, and file system UID if ugid: return ugid else: raise error.TestError( "Could not find the correct UID for process %s" % pid) exec_username = params.get("user_runas", "nobody") error.base_context("Run QEMU %s test:" % exec_username) error.context("Get the user uid and gid,using 'id -u/g username'") (exec_uid, exec_gid) = get_user_ugid(exec_username) error.context("Run the qemu as user '%s'" % exec_username) logging.info("The user %s :uid='%s', gid='%s'" % (exec_username, exec_uid, exec_gid)) params["extra_params"] = " -runas %s" % exec_username params["start_vm"] = "yes" env_process.preprocess_vm(test, params, env, params.get("main_vm")) vm = env.get_vm(params["main_vm"]) failures = [] for pid in utils.get_children_pids(vm.get_shell_pid()): error.context( "Get the process '%s' u/gid, using 'cat /proc/%s/status'" % (pid, pid), logging.info) qemu_ugid = get_ugid_from_processid(pid) logging.info("Process run as uid=%s,euid=%s,suid=%s,fsuid=%s" % tuple(qemu_ugid[0:4])) logging.info("Process run as gid=%s,egid=%s,sgid=%s,fsgid=%s" % tuple(qemu_ugid[4:])) error.context("Check if the user %s ugid is equal to the process %s" % (exec_username, pid)) #generate user uid, euid, suid, fsuid, gid, egid, sgid, fsgid user_ugid_extend = exec_uid * 4 + exec_gid * 4 if cmp(user_ugid_extend, qemu_ugid) != 0: e_msg = ("Process %s error, expect ugid is %s, real is %s" % (pid, user_ugid_extend, qemu_ugid)) failures.append(e_msg) if failures: raise error.TestFail("FAIL: Test reported %s failures:\n%s" % (len(failures), "\n".join(failures)))
def run_guest_s4(test, params, env): """ Suspend guest to disk, supports both Linux & Windows OSes. @param test: kvm test object. @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ error.base_context("before S4") vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) error.context("checking whether guest OS supports S4", logging.info) session.cmd(params.get("check_s4_support_cmd")) error.context() logging.info("Waiting until all guest OS services are fully started...") time.sleep(float(params.get("services_up_timeout", 30))) # Start up a program (tcpdump for linux & ping for Windows), as a flag. # If the program died after suspend, then fails this testcase. test_s4_cmd = params.get("test_s4_cmd") session.sendline(test_s4_cmd) time.sleep(5) # Get the second session to start S4 session2 = vm.wait_for_login(timeout=timeout) # Make sure the background program is running as expected error.context("making sure background program is running") check_s4_cmd = params.get("check_s4_cmd") session2.cmd(check_s4_cmd) logging.info("Launched background command in guest: %s", test_s4_cmd) error.context() error.base_context() # Suspend to disk logging.info("Starting suspend to disk now...") session2.sendline(params.get("set_s4_cmd")) # Make sure the VM goes down error.base_context("after S4") suspend_timeout = 240 + int(params.get("smp")) * 60 if not virt_utils.wait_for(vm.is_dead, suspend_timeout, 2, 2): raise error.TestFail("VM refuses to go down. Suspend failed.") logging.info("VM suspended successfully. Sleeping for a while before " "resuming it.") time.sleep(10) # Start vm, and check whether the program is still running logging.info("Resuming suspended VM...") vm.create() # Log into the resumed VM relogin_timeout = int(params.get("relogin_timeout", 240)) logging.info("Logging into resumed VM, timeout %s", relogin_timeout) session2 = vm.wait_for_login(timeout=relogin_timeout) # Check whether the test command is still alive error.context("making sure background program is still running", logging.info) session2.cmd(check_s4_cmd) error.context() logging.info("VM resumed successfuly after suspend to disk") session2.cmd_output(params.get("kill_test_s4_cmd")) session.close() session2.close()
def run(test, params, env): """ Test Step: 1. Boot up two virtual machine 2. Set openflow rules 3. Run ping test, nc(tcp, udp) test, check whether openflow rules take effect. Params: :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def run_tcpdump_bg(session, addresses, dump_protocol): """ Run tcpdump in background, tcpdump will exit once catch a packet match the rules. """ tcpdump_cmd = "killall -9 tcpdump; " tcpdump_cmd += "tcpdump -iany -n -v %s and 'src %s and dst %s' -c 1 &" session.cmd_output_safe(tcpdump_cmd % (dump_protocol, addresses[0], addresses[1])) if not utils_misc.wait_for(lambda: tcpdump_is_alive(session), 30, 0, 1, "Waiting tcpdump start..."): raise error.TestNAError("Error, can not run tcpdump") def dump_catch_data(session, dump_log, catch_reg): """ Search data from dump_log """ dump_info = session.cmd_output("cat %s" % dump_log) if re.findall(catch_reg, dump_info, re.I): return True return False def tcpdump_is_alive(session): """ Check whether tcpdump is alive """ if session.cmd_status("pidof tcpdump"): return False return True def tcpdump_catch_packet_test(session, drop_flow=False): """ Check whether tcpdump catch match rules packets, once catch a packet match rules tcpdump will exit. when drop_flow is 'True', tcpdump couldn't catch any packets. """ packet_receive = not tcpdump_is_alive(session) if packet_receive == drop_flow: err_msg = "Error, flow %s dropped, tcpdump %s receive the packets" raise error.TestError(err_msg % ((drop_flow and "was" or "wasn't"), (packet_receive and "can" or "can not"))) logging.info( "Correct, flow %s dropped, tcpdump %s receive the packet" % ((drop_flow and "was" or "was not"), (packet_receive and "can" or "can not"))) def arp_entry_clean(session, entry=None): """ Clean arp catch in guest """ if not entry: arp_clean_cmd = "arp -n | awk '/^[1-2]/{print \"arp -d \" $1}'|sh" else: arp_clean_cmd = "arp -d %s" % entry for session in sessions: session.cmd_output_safe(arp_clean_cmd) def ping_test(session, dst, drop_flow=False): """ Ping test, check icmp """ ping_status, ping_output = utils_test.ping(dest=dst, count=10, timeout=20, session=session) # when drop_flow is true, ping should failed(return not zero) # drop_flow is false, ping should success packets_lost = 100 if ping_status and not drop_flow: raise error.TestError("Ping should success when not drop_icmp") elif not ping_status: packets_lost = utils_test.get_loss_ratio(ping_output) if drop_flow and packets_lost != 100: raise error.TestError("When drop_icmp, ping shouldn't works") if not drop_flow and packets_lost == 100: raise error.TestError("When not drop_icmp, ping should works") info_msg = "Correct, icmp flow %s dropped, ping '%s', " info_msg += "packets lost rate is: '%s'" logging.info(info_msg % ((drop_flow and "was" or "was not"), (ping_status and "failed" or "success"), packets_lost)) def nc_connect_test(sessions, addresses, drop_flow=False, nc_port="8899", udp_model=False): """ Nc connect test, check tcp and udp """ nc_log = "/tmp/nc_log" server_cmd = "nc -l %s" client_cmd = "echo client | nc %s %s" if udp_model: server_cmd += " -u -w 3" client_cmd += " -u -w 3" server_cmd += " > %s &" client_cmd += " &" try: sessions[1].cmd_output_safe(server_cmd % (nc_port, nc_log)) sessions[0].cmd_output_safe(client_cmd % (addresses[1], nc_port)) nc_protocol = udp_model and "UDP" or "TCP" nc_connect = False if utils_misc.wait_for( lambda: dump_catch_data(sessions[1], nc_log, "client"), 10, 0, 2, text="Wait '%s' connect" % nc_protocol): nc_connect = True if nc_connect == drop_flow: err_msg = "Error, '%s' flow %s dropped, nc connect should '%s'" raise error.TestError( err_msg % (nc_protocol, (drop_flow and "was" or "was not"), (nc_connect and "failed" or "success"))) logging.info("Correct, '%s' flow %s dropped, and nc connect %s" % (nc_protocol, (drop_flow and "was" or "was not"), (nc_connect and "success" or "failed"))) finally: for session in sessions: session.cmd_output_safe("killall nc || killall ncat") session.cmd("%s %s" % (clean_cmd, nc_log), ignore_all_errors=True) timeout = int(params.get("login_timeout", '360')) clean_cmd = params.get("clean_cmd", "rm -f") sessions = [] addresses = [] vms = [] error.context("Init boot the vms") for vm_name in params.get("vms", "vm1 vm2").split(): vms.append(env.get_vm(vm_name)) for vm in vms: vm.verify_alive() sessions.append(vm.wait_for_login(timeout=timeout)) addresses.append(vm.get_address()) # set openflow rules: br_name = params.get("netdst", "ovs0") f_protocol = params.get("flow", "arp") f_base_options = "%s,nw_src=%s,nw_dst=%s" % (f_protocol, addresses[0], addresses[1]) for session in sessions: session.cmd("service iptables stop; iptables -F", ignore_all_errors=True) try: for drop_flow in [True, False]: if drop_flow: f_command = "add-flow" f_options = f_base_options + ",action=drop" drop_icmp = eval(params.get("drop_icmp", 'True')) drop_tcp = eval(params.get("drop_tcp", 'True')) drop_udp = eval(params.get("drop_udp", 'True')) else: f_command = "mod-flows" f_options = f_base_options + ",action=normal" drop_icmp = False drop_tcp = False drop_udp = False error.base_context("Test prepare") error.context("Do %s %s on %s" % (f_command, f_options, br_name)) utils_net.openflow_manager(br_name, f_command, f_options) error.context("Run tcpdump in guest %s" % vms[1].name, logging.info) run_tcpdump_bg(sessions[1], addresses, f_protocol) error.context("Clean arp cache in both guest", logging.info) arp_entry_clean(sessions[0], addresses[1]) error.base_context("Exec '%s' flow '%s' test" % (f_protocol, drop_flow and "drop" or "normal")) error.context("Ping test form vm1 to vm2", logging.info) ping_test(sessions[0], addresses[1], drop_icmp) error.context("Run nc connect test via tcp", logging.info) nc_connect_test(sessions, addresses, drop_tcp) error.context("Run nc connect test via udp", logging.info) nc_connect_test(sessions, addresses, drop_udp, udp_model=True) error.context("Check tcpdump data catch", logging.info) tcpdump_catch_packet_test(sessions[1], drop_flow) finally: utils_net.openflow_manager(br_name, "del-flows", f_protocol) for session in sessions: session.close()
def run(test, params, env): """ Test 802.1Q vlan of NIC, config it by vconfig/ip command. 1) Create two VMs. 2) load 8021q module in guest. 3) Setup vlans by vconfig/ip in guest and using hard-coded ip address. 4) Enable arp_ignore for all ipv4 device in guest. 5) Repeat steps 2 - 4 in every guest. 6) Test by ping between same and different vlans of two VMs. 7) Test by flood ping between same vlan of two VMs. 8) Test by TCP data transfer between same vlan of two VMs. 9) Remove the named vlan-device. 10) Test maximal plumb/unplumb vlans. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def add_vlan(session, v_id, iface="eth0", cmd_type="ip"): """ Creates a vlan-device on iface by cmd that assigned by cmd_type now only support 'ip' and 'vconfig' """ vlan_if = '%s.%s' % (iface, v_id) txt = "Create vlan interface '%s' on %s" % (vlan_if, iface) error.context(txt, logging.info) if cmd_type == "vconfig": cmd = "vconfig add %s %s" % (iface, v_id) elif cmd_type == "ip": v_name = "%s.%s" % (iface, v_id) cmd = "ip link add link %s %s type vlan id %s " % (iface, v_name, v_id) else: err_msg = "Unexpected vlan operation command: %s, " % cmd_type err_msg += "only support 'ip' and 'vconfig' now" raise error.TestError(err_msg) session.cmd(cmd) def set_ip_vlan(session, v_id, vlan_ip, iface="eth0"): """ Set ip address of vlan interface """ iface = "%s.%s" % (iface, v_id) txt = "Assign IP '%s' to vlan interface '%s'" % (vlan_ip, iface) error.context(txt, logging.info) session.cmd("ifconfig %s %s" % (iface, vlan_ip)) def set_arp_ignore(session): """ Enable arp_ignore for all ipv4 device in guest """ error.context("Enable arp_ignore for all ipv4 device in guest", logging.info) ignore_cmd = "echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore" session.cmd(ignore_cmd) def rem_vlan(session, v_id, iface="eth0", cmd_type="ip"): """ Removes the named vlan interface(iface+v_id) """ v_iface = '%s.%s' % (iface, v_id) if cmd_type == "vconfig": rem_vlan_cmd = "vconfig rem %s" % v_iface elif cmd_type == "ip": rem_vlan_cmd = "ip link delete %s" % v_iface else: err_msg = "Unexpected vlan operation command: %s, " % cmd_type err_msg += "only support 'ip' and 'vconfig' now" raise error.TestError(err_msg) send_cmd = "[ -e /proc/net/vlan/%s ] && %s" % (v_iface, rem_vlan_cmd) error.context("Remove vlan interface '%s'." % v_iface, logging.info) return session.cmd_status(send_cmd) def nc_transfer(src, dst): """ Transfer file by netcat """ nc_port = utils_misc.find_free_port(1025, 5334, vm_ip[dst]) listen_cmd = params.get("listen_cmd") send_cmd = params.get("send_cmd") #listen in dst listen_cmd = listen_cmd % (nc_port, "receive") sessions[dst].sendline(listen_cmd) time.sleep(2) # send file from src to dst send_cmd = send_cmd % (vlan_ip[dst], str(nc_port), "file") sessions[src].cmd(send_cmd, timeout=60) try: sessions[dst].read_up_to_prompt(timeout=60) except aexpect.ExpectError: # kill server session_ctl[dst].cmd_output_safe("killall -9 nc") raise error.TestFail("Fail to receive file" " from vm%s to vm%s" % (src + 1, dst + 1)) # check MD5 message digest of receive file in dst output = sessions[dst].cmd_output("md5sum receive").strip() digest_receive = re.findall(r'(\w+)', output)[0] if digest_receive == digest_origin[src]: logging.info("File succeed received in vm %s", vlan_ip[dst]) else: logging.info("Digest_origin is %s", digest_origin[src]) logging.info("Digest_receive is %s", digest_receive) raise error.TestFail("File transferred differ from origin") sessions[dst].cmd("rm -f receive") def flood_ping(src, dst): """ Flood ping test # we must use a dedicated session because the aexpect # does not have the other method to interrupt the process in # the guest rather than close the session. """ error.context("Flood ping from %s interface %s to %s" % (vms[src].name, ifname[src], vlan_ip[dst]), logging.info) session_flood = vms[src].wait_for_login(timeout=60) utils_test.ping(vlan_ip[dst], flood=True, interface=ifname[src], session=session_flood, timeout=10) session_flood.close() vms = [] sessions = [] session_ctl = [] ifname = [] vm_ip = [] digest_origin = [] vlan_ip = ['', ''] ip_unit = ['1', '2'] subnet = params.get("subnet", "192.168") vlan_num = int(params.get("vlan_num", 5)) maximal = int(params.get("maximal", 4094)) file_size = params.get("file_size", 4096) cmd_type = params.get("cmd_type", "ip") login_timeout = int(params.get("login_timeout", 360)) vms.append(env.get_vm(params["main_vm"])) vms.append(env.get_vm("vm2")) for vm_ in vms: vm_.verify_alive() for vm_index, vm in enumerate(vms): error.base_context("Prepare test env on %s" % vm.name) session = vm.wait_for_login(timeout=login_timeout) if not session: err_msg = "Could not log into guest %s" % vm.name raise error.TestError(err_msg) sessions.append(session) logging.info("Logged in %s successful" % vm.name) session_ctl.append(vm.wait_for_login(timeout=login_timeout)) ifname.append(utils_net.get_linux_ifname(session, vm.get_mac_address())) # get guest ip vm_ip.append(vm.get_address()) # produce sized file in vm dd_cmd = "dd if=/dev/urandom of=file bs=1M count=%s" session.cmd(dd_cmd % file_size) # record MD5 message digest of file md5sum_output = session.cmd("md5sum file", timeout=60) digest_origin.append(re.findall(r'(\w+)', md5sum_output)[0]) # stop firewall in vm session.cmd_output_safe("iptables -F; service iptables stop; true") error.context("Load 8021q module in guest %s" % vm.name, logging.info) session.cmd_output_safe("modprobe 8021q") error.context("Setup vlan environment in guest %s" % vm.name, logging.info) for vlan_i in range(1, vlan_num + 1): add_vlan(session, vlan_i, ifname[vm_index], cmd_type) v_ip = "%s.%s.%s" % (subnet, vlan_i, ip_unit[vm_index]) set_ip_vlan(session, vlan_i, v_ip, ifname[vm_index]) set_arp_ignore(session) try: for vlan in range(1, vlan_num + 1): error.base_context("Test for vlan %s" % vlan, logging.info) error.context("Ping test between vlans", logging.info) interface = ifname[0] + '.' + str(vlan) for vm_index, vm in enumerate(vms): for vlan2 in range(1, vlan_num + 1): interface = ifname[vm_index] + '.' + str(vlan) dest = ".".join((subnet, str(vlan2), ip_unit[(vm_index + 1) % 2])) status, output = utils_test.ping(dest, count=2, interface=interface, session=sessions[vm_index], timeout=30) if ((vlan == vlan2) ^ (status == 0)): err_msg = "%s ping %s unexpected, " % (interface, dest) err_msg += "error info: %s" % output raise error.TestFail(err_msg) error.context("Flood ping between vlans", logging.info) vlan_ip[0] = ".".join((subnet, str(vlan), ip_unit[0])) vlan_ip[1] = ".".join((subnet, str(vlan), ip_unit[1])) flood_ping(0, 1) flood_ping(1, 0) error.context("Transferring data between vlans by nc", logging.info) nc_transfer(0, 1) nc_transfer(1, 0) finally: # If client can not connect the nc server, need kill the server. for session in session_ctl: session.cmd_output_safe("killall -9 nc") error.base_context("Remove vlan") for vm_index, vm in enumerate(vms): for vlan in range(1, vlan_num + 1): rem_vlan(sessions[vm_index], vlan, ifname[vm_index], cmd_type) # Plumb/unplumb maximal number of vlan interfaces if params.get("do_maximal_test", "no") == "yes": try: error.base_context("Vlan scalability test") error.context("Testing the plumb of vlan interface", logging.info) for vlan_index in range(1, maximal + 1): add_vlan(sessions[0], vlan_index, ifname[0], cmd_type) vlan_added = vlan_index if vlan_added != maximal: raise error.TestFail("Maximal interface plumb test failed") finally: for vlan_index in range(1, vlan_added + 1): if not rem_vlan(sessions[0], vlan_index, ifname[0], cmd_type): logging.error("Remove vlan %s failed" % vlan_index) sessions.extend(session_ctl) for sess in sessions: if sess: sess.close()
def run_systemtap_tracing(test, params, env): """ TestStep: 1) Exec the stap script in host 2) Boot the guest, and do some operation(if needed). 3) Check the output of the stap params: :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def create_patterns_reg(trace_key): """ Create a regular exp using the tracing key, the purpose is checking the systemtap output is accord with expected. """ pattern_reg = "" for tracing_key in trace_key.split(): pattern_reg += "%s=\d+," % tracing_key return pattern_reg.rstrip(",") error.base_context("Qemu_Tracing Test") error.context("Test start ...") probe_var_key = params.get("probe_var_key") checking_pattern_re = create_patterns_reg(probe_var_key) capdata_timeout = int(params.get("capdata_timeout", "360")) timeout = int(params.get("login_timeout", "360")) time_inter = int(params.get("time_inter", "1")) if params.get("extra_params"): params["extra_params"] = params.get("extra_params") if params.get("boot_with_cdrom") == 'yes': iso_path = "%s/test.iso" % data_dir.get_tmp_dir() create_cmd = "dd if=/dev/zero of=%s bs=1M count=10" % iso_path if utils.system(create_cmd, ignore_status=True) != 0: raise error.TestNAError("Create test iso failed") params["cdrom_cd1"] = iso_path if params.get("start_vm", "yes") == "no": params["start_vm"] = "yes" env_process.preprocess_vm(test, params, env, params.get("main_vm")) vm = env.get_vm(params["main_vm"]) vm.verify_alive() if params.get("cmds_exec"): for cmd in params.get("cmds_exec").split(","): if re.findall(":", cmd): cmd_type = cmd.split(":")[0] exec_cmds = cmd.split(":")[1] else: cmd_type = "bash" exec_cmds = cmd for cmd_exec in exec_cmds.split(";"): error.context("Execute %s cmd '%s'" % (cmd_type, cmd_exec), logging.info) if cmd_type == "monitor": vm.monitor.send_args_cmd(cmd_exec) elif cmd_type == "bash": guest_session = vm.wait_for_login(timeout=timeout) guest_session.cmd(cmd_exec) error.context("Get the output of stap script", logging.info) stap_log_file = utils_misc.get_path(test.profdir, "systemtap.log") start_time = time.time() while (time.time() - start_time) < capdata_timeout: if os.path.isfile(stap_log_file): fd = open(stap_log_file, 'r') data = fd.read() if (not data) or (not re.findall(checking_pattern_re, data)): time.sleep(time_inter) fd.close() continue elif data and re.findall(checking_pattern_re, data): logging.info("Capture the data successfully") logging.info("The capture data is like: %s" % re.findall(checking_pattern_re, data)[-1]) fd.close() break else: time.sleep(time_inter) else: raise error.TestError("Timeout for capature the stap log data")
def run(test, params, env): """ KVM shutdown test: 1) Log into a guest 2) Send a shutdown command to the guest, or issue a system_powerdown monitor command (depending on the value of shutdown_method) 3) Wait until the guest is down :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ timeout = int(params.get("login_timeout", 360)) shutdown_count = int(params.get("shutdown_count", 1)) shutdown_method = params.get("shutdown_method", "shell") sleep_time = float(params.get("sleep_before_powerdown", 10)) shutdown_command = params.get("shutdown_command") check_from_monitor = params.get("check_from_monitor", "no") == "yes" for i in xrange(shutdown_count): vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) error.base_context( "shutting down the VM %s/%s" % (i + 1, shutdown_count), logging.info) if params.get("setup_runlevel") == "yes": error.context("Setup the runlevel for guest", logging.info) expect_runlevel = params.get("expect_runlevel", "3") cmd = "runlevel" if utils_misc.wait_for(lambda: session.cmd_status(cmd) == 0, 15): ori_runlevel = session.cmd(cmd) else: ori_runlevel = "0" ori_runlevel = re.findall("\d+", ori_runlevel)[-1] if ori_runlevel == expect_runlevel: logging.info("Guest runlevel is the same as expect.") else: session.cmd("init %s" % expect_runlevel) tmp_runlevel = session.cmd(cmd) tmp_runlevel = re.findall("\d+", tmp_runlevel)[-1] if tmp_runlevel != expect_runlevel: logging.warn("Failed to setup runlevel for guest") if shutdown_method == "shell": # Send a shutdown command to the guest's shell session.sendline(shutdown_command) error.context("waiting VM to go down (shutdown shell cmd)", logging.info) elif shutdown_method == "system_powerdown": # Sleep for a while -- give the guest a chance to finish booting time.sleep(sleep_time) # Send a system_powerdown monitor command vm.monitor.cmd("system_powerdown") error.context( "waiting VM to go down " "(system_powerdown monitor cmd)", logging.info) if not vm.wait_for_shutdown(360): raise error.TestFail("Guest refuses to go down") if check_from_monitor and params.get("disable_shutdown") == "yes": check_failed = False vm_status = vm.monitor.get_status() if vm.monitor.protocol == "qmp": if vm_status['status'] != "shutdown": check_failed = True else: if not re.findall("paused\s+\(shutdown\)", vm_status): check_failed = True if check_failed: raise error.TestFail("Status check from monitor " "is: %s" % str(vm_status)) if params.get("disable_shutdown") == "yes": # Quit the qemu process vm.destroy(gracefully=False) if i < shutdown_count - 1: session.close() env_process.preprocess_vm(test, params, env, params["main_vm"])
def run(test, params, env): """ QEMU flow caches stress test test 1) Make sure nf_conntrack is disabled in host and guest. If nf_conntrack is enabled in host, skip this case. 2) Boot guest with vhost=on/off. 3) Enable multi queues support in guest (optional). 4) After installation of netperf, run netserver in host. 5) Run netperf TCP_CRR protocal test in guest. 6) Transfer file between guest and host. 7) Check the md5 of copied file. This is a sample QEMU test, so people can get used to some of the test APIs. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ msg = "Make sure nf_conntrack is disabled in host and guest." error.context(msg, logging.info) if "nf_conntrack" in utils.system_output("lsmod"): err = "nf_conntrack load in host, skip this case" raise error.TestNAError(err) params["start_vm"] = "yes" error.context("Boot up guest", logging.info) env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) if "nf_conntrack" in session.cmd_output("lsmod"): msg = "Unload nf_conntrack module in guest." error.context(msg, logging.info) black_str = "#disable nf_conntrack\nblacklist nf_conntrack\n" \ "blacklist nf_conntrack_ipv6\nblacklist xt_conntrack\n" \ "blacklist nf_conntrack_ftp\nblacklist xt_state\n" \ "blacklist iptable_nat\nblacklist ipt_REDIRECT\n" \ "blacklist nf_nat\nblacklist nf_conntrack_ipv4" cmd = "echo -e '%s' >> /etc/modprobe.d/blacklist.conf" % black_str session.cmd(cmd) session = vm.reboot(session, timeout=timeout) if "nf_conntrack" in session.cmd_output("lsmod"): err = "Fail to unload nf_conntrack module in guest." error.TestError(err) netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"), params["netperf_link"]) md5sum = params.get("pkg_md5sum") win_netperf_link = params.get("win_netperf_link") if win_netperf_link: win_netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"), win_netperf_link) win_netperf_md5sum = params.get("win_netperf_md5sum") server_path = params.get("server_path", "/var/tmp/") client_path = params.get("client_path", "/var/tmp/") win_netperf_path = params.get("win_netperf_path", "c:\\") client_num = params.get("netperf_client_num", 520) netperf_timeout = int(params.get("netperf_timeout", 600)) netperf_client_ip = vm.get_address() host_ip = utils_net.get_host_ip_address(params) netperf_server_ip = params.get("netperf_server_ip", host_ip) username = params.get("username", "root") password = params.get("password", "123456") passwd = params.get("hostpasswd", "123456") client = params.get("shell_client", "ssh") port = params.get("shell_port", "22") compile_option_client = params.get("compile_option_client", "") compile_option_server = params.get("compile_option_server", "") if int(params.get("queues", 1)) > 1 and params.get("os_type") == "linux": error.context("Enable multi queues support in guest.", logging.info) guest_mac = vm.get_mac_address() ifname = utils_net.get_linux_ifname(session, guest_mac) cmd = "ethtool -L %s combined %s" % (ifname, params.get("queues")) status, out = session.cmd_status_output(cmd) msg = "Fail to enable multi queues support in guest." msg += "Command %s fail output: %s" % (cmd, out) error.TestError(msg) if params.get("os_type") == "linux": session.cmd("iptables -F", ignore_all_errors=True) g_client_link = netperf_link g_client_path = client_path g_md5sum = md5sum elif params.get("os_type") == "windows": g_client_link = win_netperf_link g_client_path = win_netperf_path g_md5sum = win_netperf_md5sum error.context("Setup netperf in guest and host", logging.info) netperf_client = utils_netperf.NetperfClient(netperf_client_ip, g_client_path, g_md5sum, g_client_link, username=username, password=password, compile_option=compile_option_client) netperf_server = utils_netperf.NetperfServer(netperf_server_ip, server_path, md5sum, netperf_link, client, port, password=passwd, compile_option=compile_option_server) try: error.base_context("Run netperf test between host and guest.") error.context("Start netserver in host.", logging.info) netperf_server.start() error.context("Start Netperf in guest for %ss." % netperf_timeout, logging.info) test_option = "-t TCP_CRR -l %s -- -b 10 -D" % netperf_timeout netperf_client.bg_start(netperf_server_ip, test_option, client_num) utils_misc.wait_for(lambda: not netperf_client.is_netperf_running(), timeout=netperf_timeout, first=590, step=2) utils_test.run_file_transfer(test, params, env) finally: netperf_server.stop() netperf_client.package.env_cleanup(True) if session: session.close()
def run(test, params, env): """ KVM shutdown test: 1) Log into a guest 2) Send a shutdown command to the guest, or issue a system_powerdown monitor command (depending on the value of shutdown_method) 3) Wait until the guest is down :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ timeout = int(params.get("login_timeout", 360)) shutdown_count = int(params.get("shutdown_count", 1)) shutdown_method = params.get("shutdown_method", "shell") sleep_time = float(params.get("sleep_before_powerdown", 10)) shutdown_command = params.get("shutdown_command") check_from_monitor = params.get("check_from_monitor", "no") == "yes" for i in xrange(shutdown_count): vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) error.base_context("shutting down the VM %s/%s" % (i + 1, shutdown_count), logging.info) if params.get("setup_runlevel") == "yes": error.context("Setup the runlevel for guest", logging.info) utils_test.qemu.setup_runlevel(params, session) if shutdown_method == "shell": # Send a shutdown command to the guest's shell session.sendline(shutdown_command) error.context("waiting VM to go down (shutdown shell cmd)", logging.info) elif shutdown_method == "system_powerdown": # Sleep for a while -- give the guest a chance to finish booting time.sleep(sleep_time) # Send a system_powerdown monitor command vm.monitor.cmd("system_powerdown") error.context("waiting VM to go down " "(system_powerdown monitor cmd)", logging.info) if not vm.wait_for_shutdown(360): raise error.TestFail("Guest refuses to go down") if check_from_monitor and params.get("disable_shutdown") == "yes": check_failed = False vm_status = vm.monitor.get_status() if vm.monitor.protocol == "qmp": if vm_status['status'] != "shutdown": check_failed = True else: if not re.findall("paused\s+\(shutdown\)", vm_status): check_failed = True if check_failed: raise error.TestFail("Status check from monitor " "is: %s" % str(vm_status)) if params.get("disable_shutdown") == "yes": # Quit the qemu process vm.destroy(gracefully=False) if i < shutdown_count - 1: session.close() env_process.preprocess_vm(test, params, env, params["main_vm"])
try: for drop_flow in [True, False]: if drop_flow: f_command = "add-flow" f_options = f_base_options + ",action=drop" drop_icmp = eval(params.get("drop_icmp", 'True')) drop_tcp = eval(params.get("drop_tcp", 'True')) drop_udp = eval(params.get("drop_udp", 'True')) else: f_command = "mod-flows" f_options = f_base_options + ",action=normal" drop_icmp = False drop_tcp = False drop_udp = False error.base_context("Test prepare") error.context("Do %s %s on %s" % (f_command, f_options, br_name)) utils_net.openflow_manager(br_name, f_command, f_options) acl_rules = utils_net.openflow_manager(br_name, "dump-flows").stdout if not acl_rules_check(acl_rules, f_options): raise error.TestFail("Can not find the rules from" " ovs-ofctl: %s" % acl_rules) error.context("Run tcpdump in guest %s" % vms[1].name, logging.info) run_tcpdump_bg(sessions[1], addresses, f_protocol) if drop_flow or f_protocol is not "arp": error.context("Clean arp cache in both guest", logging.info) arp_entry_clean(addresses[1]) error.base_context("Exec '%s' flow '%s' test" %
def run(test, params, env): """ KVM migration test: 1) Start a guest. 2) Start netperf server in guest. 3) Start multi netperf clients in host. 4) Migrate the guest in local during netperf clients working. 5) Repeatedly migrate VM and wait until netperf clients stopped. :param test: QEMU test object. :param params: Dictionary with test parameters. :param env: Dictionary with the test environment. """ def dlink_preprcess(download_link): """ Preprocess the download link """ if not download_link: raise error.TestNAError("Can not get the netperf download_link") if not utils.is_url(download_link): download_link = utils_misc.get_path(data_dir.get_deps_dir(), download_link) return download_link login_timeout = int(params.get("login_timeout", 360)) 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 netperf_timeout = int(params.get("netperf_timeout", "300")) client_num = int(params.get("client_num", "100")) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) guest_address = vm.get_address() download_link = dlink_preprcess(params.get("netperf_download_link")) md5sum = params.get("pkg_md5sum") server_download_link = params.get("server_download_link", download_link) server_md5sum = params.get("server_md5sum", md5sum) server_download_link = dlink_preprcess(server_download_link) server_path = params.get("server_path", "/tmp/server.tar.bz2") client_path = params.get("client_path", "/tmp/client.tar.bz2") username = params.get("username", "root") password = params.get("password", "redhat") passwd = params.get("hostpasswd", "redhat") client = params.get("shell_client", "ssh") port = params.get("shell_port", "22") netperf_client = utils_netperf.NetperfClient("localhost", client_path, md5sum, download_link, password=passwd) netperf_server = utils_netperf.NetperfServer(guest_address, server_path, server_md5sum, server_download_link, client, port, username=username, password=password) try: if params.get("os_type") == "linux": session.cmd("iptables -F", ignore_all_errors=True) error.base_context("Run netperf test between host and guest") error.context("Start netserver in guest.", logging.info) netperf_server.start() error.context("Start Netperf on host", logging.info) test_option = "-l %s" % netperf_timeout netperf_client.bg_start(guest_address, test_option, client_num) m_count = 0 while netperf_client.is_test_running(): m_count += 1 error.context("Start migration iterations: %s " % m_count, logging.info) vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay) finally: netperf_server.stop() netperf_server.env_cleanup(True) netperf_client.env_cleanup(True) if session: session.close()
def run_guest_s4(test, params, env): """ Suspend guest to disk, supports both Linux & Windows OSes. @param test: kvm test object. @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ error.base_context("before S4") vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) error.context("checking whether guest OS supports S4", logging.info) session.cmd(params.get("check_s4_support_cmd")) error.context() logging.info("Waiting until all guest OS services are fully started...") time.sleep(float(params.get("services_up_timeout", 30))) # Start up a program (tcpdump for linux & ping for Windows), as a flag. # If the program died after suspend, then fails this testcase. test_s4_cmd = params.get("test_s4_cmd") session.sendline(test_s4_cmd) time.sleep(5) # Get the second session to start S4 session2 = vm.wait_for_login(timeout=timeout) # Make sure the background program is running as expected error.context("making sure background program is running") check_s4_cmd = params.get("check_s4_cmd") session2.cmd(check_s4_cmd) logging.info("Launched background command in guest: %s", test_s4_cmd) error.context() error.base_context() # Suspend to disk logging.info("Starting suspend to disk now...") session2.sendline(params.get("set_s4_cmd")) # Make sure the VM goes down error.base_context("after S4") suspend_timeout = 240 + int(params.get("smp")) * 60 if not utils_misc.wait_for(vm.is_dead, suspend_timeout, 2, 2): raise error.TestFail("VM refuses to go down. Suspend failed.") logging.info("VM suspended successfully. Sleeping for a while before " "resuming it.") time.sleep(10) # Start vm, and check whether the program is still running logging.info("Resuming suspended VM...") vm.create() # Log into the resumed VM relogin_timeout = int(params.get("relogin_timeout", 240)) logging.info("Logging into resumed VM, timeout %s", relogin_timeout) session2 = vm.wait_for_login(timeout=relogin_timeout) # Check whether the test command is still alive error.context("making sure background program is still running", logging.info) session2.cmd(check_s4_cmd) error.context() logging.info("VM resumed successfuly after suspend to disk") session2.cmd_output(params.get("kill_test_s4_cmd")) session.close() session2.close()
def run(test, params, env): """ Suspend a running Virtual Machine and verify its state. 1) Boot the vm 2) Do preparation operation (Optional) 3) Start a background process (Optional) 4) Stop the VM 5) Verify the status of VM is 'paused' 6) Verify the session has no response 7) Resume the VM 8) Verify the status of VM is 'running' 9) Re-login the guest 10) Do check operation (Optional) 11) Do clean operation (Optional) :param test: Kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() login_timeout = float(params.get("login_timeout", 240)) session = vm.wait_for_login(timeout=login_timeout) session_bg = None start_bg_process = params.get("start_bg_process") try: prepare_op = params.get("prepare_op") if prepare_op: error.context("Do preparation operation: '%s'" % prepare_op, logging.info) op_timeout = float(params.get("prepare_op_timeout", 60)) session.cmd(prepare_op, timeout=op_timeout) if start_bg_process: bg_cmd = params.get("bg_cmd") error.context("Start a background process: '%s'" % bg_cmd, logging.info) session_bg = vm.wait_for_login(timeout=login_timeout) bg_cmd_timeout = float(params.get("bg_cmd_timeout", 240)) args = (bg_cmd, bg_cmd_timeout) bg = utils_test.BackgroundTest(session_bg.cmd, args) bg.start() error.base_context("Stop the VM", logging.info) vm.pause() error.context("Verify the status of VM is 'paused'", logging.info) vm.verify_status("paused") error.context("Verify the session has no response", logging.info) if session.is_responsive(): msg = "Session is still responsive after stop" logging.error(msg) raise error.TestFail(msg) session.close() time.sleep(float(params.get("pause_time", 0))) error.base_context("Resume the VM", logging.info) vm.resume() error.context("Verify the status of VM is 'running'", logging.info) vm.verify_status("running") error.context("Re-login the guest", logging.info) session = vm.wait_for_login(timeout=login_timeout) if start_bg_process: if bg: bg.join() check_op = params.get("check_op") if check_op: error.context("Do check operation: '%s'" % check_op, logging.info) op_timeout = float(params.get("check_op_timeout", 60)) s, o = session.cmd_status_output(check_op, timeout=op_timeout) if s != 0: raise error.TestFail("Something wrong after stop continue, " "check command report: %s" % o) finally: clean_op = params.get("clean_op") if clean_op: error.context("Do clean operation: '%s'" % clean_op, logging.info) op_timeout = float(params.get("clean_op_timeout", 60)) session.cmd(clean_op, timeout=op_timeout, ignore_all_errors=True) session.close() if session_bg: session_bg.close()
def run(test, params, env): """ Ping the guest with different size of packets. 1) Login to guest 2) Ping test on nic(s) from host 2.1) Ping with packet size from 0 to 65507 2.2) Flood ping test 2.3) Ping test after flood ping, Check if the network is still alive 3) Ping test from guest side, packet size is from 0 to 65507 (win guest is up to 65500) (Optional) :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def _get_loss_ratio(output): if params.get("strict_check", "no") == "yes": ratio = utils_test.get_loss_ratio(output) if ratio != 0: raise error.TestFail("Loss ratio is %s" % ratio) timeout = int(params.get("login_timeout", 360)) ping_ext_host = params.get("ping_ext_host", "no") == "yes" vm = env.get_vm(params["main_vm"]) vm.verify_alive() error.context("Login to guest", logging.info) session = vm.wait_for_login(timeout=timeout) # most of linux distribution don't add IP configuration for extra nics, # so get IP for extra nics via pre_cmd; if params.get("pre_cmd"): session.cmd(params["pre_cmd"], timeout=600) if ping_ext_host: default_host = "www.redhat.com" ext_host_get_cmd = params.get("ext_host_get_cmd", "") try: ext_host = utils.system_output(ext_host_get_cmd) except error.CmdError: logging.warn("Can't get specified host with cmd '%s'," " Fallback to default host '%s'", ext_host_get_cmd, default_host) ext_host = default_host if not ext_host: # Fallback to a hardcode host, eg: ext_host = default_host counts = params.get("ping_counts", 100) flood_minutes = float(params.get("flood_minutes", 10)) packet_sizes = params.get("packet_size", "").split() for i, nic in enumerate(vm.virtnet): ip = vm.get_address(i) if ip.upper().startswith("FE80"): interface = utils_net.get_neigh_attch_interface(ip) else: interface = None nic_name = nic.get("nic_name") if not ip: logging.error("Could not get the ip of nic index %d: %s", i, nic_name) continue error.base_context("Ping test on nic %s (index %d) from host" " side" % (nic_name, i), logging.info) for size in packet_sizes: error.context("Ping with packet size %s" % size, logging.info) status, output = utils_test.ping(ip, 10, packetsize=size, interface=interface, timeout=20) _get_loss_ratio(output) if status != 0: raise error.TestFail("Ping failed, status: %s," " output: %s" % (status, output)) error.context("Flood ping test", logging.info) utils_test.ping(ip, None, flood=True, output_func=None, interface=interface, timeout=flood_minutes * 60) error.context("Ping test after flood ping, Check if the network is" " still alive", logging.info) status, output = utils_test.ping(ip, counts, interface=interface, timeout=float(counts) * 1.5) _get_loss_ratio(output) if status != 0: raise error.TestFail("Ping returns non-zero value %s" % output) if ping_ext_host: error.base_context("Ping test from guest side," " dest: '%s'" % ext_host, logging.info) pkt_sizes = packet_sizes # There is no ping program for guest, so let's hardcode... cmd = ['ping'] cmd.append(ext_host) # external host if params.get("os_type") == "windows": cmd.append("-n 10") cmd.append("-l %s") # Windows doesn't support ping with packet # larger than '65500' pkt_sizes = [p for p in packet_sizes if p < 65500] # Add a packet size just equal '65500' for windows pkt_sizes.append(65500) else: cmd.append("-c 10") # ping 10 times cmd.append("-s %s") # packet size cmd = " ".join(cmd) for size in pkt_sizes: error.context("Ping with packet size %s" % size, logging.info) status, output = session.cmd_status_output(cmd % size, timeout=60) _get_loss_ratio(output) if status != 0: raise error.TestFail(("Ping external host failed," " status: %s, output: %s" % (status, output)))
def run(test, params, env): """ TestStep: 1) Exec the stap script in host 2) Boot the guest, and do some operation(if needed). 3) Check the output of the stap params: :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def create_patterns_reg(trace_key): """ Create a regular exp using the tracing key, the purpose is checking the systemtap output is accord with expected. """ pattern_reg = "" for tracing_key in trace_key.split(): pattern_reg += "%s=\d+," % tracing_key return pattern_reg.rstrip(",") error.base_context("Qemu_Tracing Test") error.context("Test start ...") probe_var_key = params.get("probe_var_key") checking_pattern_re = create_patterns_reg(probe_var_key) capdata_timeout = int(params.get("capdata_timeout", "360")) timeout = int(params.get("login_timeout", "360")) time_inter = int(params.get("time_inter", "1")) if params.get("extra_params"): params["extra_params"] = params.get("extra_params") if params.get("boot_with_cdrom") == 'yes': iso_path = "%s/test.iso" % data_dir.get_tmp_dir() create_cmd = "dd if=/dev/zero of=%s bs=1M count=10" % iso_path if utils.system(create_cmd, ignore_status=True) != 0: raise error.TestNAError("Create test iso failed") params["cdrom_cd1"] = iso_path if params.get("start_vm", "yes") == "no": params["start_vm"] = "yes" env_process.preprocess_vm(test, params, env, params.get("main_vm")) vm = env.get_vm(params["main_vm"]) vm.verify_alive() _params = params.object_params(vm.monitor.protocol) if _params.get("cmds_exec"): for cmd in _params.get("cmds_exec").split(","): if re.findall(":", cmd): cmd_type = cmd.split(":")[0] exec_cmds = cmd.split(":")[1] else: cmd_type = "bash" exec_cmds = cmd for cmd_exec in exec_cmds.split(";"): msg = "Execute %s cmd '%s'" % (cmd_type, cmd_exec) error.context(msg, logging.info) if cmd_type == "monitor": vm.monitor.send_args_cmd(cmd_exec) elif cmd_type == "bash": guest_session = vm.wait_for_login(timeout=timeout) guest_session.cmd(cmd_exec) error.context("Get the output of stap script", logging.info) stap_log_file = utils_misc.get_path(test.profdir, "systemtap.log") start_time = time.time() while (time.time() - start_time) < capdata_timeout: if os.path.isfile(stap_log_file): fd = open(stap_log_file, 'r') data = fd.read() if (not data) or (not re.findall(checking_pattern_re, data)): time.sleep(time_inter) fd.close() continue elif data and re.findall(checking_pattern_re, data): logging.info("Capture the data successfully") logging.info("The capture data is like: %s" % re.findall(checking_pattern_re, data)[-1]) fd.close() break else: time.sleep(time_inter) else: raise error.TestError("Timeout for capature the stap log data")
def run_openflow_test(test, params, env): """ Test Step: 1. Boot up two virtual machine 2. Set openflow rules 3. Run ping test, nc(tcp, udp) test, check whether openflow rules take effect. Params: :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def run_tcpdump_bg(session, addresses, dump_protocol): """ Run tcpdump in background, tcpdump will exit once catch a packet match the rules. """ tcpdump_cmd = "killall -9 tcpdump; " tcpdump_cmd += "tcpdump -iany -n -v %s and 'src %s and dst %s' -c 1 &" session.cmd_output_safe(tcpdump_cmd % (dump_protocol, addresses[0], addresses[1])) if not utils_misc.wait_for(lambda: tcpdump_is_alive(session), 30, 0, 1, "Waiting tcpdump start..."): raise error.TestNAError("Error, can not run tcpdump") def dump_catch_data(session, dump_log, catch_reg): """ Search data from dump_log """ dump_info = session.cmd_output("cat %s" % dump_log) if re.findall(catch_reg, dump_info, re.I): return True return False def tcpdump_is_alive(session): """ Check whether tcpdump is alive """ if session.cmd_status("pidof tcpdump"): return False return True def tcpdump_catch_packet_test(session, drop_flow=False): """ Check whether tcpdump catch match rules packets, once catch a packet match rules tcpdump will exit. when drop_flow is 'True', tcpdump couldn't catch any packets. """ packet_receive = not tcpdump_is_alive(session) if packet_receive == drop_flow: err_msg = "Error, flow %s dropped, tcpdump %s receive the packets" raise error.TestError(err_msg % ((drop_flow and "was" or "wasn't"), (packet_receive and "can" or "can not"))) logging.info("Correct, flow %s dropped, tcpdump %s receive the packet" % ((drop_flow and "was" or "was not"), (packet_receive and "can" or "can not"))) def arp_entry_clean(session, entry=None): """ Clean arp catch in guest """ if not entry: arp_clean_cmd = "arp -n | awk '/^[1-2]/{print \"arp -d \" $1}'|sh" else: arp_clean_cmd = "arp -d %s" % entry for session in sessions: session.cmd_output_safe(arp_clean_cmd) def ping_test(session, dst, drop_flow=False): """ Ping test, check icmp """ ping_status, ping_output = utils_test.ping(dest=dst, count=10, timeout=20, session=session) # when drop_flow is true, ping should failed(return not zero) # drop_flow is false, ping should success packets_lost = 100 if ping_status and not drop_flow: raise error.TestError("Ping should success when not drop_icmp") elif not ping_status: packets_lost = utils_test.get_loss_ratio(ping_output) if drop_flow and packets_lost != 100: raise error.TestError("When drop_icmp, ping shouldn't works") if not drop_flow and packets_lost == 100: raise error.TestError("When not drop_icmp, ping should works") info_msg = "Correct, icmp flow %s dropped, ping '%s', " info_msg += "packets lost rate is: '%s'" logging.info(info_msg % ((drop_flow and "was" or "was not"), (ping_status and "failed" or "success"), packets_lost)) def nc_connect_test(sessions, addresses, drop_flow=False, nc_port="8899", udp_model=False): """ Nc connect test, check tcp and udp """ nc_log = "/tmp/nc_log" server_cmd = "nc -l %s" client_cmd = "echo client | nc %s %s" if udp_model == True: server_cmd += " -u -w 3" client_cmd += " -u -w 3" server_cmd += " > %s &" client_cmd += " &" try: sessions[1].cmd_output_safe(server_cmd % (nc_port, nc_log)) sessions[0].cmd_output_safe(client_cmd % (addresses[1], nc_port)) nc_protocol = udp_model and "UDP" or "TCP" nc_connect = False if utils_misc.wait_for( lambda: dump_catch_data(sessions[1], nc_log, "client"), 10, 0, 2, text="Wait '%s' connect" % nc_protocol): nc_connect = True if nc_connect == drop_flow: err_msg = "Error, '%s' flow %s dropped, nc connect should '%s'" raise error.TestError(err_msg % (nc_protocol, (drop_flow and "was" or "was not"), (nc_connect and "failed" or "success"))) logging.info("Correct, '%s' flow %s dropped, and nc connect %s" % (nc_protocol, (drop_flow and "was" or "was not"), (nc_connect and "success" or "failed"))) finally: for session in sessions: session.cmd_output_safe("killall nc || killall ncat") session.cmd("%s %s" % (clean_cmd, nc_log), ignore_all_errors=True) timeout = int(params.get("login_timeout", '360')) clean_cmd = params.get("clean_cmd", "rm -f") sessions = [] addresses = [] vms = [] error.context("Init boot the vms") for vm_name in params.get("vms", "vm1 vm2").split(): vms.append(env.get_vm(vm_name)) for vm in vms: vm.verify_alive() sessions.append(vm.wait_for_login(timeout=timeout)) addresses.append(vm.get_address()) # set openflow rules: br_name = params.get("netdst", "ovs0") f_protocol = params.get("flow", "arp") f_base_options = "%s,nw_src=%s,nw_dst=%s" % (f_protocol, addresses[0], addresses[1]) for session in sessions: session.cmd("service iptables stop; iptables -F", ignore_all_errors=True) try: for drop_flow in [True, False]: if drop_flow: f_command = "add-flow" f_options = f_base_options + ",action=drop" drop_icmp = eval(params.get("drop_icmp", 'True')) drop_tcp = eval(params.get("drop_tcp", 'True')) drop_udp = eval(params.get("drop_udp", 'True')) else: f_command = "mod-flows" f_options = f_base_options + ",action=normal" drop_icmp = False drop_tcp = False drop_udp = False error.base_context("Test prepare") error.context("Do %s %s on %s" % (f_command, f_options, br_name)) utils_net.openflow_manager(br_name, f_command, f_options) error.context("Run tcpdump in guest %s" % vms[1].name, logging.info) run_tcpdump_bg(sessions[1], addresses, f_protocol) error.context("Clean arp cache in both guest", logging.info) arp_entry_clean(sessions[0], addresses[1]) error.base_context("Exec '%s' flow '%s' test" % (f_protocol, drop_flow and "drop" or "normal")) error.context("Ping test form vm1 to vm2", logging.info) ping_test(sessions[0], addresses[1], drop_icmp) error.context("Run nc connect test via tcp", logging.info) nc_connect_test(sessions, addresses, drop_tcp) error.context("Run nc connect test via udp", logging.info) nc_connect_test(sessions, addresses, drop_udp, udp_model=True) error.context("Check tcpdump data catch", logging.info) tcpdump_catch_packet_test(sessions[1], drop_flow) finally: utils_net.openflow_manager(br_name, "del-flows", f_protocol) for session in sessions: session.close()
def run(test, params, env): """ Test nic driver load/unload. 1) Boot a VM. 2) Get the NIC driver name. 3) Multi-session TCP transfer on test interface. 4) Repeatedly unload/load NIC driver during file transfer. 5) Check whether the test interface should still work. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def reset_guest_udevrules(session, rules_file, rules_content): """ Write guest udev rules, then reboot the guest and return the new session """ set_cmd = "echo '%s' > %s" % (rules_content, rules_file) session.cmd_output_safe(set_cmd) return vm.reboot() def all_threads_done(threads): """ Check whether all threads have finished """ for thread in threads: if thread.isAlive(): return False else: continue return True def all_threads_alive(threads): """ Check whether all threads is alive """ for thread in threads: if not thread.isAlive(): return False else: continue return True timeout = int(params.get("login_timeout", 360)) transfer_timeout = int(params.get("transfer_timeout", 1000)) filesize = int(params.get("filesize", 512)) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) vm_mac_address = vm.get_mac_address() udev_rules_file = "/etc/udev/rules.d/70-persistent-net.rules" rules = params.get("rules") if not session.cmd_status("[ -e %s ]" % udev_rules_file): if not rules: raise error.TestNAError("You must set udev rules before test") rules = rules % vm_mac_address session = reset_guest_udevrules(session, udev_rules_file, rules) error.base_context("Test env prepare") error.context("Get NIC interface name in guest.", logging.info) ethname = utils_net.get_linux_ifname(session, vm.get_mac_address(0)) # get ethernet driver from '/sys' directory. # ethtool can do the same thing and doesn't care about os type. # if we make sure all guests have ethtool, we can make a change here. sys_path = params.get("sys_path") % (ethname) # readlink in RHEL4.8 doesn't have '-e' param, should use '-f' in RHEL4.8. readlink_cmd = params.get("readlink_command", "readlink -e") driver = os.path.basename(session.cmd("%s %s" % (readlink_cmd, sys_path)).strip()) logging.info("The guest interface %s using driver %s" % (ethname, driver)) error.context("Host test file prepare, create %dMB file on host" % filesize, logging.info) tmp_dir = data_dir.get_tmp_dir() host_path = os.path.join(tmp_dir, "host_file_%s" % utils_misc.generate_random_string(8)) guest_path = os.path.join("/home", "guest_file_%s" % utils_misc.generate_random_string(8)) cmd = "dd if=/dev/zero of=%s bs=1M count=%d" % (host_path, filesize) utils.run(cmd) file_checksum = utils.hash_file(host_path, "md5") error.context("Guest test file prepare, Copy file %s from host to guest" % host_path, logging.info) vm.copy_files_to(host_path, guest_path, timeout=transfer_timeout) if session.cmd_status("md5sum %s | grep %s" % (guest_path, file_checksum)): raise error.TestNAError("File MD5SUMs changed after copy to guest") logging.info("Test env prepare successfully") error.base_context("Nic driver load/unload testing", logging.info) session_serial = vm.wait_for_serial_login(timeout=timeout) try: error.context("Transfer file between host and guest", logging.info) threads = [] file_paths = [] host_file_paths = [] for sess_index in range(int(params.get("sessions_num", "10"))): sess_path = os.path.join("/home", "dst-%s" % sess_index) host_sess_path = os.path.join(tmp_dir, "dst-%s" % sess_index) thread1 = utils.InterruptedThread(vm.copy_files_to, (host_path, sess_path), {"timeout": transfer_timeout}) thread2 = utils.InterruptedThread(vm.copy_files_from, (guest_path, host_sess_path), {"timeout": transfer_timeout}) thread1.start() threads.append(thread1) thread2.start() threads.append(thread2) file_paths.append(sess_path) host_file_paths.append(host_sess_path) utils_misc.wait_for(lambda: all_threads_alive(threads), 60, 10, 1) time.sleep(5) error.context("Repeatedly unload/load NIC driver during file transfer", logging.info) while not all_threads_done(threads): error.context("Shutdown the driver for NIC interface.", logging.info) session_serial.cmd_output_safe("ifconfig %s down" % ethname) error.context("Unload NIC driver.", logging.info) session_serial.cmd_output_safe("modprobe -r %s" % driver) error.context("Load NIC driver.", logging.info) session_serial.cmd_output_safe("modprobe %s" % driver) error.context("Activate NIC driver.", logging.info) session_serial.cmd_output_safe("ifconfig %s up" % ethname) session_serial.cmd_output_safe("sleep %s" % random.randint(10, 60)) # files md5sums check error.context("File transfer finished, checking files md5sums", logging.info) err_info = [] for copied_file in file_paths: if session_serial.cmd_status("md5sum %s | grep %s" % (copied_file, file_checksum)): err_msg = "Guest file %s md5sum changed" err_info.append(err_msg % copied_file) for copied_file in host_file_paths: if utils.system("md5sum %s | grep %s" % (copied_file, file_checksum)): err_msg = "Host file %s md5sum changed" err_info.append(err_msg % copied_file) if err_info: raise error.TestError("files MD5SUMs changed after copying %s" % err_info) except Exception: for thread in threads: thread.join(suppress_exception=True) raise else: for thread in threads: thread.join() for copied_file in file_paths: session_serial.cmd("rm -rf %s" % copied_file) for copied_file in host_file_paths: utils.system("rm -rf %s" % copied_file) session_serial.cmd("%s %s" % ("rm -rf", guest_path)) os.remove(host_path) session.close() session_serial.close()
def run_ping(test, params, env): """ Ping the guest with different size of packets. Packet Loss Test: 1) Ping the guest with different size/interval of packets. 2) Ping the external host from guest. (Optional) Stress Test: 1) Flood ping the guest. 2) Check if the network is still usable. @param test: KVM test object. @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ def _get_loss_ratio(output): if params.get("strict_check", "no") == "yes": ratio = utils_test.get_loss_ratio(output) if ratio != 0: raise error.TestFail("Loss ratio is %s" % ratio) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) ping_ext_host = params.get("ping_ext_host", "no") == "yes" if ping_ext_host: default_host = "www.redhat.com" ext_host_get_cmd = params.get("ext_host_get_cmd", "") try: ext_host = utils.system_output(ext_host_get_cmd) except error.CmdError: logging.warn("Can't get specified host with cmd '%s'," " Fallback to default host '%s'", ext_host_get_cmd, default_host) ext_host = default_host if not ext_host: # Fallback to a hardcode host, eg: ext_host = default_host counts = params.get("ping_counts", 100) flood_minutes = float(params.get("flood_minutes", 10)) packet_sizes = [0, 1, 4, 48, 512, 1440, 1500, 1505, 4054, 4055, 4096, 4192, 8878, 9000, 32767, 65507] try: for i, nic in enumerate(vm.virtnet): ip = vm.get_address(i) nic_name = nic.get("nic_name") if not ip: logging.error("Could not get the ip of nic index %d: %s", i, nic_name) continue error.base_context("Ping test on nic %s (index %d) from host" " side" % (nic_name, i), logging.info) for size in packet_sizes: error.context("Ping with packet size %s" % size, logging.info) status, output = utils_test.ping(ip, 10, packetsize=size, timeout=20) _get_loss_ratio(output) if status != 0: raise error.TestFail("Ping failed, status: %s," " output: %s" % (status, output)) error.context("Flood ping test", logging.info) utils_test.ping(ip, None, flood=True, output_func=None, timeout=flood_minutes * 60) error.context("Final ping test, Check if the network is still" " usable.", logging.info) status, output = utils_test.ping(ip, counts, timeout=float(counts) * 1.5) _get_loss_ratio(output) if status != 0: raise error.TestFail("Ping returns non-zero value %s" % output) if ping_ext_host: error.base_context("Ping test from guest side," " dest: '%s'" % ext_host, logging.info) # There is no ping program for guest, so let's hardcode... cmd = ['ping'] cmd.append(ext_host) # external host # Windows doesn't support ping with packet # larger than '65500' pkt_sizes = [p for p in packet_sizes if p < 65500] if params.get("os_type") == "windows": cmd.append("-n 10") cmd.append("-l %s") # Add a packet size just equal '65500' for windows pkt_sizes.append(65500) else: cmd.append("-c 10") # ping 10 times cmd.append("-s %s") # packet size cmd = " ".join(cmd) for size in pkt_sizes: error.context("Ping with packet size %s" % size, logging.info) status, output = session.cmd_status_output(cmd % size, timeout=20) _get_loss_ratio(output) if status != 0: raise error.TestFail(("Ping external host failed," " status: %s, output: %s" % (status, output))) finally: session.close()
def run_ping(test, params, env): """ Ping the guest with different size of packets. Packet Loss Test: 1) Ping the guest with different size/interval of packets. 2) Ping the external host from guest. (Optional) Stress Test: 1) Flood ping the guest. 2) Check if the network is still usable. @param test: KVM test object. @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ def _get_loss_ratio(output): if params.get("strict_check", "no") == "yes": ratio = utils_test.get_loss_ratio(output) if ratio != 0: raise error.TestFail("Loss ratio is %s" % ratio) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) ping_ext_host = params.get("ping_ext_host", "no") == "yes" if ping_ext_host: default_host = "www.redhat.com" ext_host_get_cmd = params.get("ext_host_get_cmd", "") try: ext_host = utils.system_output(ext_host_get_cmd) except error.CmdError: logging.warn( "Can't get specified host with cmd '%s'," " Fallback to default host '%s'", ext_host_get_cmd, default_host) ext_host = default_host if not ext_host: # Fallback to a hardcode host, eg: ext_host = default_host counts = params.get("ping_counts", 100) flood_minutes = float(params.get("flood_minutes", 10)) packet_sizes = [ 0, 1, 4, 48, 512, 1440, 1500, 1505, 4054, 4055, 4096, 4192, 8878, 9000, 32767, 65507 ] try: for i, nic in enumerate(vm.virtnet): ip = vm.get_address(i) nic_name = nic.get("nic_name") if not ip: logging.error("Could not get the ip of nic index %d: %s", i, nic_name) continue error.base_context( "Ping test on nic %s (index %d) from host" " side" % (nic_name, i), logging.info) for size in packet_sizes: error.context("Ping with packet size %s" % size, logging.info) status, output = utils_test.ping(ip, 10, packetsize=size, timeout=20) _get_loss_ratio(output) if status != 0: raise error.TestFail("Ping failed, status: %s," " output: %s" % (status, output)) error.context("Flood ping test", logging.info) utils_test.ping(ip, None, flood=True, output_func=None, timeout=flood_minutes * 60) error.context( "Final ping test, Check if the network is still" " usable.", logging.info) status, output = utils_test.ping(ip, counts, timeout=float(counts) * 1.5) _get_loss_ratio(output) if status != 0: raise error.TestFail("Ping returns non-zero value %s" % output) if ping_ext_host: error.base_context( "Ping test from guest side," " dest: '%s'" % ext_host, logging.info) # There is no ping program for guest, so let's hardcode... cmd = ['ping'] cmd.append(ext_host) # external host # Windows doesn't support ping with packet # larger than '65500' pkt_sizes = [p for p in packet_sizes if p < 65500] if params.get("os_type") == "windows": cmd.append("-n 10") cmd.append("-l %s") # Add a packet size just equal '65500' for windows pkt_sizes.append(65500) else: cmd.append("-c 10") # ping 10 times cmd.append("-s %s") # packet size cmd = " ".join(cmd) for size in pkt_sizes: error.context("Ping with packet size %s" % size, logging.info) status, output = session.cmd_status_output(cmd % size, timeout=20) _get_loss_ratio(output) if status != 0: raise error.TestFail( ("Ping external host failed," " status: %s, output: %s" % (status, output))) finally: session.close()
def run(test, params, env): """ Suspend a running Virtual Machine and verify its state. 1) Boot the vm 2) Do preparation operation (Optional) 3) Start a background process (Optional) 4) Stop the VM 5) Verify the status of VM is 'paused' 6) Verify the session has no response 7) Resume the VM 8) Verify the status of VM is 'running' 9) Re-login the guest 10) Do check operation (Optional) 11) Do clean operation (Optional) :param test: Kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() login_timeout = float(params.get("login_timeout", 240)) session = vm.wait_for_login(timeout=login_timeout) session_bg = None start_bg_process = params.get("start_bg_process") try: prepare_op = params.get("prepare_op") if prepare_op: error.context("Do preparation operation: '%s'" % prepare_op, logging.info) op_timeout = float(params.get("prepare_op_timeout", 60)) session.cmd(prepare_op, timeout=op_timeout) if start_bg_process: bg_cmd = params.get("bg_cmd") error.context("Start a background process: '%s'" % bg_cmd, logging.info) session_bg = vm.wait_for_login(timeout=login_timeout) bg_cmd_timeout = float(params.get("bg_cmd_timeout", 240)) args = (bg_cmd, bg_cmd_timeout) bg = utils_test.BackgroundTest(session_bg.cmd, args) bg.start() error.base_context("Stop the VM", logging.info) vm.pause() error.context("Verify the status of VM is 'paused'", logging.info) vm.verify_status("paused") error.context("Verify the session has no response", logging.info) if session.is_responsive(): msg = "Session is still responsive after stop" logging.error(msg) raise error.TestFail(msg) error.base_context("Resume the VM", logging.info) vm.resume() error.context("Verify the status of VM is 'running'", logging.info) vm.verify_status("running") error.context("Re-login the guest", logging.info) session = vm.wait_for_login(timeout=login_timeout) if start_bg_process: if bg: bg.join() check_op = params.get("check_op") if check_op: error.context("Do check operation: '%s'" % check_op, logging.info) op_timeout = float(params.get("check_op_timeout", 60)) s, o = session.cmd_status_output(check_op, timeout=op_timeout) if s != 0: raise error.TestFail("Something wrong after stop continue, " "check command report: %s" % o) finally: clean_op = params.get("clean_op") if clean_op: error.context("Do clean operation: '%s'" % clean_op, logging.info) op_timeout = float(params.get("clean_op_timeout", 60)) session.cmd(clean_op, timeout=op_timeout, ignore_all_errors=True)
def run(test, params, env): """ KVM migration test: 1) Start a guest. 2) Start netperf server in guest. 3) Start multi netperf clients in host. 4) Migrate the guest in local during netperf clients working. 5) Repeatedly migrate VM and wait until netperf clients stopped. :param test: QEMU test object. :param params: Dictionary with test parameters. :param env: Dictionary with the test environment. """ login_timeout = int(params.get("login_timeout", 360)) 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 netperf_timeout = int(params.get("netperf_timeout", "300")) client_num = int(params.get("client_num", "100")) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) guest_address = vm.get_address() host_address = utils_net.get_host_ip_address(params) remote_ip = params.get("remote_host", host_address) netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"), params.get("netperf_link")) md5sum = params.get("pkg_md5sum") netperf_link_win = params.get("netperf_link_win") if netperf_link_win: netperf_link_win = utils_misc.get_path(data_dir.get_deps_dir("netperf"), netperf_link_win) netperf_md5sum_win = params.get("netperf_md5sum_win") netperf_server_link = params.get("netperf_server_link", netperf_link) server_md5sum = params.get("server_md5sum", md5sum) netperf_server_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"), netperf_server_link) server_path = params.get("server_path", "/var/tmp/") client_path = params.get("client_path", "/var/tmp/") server_path_win = params.get("server_path_win") client_path_win = params.get("client_path_win") username = params.get("username", "root") password = params.get("password", "redhat") passwd = params.get("hostpasswd", "redhat") client = params.get("shell_client", "ssh") port = params.get("shell_port", "22") if params.get("os_type") == "linux": session.cmd("iptables -F", ignore_all_errors=True) g_client_link = netperf_link g_server_path = server_path g_client_path = client_path g_client_install = False elif params.get("os_type") == "windows": g_client_link = netperf_link_win g_server_path = server_path_win g_client_path = client_path_win md5sum = netperf_md5sum_win g_client_install = True netperf_client_g = None netperf_client_h = None netperf_server_g = None netperf_server_h = None try: netperf_client_g = utils_netperf.NetperfClient(guest_address, g_client_path, md5sum, g_client_link, client=client, port=port, username=username, password=password, install=g_client_install) netperf_server_h = utils_netperf.NetperfServer(remote_ip, server_path, server_md5sum, netperf_link, password=passwd, install=False) netperf_client_h = utils_netperf.NetperfClient(remote_ip, client_path, md5sum, netperf_link, password=passwd) netperf_server_g = utils_netperf.NetperfServer(guest_address, g_server_path, server_md5sum, netperf_server_link, client=client, port=port, username=username, password=password) error.base_context("Run netperf test between host and guest") error.context("Start netserver in guest.", logging.info) netperf_server_g.start() if netperf_server_h: error.context("Start netserver in host.", logging.info) netperf_server_h.start() error.context("Start Netperf in host", logging.info) test_option = "-l %s" % netperf_timeout netperf_client_h.bg_start(guest_address, test_option, client_num) if netperf_client_g: error.context("Start Netperf in guest", logging.info) netperf_client_g.bg_start(host_address, test_option, client_num) m_count = 0 while netperf_client_h.is_netperf_running(): m_count += 1 error.context("Start migration iterations: %s " % m_count, logging.info) vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay, env=env) finally: if netperf_server_g: if netperf_server_g.is_server_running(): netperf_server_g.stop() netperf_server_g.package.env_cleanup(True) if netperf_server_h: if netperf_server_h.is_server_running(): netperf_server_h.stop() netperf_server_h.package.env_cleanup(True) if netperf_client_h: if netperf_client_h.is_netperf_running(): netperf_client_h.stop() netperf_client_h.package.env_cleanup(True) if netperf_client_g: if netperf_client_g.is_netperf_running(): netperf_client_g.stop() netperf_client_g.package.env_cleanup(True) if session: session.close()
def run_nicdriver_unload(test, params, env): """ Test nic driver load/unload. 1) Boot a VM. 2) Get the NIC driver name. 3) Multi-session TCP transfer on test interface. 4) Repeatedly unload/load NIC driver during file transfer. 5) Check whether the test interface should still work. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def all_threads_done(threads): for thread in threads: if thread.isAlive(): return False else: continue return True def all_threads_alive(threads): for thread in threads: if not thread.isAlive(): return False else: continue return True timeout = int(params.get("login_timeout", 360)) transfer_timeout = int(params.get("transfer_timeout", 1000)) filesize = int(params.get("filesize", 512)) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) error.base_context("Test env prepare") error.context("Get NIC interface name in guest.", logging.info) ethname = utils_net.get_linux_ifname(session, vm.get_mac_address(0)) # get ethernet driver from '/sys' directory. # ethtool can do the same thing and doesn't care about os type. # if we make sure all guests have ethtool, we can make a change here. sys_path = params.get("sys_path") % (ethname) # readlink in RHEL4.8 doesn't have '-e' param, should use '-f' in RHEL4.8. readlink_cmd = params.get("readlink_command", "readlink -e") driver = os.path.basename( session.cmd("%s %s" % (readlink_cmd, sys_path)).strip()) logging.info("The guest interface %s using driver %s" % (ethname, driver)) error.context( "Host test file prepare, create %dMB file on host" % filesize, logging.info) tmp_dir = data_dir.get_tmp_dir() host_path = os.path.join( tmp_dir, "host_file_%s" % utils_misc.generate_random_string(8)) guest_path = os.path.join( "/home", "guest_file_%s" % utils_misc.generate_random_string(8)) cmd = "dd if=/dev/zero of=%s bs=1M count=%d" % (host_path, filesize) utils.run(cmd) file_checksum = utils.hash_file(host_path, "md5") error.context( "Guest test file prepare, Copy file %s from host to guest" % host_path, logging.info) vm.copy_files_to(host_path, guest_path, timeout=transfer_timeout) if session.cmd_status("md5sum %s | grep %s" % (guest_path, file_checksum)): raise error.TestNAError("File MD5SUMs changed after copy to guest") logging.info("Test env prepare successfully") error.base_context("Nic driver load/unload testing", logging.info) session_serial = vm.wait_for_serial_login(timeout=timeout) try: error.context("Transfer file between host and guest", logging.info) threads = [] file_paths = [] host_file_paths = [] for sess_index in range(int(params.get("sessions_num", "10"))): sess_path = os.path.join("/home", "dst-%s" % sess_index) host_sess_path = os.path.join(tmp_dir, "dst-%s" % sess_index) thread1 = utils.InterruptedThread(vm.copy_files_to, (host_path, sess_path), {"timeout": transfer_timeout}) thread2 = utils.InterruptedThread(vm.copy_files_from, (guest_path, host_sess_path), {"timeout": transfer_timeout}) thread1.start() threads.append(thread1) thread2.start() threads.append(thread2) file_paths.append(sess_path) host_file_paths.append(host_sess_path) utils_misc.wait_for(lambda: all_threads_alive(threads), 60, 10, 1) time.sleep(5) error.context("Repeatedly unload/load NIC driver during file transfer", logging.info) while not all_threads_done(threads): error.context("Shutdown the driver for NIC interface.", logging.info) session_serial.cmd_output_safe("ifconfig %s down" % ethname) error.context("Unload NIC driver.", logging.info) session_serial.cmd_output_safe("modprobe -r %s" % driver) error.context("Load NIC driver.", logging.info) session_serial.cmd_output_safe("modprobe %s" % driver) error.context("Activate NIC driver.", logging.info) session_serial.cmd_output_safe("ifconfig %s up" % ethname) session_serial.cmd_output_safe("sleep %s" % random.randint(10, 60)) # files md5sums check error.context("File transfer finished, checking files md5sums", logging.info) err_info = [] for copied_file in file_paths: if session_serial.cmd_status("md5sum %s | grep %s" % (copied_file, file_checksum)): err_msg = "Guest file %s md5sum changed" err_info.append(err_msg % copied_file) for copied_file in host_file_paths: if utils.system("md5sum %s | grep %s" % (copied_file, file_checksum)): err_msg = "Host file %s md5sum changed" err_info.append(err_msg % copied_file) if err_info: raise error.TestError("files MD5SUMs changed after copying %s" % err_info) except Exception: for thread in threads: thread.join(suppress_exception=True) raise else: for thread in threads: thread.join() for copied_file in file_paths: session_serial.cmd("rm -rf %s" % copied_file) for copied_file in host_file_paths: utils.system("rm -rf %s" % copied_file) session_serial.cmd("%s %s" % ("rm -rf", guest_path)) os.remove(host_path) session.close() session_serial.close()
try: for drop_flow in [True, False]: if drop_flow: f_command = "add-flow" f_options = f_base_options + ",action=drop" drop_icmp = eval(params.get("drop_icmp", 'True')) drop_tcp = eval(params.get("drop_tcp", 'True')) drop_udp = eval(params.get("drop_udp", 'True')) else: f_command = "mod-flows" f_options = f_base_options + ",action=normal" drop_icmp = False drop_tcp = False drop_udp = False error.base_context("Test prepare") error.context("Do %s %s on %s" % (f_command, f_options, br_name)) utils_net.openflow_manager(br_name, f_command, f_options) acl_rules = utils_net.openflow_manager(br_name, "dump-flows").stdout if not acl_rules_check(acl_rules, f_options): raise error.TestFail("Can not find the rules from" " ovs-ofctl: %s" % acl_rules) error.context("Run tcpdump in guest %s" % vms[1].name, logging.info) run_tcpdump_bg(sessions[1], addresses, f_protocol) if drop_flow or f_protocol is not "arp": error.context("Clean arp cache in both guest", logging.info) arp_entry_clean(addresses[1])