def find_hbas(hba_type="hba", status="online"): """ Find online hba/vhba cards. :params hba_type: "vhba" or "hba" :params status: "online" or "offline" :return: A list contains the online/offline vhba/hba list """ # TODO: add status=offline/online judgement, we don't test offline vhba now # so leave it here as a placeholder. result = virsh.nodedev_list(cap="scsi_host") if result.exit_status: raise exceptions.TestFail(result.stderr_text) scsi_hosts = result.stdout_text.strip().splitlines() online_hbas_list = [] online_vhbas_list = [] # go through all scsi hosts, and split hbas/vhbas into lists for scsi_host in scsi_hosts: result = virsh.nodedev_dumpxml(scsi_host) stdout = result.stdout_text.strip() if result.exit_status: raise exceptions.TestFail(result.stderr_text) if (re.search('vport_ops', stdout) and not re.search( '<fabric_wwn>ffffffffffffffff</fabric_wwn>', stdout) and not re.search('<fabric_wwn>0</fabric_wwn>', stdout)): online_hbas_list.append(scsi_host) if re.search('fc_host', stdout) and not re.search('vport_ops', stdout): online_vhbas_list.append(scsi_host) if hba_type == "hba": return online_hbas_list if hba_type == "vhba": return online_vhbas_list
def find_hbas(hba_type="hba", status="online"): """ Find online hba/vhba cards. :params hba_type: "vhba" or "hba" :params status: "online" or "offline" :return: A list contains the online/offline vhba/hba list """ # TODO: add offline/online judgement, fc storage not stable for now, so # leave this part after we buy npiv server result = virsh.nodedev_list(cap="scsi_host") if result.exit_status: raise exceptions.TestFail(result.stderr) scsi_hosts = result.stdout.strip().splitlines() online_hbas_list = [] online_vhbas_list = [] # go through all scsi hosts, and split hbas/vhbas into lists for scsi_host in scsi_hosts: result = virsh.nodedev_dumpxml(scsi_host) stdout = result.stdout.strip() if result.exit_status: raise exceptions.TestFail(result.stderr) if re.search('vport_ops', stdout) and not re.search('<fabric_wwn>' 'ffffffffffffffff</fabric_wwn>' '', stdout): online_hbas_list.append(scsi_host) if re.search('fc_host', stdout) and not re.search('vport_ops', stdout): online_vhbas_list.append(scsi_host) if hba_type == "hba": return online_hbas_list if hba_type == "vhba": return online_vhbas_list
def find_hbas(hba_type="hba", status="online"): """ Find online hba/vhba cards. :params hba_type: "vhba" or "hba" :params status: "online" or "offline" :return: A list contains the online/offline vhba/hba list """ # TODO: add offline/online judgement, fc storage not stable for now, so # leave this part after we buy npiv server result = virsh.nodedev_list(cap="scsi_host") if result.exit_status: raise exceptions.TestFail(result.stderr) scsi_hosts = result.stdout.strip().splitlines() online_hbas_list = [] online_vhbas_list = [] # go through all scsi hosts, and split hbas/vhbas into lists for scsi_host in scsi_hosts: result = virsh.nodedev_dumpxml(scsi_host) stdout = result.stdout.strip() if result.exit_status: raise exceptions.TestFail(result.stderr) if re.search('vport_ops', stdout) and not re.search( '<fabric_wwn>' 'ffffffffffffffff</fabric_wwn>' '', stdout): online_hbas_list.append(scsi_host) if re.search('fc_host', stdout) and not re.search('vport_ops', stdout): online_vhbas_list.append(scsi_host) if hba_type == "hba": return online_hbas_list if hba_type == "vhba": return online_vhbas_list
def find_hbas(hba_type="hba", status="online"): """ Find online hba/vhba cards. :params hba_type: "vhba" or "hba" :params status: "online" or "offline" :return: A list contains the online/offline vhba/hba list """ # TODO: add status=offline/online judgement, we don't test offline vhba now # so leave it here as a placeholder. result = virsh.nodedev_list(cap="scsi_host") if result.exit_status: raise exceptions.TestFail(results_stderr_52lts(result)) scsi_hosts = results_stdout_52lts(result).strip().splitlines() online_hbas_list = [] online_vhbas_list = [] # go through all scsi hosts, and split hbas/vhbas into lists for scsi_host in scsi_hosts: result = virsh.nodedev_dumpxml(scsi_host) stdout = results_stdout_52lts(result).strip() if result.exit_status: raise exceptions.TestFail(results_stderr_52lts(result)) if (re.search('vport_ops', stdout) and not re.search('<fabric_wwn>ffffffffffffffff</fabric_wwn>', stdout) and not re.search('<fabric_wwn>0</fabric_wwn>', stdout)): online_hbas_list.append(scsi_host) if re.search('fc_host', stdout) and not re.search('vport_ops', stdout): online_vhbas_list.append(scsi_host) if hba_type == "hba": return online_hbas_list if hba_type == "vhba": return online_vhbas_list
def dump_nodedev_xml(dev_name, dev_opt="", **dargs): """ Do dumpxml and check the result. step1.execute nodedev-dumpxml command. step1.compare info in xml with info in sysfs. :param dev_name: name of device. :param dev_opt: command extra options :param dargs: extra dict args """ result = virsh.nodedev_dumpxml(dev_name, options=dev_opt, **dargs) libvirt.check_exit_status(result) logging.debug('Executing "virsh nodedev-dumpxml %s" finished.', dev_name) # Compare info in xml with info in sysfs. nodedevice_xml = nodedev_xml.NodedevXML.new_from_dumpxml(dev_name) if not nodedevice_xml.validates: test.error("nodedvxml of %s is not validated." % (dev_name)) # Get the dict of key to value in xml. # nodedev_dict_xml contain the all keys and values in xml need checking. nodedev_dict_xml = nodedevice_xml.get_key2value_dict() # Get the dict of key to path in sysfs. # nodedev_syspath_dict contain the all keys and the path of file which contain # information for each key. nodedev_syspath_dict = nodedevice_xml.get_key2syspath_dict() # Get the values contained in files. # nodedev_dict_sys contain the all keys and values in sysfs. nodedev_dict_sys = {} for key, filepath in list(nodedev_syspath_dict.items()): with open(filepath, 'r') as f: value = f.readline().rstrip('\n') nodedev_dict_sys[key] = value # Compare the value in xml and in syspath. for key in nodedev_dict_xml: xml_value = nodedev_dict_xml.get(key) sys_value = nodedev_dict_sys.get(key) if not xml_value == sys_value: if (key == 'numa_node' and not libvirt_version.version_compare(1, 2, 5)): logging.warning("key: %s in xml is not supported yet" % key) else: test.error("key: %s in xml is %s," "but in sysfs is %s." % (key, xml_value, sys_value)) else: continue logging.debug( "Compare info in xml and info in sysfs finished" "for device %s.", dev_name)
def do_nodedev_dumpxml(dev_name, dev_opt="", **dargs): """ Do dumpxml and check the result. (1).execute nodedev-dumpxml command. (2).compare info in xml with info in sysfs. :param dev_name: name of device. :param dev_opt: command extra options :param dargs: extra dict args :raise TestFail: if execute command failed or check result failed. """ result = virsh.nodedev_dumpxml(dev_name, options=dev_opt, **dargs) if result.exit_status: raise error.TestError("Dumpxml node device %s failed.\n" "Detail:%s." % (dev_name, result.stderr)) logging.debug('Executing "virsh nodedev-dumpxml %s" finished.', dev_name) # compare info in xml with info in sysfs. nodedevxml = nodedev_xml.NodedevXML.new_from_dumpxml(dev_name) if not nodedevxml.validates: raise error.TestError("nodedvxml of %s is not validated." % (dev_name)) # Get the dict of key to value in xml. # key2value_dict_xml contain the all keys and values in xml need checking. key2value_dict_xml = nodedevxml.get_key2value_dict() # Get the dict of key to path in sysfs. # key2syspath_dict contain the all keys and the path of file which contain # information for each key. key2syspath_dict = nodedevxml.get_key2syspath_dict() # Get the values contained in files. # key2value_dict_sys contain the all keys and values in sysfs. key2value_dict_sys = {} for key, filepath in key2syspath_dict.items(): value = utils.read_one_line(filepath) key2value_dict_sys[key] = value # Compare the value in xml and in syspath. for key in key2value_dict_xml: value_xml = key2value_dict_xml.get(key) value_sys = key2value_dict_sys.get(key) if not value_xml == value_sys: if (key == 'numa_node' and not libvirt_version.version_compare(1, 2, 5)): logging.warning("key: %s in xml is not supported yet" % key) else: raise error.TestError("key: %s in xml is %s," "but in sysfs is %s." % (key, value_xml, value_sys)) else: continue logging.debug( "Compare info in xml and info in sysfs finished" "for device %s.", dev_name)
def dump_nodedev_xml(dev_name, dev_opt="", **dargs): """ Do dumpxml and check the result. step1.execute nodedev-dumpxml command. step1.compare info in xml with info in sysfs. :param dev_name: name of device. :param dev_opt: command extra options :param dargs: extra dict args """ result = virsh.nodedev_dumpxml(dev_name, options=dev_opt, **dargs) libvirt.check_exit_status(result) logging.debug('Executing "virsh nodedev-dumpxml %s" finished.', dev_name) # Compare info in xml with info in sysfs. nodedevice_xml = nodedev_xml.NodedevXML.new_from_dumpxml(dev_name) if not nodedevice_xml.validates: test.error("nodedvxml of %s is not validated." % (dev_name)) # Get the dict of key to value in xml. # nodedev_dict_xml contain the all keys and values in xml need checking. nodedev_dict_xml = nodedevice_xml.get_key2value_dict() # Get the dict of key to path in sysfs. # nodedev_syspath_dict contain the all keys and the path of file which contain # information for each key. nodedev_syspath_dict = nodedevice_xml.get_key2syspath_dict() # Get the values contained in files. # nodedev_dict_sys contain the all keys and values in sysfs. nodedev_dict_sys = {} for key, filepath in list(nodedev_syspath_dict.items()): with open(filepath, 'r') as f: value = f.readline().rstrip('\n') nodedev_dict_sys[key] = value # Compare the value in xml and in syspath. for key in nodedev_dict_xml: xml_value = nodedev_dict_xml.get(key) sys_value = nodedev_dict_sys.get(key) if not xml_value == sys_value: if (key == 'numa_node' and not libvirt_version.version_compare(1, 2, 5)): logging.warning("key: %s in xml is not supported yet" % key) else: test.error("key: %s in xml is %s," "but in sysfs is %s." % (key, xml_value, sys_value)) else: continue logging.debug("Compare info in xml and info in sysfs finished" "for device %s.", dev_name)
def restart_libvirtd_and_check_vhbaxml(scsi_host, test): """ Check a vhba's xml before and after restart libvirtd. Return false if vhba's xml chnaged. """ libvirtd = utils_libvirtd.Libvirtd() cmd_result = virsh.nodedev_dumpxml(scsi_host) scsi_host_xml = cmd_result.stdout.strip() if "<device>" not in scsi_host_xml: test.fail("node device %s has invalid xml: %s" % (scsi_host, scsi_host_xml)) libvirtd.restart() cmd_result = virsh.nodedev_dumpxml(scsi_host) scsi_host_xml_new = cmd_result.stdout.strip() if (scsi_host_xml == scsi_host_xml_new): logging.debug("vhba's xml is same before&after libvirtd restarted:\n%s" % scsi_host_xml_new) return True logging.debug("vhba's xml is not same before&after libvirtd restarted " "before: %s\nafter: %s" % (scsi_host_xml, scsi_host_xml_new)) return False
def nodedev_validate(file=None, **virsh_dargs): """ Test for schema nodedev """ # Get dev name cmd_result = virsh.nodedev_list() libvirt.check_exit_status(cmd_result) dev_name = cmd_result.stdout.strip().splitlines()[1] if dev_name: cmd_result = virsh.nodedev_dumpxml(dev_name, to_file=file) libvirt.check_exit_status(cmd_result)
def do_nodedev_dumpxml(dev_name, dev_opt="", **dargs): """ Do dumpxml and check the result. (1).execute nodedev-dumpxml command. (2).compare info in xml with info in sysfs. :param dev_name: name of device. :param dev_opt: command extra options :param dargs: extra dict args :raise TestFail: if execute command failed or check result failed. """ result = virsh.nodedev_dumpxml(dev_name, options=dev_opt, **dargs) if result.exit_status: raise error.TestError("Dumpxml node device %s failed.\n" "Detail:%s." % (dev_name, result.stderr)) logging.debug('Executing "virsh nodedev-dumpxml %s" finished.', dev_name) # compare info in xml with info in sysfs. nodedevxml = nodedev_xml.NodedevXML.new_from_dumpxml(dev_name) if not nodedevxml.validates: raise error.TestError("nodedvxml of %s is not validated." % (dev_name)) # Get the dict of key to value in xml. # key2value_dict_xml contain the all keys and values in xml need checking. key2value_dict_xml = nodedevxml.get_key2value_dict() # Get the dict of key to path in sysfs. # key2syspath_dict contain the all keys and the path of file which contain # information for each key. key2syspath_dict = nodedevxml.get_key2syspath_dict() # Get the values contained in files. # key2value_dict_sys contain the all keys and values in sysfs. key2value_dict_sys = {} for key, filepath in key2syspath_dict.items(): value = utils.read_one_line(filepath) key2value_dict_sys[key] = value # Compare the value in xml and in syspath. for key in key2value_dict_xml: value_xml = key2value_dict_xml.get(key) value_sys = key2value_dict_sys.get(key) if not value_xml == value_sys: if (key == 'numa_node' and not libvirt_version.version_compare(1, 2, 5)): logging.warning("key: %s in xml is not supported yet" % key) else: raise error.TestError("key: %s in xml is %s," "but in sysfs is %s." % (key, value_xml, value_sys)) else: continue logging.debug("Compare info in xml and info in sysfs finished" "for device %s.", dev_name)
def get_nodedev_dumpxml(selected_device): """ Returns LibvirtXMLBase instance holding the nodedev xml. :param selected_device: device identifier :return: LibvirtXMLBase instance from nodedev-dumpxml output """ result = virsh.nodedev_dumpxml(selected_device, ignore_status=False) xml = LibvirtXMLBase() xml.xml = result.stdout_text logging.debug("nodedev-dumpxml for '%s': %s", selected_device, xml.xmltreefile) return xml
def check_vport_ops_cap(test, scsi_hosts): """ Check vport operation capability :params scsi_hosts: list of the scsi_host """ vport_ops_list = [] for scsi_host in scsi_hosts: result = virsh.nodedev_dumpxml(scsi_host) if result.exit_status: test.fail(result.stderr) if re.search('vport_ops', result.stdout.strip()): vport_ops_list.append(scsi_host) logging.debug("The vport_ops list: %s", vport_ops_list) return vport_ops_list
def check_vport_ops_cap(scsi_hosts): """ Check vport operation capability :params scsi_hosts: list of the scsi_host """ vport_ops_list = [] for scsi_host in scsi_hosts: result = virsh.nodedev_dumpxml(scsi_host) if result.exit_status: raise error.TestFail(result.stderr) if re.search('vport_ops', result.stdout.strip()): vport_ops_list.append(scsi_host) logging.debug("The vport_ops list: %s", vport_ops_list) return vport_ops_list