def load_stress(vms, stress_type, params={}): """ Load different stress in vm: unixbench, stress, running vms and so on """ fail_info = [] # Special operations for test if stress_type in ["stress_in_vms", "stress_on_host"]: logging.debug("Run stress %s", stress_type) fail_info = utils_test.load_stress(stress_type, vms, params) elif stress_type == "inject_nmi": inject_times = int(params.get("inject_times", 10)) for vm in vms: while inject_times > 0: try: inject_times -= 1 virsh.inject_nmi(vm.name, debug=True, ignore_status=False) except error.CmdError, detail: fail_info.append("Inject operations failed:%s", detail)
def load_stress(vms, stress_type, params={}): """ Load different stress in vm: unixbench, stress, running vms and so on """ fail_info = [] # Special operations for test if stress_type in ["stress_in_vms", "stress_on_host"]: logging.debug("Run stress %s", stress_type) fail_info = utils_test.load_stress(stress_type, vms, params) elif stress_type == "inject_nmi": inject_times = int(params.get("inject_times", 10)) for vm in vms: while inject_times > 0: try: inject_times -= 1 virsh.inject_nmi(vm.name, debug=True, ignore_status=False) except error.CmdError, detail: fail_info.append("Inject operations failed:%s", detail)
def manipulate_vm(vm, operation, params=None): """ Manipulate the VM. :param vm: VM instance :param operation: stress_in_vms, inject_nmi, dump, suspend_resume or save_restore :param params: Test parameters """ err_msg = '' # Special operations for test if operation == "stress": logging.debug("Load stress in VM") err_msg = utils_test.load_stress(operation, [vm], params)[0] elif operation == "inject_nmi": inject_times = int(params.get("inject_times", 10)) logging.info("Trying to inject nmi %s times", inject_times) while inject_times > 0: try: inject_times -= 1 virsh.inject_nmi(vm.name, debug=True, ignore_status=False) except error.CmdError, detail: err_msg = "Inject nmi failed: %s" % detail
def manipulate_vm(vm, operation, params=None): """ Manipulate the VM. :param vm: VM instance :param operation: stress_in_vms, inject_nmi, dump, suspend_resume or save_restore :param params: Test parameters """ err_msg = '' # Special operations for test if operation == "stress": logging.debug("Load stress in VM") err_msg = utils_test.load_stress(operation, [vm], params)[0] elif operation == "inject_nmi": inject_times = int(params.get("inject_times", 10)) logging.info("Trying to inject nmi %s times", inject_times) while inject_times > 0: try: inject_times -= 1 virsh.inject_nmi(vm.name, debug=True, ignore_status=False) except error.CmdError, detail: err_msg = "Inject nmi failed: %s" % detail
def run(test, params, env): """ 1. Configure kernel cmdline to support kdump 2. Start kdump service 3. Inject NMI to the guest 4. Check NMI times """ for cmd in 'inject-nmi', 'qemu-monitor-command': if not virsh.has_help_command(cmd): test.cancel( "This version of libvirt does not " " support the %s test", cmd) vm_name = params.get("main_vm", "avocado-vt-vm1") vm = env.get_vm(vm_name) start_vm = params.get("start_vm") expected_nmi_times = params.get("expected_nmi_times", '0') kernel_params = params.get("kernel_params", "") unprivileged_user = params.get('unprivileged_user') if unprivileged_user: if unprivileged_user.count('EXAMPLE'): unprivileged_user = '******' if not libvirt_version.version_compare(1, 1, 1): if params.get('setup_libvirt_polkit') == 'yes': test.cancel("API acl test not supported in current" " libvirt version.") try: if kernel_params: update_boot_option_and_reboot(vm, kernel_params, test) if start_vm == "yes": # start kdump service in the guest cmd = "which kdump" try: run_cmd_in_guest(vm, cmd, test) except Exception: try: # try to install kexec-tools on fedoraX/rhelx.y guest run_cmd_in_guest(vm, "yum install -y kexec-tools", test) except Exception: test.error( "Requires kexec-tools(or the equivalent for your distro)" ) # enable kdump service in the guest cmd = "service kdump start" run_cmd_in_guest(vm, cmd, test, timeout=120) # filter original 'NMI' information from the /proc/interrupts cmd = "grep NMI /proc/interrupts" nmi_str = run_cmd_in_guest(vm, cmd, test) # filter CPU from the /proc/cpuinfo and count number cmd = "grep -E '^process' /proc/cpuinfo | wc -l" vcpu_num = run_cmd_in_guest(vm, cmd, test).strip() logging.info("Inject NMI to the guest via virsh inject_nmi") virsh.inject_nmi(vm_name, debug=True, ignore_status=False) logging.info( "Inject NMI to the guest via virsh qemu_monitor_command") virsh.qemu_monitor_command(vm_name, '{"execute":"inject-nmi"}') # injects a Non-Maskable Interrupt into the default CPU (x86/s390) # or all CPUs (ppc64), as usual, the default CPU index is 0 cmd = "grep NMI /proc/interrupts | awk '{print $2}'" nmi_from_default_vcpu = run_cmd_in_guest(vm, cmd, test) real_nmi_times = nmi_from_default_vcpu.splitlines()[0] logging.debug("The current Non-Maskable Interrupts: %s", real_nmi_times) # check Non-maskable interrupts times if real_nmi_times != expected_nmi_times: test.fail("NMI times aren't expected %s:%s" % (real_nmi_times, expected_nmi_times)) finally: if kernel_params: cmd = "grubby --update-kernel=`grubby --default-kernel` --remove-args='%s'" % kernel_params run_cmd_in_guest(vm, cmd, test) vm.reboot()
def run(test, params, env): """ 1. Configure kernel cmdline to support kdump 2. Start kdump service 3. Inject NMI to the guest 4. Check NMI times """ for cmd in 'inject-nmi', 'qemu-monitor-command': if not virsh.has_help_command(cmd): raise error.TestNAError("This version of libvirt does not " " support the %s test", cmd) vm_name = params.get("main_vm", "virt-tests-vm1") vm = env.get_vm(vm_name) start_vm = params.get("start_vm") expected_nmi_times = params.get("expected_nmi_times", '0') unprivileged_user = params.get('unprivileged_user') if unprivileged_user: if unprivileged_user.count('EXAMPLE'): unprivileged_user = '******' if not libvirt_version.version_compare(1, 1, 1): if params.get('setup_libvirt_polkit') == 'yes': raise error.TestNAError("API acl test not supported in current" " libvirt version.") if start_vm == "yes": # start kdump service in the guest cmd = "which kdump" try: run_cmd_in_guest(vm, cmd) except: try: # try to install kexec-tools on fedoraX/rhelx.y guest run_cmd_in_guest(vm, "yum install -y kexec-tools") except: raise error.TestNAError("Requires kexec-tools(or the " "equivalent for your distro)") # enable kdump service in the guest cmd = "service kdump start" run_cmd_in_guest(vm, cmd) # filter original 'NMI' information from the /proc/interrupts cmd = "grep NMI /proc/interrupts" nmi_str = run_cmd_in_guest(vm, cmd) # filter CPU from the /proc/cpuinfo and count number cmd = "grep -E '^process' /proc/cpuinfo | wc -l" vcpu_num = run_cmd_in_guest(vm, cmd).strip() logging.info("Inject NMI to the guest via virsh inject_nmi") virsh.inject_nmi(vm_name, debug=True, ignore_status=False) logging.info("Inject NMI to the guest via virsh qemu_monitor_command") virsh.qemu_monitor_command(vm_name, '{"execute":"inject-nmi"}') # injects a Non-Maskable Interrupt into the default CPU (x86/s390) # or all CPUs (ppc64), as usual, the default CPU index is 0 cmd = "grep NMI /proc/interrupts | awk '{print $2}'" nmi_from_default_vcpu = run_cmd_in_guest(vm, cmd) real_nmi_times = nmi_from_default_vcpu.splitlines()[0] logging.debug("The current Non-Maskable Interrupts: %s", real_nmi_times) # check Non-maskable interrupts times if real_nmi_times != expected_nmi_times: raise error.TestFail("NMI times aren't expected %s:%s", real_nmi_times, expected_nmi_times)
def manipulate_vm(vm, operation, params=None): """ Manipulate the VM. :param vm: VM instance :param operation: stress_in_vms, inject_nmi, dump, suspend_resume or save_restore :param params: Test parameters """ err_msg = '' # Special operations for test if operation == "stress": logging.debug("Load stress in VM") err_msg = utils_test.load_stress(operation, params=params, vms=[vm])[0] elif operation == "inject_nmi": inject_times = int(params.get("inject_times", 10)) logging.info("Trying to inject nmi %s times", inject_times) while inject_times > 0: try: inject_times -= 1 virsh.inject_nmi(vm.name, debug=True, ignore_status=False) except process.CmdError as detail: err_msg = "Inject nmi failed: %s" % detail elif operation == "dump": dump_times = int(params.get("dump_times", 10)) logging.info("Trying to dump vm %s times", dump_times) while dump_times > 0: dump_times -= 1 dump_path = os.path.join(data_dir.get_tmp_dir(), "dump.file") try: virsh.dump(vm.name, dump_path, debug=True, ignore_status=False) except (process.CmdError, OSError) as detail: err_msg = "Dump %s failed: %s" % (vm.name, detail) try: os.remove(dump_path) except OSError: pass elif operation == "suspend_resume": paused_times = int(params.get("paused_times", 10)) logging.info("Trying to suspend/resume vm %s times", paused_times) while paused_times > 0: paused_times -= 1 try: virsh.suspend(vm.name, debug=True, ignore_status=False) virsh.resume(vm.name, debug=True, ignore_status=False) except process.CmdError as detail: err_msg = "Suspend-Resume %s failed: %s" % (vm.name, detail) elif operation == "save_restore": save_times = int(params.get("save_times", 10)) logging.info("Trying to save/restore vm %s times", save_times) while save_times > 0: save_times -= 1 save_path = os.path.join(data_dir.get_tmp_dir(), "save.file") try: virsh.save(vm.name, save_path, debug=True, ignore_status=False) virsh.restore(save_path, debug=True, ignore_status=False) except process.CmdError as detail: err_msg = "Save-Restore %s failed: %s" % (vm.name, detail) try: os.remove(save_path) except OSError: pass else: err_msg = "Unsupported operation in this function: %s" % operation return err_msg
def manipulate_vm(vm, operation, params=None): """ Manipulate the VM. :param vm: VM instance :param operation: stress_in_vms, inject_nmi, dump, suspend_resume or save_restore :param params: Test parameters """ err_msg = '' # Special operations for test if operation == "stress": logging.debug("Load stress in VM") err_msg = utils_test.load_stress(operation, params=params, vms=[vm])[0] elif operation == "inject_nmi": inject_times = int(params.get("inject_times", 10)) logging.info("Trying to inject nmi %s times", inject_times) while inject_times > 0: try: inject_times -= 1 virsh.inject_nmi(vm.name, debug=True, ignore_status=False) except process.CmdError as detail: err_msg = "Inject nmi failed: %s" % detail elif operation == "dump": dump_times = int(params.get("dump_times", 10)) logging.info("Trying to dump vm %s times", dump_times) while dump_times > 0: dump_times -= 1 dump_path = os.path.join(data_dir.get_tmp_dir(), "dump.file") try: virsh.dump(vm.name, dump_path, debug=True, ignore_status=False) except (process.CmdError, OSError) as detail: err_msg = "Dump %s failed: %s" % (vm.name, detail) try: os.remove(dump_path) except OSError: pass elif operation == "suspend_resume": paused_times = int(params.get("paused_times", 10)) logging.info("Trying to suspend/resume vm %s times", paused_times) while paused_times > 0: paused_times -= 1 try: virsh.suspend(vm.name, debug=True, ignore_status=False) virsh.resume(vm.name, debug=True, ignore_status=False) except process.CmdError as detail: err_msg = "Suspend-Resume %s failed: %s" % (vm.name, detail) elif operation == "save_restore": save_times = int(params.get("save_times", 10)) logging.info("Trying to save/restore vm %s times", save_times) while save_times > 0: save_times -= 1 save_path = os.path.join(data_dir.get_tmp_dir(), "save.file") try: virsh.save(vm.name, save_path, debug=True, ignore_status=False) virsh.restore(save_path, debug=True, ignore_status=False) except process.CmdError as detail: err_msg = "Save-Restore %s failed: %s" % (vm.name, detail) try: os.remove(save_path) except OSError: pass else: err_msg = "Unsupport operation in this function: %s" % operation return err_msg