Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions test_tools/disk_finder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
# Copyright(c) 2026 Unvertical
# SPDX-License-Identifier: BSD-3-Clause
#
import os
Expand Down Expand Up @@ -141,17 +142,21 @@ def __get_slaves(device_name: str):


def resolve_to_by_id_link(path):
by_id_paths = TestRun.executor.run_expect_success("ls /dev/disk/by-id -1").stdout.splitlines()
dev_full_paths = [
posixpath.join("/dev/disk/by-id", by_id_path) for by_id_path in by_id_paths
]
link_dirs = ["/dev/disk/by-id", "/dev/disk/by-path"]
dev_target = readlink(posixpath.join("/dev", path))

for full_path in dev_full_paths:
# handle exception for broken links
for link_dir in link_dirs:
try:
if readlink(full_path) == readlink(posixpath.join("/dev", path)):
return full_path
links = TestRun.executor.run_expect_success(f"ls {link_dir} -1").stdout.splitlines()
except CmdException:
continue
continue # directory may not exist if there are no links of this type
for link in links:
full_path = posixpath.join(link_dir, link)
# handle exception for broken links
try:
if readlink(full_path) == dev_target:
return full_path
except CmdException:
continue

raise ValueError(f'By-id device link not found for device {path}')
raise ValueError(f'By-id or by-path device link not found for device {path}')
11 changes: 9 additions & 2 deletions test_tools/disk_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,13 @@ def _is_by_id_path(path: str):
return path in [posixpath.join(dev_by_id_dir, id_path.full_path) for id_path in by_id_paths]


def _is_by_path_path(path: str):
"""check if given path already is proper by-path path"""
dev_by_path_dir = "/dev/disk/by-path"
by_path_paths = parse_ls_output(ls(dev_by_path_dir), dev_by_path_dir)
return path in [posixpath.join(dev_by_path_dir, p.full_path) for p in by_path_paths]


def _is_dev_path_whitelisted(path: str):
"""check if given path is whitelisted"""
whitelisted_paths = [
Expand All @@ -338,10 +345,10 @@ def validate_dev_path(path: str):
if _is_dev_path_whitelisted(path):
return path

if _is_by_id_path(path):
if _is_by_id_path(path) or _is_by_path_path(path):
return path

raise ValueError(f'By-id device link {path} is broken.')
raise ValueError(f'Device link {path} is not a valid by-id or by-path link.')


def get_block_device_names_list(exclude_list: List[int] = None) -> List[str]:
Expand Down
Loading