find the nic devices with vmbus or MSFT in the path

This commit is contained in:
Lili Deng 2024-10-29 23:30:01 +08:00 коммит произвёл LiliDeng
Родитель 7cf740191c
Коммит 99db9232d2
2 изменённых файлов: 16 добавлений и 8 удалений

Просмотреть файл

@ -517,7 +517,7 @@ class Ethtool(Tool):
netdirs = find_tool.find_files(
self.node.get_pure_path("/sys/devices"),
name_pattern="net",
path_pattern="*vmbus*",
path_pattern=["*vmbus*", "*MSFT*"],
ignore_case=True,
)
for netdir in netdirs:

Просмотреть файл

@ -2,7 +2,7 @@
# Licensed under the MIT license.
from pathlib import PurePath
from typing import List, Optional, Type
from typing import List, Optional, Type, Union
from lisa.executable import Tool
from lisa.util import LisaException
@ -27,7 +27,7 @@ class Find(Tool):
self,
start_path: PurePath,
name_pattern: str = "",
path_pattern: str = "",
path_pattern: Union[str, List[str]] = "",
file_type: str = "",
ignore_case: bool = False,
sudo: bool = False,
@ -46,11 +46,19 @@ class Find(Tool):
cmd += f" -iname '{name_pattern}'"
else:
cmd += f" -name '{name_pattern}'"
if path_pattern:
if ignore_case:
cmd += f" -ipath '{path_pattern}'"
else:
cmd += f" -path '{path_pattern}'"
# Ensure path_patterns is a list
if isinstance(path_pattern, str):
path_pattern = [path_pattern]
# Build the path pattern part with -o (OR) between patterns
path_conditions = []
for pattern in path_pattern:
path_option = "-ipath" if ignore_case else "-path"
path_conditions.append(f"{path_option} '{pattern}'")
cmd += " \\( " + " -o ".join(path_conditions) + " \\)"
if file_type:
cmd += f" -type '{file_type}'"
@ -74,7 +82,7 @@ class WindowsFind(Find):
self,
start_path: PurePath,
name_pattern: str = "",
path_pattern: str = "",
path_pattern: Union[str, List[str]] = "",
file_type: str = "",
ignore_case: bool = False,
sudo: bool = False,