def nodedev_create_from_xml(params): """ Create a node device with a xml object. :param params: Including nodedev_parent, scsi_wwnn, scsi_wwpn set in xml :return: The scsi device name just created """ nodedev_parent = params.get("nodedev_parent") scsi_wwnn = params.get("scsi_wwnn") scsi_wwpn = params.get("scsi_wwpn") status_error = params.get("status_error", "no") vhba_xml = NodedevXML() vhba_xml.cap_type = 'scsi_host' vhba_xml.fc_type = 'fc_host' vhba_xml.parent = nodedev_parent vhba_xml.wwnn = scsi_wwnn vhba_xml.wwpn = scsi_wwpn logging.debug("Prepare the nodedev XML: %s", vhba_xml) vhba_file = mktemp() with open(vhba_file, 'w') as xml_object: xml_object.write(str(vhba_xml)) result = virsh.nodedev_create( vhba_file, debug=True, ) status = result.exit_status # Remove temprorary file os.unlink(vhba_file) # Check status_error if status_error == "yes": if status: logging.info("It's an expected %s", result.stderr) else: raise exceptions.TestFail( "%d not a expected command " "return value", status) elif status_error == "no": if status: raise exceptions.TestFail(result.stderr) else: output = result.stdout logging.info(output) for scsi in output.split(): if scsi.startswith('scsi_host'): # Check node device utils_misc.wait_for( lambda: check_nodedev(scsi, nodedev_parent), timeout=_DELAY_TIME) if check_nodedev(scsi, nodedev_parent): return scsi else: raise exceptions.TestFail( "XML of vHBA card '%s' is not correct," "Please refer to log errors for detailed info" % scsi)
def nodedev_create_from_xml(params): """ Create a node device with a xml object. :param params: Including nodedev_parent, scsi_wwnn, scsi_wwpn set in xml :return: The scsi device name just created """ nodedev_parent = params.get("nodedev_parent") scsi_wwnn = params.get("scsi_wwnn") scsi_wwpn = params.get("scsi_wwpn") status_error = params.get("status_error", "no") vhba_xml = NodedevXML() vhba_xml.cap_type = 'scsi_host' vhba_xml.fc_type = 'fc_host' vhba_xml.parent = nodedev_parent vhba_xml.wwnn = scsi_wwnn vhba_xml.wwpn = scsi_wwpn logging.debug("Prepare the nodedev XML: %s", vhba_xml) vhba_file = mktemp() with open(vhba_file, 'w') as xml_object: xml_object.write(str(vhba_xml)) result = virsh.nodedev_create(vhba_file, debug=True, ) status = result.exit_status # Remove temprorary file os.unlink(vhba_file) # Check status_error if status_error == "yes": if status: logging.info("It's an expected %s", result.stderr) else: raise exceptions.TestFail("%d not a expected command " "return value", status) elif status_error == "no": if status: raise exceptions.TestFail(result.stderr) else: output = result.stdout logging.info(output) for scsi in output.split(): if scsi.startswith('scsi_host'): # Check node device utils_misc.wait_for( lambda: check_nodedev(scsi, nodedev_parent), timeout=_DELAY_TIME) if check_nodedev(scsi, nodedev_parent): return scsi else: raise exceptions.TestFail( "XML of vHBA card '%s' is not correct," "Please refer to log errors for detailed info" % scsi)
def nodedev_create_from_xml(params): """ Create a node device with a xml object. :param params: Including nodedev_parent, scsi_wwnn, scsi_wwpn set in xml :return: The scsi device name just created """ nodedev_parent = params.get("nodedev_parent") scsi_wwnn = params.get("scsi_wwnn") scsi_wwpn = params.get("scsi_wwpn") status_error = "yes" == params.get("status_error", "no") vhba_xml = NodedevXML() vhba_xml.cap_type = 'scsi_host' vhba_xml.fc_type = 'fc_host' vhba_xml.parent = nodedev_parent vhba_xml.wwnn = scsi_wwnn vhba_xml.wwpn = scsi_wwpn LOG.debug("Prepare the nodedev XML: %s", vhba_xml) vhba_file = mktemp() with open(vhba_file, 'w') as xml_object: xml_object.write(str(vhba_xml)) result = virsh.nodedev_create( vhba_file, debug=True, ) # Remove temporary file os.unlink(vhba_file) libvirt.check_exit_status(result, status_error) output = result.stdout_text LOG.info(output) for scsi in output.split(): if scsi.startswith('scsi_host'): # Check node device utils_misc.wait_for(lambda: check_nodedev(scsi, nodedev_parent), timeout=_TIMEOUT) if check_nodedev(scsi, nodedev_parent): return scsi else: raise exceptions.TestFail( "XML of vHBA card '%s' is not correct," "Please refer to log err for detailed info" % scsi)