+ 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)
+
+ @staticmethod
+ def get_pci_dev_driver(node, pci_addr):
+ """Get current PCI device driver on node.
+
+ .. note::
+ # lspci -vmmks 0000:00:05.0
+ Slot: 00:05.0
+ Class: Ethernet controller
+ Vendor: Red Hat, Inc
+ Device: Virtio network device
+ SVendor: Red Hat, Inc
+ SDevice: Device 0001
+ PhySlot: 5
+ Driver: virtio-pci
+
+ :param node: DUT node.
+ :param pci_addr: PCI device address.
+ :type node: dict
+ :type pci_addr: str
+ :returns: Driver or None
+ :raises RuntimeError: If PCI rescan or lspci command execution failed.
+ :raises RuntimeError: If it is not possible to get the interface driver
+ information from the node.
+ """
+ ssh = SSH()
+ ssh.connect(node)
+
+ for i in range(3):
+ logger.trace('Try number {0}: Get PCI device driver'.format(i))
+
+ cmd = 'lspci -vmmks {0}'.format(pci_addr)
+ ret_code, stdout, _ = ssh.exec_command(cmd)
+ if int(ret_code):
+ raise RuntimeError("'{0}' failed on '{1}'"
+ .format(cmd, node['host']))
+
+ for line in stdout.splitlines():
+ if not line:
+ continue
+ name = None
+ value = None
+ try:
+ name, value = line.split("\t", 1)
+ except ValueError:
+ if name == "Driver:":
+ return None
+ if name == 'Driver:':
+ return value
+
+ if i < 2:
+ logger.trace('Driver for PCI device {} not found, executing '
+ 'pci rescan and retrying'.format(pci_addr))
+ cmd = 'sh -c "echo 1 > /sys/bus/pci/rescan"'
+ ret_code, _, _ = ssh.exec_command_sudo(cmd)
+ if int(ret_code) != 0:
+ raise RuntimeError("'{0}' failed on '{1}'"
+ .format(cmd, node['host']))
+
+ return None
+
+ @staticmethod
+ def verify_kernel_module(node, module, force_load=False):
+ """Verify if kernel module is loaded on node. If parameter force
+ load is set to True, then try to load the modules.
+
+ :param node: Node.
+ :param module: Module to verify.
+ :param force_load: If True then try to load module.
+ :type node: dict
+ :type module: str
+ :type force_load: bool
+ :raises RuntimeError: If module is not loaded or failed to load.
+ """
+ command = 'grep -w {module} /proc/modules'.format(module=module)
+ message = 'Kernel module {module} is not loaded on host {host}'.\
+ format(module=module, host=node['host'])
+
+ try:
+ exec_cmd_no_error(node, command, timeout=30, sudo=False,
+ message=message)
+ except RuntimeError:
+ if force_load:
+ # Module is not loaded and we want to load it
+ DUTSetup.load_kernel_module(node, module)
+ else:
+ raise
+
+ @staticmethod
+ def verify_kernel_module_on_all_duts(nodes, module, force_load=False):
+ """Verify if kernel module is loaded on all DUTs. If parameter force
+ load is set to True, then try to load the modules.
+
+ :param node: DUT nodes.
+ :param module: Module to verify.
+ :param force_load: If True then try to load module.
+ :type node: dict
+ :type module: str
+ :type force_load: bool
+ """
+ for node in nodes.values():
+ if node['type'] == NodeType.DUT:
+ DUTSetup.verify_kernel_module(node, module, force_load)
+
+ @staticmethod
+ def verify_uio_driver_on_all_duts(nodes):
+ """Verify if uio driver kernel module is loaded on all DUTs. If module
+ is not present it will try to load it.
+
+ :param node: DUT nodes.
+ :type node: dict
+ """