Skip to content

Commit

Permalink
Adding util to get the NIC model, xfail QinQ on xxv710, and mock (#134)
Browse files Browse the repository at this point in the history
* Adding util to get the NIC model, skip QinQ on xxv710, and mock
  • Loading branch information
dkosteck authored Mar 6, 2023
1 parent 459868b commit 5ff9f9e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
24 changes: 24 additions & 0 deletions sriov/common/test_utils_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
set_pipefail,
execute_until_timeout,
calc_required_pages_2M,
get_nic_model,
) # noqa: E402
import unittest

Expand Down Expand Up @@ -202,18 +203,41 @@ 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"]
elif args[1] == "1G":
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()
33 changes: 25 additions & 8 deletions sriov/common/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from sriov.common.configtestdata import ConfigTestData
from sriov.common.exec import ShellHandler
import time
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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()
12 changes: 11 additions & 1 deletion sriov/tests/SR_IOV_QinQ/test_SR_IOV_QinQ.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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 = [
Expand Down

0 comments on commit 5ff9f9e

Please sign in to comment.