def run(test, params, env): """ Test command: virsh setvcpus. The conmand can change the number of virtual CPUs in the guest domain. 1.Prepare test environment,destroy or suspend a VM. 2.Perform virsh setvcpus operation. 3.Recover test environment. 4.Confirm the test result. """ vm_name = params.get("main_vm") vm = env.get_vm(vm_name) xml_file = params.get("setvcpus_xml_file", "vm.xml") virsh.dumpxml(vm_name, extra="--inactive", to_file=xml_file) tmp_file = params.get("setvcpus_tmp_file", "tmp.xml") pre_vm_state = params.get("setvcpus_pre_vm_state") command = params.get("setvcpus_command", "setvcpus") options = params.get("setvcpus_options") domain = params.get("setvcpus_domain") count = params.get("setvcpus_count") extra_param = params.get("setvcpus_extra_param") count_option = "%s %s" % (count, extra_param) status_error = params.get("status_error") def get_current_vcpus(): """ Get current vcpu number. """ vcpus_set = "" virsh.dumpxml(vm_name, extra="", to_file=tmp_file) dom = parse(tmp_file) root = dom.documentElement vcpus_2 = root.getElementsByTagName("vcpu") for n in vcpus_2: vcpus_set += n.getAttribute("current") vcpus_set = int(vcpus_set) dom.unlink() return vcpus_set if vm.is_alive(): vm.destroy() vm_xml = libvirt_xml.VMXML() vm_xml.set_vm_vcpus(vm_name, 2) vm.start() vm.wait_for_login() if status_error == "no": vcpus_new = len(vm.vcpuinfo()) domid = vm.get_id() domuuid = vm.get_uuid() if pre_vm_state == "paused": vm.pause() elif pre_vm_state == "shut off": vm.destroy() if domain == "remote_name": remote_ssh_addr = params.get("remote_ip", None) remote_addr = params.get("local_ip", None) remote_password = params.get("remote_password", None) host_type = virsh.driver() if host_type == "qemu": remote_string = "qemu+ssh://%s/system" % remote_addr elif host_type == "xen": remote_string = "xen+ssh://%s" % remote_addr command = "virsh -c %s setvcpus %s 1 --live" % (remote_string, vm_name) if virsh.has_command_help_match(command, "--live") is None: status_error = "yes" session = remote.remote_login("ssh", remote_ssh_addr, "22", "root", remote_password, "#") session.cmd_output('LANG=C') status, output = session.cmd_status_output(command, internal_timeout=5) session.close() vcpus_current = len(vm.vcpuinfo()) else: if domain == "name": dom_option = vm_name elif domain == "id": dom_option = domid if params.get("setvcpus_hex_id") is not None: dom_option = hex(int(domid)) elif params.get("setvcpus_invalid_id") is not None: dom_option = params.get("setvcpus_invalid_id") elif domain == "uuid": dom_option = domuuid if params.get("setvcpus_invalid_uuid") is not None: dom_option = params.get("setvcpus_invalid_uuid") else: dom_option = domain option_list = options.split(" ") for item in option_list: if virsh.has_command_help_match(command, item) is None: status_error = "yes" break status = virsh.setvcpus(dom_option, count_option, options, ignore_status=True).exit_status if pre_vm_state == "paused": virsh.resume(vm_name, ignore_status=True) if status_error == "no": if status == 0: if pre_vm_state == "shut off": if options == "--config": vcpus_set = len(vm.vcpuinfo()) elif options == "--current": vcpus_set = get_current_vcpus() elif options == "--maximum --config": vcpus_set = "" dom = parse("/etc/libvirt/qemu/%s.xml" % vm_name) vcpus_set = dom.getElementsByTagName( "vcpu")[0].firstChild.data vcpus_set = int(vcpus_set) dom.unlink() else: vcpus_set = len(vm.vcpuinfo()) if domain == "id": cmd_chk = "cat /etc/libvirt/qemu/%s.xml" % vm_name output1 = commands.getoutput(cmd_chk) logging.info("guest-info:\n%s" % output1) virsh.destroy(vm_name) virsh.undefine(vm_name) virsh.define(xml_file) if os.path.exists(xml_file): os.remove(xml_file) if os.path.exists(tmp_file): os.remove(tmp_file) # check status_error if status_error == "yes": if status == 0: raise error.TestFail("Run successfully with wrong command!") else: if status != 0: raise error.TestFail("Run failed with right command") else: if options == "--maximum --config": if vcpus_set != 4: raise error.TestFail("Run failed with right command1") elif domain == "id": if options == "--config": if vcpus_set != vcpus_new or not re.search( '<vcpu current=\'1\'>%s</vcpu>' % vcpus_new, output1): raise error.TestFail("Run failed with right command2") elif options == "--config --live": if vcpus_set != 1 or not re.search( '<vcpu current=\'1\'>%s</vcpu>' % vcpus_new, output1): raise error.TestFail("Run failed with right command3") else: if vcpus_set != 1 or re.search( '<vcpu current=\'1\'>%s</vcpu>' % vcpus_new, output1): raise error.TestFail("Run failed with right command4") else: if vcpus_set != 1: raise error.TestFail("Run failed with right command5")
def run(test, params, env): """ Test command: virsh connect. """ def unix_transport_setup(): """ Setup a unix connect to local libvirtd. """ shutil.copy(libvirtd_conf_path, libvirtd_conf_bak_path) with open(libvirtd_conf_path, 'r') as libvirtdconf_file: line_list = libvirtdconf_file.readlines() conf_dict = {r'auth_unix_rw\s*=': 'auth_unix_rw="none"\n', } for key in conf_dict: pattern = key conf_line = conf_dict[key] flag = False for index in range(len(line_list)): line = line_list[index] if not re.search(pattern, line): continue else: line_list[index] = conf_line flag = True break if not flag: line_list.append(conf_line) with open(libvirtd_conf_path, 'w') as libvirtdconf_file: libvirtdconf_file.writelines(line_list) # restart libvirtd service utils_libvirtd.libvirtd_restart() def unix_transport_recover(): """ Recover the libvirtd on local. """ if os.path.exists(libvirtd_conf_bak_path): shutil.copy(libvirtd_conf_bak_path, libvirtd_conf_path) utils_libvirtd.libvirtd_restart() # get the params from subtests. # params for general. connect_arg = params.get("connect_arg", "") connect_opt = params.get("connect_opt", "") status_error = params.get("status_error", "no") # params for transport connect. local_ip = params.get("local_ip", "ENTER.YOUR.LOCAL.IP") local_pwd = params.get("local_pwd", "ENTER.YOUR.LOCAL.ROOT.PASSWORD") transport_type = params.get("connect_transport_type", "local") transport = params.get("connect_transport", "ssh") client_ip = local_ip client_pwd = local_pwd server_ip = local_ip server_pwd = local_pwd # params special for tls connect. server_cn = params.get("connect_server_cn", "TLSServer") client_cn = params.get("connect_client_cn", "TLSClient") # params special for tcp connect. tcp_port = params.get("tcp_port", '16509') # params special for unix transport. libvirtd_conf_path = '/etc/libvirt/libvirtd.conf' libvirtd_conf_bak_path = '%s/libvirtd.conf.bak' % data_dir.get_tmp_dir() # check the config if (connect_arg == "transport" and transport_type == "remote" and local_ip.count("ENTER")): test.cancel("Parameter local_ip is not configured" "in remote test.") if (connect_arg == "transport" and transport_type == "remote" and local_pwd.count("ENTER")): test.cancel("Parameter local_pwd is not configured" "in remote test.") # In Ubuntu libvirt_lxc available in /usr/lib/libvirt if (connect_arg.count("lxc") and (not (os.path.exists("/usr/libexec/libvirt_lxc") or os.path.exists("/usr/lib/libvirt/libvirt_lxc")))): test.cancel("Connect test of lxc:/// is not suggested on " "the host with no lxc driver.") if connect_arg.count("xen") and (not os.path.exists("/var/run/xend")): test.cancel("Connect test of xen:/// is not suggested on " "the host with no xen driver.") if connect_arg.count("qemu") and (not os.path.exists("/dev/kvm")): test.cancel("Connect test of qemu:/// is not suggested" "on the host with no qemu driver.") if connect_arg == "transport": canonical_uri_type = virsh.driver() if transport == "ssh": ssh_connection = utils_conn.SSHConnection(server_ip=server_ip, server_pwd=server_pwd, client_ip=client_ip, client_pwd=client_pwd) try: ssh_connection.conn_check() except utils_conn.ConnectionError: ssh_connection.conn_setup() ssh_connection.conn_check() connect_uri = libvirt_vm.get_uri_with_transport( uri_type=canonical_uri_type, transport=transport, dest_ip=server_ip) elif transport == "tls": tls_connection = utils_conn.TLSConnection(server_ip=server_ip, server_pwd=server_pwd, client_ip=client_ip, client_pwd=client_pwd, server_cn=server_cn, client_cn=client_cn) tls_connection.conn_setup() connect_uri = libvirt_vm.get_uri_with_transport( uri_type=canonical_uri_type, transport=transport, dest_ip=server_cn) elif transport == "tcp": tcp_connection = utils_conn.TCPConnection(server_ip=server_ip, server_pwd=server_pwd, tcp_port=tcp_port) tcp_connection.conn_setup() connect_uri = libvirt_vm.get_uri_with_transport( uri_type=canonical_uri_type, transport=transport, dest_ip="%s:%s" % (server_ip, tcp_port)) elif transport == "unix": unix_transport_setup() connect_uri = libvirt_vm.get_uri_with_transport( uri_type=canonical_uri_type, transport=transport, dest_ip="") else: test.cancel("Configuration of transport=%s is " "not recognized." % transport) else: connect_uri = connect_arg try: try: uri = do_virsh_connect(connect_uri, connect_opt) # connect successfully if status_error == "yes": test.fail("Connect successfully in the " "case expected to fail.") # get the expect uri when connect argument is "" if connect_uri == "": connect_uri = virsh.canonical_uri().split()[-1] logging.debug("expected uri is: %s", connect_uri) logging.debug("actual uri after connect is: %s", uri) if not uri == connect_uri: test.fail("Command exit normally but the uri is " "not setted as expected.") except process.CmdError as detail: if status_error == "no": test.fail("Connect failed in the case expected" "to success.\n" "Error: %s" % detail) finally: if transport == "unix": unix_transport_recover() if transport == "tcp": tcp_connection.conn_recover() if transport == "tls": tls_connection.conn_recover()
def run_virsh_setvcpus(test, params, env): """ Test command: virsh setvcpus. The conmand can change the number of virtual CPUs in the guest domain. 1.Prepare test environment,destroy or suspend a VM. 2.Perform virsh setvcpus operation. 3.Recover test environment. 4.Confirm the test result. """ vm_name = params.get("main_vm") vm = env.get_vm(vm_name) xml_file = params.get("setvcpus_xml_file", "vm.xml") virsh.dumpxml(vm_name, extra="--inactive", to_file=xml_file) tmp_file = params.get("setvcpus_tmp_file", "tmp.xml") pre_vm_state = params.get("setvcpus_pre_vm_state") command = params.get("setvcpus_command", "setvcpus") options = params.get("setvcpus_options") domain = params.get("setvcpus_domain") count = params.get("setvcpus_count") extra_param = params.get("setvcpus_extra_param") count_option = "%s %s" % (count, extra_param) status_error = params.get("status_error") def get_current_vcpus(): """ Get current vcpu number. """ vcpus_set = "" virsh.dumpxml(vm_name, extra="", to_file=tmp_file) dom = parse(tmp_file) root = dom.documentElement vcpus_2 = root.getElementsByTagName("vcpu") for n in vcpus_2: vcpus_set += n.getAttribute("current") vcpus_set = int(vcpus_set) dom.unlink() return vcpus_set if vm.is_alive(): vm.destroy() vm_xml = libvirt_xml.VMXML() vm_xml.set_vm_vcpus(vm_name, 2) vm.start() vm.wait_for_login() if status_error == "no": vcpus_new = len(vm.vcpuinfo()) domid = vm.get_id() domuuid = vm.get_uuid() if pre_vm_state == "paused": vm.pause() elif pre_vm_state == "shut off": vm.destroy() if domain == "remote_name": remote_ssh_addr = params.get("remote_ip", None) remote_addr = params.get("local_ip", None) remote_password = params.get("remote_password", None) host_type = virsh.driver() if host_type == "qemu": remote_string = "qemu+ssh://%s/system" % remote_addr elif host_type == "xen": remote_string = "xen+ssh://%s" % remote_addr command = "virsh -c %s setvcpus %s 1 --live" % (remote_string, vm_name) if virsh.has_command_help_match(command, "--live") is None: status_error = "yes" session = remote.remote_login( "ssh", remote_ssh_addr, "22", "root", remote_password, "#") session.cmd_output('LANG=C') status, output = session.cmd_status_output(command, internal_timeout=5) session.close() vcpus_current = len(vm.vcpuinfo()) else: if domain == "name": dom_option = vm_name elif domain == "id": dom_option = domid if params.get("setvcpus_hex_id") is not None: dom_option = hex(int(domid)) elif params.get("setvcpus_invalid_id") is not None: dom_option = params.get("setvcpus_invalid_id") elif domain == "uuid": dom_option = domuuid if params.get("setvcpus_invalid_uuid") is not None: dom_option = params.get("setvcpus_invalid_uuid") else: dom_option = domain option_list = options.split(" ") for item in option_list: if virsh.has_command_help_match(command, item) is None: status_error = "yes" break status = virsh.setvcpus( dom_option, count_option, options, ignore_status=True).exit_status if pre_vm_state == "paused": virsh.resume(vm_name, ignore_status=True) if status_error == "no": if status == 0: if pre_vm_state == "shut off": if options == "--config": vcpus_set = len(vm.vcpuinfo()) elif options == "--current": vcpus_set = get_current_vcpus() elif options == "--maximum --config": vcpus_set = "" dom = parse("/etc/libvirt/qemu/%s.xml" % vm_name) vcpus_set = dom.getElementsByTagName( "vcpu")[0].firstChild.data vcpus_set = int(vcpus_set) dom.unlink() else: vcpus_set = len(vm.vcpuinfo()) if domain == "id": cmd_chk = "cat /etc/libvirt/qemu/%s.xml" % vm_name output1 = commands.getoutput(cmd_chk) logging.info("guest-info:\n%s" % output1) virsh.destroy(vm_name) virsh.undefine(vm_name) virsh.define(xml_file) if os.path.exists(xml_file): os.remove(xml_file) if os.path.exists(tmp_file): os.remove(tmp_file) # check status_error if status_error == "yes": if status == 0: raise error.TestFail("Run successfully with wrong command!") else: if status != 0: raise error.TestFail("Run failed with right command") else: if options == "--maximum --config": if vcpus_set != 4: raise error.TestFail("Run failed with right command1") elif domain == "id": if options == "--config": if vcpus_set != vcpus_new or not re.search('<vcpu current=\'1\'>%s</vcpu>' % vcpus_new, output1): raise error.TestFail("Run failed with right command2") elif options == "--config --live": if vcpus_set != 1 or not re.search('<vcpu current=\'1\'>%s</vcpu>' % vcpus_new, output1): raise error.TestFail("Run failed with right command3") else: if vcpus_set != 1 or re.search('<vcpu current=\'1\'>%s</vcpu>' % vcpus_new, output1): raise error.TestFail("Run failed with right command4") else: if vcpus_set != 1: raise error.TestFail("Run failed with right command5")
def run(test, params, env): """ Test the command virsh maxvcpus (1) Call virsh maxvcpus (2) Call virsh -c remote_uri maxvcpus (3) Call virsh maxvcpus with an unexpected option """ # get the params from subtests. # params for general. option = params.get("virsh_maxvcpus_options") status_error = params.get("status_error") connect_arg = params.get("connect_arg", "") # params for transport connect. local_ip = params.get("local_ip", "ENTER.YOUR.LOCAL.IP") local_pwd = params.get("local_pwd", "ENTER.YOUR.LOCAL.ROOT.PASSWORD") server_ip = params.get("remote_ip", local_ip) server_pwd = params.get("remote_pwd", local_pwd) transport_type = params.get("connect_transport_type", "local") transport = params.get("connect_transport", "ssh") connect_uri = None # check the config if (connect_arg == "transport" and transport_type == "remote" and local_ip.count("ENTER")): raise exceptions.TestSkipError("Parameter local_ip is not configured " "in remote test.") if (connect_arg == "transport" and transport_type == "remote" and local_pwd.count("ENTER")): raise exceptions.TestSkipError("Parameter local_pwd is not configured " "in remote test.") if connect_arg == "transport": canonical_uri_type = virsh.driver() if transport == "ssh": ssh_connection = utils_conn.SSHConnection(server_ip=server_ip, server_pwd=server_pwd, client_ip=local_ip, client_pwd=local_pwd) try: ssh_connection.conn_check() except utils_conn.ConnectionError: ssh_connection.conn_setup() ssh_connection.conn_check() connect_uri = libvirt_vm.get_uri_with_transport( uri_type=canonical_uri_type, transport=transport, dest_ip=server_ip) virsh_dargs = { 'remote_ip': server_ip, 'remote_user': '******', 'remote_pwd': server_pwd, 'ssh_remote_auth': True } virsh_instance = virsh.VirshPersistent(**virsh_dargs) else: connect_uri = connect_arg virsh_instance = virsh if libvirt_version.version_compare(2, 3, 0): try: maxvcpus = None maxvcpus_cap = None dom_capabilities = None # make sure we take maxvcpus from right host, helps in case remote try: dom_capabilities = domcap.DomCapabilityXML( virsh_instance=virsh_instance) maxvcpus = dom_capabilities.max logging.debug( "maxvcpus calculate from domcapabilities " "is %s", maxvcpus) except Exception as details: raise exceptions.TestFail("Failed to get maxvcpus from " "domcapabilities xml:\n%s" % dom_capabilities) try: cap_xml = capability_xml.CapabilityXML() maxvcpus_cap = cap_xml.get_guest_capabilities()['hvm'][ platform.machine()]['maxcpus'] logging.debug('maxvcpus_cap is %s', maxvcpus_cap) except Exception as details: logging.debug( "Failed to get maxvcpu from virsh " "capabilities: %s", details) # Let's fall back in case of failure maxvcpus_cap = maxvcpus if not maxvcpus: raise exceptions.TestFail("Failed to get max value for vcpu" "from domcapabilities " "xml:\n%s" % dom_capabilities) except Exception as details: raise exceptions.TestFail( "Failed get the virsh instance with uri: " "%s\n Details: %s" % (connect_uri, details)) is_arm = "aarch" in platform.machine() gic_version = '' if is_arm: for gic_enum in domcap.DomCapabilityXML()['features']['gic_enums']: if gic_enum['name'] == "version": gic_version = gic_enum['values'][0].get_value() # Run test case result = virsh.maxvcpus(option, uri=connect_uri, ignore_status=True, debug=True) maxvcpus_test = result.stdout.strip() status = result.exit_status # Check status_error if status_error == "yes": if status == 0: raise exceptions.TestFail("Run succeeded with unsupported option!") else: logging.info("Run failed with unsupported option %s " % option) elif status_error == "no": if status == 0: if not libvirt_version.version_compare(2, 3, 0): if "kqemu" in option: if not maxvcpus_test == '1': raise exceptions.TestFail("Command output %s is not " "expected for %s " % (maxvcpus_test, option)) elif option in ['qemu', '--type qemu', '']: if not maxvcpus_test == '16': raise exceptions.TestFail("Command output %s is not " "expected for %s " % (maxvcpus_test, option)) else: # No check with other types pass else: # It covers all possible combinations if option in [ 'qemu', 'kvm', '--type qemu', '--type kvm', 'kqemu', '--type kqemu', '' ]: if (is_arm and gic_version == '2' and option in ['kvm', '']): if not maxvcpus_test == '8': raise exceptions.TestFail( "Command output %s is not " "expected for %s " % (maxvcpus_test, option)) elif not (maxvcpus_test == maxvcpus or maxvcpus_test == maxvcpus_cap): raise exceptions.TestFail("Command output %s is not " "expected for %s " % (maxvcpus_test, option)) else: # No check with other types pass else: raise exceptions.TestFail("Run command failed")
def run(test, params, env): """ Test the command virsh maxvcpus (1) Call virsh maxvcpus (2) Call virsh -c remote_uri maxvcpus (3) Call virsh maxvcpus with an unexpected option """ # get the params from subtests. # params for general. option = params.get("virsh_maxvcpus_options") status_error = params.get("status_error") connect_arg = params.get("connect_arg", "") # params for transport connect. local_ip = params.get("local_ip", "ENTER.YOUR.LOCAL.IP") local_pwd = params.get("local_pwd", "ENTER.YOUR.LOCAL.ROOT.PASSWORD") server_ip = params.get("remote_ip", local_ip) server_pwd = params.get("remote_pwd", local_pwd) transport_type = params.get("connect_transport_type", "local") transport = params.get("connect_transport", "ssh") # check the config if (connect_arg == "transport" and transport_type == "remote" and local_ip.count("ENTER")): raise error.TestNAError("Parameter local_ip is not configured" "in remote test.") if (connect_arg == "transport" and transport_type == "remote" and local_pwd.count("ENTER")): raise error.TestNAError("Parameter local_pwd is not configured" "in remote test.") if connect_arg == "transport": canonical_uri_type = virsh.driver() if transport == "ssh": ssh_connection = utils_conn.SSHConnection(server_ip=server_ip, server_pwd=server_pwd, client_ip=local_ip, client_pwd=local_pwd) try: ssh_connection.conn_check() except utils_conn.ConnectionError: ssh_connection.conn_setup() ssh_connection.conn_check() connect_uri = libvirt_vm.get_uri_with_transport( uri_type=canonical_uri_type, transport=transport, dest_ip=server_ip) else: connect_uri = connect_arg # Run test case result = virsh.maxvcpus(option, uri=connect_uri, ignore_status=True, debug=True) maxvcpus_test = result.stdout.strip() status = result.exit_status # Check status_error if status_error == "yes": if status == 0: raise error.TestFail("Run successed with unsupported option!") else: logging.info("Run failed with unsupported option %s " % option) elif status_error == "no": if status == 0: if "kqemu" in option: if not maxvcpus_test == '1': raise error.TestFail("Command output %s is not expected " "for %s " % (maxvcpus_test, option)) elif option == 'qemu' or option == '--type qemu' or option == '': if not maxvcpus_test == '16': raise error.TestFail("Command output %s is not expected " "for %s " % (maxvcpus_test, option)) else: # No check with other types pass else: raise error.TestFail("Run command failed")
def run(test, params, env): """ Test command: virsh connect. """ def unix_transport_setup(): """ Setup a unix connect to local libvirtd. """ shutil.copy(libvirtd_conf_path, libvirtd_conf_bak_path) with open(libvirtd_conf_path, 'r') as libvirtdconf_file: line_list = libvirtdconf_file.readlines() conf_dict = { r'auth_unix_rw\s*=': 'auth_unix_rw="none"\n', } for key in conf_dict: pattern = key conf_line = conf_dict[key] flag = False for index in range(len(line_list)): line = line_list[index] if not re.search(pattern, line): continue else: line_list[index] = conf_line flag = True break if not flag: line_list.append(conf_line) with open(libvirtd_conf_path, 'w') as libvirtdconf_file: libvirtdconf_file.writelines(line_list) # restart libvirtd service utils_libvirtd.libvirtd_restart() def unix_transport_recover(): """ Recover the libvirtd on local. """ if os.path.exists(libvirtd_conf_bak_path): shutil.copy(libvirtd_conf_bak_path, libvirtd_conf_path) utils_libvirtd.libvirtd_restart() # get the params from subtests. # params for general. connect_arg = params.get("connect_arg", "") connect_opt = params.get("connect_opt", "") status_error = params.get("status_error", "no") # params for transport connect. local_ip = params.get("local_ip", "ENTER.YOUR.LOCAL.IP") local_pwd = params.get("local_pwd", "ENTER.YOUR.LOCAL.ROOT.PASSWORD") transport_type = params.get("connect_transport_type", "local") transport = params.get("connect_transport", "ssh") client_ip = local_ip client_pwd = local_pwd server_ip = local_ip server_pwd = local_pwd # params special for tls connect. server_cn = params.get("connect_server_cn", "TLSServer") client_cn = params.get("connect_client_cn", "TLSClient") # params special for tcp connect. tcp_port = params.get("tcp_port", '16509') # params special for unix transport. libvirtd_conf_path = '/etc/libvirt/libvirtd.conf' libvirtd_conf_bak_path = '%s/libvirtd.conf.bak' % data_dir.get_tmp_dir() # special params for test connection alive alive = params.get('alive', None) if alive: check_virsh_connect_alive(test, params) return # check the config if (connect_arg == "transport" and transport_type == "remote" and local_ip.count("ENTER")): test.cancel("Parameter local_ip is not configured" "in remote test.") if (connect_arg == "transport" and transport_type == "remote" and local_pwd.count("ENTER")): test.cancel("Parameter local_pwd is not configured" "in remote test.") # In Ubuntu libvirt_lxc available in /usr/lib/libvirt if (connect_arg.count("lxc") and (not (os.path.exists("/usr/libexec/libvirt_lxc") or os.path.exists("/usr/lib/libvirt/libvirt_lxc")))): test.cancel("Connect test of lxc:/// is not suggested on " "the host with no lxc driver.") if connect_arg.count("xen") and (not os.path.exists("/var/run/xend")): test.cancel("Connect test of xen:/// is not suggested on " "the host with no xen driver.") if connect_arg.count("qemu") and (not os.path.exists("/dev/kvm")): test.cancel("Connect test of qemu:/// is not suggested" "on the host with no qemu driver.") if connect_arg == "transport": canonical_uri_type = virsh.driver() if transport == "ssh": ssh_connection = utils_conn.SSHConnection(server_ip=server_ip, server_pwd=server_pwd, client_ip=client_ip, client_pwd=client_pwd) try: ssh_connection.conn_check() except utils_conn.ConnectionError: ssh_connection.conn_setup() ssh_connection.conn_check() connect_uri = libvirt_vm.get_uri_with_transport( uri_type=canonical_uri_type, transport=transport, dest_ip=server_ip) elif transport == "tls": tls_connection = utils_conn.TLSConnection(server_ip=server_ip, server_pwd=server_pwd, client_ip=client_ip, client_pwd=client_pwd, server_cn=server_cn, client_cn=client_cn, special_cn='yes') tls_connection.conn_setup() connect_uri = libvirt_vm.get_uri_with_transport( uri_type=canonical_uri_type, transport=transport, dest_ip=server_cn) elif transport == "tcp": tcp_connection = utils_conn.TCPConnection(server_ip=server_ip, server_pwd=server_pwd, tcp_port=tcp_port) tcp_connection.conn_setup() connect_uri = libvirt_vm.get_uri_with_transport( uri_type=canonical_uri_type, transport=transport, dest_ip="%s:%s" % (server_ip, tcp_port)) elif transport == "unix": unix_transport_setup() connect_uri = libvirt_vm.get_uri_with_transport( uri_type=canonical_uri_type, transport=transport, dest_ip="") else: test.cancel("Configuration of transport=%s is " "not recognized." % transport) else: connect_uri = connect_arg try: try: uri = do_virsh_connect(connect_uri, connect_opt) # connect successfully if status_error == "yes": test.fail("Connect successfully in the " "case expected to fail.") # get the expect uri when connect argument is "" if connect_uri == "": connect_uri = virsh.canonical_uri().split()[-1] logging.debug("expected uri is: %s", connect_uri) logging.debug("actual uri after connect is: %s", uri) if not uri == connect_uri: test.fail("Command exit normally but the uri is " "not set as expected.") except process.CmdError as detail: if status_error == "no": test.fail("Connect failed in the case expected" "to success.\n" "Error: %s" % detail) finally: if transport == "unix": unix_transport_recover() if transport == "tcp": tcp_connection.conn_recover() if transport == "tls": tls_connection.conn_recover()
def run_virsh_domblkinfo(test, params, env): """ Test command: virsh domblkinfo. 1.Prepare test environment. 2.Get vm's driver. 3.According to driver perform virsh domblkinfo operation. 4.Recover test environment. 5.Confirm the test result. """ def attach_disk_test(): """ Attach-disk testcase. 1.Attch a disk to guest. 2.Perform domblkinfo operation. 3.Detach the disk. :return: Command status and output. """ try: source_file = open(test_disk_source, 'wb') source_file.seek((512 * 1024 * 1024) - 1) source_file.write(str(0)) source_file.close() virsh.attach_disk(vm_name, test_disk_source, front_dev, debug=True) vm_ref = vm_name result_source = virsh.domblkinfo(vm_ref, test_disk_source, ignore_status=True, debug=True) status_source = result_source.exit_status output_source = result_source.stdout.strip() if driver == "qemu": result_target = virsh.domblkinfo(vm_ref, front_dev, ignore_status=True, debug=True) status_target = result_target.exit_status output_target = result_target.stdout.strip() else: status_target = 0 output_target = "Xen doesn't support domblkinfo target!" virsh.detach_disk(vm_name, front_dev, debug=True) return status_target, output_target, status_source, output_source except (error.CmdError, IOError): return 1, "", 1, "" def check_disk_info(): """ Ckeck virsh domblkinfo output. """ if driver == "qemu" and output_source.strip() != output_target.strip(): raise error.TestFail("Command domblkinfo target/source" " got different information!") if output_source != "": lines = output_source.splitlines() capacity_cols = lines[0].split(":") size = int(capacity_cols[1].strip()) if disk_size != size and disk_size_check: raise error.TestFail("Command domblkinfo output is wrong! " "'%d' != '%d'" % (disk_size, size)) else: raise error.TestFail("Command domblkinfo has no output!") vm_name = params.get("main_vm") vm = env.get_vm(vm_name) # Get all parameters from configuration. vm_ref = params.get("domblkinfo_vm_ref") device = params.get("domblkinfo_device", "yes") front_dev = params.get("domblkinfo_front_dev", "vdd") extra = params.get("domblkinfo_extra", "") status_error = params.get("status_error", "no") test_attach_disk = os.path.join(test.virtdir, "tmp.img") domid = vm.get_id() domuuid = vm.get_uuid() driver = virsh.driver() blklist = vm_xml.VMXML.get_disk_blk(vm_name) sourcelist = vm_xml.VMXML.get_disk_source(vm_name) test_disk_target = blklist[0] test_disk_source = sourcelist[0].find('source').get('file') test_disk_format = sourcelist[0].find('driver').get('type') disk_size_check = False if test_disk_format == "raw": disk_size_check = True if device == "no": test_disk_target = "" test_disk_source = "" 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 vm_ref == "test_attach_disk": test_disk_source = test_attach_disk disk_size_check = True (status_target, output_target, status_source, output_source) = attach_disk_test() else: result_source = virsh.domblkinfo(vm_ref, test_disk_source, ignore_status=True, debug=True) status_source = result_source.exit_status output_source = result_source.stdout.strip() if driver == "qemu": result_target = virsh.domblkinfo(vm_ref, test_disk_target, ignore_status=True, debug=True) status_target = result_target.exit_status output_target = result_target.stdout.strip() else: status_target = 0 output_target = "xen doesn't support domblkinfo target!" disk_size = 0 if os.path.exists(test_disk_source): disk_size = os.path.getsize(test_disk_source) # Recover enviremont if os.path.exists(test_attach_disk): os.remove(test_attach_disk) # Check status_error if status_error == "yes": if status_target == 0 or status_source == 0: raise error.TestFail("Run successfully with wrong command!") elif status_error == "no": if status_target != 0 or status_source != 0: raise error.TestFail("Run failed with right command") # Check source information. check_disk_info() else: raise error.TestFail("The status_error must be 'yes' or 'no'!")
def run(test, params, env): """ Test command: virsh domblkinfo. 1.Prepare test environment. 2.Get vm's driver. 3.According to driver perform virsh domblkinfo operation. 4.Recover test environment. 5.Confirm the test result. """ def attach_disk_test(test_disk_source, front_dev): """ Attach-disk testcase. 1.Attch a disk to guest. 2.Perform domblkinfo operation. 3.Detach the disk. :param: test_disk_source disk source file path. :param: front_dev front end device name. :return: Command status and output. """ try: disk_source = test_disk_source front_device = front_dev with open(disk_source, 'wb') as source_file: source_file.seek((512 * 1024 * 1024) - 1) source_file.write(str(0).encode()) virsh.attach_disk(vm_name, disk_source, front_device, debug=True) vm_ref = vm_name if "--all" in extra: disk_source = "" vm_ref = "%s %s" % (vm_name, extra) result_source = virsh.domblkinfo(vm_ref, disk_source, ignore_status=True, debug=True) status_source = result_source.exit_status output_source = result_source.stdout.strip() if driver == "qemu": if "--all" in extra: front_device = "" result_target = virsh.domblkinfo(vm_ref, front_device, ignore_status=True, debug=True) status_target = result_target.exit_status output_target = result_target.stdout.strip() else: status_target = 0 output_target = "Xen doesn't support domblkinfo target!" front_device = front_dev virsh.detach_disk(vm_name, front_device, debug=True) return status_target, output_target, status_source, output_source except (process.CmdError, IOError): return 1, "", 1, "" def check_disk_info(): """ Ckeck virsh domblkinfo output. """ if driver == "qemu" and output_source.strip() != output_target.strip(): test.fail("Command domblkinfo target/source" " got different information!") if output_source != "": lines = output_source.splitlines() if "--human" in extra and not any( re.findall(r'GiB|MiB', lines[0], re.IGNORECASE)): test.fail("Command domblkinfo human output is wrong") if "--all" in extra: blocklist = vm_xml.VMXML.get_disk_blk(vm_name) if not all( re.findall(r''.join(block), output_source, re.IGNORECASE) for block in blocklist): test.fail("Command domblkinfo --all output is wrong") return if disk_size_check: capacity_cols = lines[0].split(":") if "--human" in extra: size = float(capacity_cols[1].strip().split(" ")[0]) else: size = int(capacity_cols[1].strip()) if disk_size != size: test.fail("Command domblkinfo output is wrong! " "'%d' != '%d'" % (disk_size, size)) else: test.fail("Command domblkinfo has no output!") vm_name = params.get("main_vm") vm = env.get_vm(vm_name) # Get all parameters from configuration. vm_ref = params.get("domblkinfo_vm_ref") device = params.get("domblkinfo_device", "yes") front_dev = params.get("domblkinfo_front_dev", "vdd") extra = params.get("domblkinfo_extra", "") status_error = params.get("status_error", "no") test_attach_disk = os.path.join(test.virtdir, "tmp.img") domid = vm.get_id() domuuid = vm.get_uuid() driver = virsh.driver() blklist = vm_xml.VMXML.get_disk_blk(vm_name) sourcelist = vm_xml.VMXML.get_disk_source(vm_name) test_disk_target = blklist[0] test_disk_source = sourcelist[0].find('source').get('file') test_disk_format = sourcelist[0].find('driver').get('type') disk_size_check = False if test_disk_format == "raw": disk_size_check = True if device == "no": test_disk_target = "" test_disk_source = "" 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 any(re.findall( r'--all|--human', extra, re.IGNORECASE)) and not libvirt_version.version_compare(4, 5, 0): test.cancel( "--all and --human options are supported until libvirt 4.5.0 version" ) if vm_ref == "test_attach_disk": test_disk_source = test_attach_disk disk_size_check = True (status_target, output_target, status_source, output_source) = attach_disk_test(test_disk_source, front_dev) else: result_source = virsh.domblkinfo(vm_ref, test_disk_source, ignore_status=True, debug=True) status_source = result_source.exit_status output_source = result_source.stdout.strip() if driver == "qemu": result_target = virsh.domblkinfo(vm_ref, test_disk_target, ignore_status=True, debug=True) status_target = result_target.exit_status output_target = result_target.stdout.strip() else: status_target = 0 output_target = "xen doesn't support domblkinfo target!" disk_size = 0 if os.path.exists(test_disk_source): disk_size = os.path.getsize(test_disk_source) # Recover enviremont if os.path.exists(test_attach_disk): os.remove(test_attach_disk) # Check status_error if status_error == "yes": if status_target == 0 or status_source == 0: test.fail("Run successfully with wrong command!") elif status_error == "no": if status_target != 0 or status_source != 0: test.fail("Run failed with right command") # Check source information. check_disk_info() else: test.fail("The status_error must be 'yes' or 'no'!")
def run(test, params, env): """ Test the command virsh maxvcpus (1) Call virsh maxvcpus (2) Call virsh -c remote_uri maxvcpus (3) Call virsh maxvcpus with an unexpected option """ # get the params from subtests. # params for general. option = params.get("virsh_maxvcpus_options") status_error = params.get("status_error") connect_arg = params.get("connect_arg", "") # params for transport connect. local_ip = params.get("local_ip", "ENTER.YOUR.LOCAL.IP") local_pwd = params.get("local_pwd", "ENTER.YOUR.LOCAL.ROOT.PASSWORD") server_ip = params.get("remote_ip", local_ip) server_pwd = params.get("remote_pwd", local_pwd) transport_type = params.get("connect_transport_type", "local") transport = params.get("connect_transport", "ssh") connect_uri = None # check the config if (connect_arg == "transport" and transport_type == "remote" and local_ip.count("ENTER")): raise exceptions.TestSkipError("Parameter local_ip is not configured " "in remote test.") if (connect_arg == "transport" and transport_type == "remote" and local_pwd.count("ENTER")): raise exceptions.TestSkipError("Parameter local_pwd is not configured " "in remote test.") if connect_arg == "transport": canonical_uri_type = virsh.driver() if transport == "ssh": ssh_connection = utils_conn.SSHConnection(server_ip=server_ip, server_pwd=server_pwd, client_ip=local_ip, client_pwd=local_pwd) try: ssh_connection.conn_check() except utils_conn.ConnectionError: ssh_connection.conn_setup() ssh_connection.conn_check() connect_uri = libvirt_vm.get_uri_with_transport( uri_type=canonical_uri_type, transport=transport, dest_ip=server_ip) else: connect_uri = connect_arg if libvirt_version.version_compare(2, 3, 0): try: maxvcpus = None dom_capabilities = None # make sure we take maxvcpus from right host, helps incase remote try: dom_capabilities = domcap.DomCapabilityXML() maxvcpus = dom_capabilities.max logging.debug("maxvcpus calculate from domcapabilities " "is %s", maxvcpus) except Exception as details: raise exceptions.TestFail("Failed to get maxvcpus from " "domcapabilities xml:\n%s" % dom_capabilities) if not maxvcpus: raise exceptions.TestFail("Failed to get max value for vcpu" "from domcapabilities " "xml:\n%s" % dom_capabilities) except Exception as details: raise exceptions.TestFail("Failed get the virsh instance with uri: " "%s\n Details: %s" % (connect_uri, details)) is_arm = "aarch" in platform.machine() if is_arm: for gic_enum in domcap.DomCapabilityXML()['features']['gic_enums']: if gic_enum['name'] == "version": gic_version = gic_enum['values'][0].get_value() # Run test case result = virsh.maxvcpus(option, uri=connect_uri, ignore_status=True, debug=True) maxvcpus_test = result.stdout.strip() status = result.exit_status # Check status_error if status_error == "yes": if status == 0: raise exceptions.TestFail("Run successed with unsupported option!") else: logging.info("Run failed with unsupported option %s " % option) elif status_error == "no": if status == 0: if not libvirt_version.version_compare(2, 3, 0): if "kqemu" in option: if not maxvcpus_test == '1': raise exceptions.TestFail("Command output %s is not " "expected for %s " % (maxvcpus_test, option)) elif option in ['qemu', '--type qemu', '']: if not maxvcpus_test == '16': raise exceptions.TestFail("Command output %s is not " "expected for %s " % (maxvcpus_test, option)) else: # No check with other types pass else: # It covers all possible combinations if option in ['qemu', 'kvm', '--type qemu', '--type kvm', 'kqemu', '--type kqemu', '']: if (is_arm and gic_version == '2' and option in ['kvm', '']): if not maxvcpus_test == '8': raise exceptions.TestFail("Command output %s is not " "expected for %s " % (maxvcpus_test, option)) elif not maxvcpus_test == maxvcpus: raise exceptions.TestFail("Command output %s is not " "expected for %s " % (maxvcpus_test, option)) else: # No check with other types pass else: raise exceptions.TestFail("Run command failed")
def run(test, params, env): """ Test command: virsh domblkinfo. 1.Prepare test environment. 2.Get vm's driver. 3.According to driver perform virsh domblkinfo operation. 4.Recover test environment. 5.Confirm the test result. """ def attach_disk_test(): """ Attach-disk testcase. 1.Attch a disk to guest. 2.Perform domblkinfo operation. 3.Detach the disk. :return: Command status and output. """ try: source_file = open(test_disk_source, 'wb') source_file.seek((512 * 1024 * 1024) - 1) source_file.write(str(0)) source_file.close() virsh.attach_disk(vm_name, test_disk_source, front_dev, debug=True) vm_ref = vm_name result_source = virsh.domblkinfo(vm_ref, test_disk_source, ignore_status=True, debug=True) status_source = result_source.exit_status output_source = result_source.stdout.strip() if driver == "qemu": result_target = virsh.domblkinfo(vm_ref, front_dev, ignore_status=True, debug=True) status_target = result_target.exit_status output_target = result_target.stdout.strip() else: status_target = 0 output_target = "Xen doesn't support domblkinfo target!" virsh.detach_disk(vm_name, front_dev, debug=True) return status_target, output_target, status_source, output_source except (error.CmdError, IOError): return 1, "", 1, "" def check_disk_info(): """ Ckeck virsh domblkinfo output. """ if driver == "qemu" and output_source.strip() != output_target.strip(): raise error.TestFail("Command domblkinfo target/source" " got different information!") if output_source != "": lines = output_source.splitlines() capacity_cols = lines[0].split(":") size = int(capacity_cols[1].strip()) if disk_size != size and disk_size_check: raise error.TestFail("Command domblkinfo output is wrong! " "'%d' != '%d'" % (disk_size, size)) else: raise error.TestFail("Command domblkinfo has no output!") vm_name = params.get("main_vm") vm = env.get_vm(vm_name) # Get all parameters from configuration. vm_ref = params.get("domblkinfo_vm_ref") device = params.get("domblkinfo_device", "yes") front_dev = params.get("domblkinfo_front_dev", "vdd") extra = params.get("domblkinfo_extra", "") status_error = params.get("status_error", "no") test_attach_disk = os.path.join(test.virtdir, "tmp.img") domid = vm.get_id() domuuid = vm.get_uuid() driver = virsh.driver() blklist = vm_xml.VMXML.get_disk_blk(vm_name) sourcelist = vm_xml.VMXML.get_disk_source(vm_name) test_disk_target = blklist[0] test_disk_source = sourcelist[0].find('source').get('file') test_disk_format = sourcelist[0].find('driver').get('type') disk_size_check = False if test_disk_format == "raw": disk_size_check = True if device == "no": test_disk_target = "" test_disk_source = "" 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 vm_ref == "test_attach_disk": test_disk_source = test_attach_disk disk_size_check = True (status_target, output_target, status_source, output_source) = attach_disk_test() else: result_source = virsh.domblkinfo(vm_ref, test_disk_source, ignore_status=True, debug=True) status_source = result_source.exit_status output_source = result_source.stdout.strip() if driver == "qemu": result_target = virsh.domblkinfo(vm_ref, test_disk_target, ignore_status=True, debug=True) status_target = result_target.exit_status output_target = result_target.stdout.strip() else: status_target = 0 output_target = "xen doesn't support domblkinfo target!" disk_size = 0 if os.path.exists(test_disk_source): disk_size = os.path.getsize(test_disk_source) # Recover enviremont if os.path.exists(test_attach_disk): os.remove(test_attach_disk) # Check status_error if status_error == "yes": if status_target == 0 or status_source == 0: raise error.TestFail("Run successfully with wrong command!") elif status_error == "no": if status_target != 0 or status_source != 0: raise error.TestFail("Run failed with right command") # Check source information. check_disk_info() else: raise error.TestFail("The status_error must be 'yes' or 'no'!")
def run(test, params, env): """ Test the command virsh maxvcpus (1) Call virsh maxvcpus (2) Call virsh -c remote_uri maxvcpus (3) Call virsh maxvcpus with an unexpected option """ # get the params from subtests. # params for general. option = params.get("virsh_maxvcpus_options") status_error = params.get("status_error") connect_arg = params.get("connect_arg", "") # params for transport connect. local_ip = params.get("local_ip", "ENTER.YOUR.LOCAL.IP") local_pwd = params.get("local_pwd", "ENTER.YOUR.LOCAL.ROOT.PASSWORD") server_ip = params.get("remote_ip", local_ip) server_pwd = params.get("remote_pwd", local_pwd) transport_type = params.get("connect_transport_type", "local") transport = params.get("connect_transport", "ssh") connect_uri = None # check the config if (connect_arg == "transport" and transport_type == "remote" and local_ip.count("ENTER")): raise exceptions.TestSkipError("Parameter local_ip is not configured " "in remote test.") if (connect_arg == "transport" and transport_type == "remote" and local_pwd.count("ENTER")): raise exceptions.TestSkipError("Parameter local_pwd is not configured " "in remote test.") if connect_arg == "transport": canonical_uri_type = virsh.driver() if transport == "ssh": ssh_connection = utils_conn.SSHConnection(server_ip=server_ip, server_pwd=server_pwd, client_ip=local_ip, client_pwd=local_pwd) try: ssh_connection.conn_check() except utils_conn.ConnectionError: ssh_connection.conn_setup() ssh_connection.conn_check() connect_uri = libvirt_vm.get_uri_with_transport( uri_type=canonical_uri_type, transport=transport, dest_ip=server_ip) else: connect_uri = connect_arg if libvirt_version.version_compare(2, 3, 0): try: maxvcpus = None dom_capabilities = None # make sure we take maxvcpus from right host, helps incase remote try: dom_capabilities = domcap.DomCapabilityXML() maxvcpus = dom_capabilities.max logging.debug("maxvcpus calculate from domcapabilities " "is %s", maxvcpus) except: raise exceptions.TestFail("Failed to get maxvcpus from " "domcapabilities xml:\n%s" % dom_capabilities) if not maxvcpus: raise exceptions.TestFail("Failed to get max value for vcpu" "from domcapabilities " "xml:\n%s" % dom_capabilities) except Exception, details: raise exceptions.TestFail("Failed get the virsh instance with uri: " "%s\n Details: %s" % (connect_uri, details))
def run(test, params, env): """ Test the command virsh maxvcpus (1) Call virsh maxvcpus (2) Call virsh -c remote_uri maxvcpus (3) Call virsh maxvcpus with an unexpected option """ # get the params from subtests. # params for general. option = params.get("virsh_maxvcpus_options") status_error = params.get("status_error") connect_arg = params.get("connect_arg", "") # params for transport connect. local_ip = params.get("local_ip", "ENTER.YOUR.LOCAL.IP") local_pwd = params.get("local_pwd", "ENTER.YOUR.LOCAL.ROOT.PASSWORD") server_ip = params.get("remote_ip", local_ip) server_pwd = params.get("remote_pwd", local_pwd) transport_type = params.get("connect_transport_type", "local") transport = params.get("connect_transport", "ssh") connect_uri = None # check the config if (connect_arg == "transport" and transport_type == "remote" and local_ip.count("ENTER")): raise exceptions.TestSkipError("Parameter local_ip is not configured " "in remote test.") if (connect_arg == "transport" and transport_type == "remote" and local_pwd.count("ENTER")): raise exceptions.TestSkipError("Parameter local_pwd is not configured " "in remote test.") if connect_arg == "transport": canonical_uri_type = virsh.driver() if transport == "ssh": ssh_connection = utils_conn.SSHConnection(server_ip=server_ip, server_pwd=server_pwd, client_ip=local_ip, client_pwd=local_pwd) try: ssh_connection.conn_check() except utils_conn.ConnectionError: ssh_connection.conn_setup() ssh_connection.conn_check() connect_uri = libvirt_vm.get_uri_with_transport( uri_type=canonical_uri_type, transport=transport, dest_ip=server_ip) else: connect_uri = connect_arg if libvirt_version.version_compare(2, 3, 0): try: maxvcpus = None dom_capabilities = None # make sure we take maxvcpus from right host, helps incase remote try: dom_capabilities = domcap.DomCapabilityXML() maxvcpus = dom_capabilities.max logging.debug( "maxvcpus calculate from domcapabilities " "is %s", maxvcpus) except: raise exceptions.TestFail("Failed to get maxvcpus from " "domcapabilities xml:\n%s" % dom_capabilities) if not maxvcpus: raise exceptions.TestFail("Failed to get max value for vcpu" "from domcapabilities " "xml:\n%s" % dom_capabilities) except Exception, details: raise exceptions.TestFail( "Failed get the virsh instance with uri: " "%s\n Details: %s" % (connect_uri, details))
def run(test, params, env): """ Test the command virsh maxvcpus (1) Call virsh maxvcpus (2) Call virsh -c remote_uri maxvcpus (3) Call virsh maxvcpus with an unexpected option """ # get the params from subtests. # params for general. option = params.get("virsh_maxvcpus_options") status_error = params.get("status_error") connect_arg = params.get("connect_arg", "") # params for transport connect. local_ip = params.get("local_ip", "ENTER.YOUR.LOCAL.IP") local_pwd = params.get("local_pwd", "ENTER.YOUR.LOCAL.ROOT.PASSWORD") server_ip = params.get("remote_ip", local_ip) server_pwd = params.get("remote_pwd", local_pwd) transport_type = params.get("connect_transport_type", "local") transport = params.get("connect_transport", "ssh") # check the config if (connect_arg == "transport" and transport_type == "remote" and local_ip.count("ENTER")): raise exceptions.TestSkipError("Parameter local_ip is not configured " "in remote test.") if (connect_arg == "transport" and transport_type == "remote" and local_pwd.count("ENTER")): raise exceptions.TestSkipError("Parameter local_pwd is not configured " "in remote test.") if connect_arg == "transport": canonical_uri_type = virsh.driver() if transport == "ssh": ssh_connection = utils_conn.SSHConnection(server_ip=server_ip, server_pwd=server_pwd, client_ip=local_ip, client_pwd=local_pwd) try: ssh_connection.conn_check() except utils_conn.ConnectionError: ssh_connection.conn_setup() ssh_connection.conn_check() connect_uri = libvirt_vm.get_uri_with_transport( uri_type=canonical_uri_type, transport=transport, dest_ip=server_ip) else: connect_uri = connect_arg if libvirt_version.version_compare(2, 3, 0): try: maxvcpus = None # make sure we take maxvcpus from right host, helps incase remote virsh_dargs = {'uri': connect_uri} virsh_instance = virsh.Virsh(virsh_dargs) try: capa = capability_xml.CapabilityXML(virsh_instance) host_arch = capa.arch maxvcpus = capa.get_guest_capabilities( )['hvm'][host_arch]['maxcpus'] except: raise exceptions.TestFail("Failed to get maxvcpus from " "capabilities xml\n%s" % capa) if not maxvcpus: raise exceptions.TestFail("Failed to get guest section for " "host arch: %s from capabilities " "xml\n%s" % (host_arch, capa)) except Exception, details: raise exceptions.TestFail( "Failed get the virsh instance with uri: " "%s\n Details: %s" % (connect_uri, details))