1313from assertpy import assert_that
1414from retry import retry
1515
16- from lisa .tools import Cat , Ip , KernelConfig , Ls , Lspci , Modprobe , Tee
16+ from lisa .tools import Cat , Ip , KernelConfig , Ls , Lspci , Modprobe , Readlink , Tee
1717from lisa .util import InitializableMixin , LisaException , constants , find_groups_in_lines
1818
1919if TYPE_CHECKING :
@@ -121,11 +121,6 @@ class Nics(InitializableMixin):
121121 )
122122 )
123123
124- # PCI slot pattern: XXXX:XX:XX.X (e.g., 34da:00:02.0)
125- __pci_slot_pattern = re .compile (
126- r"([a-zA-Z0-9]{4}:[a-zA-Z0-9]{2}:[a-zA-Z0-9]{2}\.[a-zA-Z0-9])"
127- )
128-
129124 _file_not_exist = re .compile (r"No such file or directory" , re .MULTILINE )
130125
131126 # ConnectX-3 uses mlx4_core
@@ -232,10 +227,12 @@ def get_nic_driver(self, nic_name: str) -> str:
232227 # get the current driver for the nic from the node
233228 # sysfs provides a link to the driver entry at device/driver
234229 nic = self .get_nic (nic_name )
235- cmd = f"readlink -f /sys/class/net/ { nic_name } /device/driver"
230+ readlink = self . _node . tools [ Readlink ]
236231 # ex return value:
237232 # /sys/bus/vmbus/drivers/hv_netvsc
238- found_link = self ._node .execute (cmd , expected_exit_code = 0 ).stdout
233+ found_link = readlink .get_canonical_path (
234+ f"/sys/class/net/{ nic_name } /device/driver"
235+ )
239236 assert_that (found_link ).described_as (
240237 f"sysfs check for NIC device { nic_name } driver returned no output"
241238 ).is_not_equal_to ("" )
@@ -400,8 +397,9 @@ def _get_nic_names(self) -> List[str]:
400397 return non_virtual_nics
401398
402399 def _get_nic_uuid (self , nic_name : str ) -> str :
403- full_dev_path = self ._node .execute (f"readlink /sys/class/net/{ nic_name } /device" )
404- uuid = os .path .basename (full_dev_path .stdout .strip ())
400+ readlink = self ._node .tools [Readlink ]
401+ full_dev_path = readlink .get_target (f"/sys/class/net/{ nic_name } /device" )
402+ uuid = os .path .basename (full_dev_path )
405403 self ._node .log .debug (f"{ nic_name } UUID:{ uuid } " )
406404 return uuid
407405
@@ -519,6 +517,7 @@ def _discover_standalone_pci_nics(self, lspci: Lspci) -> None:
519517 """
520518 # Get unpaired NICs that might have PCI devices
521519 unpaired_nics = self .get_unpaired_devices ()
520+ readlink = self ._node .tools [Readlink ]
522521
523522 for nic_name in unpaired_nics :
524523 nic = self .nics [nic_name ]
@@ -527,16 +526,15 @@ def _discover_standalone_pci_nics(self, lspci: Lspci) -> None:
527526 continue
528527
529528 # Try to find the PCI slot for this NIC by checking its device path
530- result = self . _node . execute (
531- f"readlink -f /sys/class/net/{ nic_name } /device" ,
532- shell = True ,
529+ device_path = readlink . get_canonical_path (
530+ f"/sys/class/net/{ nic_name } /device" ,
531+ no_error_log = True ,
533532 )
534- if result . exit_code == 0 and result . stdout . strip () :
535- # Extract PCI slot from device path
533+ if device_path :
534+ # Extract PCI slot from device path using lspci tool
536535 # Path format: /sys/devices/.../XXXX:XX:XX.X/net/nicname
537- match = self .__pci_slot_pattern .search (result .stdout )
538- if match :
539- pci_slot = match .group (1 )
536+ pci_slot = lspci .get_pci_slot_from_device_path (device_path )
537+ if pci_slot :
540538 # Get the module name for this PCI device
541539 try :
542540 module_name = lspci .get_used_module (pci_slot )
@@ -561,9 +559,10 @@ def _discover_standalone_pci_nics(self, lspci: Lspci) -> None:
561559 else :
562560 self ._node .log .debug (
563561 f"Could not extract PCI slot from device path for { nic_name } : "
564- f"{ result . stdout . strip () } "
562+ f"{ device_path } "
565563 )
566564
565+
567566 def _get_default_nic (self ) -> None :
568567 self .default_nic : str = ""
569568 self .default_nic_route : str = ""
0 commit comments