From 5ff9f9e1e402fb32ec528846343a0d1c75b0a6f6 Mon Sep 17 00:00:00 2001 From: Daniel Kostecki <84861140+dkosteck@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:09:10 -0500 Subject: [PATCH] Adding util to get the NIC model, xfail QinQ on xxv710, and mock (#134) * Adding util to get the NIC model, skip QinQ on xxv710, and mock --- sriov/common/test_utils_mock.py | 24 +++++++++++++++ sriov/common/utils.py | 33 ++++++++++++++++----- sriov/tests/SR_IOV_QinQ/test_SR_IOV_QinQ.py | 12 +++++++- 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/sriov/common/test_utils_mock.py b/sriov/common/test_utils_mock.py index 9bb1315..e391662 100644 --- a/sriov/common/test_utils_mock.py +++ b/sriov/common/test_utils_mock.py @@ -25,6 +25,7 @@ set_pipefail, execute_until_timeout, calc_required_pages_2M, + get_nic_model, ) # noqa: E402 import unittest @@ -202,6 +203,7 @@ def test_calc_required_pages_2M(self, mock_get_hugepage_info): ] for testcase in testcases: + def get_hugepage_info_side_effect(*args, **kwargs): if args[1] == "2M": return testcase["2M"] @@ -209,11 +211,33 @@ def get_hugepage_info_side_effect(*args, **kwargs): return testcase["1G"] else: raise Exception("Invalid input") + mock_get_hugepage_info.side_effect = get_hugepage_info_side_effect actual = calc_required_pages_2M(ssh_obj, testcase["instance"]) expected = testcase["expected"] assert actual == expected, f"actual: {actual}, expected: {expected}" + def test_get_nic_model(self): + ssh_obj = self.create_mock_ssh_obj( + 0, + [ + " CPUID PCI (sysfs) ISA PnP PnP " + + "(sysfs) PCMCIA PCMCIA Virtual I/O (VIRTIO) " + + "devices IBM Virtual I/O (VIO) " + + " kernel device tree (sysfs) " + + " USB IDE SCSI NVMe MMC sound graphics " + + "input S/390 devices Network interfaces " + + " Framebuffer devices Display " + + "CPUFreq ABI pci@0000:00:00.0 ens0f0 network " + + " Ethernet Controller XXV710 for 25GbE SFP28\n" + ], + "", + ) + assert ( + get_nic_model(ssh_obj, "ens0f0") + == "Ethernet Controller XXV710 for 25GbE SFP28" + ) + if __name__ == "__main__": unittest.main() diff --git a/sriov/common/utils.py b/sriov/common/utils.py index 73b7bb3..0f76650 100644 --- a/sriov/common/utils.py +++ b/sriov/common/utils.py @@ -1,3 +1,4 @@ +import re from sriov.common.configtestdata import ConfigTestData from sriov.common.exec import ShellHandler import time @@ -104,7 +105,7 @@ def config_interface(ssh_obj: ShellHandler, intf: str, vlan: int, ip: str) -> bo else: steps = [ f"ip add del {ip}/24 dev {intf} 2>/dev/null || true", - f"ip add add {ip}/24 dev {intf}" + f"ip add add {ip}/24 dev {intf}", ] for step in steps: ssh_obj.log_str(step) @@ -114,8 +115,9 @@ def config_interface(ssh_obj: ShellHandler, intf: str, vlan: int, ip: str) -> bo return True -def config_interface_ipv6(ssh_obj: ShellHandler, intf: str, - vlan: int, ipv6: str) -> bool: +def config_interface_ipv6( + ssh_obj: ShellHandler, intf: str, vlan: int, ipv6: str +) -> bool: """Config an IPv6 address on VLAN interface; if VLAN is 0, config IPv6 on main interface @@ -151,8 +153,7 @@ def config_interface_ipv6(ssh_obj: ShellHandler, intf: str, return True -def clear_interface(ssh_obj: ShellHandler, intf: str, ip: str, - vlan: int = 0) -> bool: +def clear_interface(ssh_obj: ShellHandler, intf: str, ip: str, vlan: int = 0) -> bool: """Clear the IP address from the VLAN interface and the main interface Args: @@ -179,8 +180,9 @@ def clear_interface(ssh_obj: ShellHandler, intf: str, ip: str, return True -def clear_interface_ipv6(ssh_obj: ShellHandler, intf: str, ipv6: str, - vlan: int = 0) -> bool: +def clear_interface_ipv6( + ssh_obj: ShellHandler, intf: str, ipv6: str, vlan: int = 0 +) -> bool: """Clear the IPv6 address from the VLAN interface and the main interface Args: @@ -1006,7 +1008,7 @@ def switch_detected(ssh_obj: ShellHandler, interface: str) -> bool: return code == 0 -def is_package_installed(ssh_obj: ShellHandler, package_name) -> bool: +def is_package_installed(ssh_obj: ShellHandler, package_name: str) -> bool: """Test if the specified RPM package is installed Args: @@ -1020,3 +1022,18 @@ def is_package_installed(ssh_obj: ShellHandler, package_name) -> bool: ssh_obj.log_str(cmd) code, _, _ = ssh_obj.execute(cmd) return code == 0 + + +def get_nic_model(ssh_obj: ShellHandler, pf: str) -> str: + """Get the NIC model + + Args: + ssh_obj (ShellHandler): ssh connection obj + pf (str): interface name + + Returns: + str: The model of the NIC + """ + cmd = [f"lshw -C network -businfo | grep {pf}"] + outs, _ = execute_and_assert(ssh_obj, cmd, 0) + return re.split("\\s{2,}", outs[0][0])[-1].strip() diff --git a/sriov/tests/SR_IOV_QinQ/test_SR_IOV_QinQ.py b/sriov/tests/SR_IOV_QinQ/test_SR_IOV_QinQ.py index 9cd641d..f42ce35 100644 --- a/sriov/tests/SR_IOV_QinQ/test_SR_IOV_QinQ.py +++ b/sriov/tests/SR_IOV_QinQ/test_SR_IOV_QinQ.py @@ -1,4 +1,11 @@ -from sriov.common.utils import create_vfs, execute_and_assert, start_tmux, stop_tmux +import pytest +from sriov.common.utils import ( + create_vfs, + execute_and_assert, + get_nic_model, + start_tmux, + stop_tmux, +) def test_SR_IOV_QinQ(dut, trafficgen, settings, testdata): @@ -16,6 +23,9 @@ def test_SR_IOV_QinQ(dut, trafficgen, settings, testdata): inside_tag = 20 pf = settings.config["dut"]["interface"]["pf1"]["name"] + if "xxv710" in get_nic_model(dut, pf).lower(): + pytest.skip("QinQ unsupported on XXV710 NICs - skipping test.") + assert create_vfs(dut, pf, 1) steps = [