- if dut_node['type'] == NodeType.DUT:
- pci_address1 = Topology.get_interface_pci_addr(dut_node, dut_if1)
- if1_driver = Topology.get_interface_driver(dut_node, dut_if1)
- pci_address2 = Topology.get_interface_pci_addr(dut_node, dut_if2)
- if2_driver = Topology.get_interface_driver(dut_node, dut_if2)
-
- ssh = SSH()
- ssh.connect(dut_node)
-
- cmd = '{fwdir}/tests/dpdk/dpdk_scripts/cleanup_dpdk.sh ' \
- '{drv1} {pci1} {drv2} {pci2}'.\
- format(fwdir=Constants.REMOTE_FW_DIR, drv1=if1_driver,
- pci1=pci_address1, drv2=if2_driver, pci2=pci_address2)
-
- ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=600)
- if ret_code != 0:
- raise RuntimeError('Failed to cleanup the dpdk at node {name}'
- .format(name=dut_node['host']))
+ if node[u"type"] == NodeType.DUT:
+ pci_address1 = Topology.get_interface_pci_addr(node, if1)
+ pci_address2 = Topology.get_interface_pci_addr(node, if2)
+ # We are not supporting more than one driver yet.
+ nic_driver = Topology.get_interface_driver(node, if1)
+
+ command = f"{Constants.REMOTE_FW_DIR}/{Constants.RESOURCES_LIB_SH}"\
+ f"/entry/cleanup_dpdk.sh " \
+ f"{nic_driver} {pci_address1} {pci_address2}"
+ message = u"Cleanup the DPDK failed!"
+ exec_cmd_no_error(node, command, timeout=1200, message=message)
+
+ @staticmethod
+ def get_dpdk_version(node):
+ """Log and return the installed DPDK version.
+
+ The logged string ends with newline, the returned one is stripped.
+
+ :param node: Node from topology file.
+ :type node: dict
+ :returns: Stripped DPDK version string.
+ :rtype: str
+ :raises RuntimeError: If command returns nonzero return code.
+ """
+ command = f"cat {Constants.REMOTE_FW_DIR}/dpdk*/VERSION"
+ message = u"Get DPDK version failed!"
+ stdout, _ = exec_cmd_no_error(node, command, message=message)
+ # TODO: PAL should already tolerate stripped value in the log.
+ logger.info(f"DPDK Version: {stdout}")
+ return stdout.strip()
+
+ @staticmethod
+ def install_dpdk_framework(node):
+ """
+ Prepare the DPDK framework on the DUT node.
+
+ :param node: Node from topology file.
+ :type node: dict
+ :raises RuntimeError: If command returns nonzero return code.
+ """
+ command = f"{Constants.REMOTE_FW_DIR}/{Constants.RESOURCES_LIB_SH}" \
+ f"/entry/install_dpdk.sh"
+ message = u"Install the DPDK failed!"
+ exec_cmd_no_error(node, command, timeout=3600, message=message)
+ DPDKTools.get_dpdk_version(node)
+
+ @staticmethod
+ def install_dpdk_framework_on_all_duts(nodes):
+ """
+ Prepare the DPDK framework on all DUTs.
+
+ :param nodes: Nodes from topology file.
+ :type nodes: dict
+ """
+ for node in list(nodes.values()):
+ if node[u"type"] == NodeType.DUT:
+ DPDKTools.install_dpdk_framework(node)