+ command = "sh -c "\
+ "'echo {pci} | tee /sys/bus/pci/drivers/{driver}/bind'".\
+ format(pci=pci_addr, driver=driver)
+
+ exec_cmd_no_error(node, command, timeout=120, sudo=True,
+ message=message)
+
+ command = "sh -c "\
+ "'echo | tee /sys/bus/pci/devices/{pci}/driver_override'".\
+ format(pci=pci_addr.replace(':', r'\:'))
+
+ exec_cmd_no_error(node, command, timeout=120, sudo=True,
+ message=message)
+
+ @staticmethod
+ def pci_vf_driver_unbind(node, pf_pci_addr, vf_id):
+ """Unbind Virtual Function from driver on node.
+
+ :param node: DUT node.
+ :param pf_pci_addr: PCI device address.
+ :param vf_id: Virtual Function ID.
+ :type node: dict
+ :type pf_pci_addr: str
+ :type vf_id: int
+ :raises RuntimeError: If Virtual Function unbind failed.
+ """
+ vf_pci_addr = DUTSetup.get_virtfn_pci_addr(node, pf_pci_addr, vf_id)
+ vf_path = "/sys/bus/pci/devices/{pf_pci_addr}/virtfn{vf_id}".\
+ format(pf_pci_addr=pf_pci_addr.replace(':', r'\:'), vf_id=vf_id)
+
+ command = "sh -c "\
+ "'echo {vf_pci_addr} | tee {vf_path}/driver/unbind'".\
+ format(vf_pci_addr=vf_pci_addr, vf_path=vf_path)
+
+ message = 'Failed to unbind VF {vf_pci_addr} to on {host}'.\
+ format(vf_pci_addr=vf_pci_addr, host=node['host'])
+
+ exec_cmd_no_error(node, command, timeout=120, sudo=True,
+ message=message)
+
+ @staticmethod
+ def pci_vf_driver_bind(node, pf_pci_addr, vf_id, driver):
+ """Bind Virtual Function to driver on node.
+
+ :param node: DUT node.
+ :param pf_pci_addr: PCI device address.
+ :param vf_id: Virtual Function ID.
+ :param driver: Driver to bind.
+ :type node: dict
+ :type pf_pci_addr: str
+ :type vf_id: int
+ :type driver: str
+ :raises RuntimeError: If PCI device bind failed.
+ """
+ vf_pci_addr = DUTSetup.get_virtfn_pci_addr(node, pf_pci_addr, vf_id)
+ vf_path = "/sys/bus/pci/devices/{pf_pci_addr}/virtfn{vf_id}".\
+ format(pf_pci_addr=pf_pci_addr.replace(':', r'\:'), vf_id=vf_id)
+
+ message = 'Failed to bind VF {vf_pci_addr} to {driver} on {host}'.\
+ format(vf_pci_addr=vf_pci_addr, driver=driver, host=node['host'])
+
+ command = "sh -c "\
+ "'echo {driver} | tee {vf_path}/driver_override'".\
+ format(driver=driver, vf_path=vf_path)
+
+ exec_cmd_no_error(node, command, timeout=120, sudo=True,
+ message=message)
+
+ command = "sh -c "\
+ "'echo {vf_pci_addr} | tee /sys/bus/pci/drivers/{driver}/bind'".\
+ format(vf_pci_addr=vf_pci_addr, driver=driver)
+
+ exec_cmd_no_error(node, command, timeout=120, sudo=True,
+ message=message)
+
+ command = "sh -c "\
+ "'echo | tee {vf_path}/driver_override'".\
+ format(vf_path=vf_path)
+
+ exec_cmd_no_error(node, command, timeout=120, sudo=True,
+ message=message)