From d358c154ee2cac6545562247e4b24d909c01e536 Mon Sep 17 00:00:00 2001 From: Abdul Haleem Date: Mon, 8 Jan 2024 21:44:26 +0530 Subject: [PATCH 1/3] network_stress: support hw addr as input name Add support for mac addr as input, in case if the device names are not persistent across os install the test should still run via unique mac addr in end to end automated environment Signed-off-by: Abdul Haleem --- io/net/network_test.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/io/net/network_test.py b/io/net/network_test.py index 4953734df..25c13e87f 100755 --- a/io/net/network_test.py +++ b/io/net/network_test.py @@ -23,7 +23,6 @@ import os import hashlib -import netifaces from avocado import Test from avocado.utils.software_manager.manager import SoftwareManager from avocado.utils import process @@ -56,21 +55,25 @@ def setUp(self): for pkg in pkgs: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package is need to test" % pkg) - interfaces = netifaces.interfaces() - interface = self.params.get("interface") - if interface not in interfaces: - self.cancel("%s interface is not available" % interface) - self.iface = interface + interfaces = os.listdir('/sys/class/net') + local = LocalHost() + device = self.params.get("interface") + if device in interfaces: + self.interface = device + elif local.validate_mac_addr(device) and device in local.get_all_hwaddr(): + self.interface = local.get_interface_by_hwaddr(device).name + else: + self.interface = None + self.cancel("Please check the network device") self.ipaddr = self.params.get("host_ip", default="") self.netmask = self.params.get("netmask", default="") self.ip_config = self.params.get("ip_config", default=True) self.hbond = self.params.get("hbond", default=False) - local = LocalHost() if self.hbond: self.networkinterface = NetworkInterface( - self.iface, local, if_type='Bond') + self.interface, local, if_type='Bond') else: - self.networkinterface = NetworkInterface(self.iface, local) + self.networkinterface = NetworkInterface(self.interface, local) if self.ip_config: try: self.networkinterface.add_ipaddr(self.ipaddr, self.netmask) @@ -149,7 +152,7 @@ def test_lro(self): ''' ro_type = "lro" ro_type_full = "large-receive-offload" - path = '/sys/class/net/%s/device/uevent' % self.iface + path = '/sys/class/net/%s/device/uevent' % self.interface if os.path.exists(path): output = open(path, 'r').read() for line in output.splitlines(): @@ -250,8 +253,8 @@ def test_statistics(self): ''' Test Statistics ''' - rx_file = "/sys/class/net/%s/statistics/rx_packets" % self.iface - tx_file = "/sys/class/net/%s/statistics/tx_packets" % self.iface + rx_file = "/sys/class/net/%s/statistics/rx_packets" % self.interface + tx_file = "/sys/class/net/%s/statistics/tx_packets" % self.interface rx_before = genio.read_file(rx_file) tx_before = genio.read_file(tx_file) self.networkinterface.ping_check(self.peer, self.count, options='-f') @@ -289,7 +292,7 @@ def offload_state_change(self, ro_type, ro_type_full, state): ''' Change the state of LRO / GRO / GSO / TSO to specified state ''' - cmd = "ethtool -K %s %s %s" % (self.iface, ro_type, state) + cmd = "ethtool -K %s %s %s" % (self.interface, ro_type, state) if process.system(cmd, shell=True, ignore_status=True) != 0: return False if self.offload_state(ro_type_full) != state: @@ -302,7 +305,7 @@ def offload_state(self, ro_type_full): If the state can not be changed, we return 'fixed'. If any other error, we return ''. ''' - cmd = "ethtool -k %s" % self.iface + cmd = "ethtool -k %s" % self.interface output = process.system_output(cmd, shell=True, ignore_status=True).decode("utf-8") for line in output.splitlines(): @@ -316,11 +319,11 @@ def test_promisc(self): ''' promisc mode testing ''' - cmd = "ip link set %s promisc on" % self.iface + cmd = "ip link set %s promisc on" % self.interface if process.system(cmd, shell=True, ignore_status=True) != 0: self.fail("failed to enable promisc mode") self.networkinterface.ping_check(self.peer, self.count, options='-f') - cmd = "ip link set %s promisc off" % self.iface + cmd = "ip link set %s promisc off" % self.interface if process.system(cmd, shell=True, ignore_status=True) != 0: self.fail("failed to disable promisc mode") self.networkinterface.ping_check(self.peer, count=5) From 982be448a91f491a8dc78e226608348e2240c6ea Mon Sep 17 00:00:00 2001 From: Abdul Haleem Date: Mon, 8 Jan 2024 22:19:32 +0530 Subject: [PATCH 2/3] numactl.py: support hw addr as input name Add support for mac addr as input, in case if the device names are not persistent across os install the test should still run via unique mac addr in end to end automated environment Signed-off-by: Abdul Haleem --- cpu/numactl.py | 55 +++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/cpu/numactl.py b/cpu/numactl.py index fd3c121e8..7712e43f4 100644 --- a/cpu/numactl.py +++ b/cpu/numactl.py @@ -69,23 +69,24 @@ def setUp(self): process.run('./configure', shell=True) build.make(self.sourcedir) - - self.iface = self.params.get("interface", default="") + self.localhost = LocalHost() + self.interface = None + interfaces = os.listdir('/sys/class/net') + iface = self.params.get("interface", default="") self.disk = self.params.get("disk", default="") - - if self.iface: + if iface: + if iface in interfaces: + self.interface = iface + elif self.localhost.validate_mac_addr(iface) and iface in self.localhost.get_all_hwaddr(): + self.interface = self.localhost.get_interface_by_hwaddr(iface).name + else: + self.cancel("Please check the network device") self.ping_count = self.params.get("ping_count", default=100) self.peer = self.params.get("peer_ip", default="") - interfaces = os.listdir('/sys/class/net') - if not self.iface: - self.cancel("Please specify interface to be used") - if self.iface not in interfaces: - self.cancel("%s interface is not available" % self.iface) if not self.peer: self.cancel("peer ip need to specify in YAML") self.ipaddr = self.params.get("host_ip", default="") - self.localhost = LocalHost() - self.networkinterface = NetworkInterface(self.iface, + self.networkinterface = NetworkInterface(self.interface, self.localhost) if not self.networkinterface.validate_ipv4_format(self.ipaddr): self.cancel("Host IP formatt in YAML is incorrect," @@ -178,11 +179,11 @@ def test_interleave(self): ''' To check memory interleave on NUMA nodes. ''' - if not self.iface and not self.disk: + if not self.interface and not self.disk: self.cancel("Network inferface or disk/device input missing") - if self.iface: + if self.interface: cmd = "numactl --interleave=all ping -I %s %s -c %s -f"\ - % (self.iface, self.peer, self.ping_count) + % (self.interface, self.peer, self.ping_count) self.numa_ping(cmd) if self.disk: @@ -198,11 +199,11 @@ def test_localalloc(self): ''' Test memory allocation on the current node ''' - if not self.iface and not self.disk: + if not self.interface and not self.disk: self.cancel("Network inferface or disk/device input missing") - if self.iface: + if self.interface: cmd = "numactl --localalloc ping -I %s %s -c %s -f"\ - % (self.iface, self.peer, self.ping_count) + % (self.interface, self.peer, self.ping_count) self.numa_ping(cmd) if self.disk: @@ -218,17 +219,17 @@ def test_preferred_node(self): ''' Test Preferably allocate memory on node ''' - if not self.iface and not self.disk: + if not self.interface and not self.disk: self.cancel("Network inferface or disk/device input missing") if self.check_numa_nodes(): self.node_number = [key for key in self.numa_dict.keys()][1] - if self.iface: + if self.interface: cmd = "numactl --preferred=%s ping -I %s %s -c %s -f" \ % (self.node_number, - self.iface, + self.interface, self.peer, self.ping_count) self.numa_ping(cmd) @@ -247,7 +248,7 @@ def test_cpunode_with_membind(self): ''' Test CPU and memory bind ''' - if not self.iface and not self.disk: + if not self.interface and not self.disk: self.cancel("Network inferface or disk/device input missing") if self.check_numa_nodes(): self.first_cpu_node_number = [key @@ -259,13 +260,13 @@ def test_cpunode_with_membind(self): self.membind_node_number = [key for key in self.numa_dict.keys()][1] - if self.iface: + if self.interface: for cpu in [self.first_cpu_node_number, self.second_cpu_node_number]: cmd = "numactl --cpunodebind=%s --membind=%s ping -I %s \ %s -c %s -f" % (cpu, self.membind_node_number, - self.iface, + self.interface, self.peer, self.ping_count) self.numa_ping(cmd) @@ -286,16 +287,16 @@ def test_physical_cpu_bind(self): ''' Test physcial CPU binds ''' - if not self.iface and not self.disk: + if not self.interface and not self.disk: self.cancel("Network inferface or disk/device input missing") if self.check_numa_nodes(): self.cpu_number = [value for value in self.numa_dict.values()][0][1] - if self.iface: + if self.interface: cmd = "numactl --physcpubind=%s ping -I %s %s -c %s -f"\ - % (self.cpu_number, self.iface, self.peer, self.ping_count) + % (self.cpu_number, self.interface, self.peer, self.ping_count) self.numa_ping(cmd) if self.disk: @@ -325,7 +326,7 @@ def tearDown(self): ''' Cleaning up Host IP address ''' - if self.iface: + if self.interface: if self.networkinterface: self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask) try: From b51a77a88ff5c4b536fa3d3411e889814f7674f6 Mon Sep 17 00:00:00 2001 From: Abdul Haleem Date: Mon, 8 Jan 2024 23:05:26 +0530 Subject: [PATCH 3/3] irqbalance: support hw addr as input name Add support for mac addr as input, in case if the device names are not persistent across os install the test should still run via unique mac addr in end to end automated environment Signed-off-by: Abdul Haleem --- io/net/irqbalance.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/io/net/irqbalance.py b/io/net/irqbalance.py index 92c93971f..c9b133469 100755 --- a/io/net/irqbalance.py +++ b/io/net/irqbalance.py @@ -56,21 +56,23 @@ def setUp(self): ''' Set up ''' - self.iface = self.params.get("interface", default=None) + self.interface = None + device = self.params.get("interface", default=None) self.disk = self.params.get("disk", default=None) - if self.iface: + if device: self.peer_ip = self.params.get("peer_ip", default=None) self.ping_count = self.params.get("ping_count", default=None) interfaces = os.listdir('/sys/class/net') - self.interface = self.params.get("interface", default=None) - if not self.interface: - self.cancel("Please specify interface to be used") - if self.interface not in interfaces: - self.cancel("%s interface is not available" % self.interface) + self.localhost = LocalHost() + if device in interfaces: + self.interface = device + elif self.localhost.validate_mac_addr(device) and device in self.localhost.get_all_hwaddr(): + self.interface = self.localhost.get_interface_by_hwaddr(device).name + else: + self.cancel("Please check the network device") if not self.peer_ip: self.cancel("peer ip need to specify in YAML") self.ipaddr = self.params.get("host_ip", default="") - self.localhost = LocalHost() self.networkinterface = NetworkInterface(self.interface, self.localhost) if not self.networkinterface.validate_ipv4_format(self.ipaddr): @@ -217,7 +219,7 @@ def taskset_cpu_validation(self): Function to validate the CPU number set by "taskset" command. Returns : value set by script. ''' - if self.iface: + if self.interface: cmd = "ps -o psr -p %s | awk 'NR>1 {print $1}'" % ( self.get_ping_process_pid() ) @@ -385,7 +387,7 @@ def test_taskset(self): CPU1 ---> CPU2 CPU2 ---> CPU3, ----> till last availble CPU number. ''' - if self.iface: + if self.interface: for cpu_number in self.cpu_list: if self.networkinterface.ping_flood(self.interface, self.peer_ip, @@ -447,7 +449,7 @@ def tearDown(self): shell=True ) self.__online_cpus(totalcpus) - if self.iface: + if self.interface: if self.networkinterface: self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask) try: