From 982be448a91f491a8dc78e226608348e2240c6ea Mon Sep 17 00:00:00 2001 From: Abdul Haleem Date: Mon, 8 Jan 2024 22:19:32 +0530 Subject: [PATCH] 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: