def create_nodedev_from_xml(uuid, adapter, domain): """ Create a device defined by an XML file on the node :param uuid: id for mediated device :param adapter: adapter of crypto device in host :param domain: domain of crypto device in host """ device_xml = """ <device> <parent>ap_matrix</parent> <capability type='mdev'> <uuid>%s</uuid> <type id='vfio_ap-passthrough'/> <attr name="assign_adapter" value="0x%s"/> <attr name="assign_domain" value="0x%s"/> </capability> </device> """ % (uuid, adapter, domain) logging.debug("Prepare the nodedev XML: %s", device_xml) device_file = mktemp() with open(device_file, 'w') as xml_object: xml_object.write(device_xml) virsh.nodedev_create(device_file, debug=True) return device_file
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 create_nodedev_from_xml(params): """ Create a device defined by an XML file on the node :params: the parameter dictionary """ scsi_host = params.get("nodedev_scsi_host") options = params.get("nodedev_options") status_error = params.get("status_error", "no") vhba_xml = """ <device> <parent>%s</parent> <capability type='scsi_host'> <capability type='fc_host'> </capability> </capability> </device> """ % scsi_host logging.debug("Prepare the nodedev XML: %s", vhba_xml) vhba_file = mktemp() xml_object = open(vhba_file, 'w') xml_object.write(vhba_xml) xml_object.close() result = virsh.nodedev_create(vhba_file, options) 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 error.TestFail("%d not a expected command " "return value", status) elif status_error == "no": if status: raise error.TestFail(result.stderr) else: output = result.stdout logging.info(output) for scsi in output.split(): if scsi.startswith('scsi_host'): # Check node device if check_nodedev(scsi, scsi_host): return scsi else: raise error.TestFail("Can't find %s", 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)
def create_nodedev_from_xml(test, params): """ Create a device defined by an XML file on the node :params: the parameter dictionary """ dev_name = params.get("nodedev_dev_name") if dev_name == "nodedev_NIC_name": device_xml = """ <device> <name>net_ens6f1_90_e2_ba_11_d7_a5</name> <path>/sys/devices/pci0000:00/0000:00:07.0/0000:13:00.1/net/ens6f1</path> <parent>pci_0000_13_00_1</parent> <capability type='net'> <interface>ens6f1</interface> <address>90:e2:ba:11:d7:a5</address> <link state='down'/> <feature name='gro'/> <capability type='80203'/> </capability> </device> """ logging.debug("Prepare the nodedev XML: %s", device_xml) else: scsi_host = params.get("nodedev_scsi_host") device_xml = """ <device> <parent>%s</parent> <capability type='scsi_host'> <capability type='fc_host'> </capability> </capability> </device> """ % scsi_host logging.debug("Prepare the nodedev XML: %s", device_xml) options = params.get("nodedev_options") status_error = params.get("status_error", "no") # libvirt acl polkit related params uri = params.get("virsh_uri") unprivileged_user = params.get('unprivileged_user') if unprivileged_user: if unprivileged_user.count('EXAMPLE'): unprivileged_user = '******' device_file = mktemp() with open(device_file, 'w') as xml_object: xml_object.write(device_xml) result = virsh.nodedev_create(device_file, options, uri=uri, debug=True, unprivileged_user=unprivileged_user) status = result.exit_status # Remove temporary file os.unlink(device_file) # Check status_error if status_error == "yes": if status: logging.info("It's an expected %s", result.stderr) else: test.fail("%d not a expected command " "return value", status) elif status_error == "no": if status: test.fail(result.stderr) else: output = result.stdout.strip() logging.info(output) for scsi in output.split(): if scsi.startswith('scsi_host'): # Check node device if check_nodedev(scsi, scsi_host): return scsi else: test.fail("Can't find %s" % scsi)
def create_nodedev_from_xml(test, params): """ Create a device defined by an XML file on the node :params: the parameter dictionary """ dev_name = params.get("nodedev_dev_name") if dev_name == "nodedev_NIC_name": device_xml = """ <device> <name>net_ens6f1_90_e2_ba_11_d7_a5</name> <path>/sys/devices/pci0000:00/0000:00:07.0/0000:13:00.1/net/ens6f1</path> <parent>pci_0000_13_00_1</parent> <capability type='net'> <interface>ens6f1</interface> <address>90:e2:ba:11:d7:a5</address> <link state='down'/> <feature name='gro'/> <capability type='80203'/> </capability> </device> """ logging.debug("Prepare the nodedev XML: %s", device_xml) else: scsi_host = params.get("nodedev_scsi_host") device_xml = """ <device> <parent>%s</parent> <capability type='scsi_host'> <capability type='fc_host'> </capability> </capability> </device> """ % scsi_host logging.debug("Prepare the nodedev XML: %s", device_xml) options = params.get("nodedev_options") status_error = params.get("status_error", "no") # libvirt acl polkit related params uri = params.get("virsh_uri") unprivileged_user = params.get('unprivileged_user') if unprivileged_user: if unprivileged_user.count('EXAMPLE'): unprivileged_user = '******' device_file = mktemp() with open(device_file, 'w') as xml_object: xml_object.write(device_xml) result = virsh.nodedev_create(device_file, options, uri=uri, debug=True, unprivileged_user=unprivileged_user) status = result.exit_status # Remove temprorary file os.unlink(device_file) # Check status_error if status_error == "yes": if status: logging.info("It's an expected %s", result.stderr) else: test.fail("%d not a expected command " "return value", status) elif status_error == "no": if status: test.fail(result.stderr) else: output = result.stdout.strip() logging.info(output) for scsi in output.split(): if scsi.startswith('scsi_host'): # Check node device if check_nodedev(scsi, scsi_host): return scsi else: test.fail("Can't find %s" % scsi)
def create_nodedev_from_xml(test, params): """ Create a device defined by an XML file on the node :params: the parameter dictionary """ scsi_host = params.get("nodedev_scsi_host") options = params.get("nodedev_options") status_error = params.get("status_error", "no") # libvirt acl polkit related params uri = params.get("virsh_uri") unprivileged_user = params.get('unprivileged_user') if unprivileged_user: if unprivileged_user.count('EXAMPLE'): unprivileged_user = '******' vhba_xml = """ <device> <parent>%s</parent> <capability type='scsi_host'> <capability type='fc_host'> </capability> </capability> </device> """ % scsi_host logging.debug("Prepare the nodedev XML: %s", vhba_xml) vhba_file = mktemp() with open(vhba_file, 'w') as xml_object: xml_object.write(vhba_xml) result = virsh.nodedev_create(vhba_file, options, uri=uri, debug=True, unprivileged_user=unprivileged_user) 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: test.fail("%d not a expected command " "return value", status) elif status_error == "no": if status: test.fail(result.stderr) else: output = result.stdout logging.info(output) for scsi in output.split(): if scsi.startswith('scsi_host'): # Check node device if check_nodedev(scsi, scsi_host): return scsi else: test.fail("Can't find %s" % scsi)