def get_info(self, name): infos = {} for line in virsh.dominfo(name).stdout.strip().splitlines(): key, value = line.split(':', 1) infos[key.lower()] = value.strip() infos['inactive xml'] = virsh.dumpxml( name, extra='--inactive').stdout.splitlines() return infos
def check_dominfo_and_ausearch(dominfo_check, ausearch_check): """ Check output of virsh dominfo and ausearch command :param dominfo_check: patterns to search in dominfo output :param ausearch_check: patterns to search in ausearch output """ if dominfo_check: dominfo = virsh.dominfo(vm_name, **VIRSH_ARGS) libvirt.check_result(dominfo, expected_match=dominfo_check) if ausearch_check: ausearch_result = process.run(audit_cmd, verbose=True, shell=True) libvirt.check_result(ausearch_result, expected_match=ausearch_check)
def check_dominfo(test, vm_name, deprecated_list, empty=False): """ Check a virsh dominfo for a 'Messages' section and particular deprecated features. :param test: Test instance. :param vm_name: Name of the VM to be checked for dominfo :param deprecated_list: List of deprecated items expected in dominfo. :param empty: Flag used for checking the Messages section, for no Messages section is set to True. """ res = virsh.dominfo(vm_name) tainted_message = "tainted: use of deprecated configuration settings" if tainted_message not in res.stdout_text: if empty: logging.debug( "No Messages are found in dominfo output as expected.") else: test.fail("There is no tainted deprecated message: {} in dominfo " "output: {}".format(tainted_message, res.stdout_text)) else: if empty: test.fail("Tainted deprecated message: '{}' found in dominfo: {}," "but no Messages output is expected in dominfo.".format( tainted_message, res.stdout_text)) else: logging.debug( "Tainted deprecated message: '{}' found in dominfo.".format( tainted_message)) if not empty: for item in deprecated_list: deprecated_message = "deprecated configuration:.*'{}'".format(item) found = False for line in res.stdout_text.split('\n'): if re.search(deprecated_message, line): found = True break if not found: test.fail("There is no deprecated configuration: {} found in " "dominfo output: {}".format(deprecated_message, res.stdout_text)) else: logging.debug("Deprecated configuration: {} found in dominfo " "output.".format(deprecated_message))
def run_virsh_dominfo(test, params, env): """ Test command: virsh dominfo. The command returns basic information about the domain. 1.Prepare test environment. 2.When the libvirtd == "off", stop the libvirtd service. 3.Perform virsh dominfo operation. 4.Recover test environment. 5.Confirm the test result. """ vm_name = params.get("main_vm", "vm1") vm = env.get_vm(vm_name) if vm.is_alive() and params.get("start_vm") == "no": vm.destroy() domid = vm.get_id() domuuid = vm.get_uuid() vm_ref = params.get("dominfo_vm_ref") extra = params.get("dominfo_extra", "") status_error = params.get("status_error", "no") libvirtd = params.get("libvirtd", "on") def remote_test(params, vm_name): """ Test remote case. """ remote_ip = params.get("remote_ip", "REMOTE.EXAMPLE.COM") local_ip = params.get("local_ip", "LOCAL.EXAMPLE.COM") remote_pwd = params.get("remote_pwd", "") status = 0 output = "" err = "" try: if remote_ip.count("EXAMPLE.COM") or local_ip.count("EXAMPLE.COM"): raise error.TestNAError("remote_ip and/or local_ip parameters " "not changed from default values.") uri = libvirt_vm.complete_uri(local_ip) session = remote.remote_login("ssh", remote_ip, "22", "root", remote_pwd, "#") session.cmd_output('LANG=C') command = "virsh -c %s dominfo %s" % (uri, vm_name) status, output = session.cmd_status_output(command, internal_timeout=5) if status != 0: err = output session.close() except error.CmdError: status = 1 output = "" err = "remote test failed" return status, output, err #run test case if vm_ref == "id": vm_ref = domid elif vm_ref == "hex_id": vm_ref = hex(int(domid)) elif vm_ref.find("invalid") != -1: vm_ref = params.get(vm_ref) elif vm_ref == "name": vm_ref = "%s %s" % (vm_name, extra) elif vm_ref == "uuid": vm_ref = domuuid if libvirtd == "off": utils_libvirtd.libvirtd_stop() if vm_ref != "remote": result = virsh.dominfo(vm_ref, ignore_status=True) status = result.exit_status output = result.stdout.strip() err = result.stderr.strip() else: status, output, err = remote_test(params, vm_name) #recover libvirtd service start if libvirtd == "off": utils_libvirtd.libvirtd_start() #check status_error if status_error == "yes": if status == 0 or err == "": raise error.TestFail("Run successfully with wrong command!") elif status_error == "no": if status != 0 or output == "": raise error.TestFail("Run failed with right command")
def run_test_audit_size(case): """ Audit memory size with memory hot-plug/unplug operations :param case: test case """ numa_node_size = int(params.get('numa_node_size')) at_size = int(params.get('at_size')) current_mem = int(params.get('vmxml_current_mem')) audit_cmd = params.get('audit_cmd') dominfo_check_0 = params.get('dominfo_check_0') % ( numa_node_size * 2, current_mem) dominfo_check_1 = params.get('dominfo_check_1') % ( numa_node_size * 2 + at_size, current_mem + at_size ) ausearch_check_1 = params.get('ausearch_check_1') % ( 0, numa_node_size * 2, numa_node_size * 2, numa_node_size * 2 + at_size ) ausearch_check_2 = params.get('ausearch_check_2') % ( numa_node_size * 2 + at_size, numa_node_size * 2 + at_size ) dominfo_check_3 = dominfo_check_0 ausearch_check_3 = params.get('ausearch_check_3') % ( numa_node_size * 2 + at_size, numa_node_size * 2 ) # Start vm and wait for vm to bootup vm.start() vm.wait_for_login().close() logging.debug('Vmxml after started:\n%s', virsh.dumpxml(vm_name).stdout_text) # Check dominfo before hotplug mem device dominfo = virsh.dominfo(vm_name, **VIRSH_ARGS) libvirt.check_result(dominfo, expected_match=dominfo_check_0) # Prepare dimm memory devices to be attached dimm_devices = [] for i in (0, 1): dimm_device = Memory() dimm_device_attrs = eval( params.get('dimm_device_%d_attrs' % i, '{}')) dimm_device.setup_attrs(**dimm_device_attrs) dimm_devices.append(dimm_device) def check_dominfo_and_ausearch(dominfo_check, ausearch_check): """ Check output of virsh dominfo and ausearch command :param dominfo_check: patterns to search in dominfo output :param ausearch_check: patterns to search in ausearch output """ if dominfo_check: dominfo = virsh.dominfo(vm_name, **VIRSH_ARGS) libvirt.check_result(dominfo, expected_match=dominfo_check) if ausearch_check: ausearch_result = process.run(audit_cmd, verbose=True, shell=True) libvirt.check_result(ausearch_result, expected_match=ausearch_check) # Hotplug dimm device to guest virsh.attach_device(vm_name, dimm_devices[1].xml, **VIRSH_ARGS) check_dominfo_and_ausearch(dominfo_check_1, ausearch_check_1) # Hotplug dimm device with size 0 G, should fail with error message at_result = virsh.attach_device(vm_name, dimm_devices[0].xml, debug=True) libvirt.check_result(at_result, error_msg) check_dominfo_and_ausearch(None, ausearch_check_2) # HotUnplug the dimm device virsh.detach_device(vm_name, dimm_devices[1].xml, **VIRSH_ARGS) check_dominfo_and_ausearch(dominfo_check_3, ausearch_check_3)
def run(test, params, env): """ Test command: virsh dominfo. The command returns basic information about the domain. 1.Prepare test environment. 2.When the libvirtd == "off", stop the libvirtd service. 3.Perform virsh dominfo operation. 4.Recover test environment. 5.Confirm the test result. """ vm_name = params.get("main_vm", "vm1") vm = env.get_vm(vm_name) if vm.is_alive() and params.get("start_vm") == "no": vm.destroy() domid = vm.get_id() domuuid = vm.get_uuid() vm_ref = params.get("dominfo_vm_ref") extra = params.get("dominfo_extra", "") status_error = params.get("status_error", "no") libvirtd = params.get("libvirtd", "on") remote_ip = params.get("remote_ip", "REMOTE.EXAMPLE.COM") remote_pwd = params.get("remote_pwd", "") remote_user = params.get("remote_user", "root") remote_uri = params.get("remote_uri") # run test case if vm_ref == "id": vm_ref = domid elif vm_ref == "hex_id": vm_ref = hex(int(domid)) elif vm_ref.find("invalid") != -1: vm_ref = params.get(vm_ref) elif vm_ref == "name": vm_ref = "%s %s" % (vm_name, extra) elif vm_ref == "uuid": vm_ref = domuuid if libvirtd == "off": utils_libvirtd.libvirtd_stop() if remote_uri: if remote_ip.count("EXAMPLE.COM"): test.cancel("please configure remote_ip first.") ssh_key.setup_ssh_key(remote_ip, remote_user, remote_pwd) result = virsh.dominfo(vm_ref, ignore_status=True, debug=True, uri=remote_uri) status = result.exit_status output = result.stdout.strip() err = result.stderr.strip() # recover libvirtd service start if libvirtd == "off": utils_libvirtd.libvirtd_start() # check status_error if status_error == "yes": if status == 0 or err == "": test.fail("Run successfully with wrong command!") elif status_error == "no": if status != 0 or output == "": test.fail("Run failed with right command")