From 83e8064bfb087c94516ae894380b9e0676eeb935 Mon Sep 17 00:00:00 2001 From: Kamil Gierszewski Date: Tue, 14 Nov 2023 16:23:45 +0100 Subject: [PATCH] test-framework: Add nullblock to test-framework Signed-off-by: Kamil Gierszewski --- test_tools/disk_utils.py | 9 ++++++++- test_tools/fs_utils.py | 8 ++++++-- test_utils/filesystem/symlink.py | 7 +++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/test_tools/disk_utils.py b/test_tools/disk_utils.py index 38ac3a7..9092900 100644 --- a/test_tools/disk_utils.py +++ b/test_tools/disk_utils.py @@ -1,5 +1,6 @@ # # Copyright(c) 2019-2022 Intel Corporation +# Copyright(c) 2023 Huawei Technologies Co., Ltd. # SPDX-License-Identifier: BSD-3-Clause # @@ -375,7 +376,13 @@ def _is_by_id_path(path: str): def _is_dev_path_whitelisted(path: str): """check if given path is whitelisted""" - whitelisted_paths = [r"cas\d+-\d+", r"/dev/dm-\d+"] + whitelisted_paths = [ + r"/dev/ram\d+", + r"/nullb\d+", + r"/dev/drbd\d+", + r"cas\d+-\d+", + r"/dev/dm-\d+" + ] for whitelisted_path in whitelisted_paths: if re.search(whitelisted_path, path) is not None: diff --git a/test_tools/fs_utils.py b/test_tools/fs_utils.py index 512bacc..e620bfd 100644 --- a/test_tools/fs_utils.py +++ b/test_tools/fs_utils.py @@ -1,5 +1,6 @@ # # Copyright(c) 2019-2022 Intel Corporation +# Copyright(c) 2023 Huawei Technologies Co., Ltd. # SPDX-License-Identifier: BSD-3-Clause # @@ -99,6 +100,10 @@ def check_if_regular_file_exists(path): return TestRun.executor.run(f"test -f \"{path}\"").exit_code == 0 +def check_if_special_block_exist(path): + return TestRun.executor.run(f"test -b \"{path}\"").exit_code == 0 + + def check_if_symlink_exists(path): return TestRun.executor.run(f"test -L \"{path}\"").exit_code == 0 @@ -266,7 +271,7 @@ def uncompress_archive(file, destination=None): def ls(path, options=''): default_options = "-lA --time-style=+'%Y-%m-%d %H:%M:%S'" output = TestRun.executor.run( - f"ls {default_options} {options} \"{path}\"") + f"ls {default_options} {options} {path}") return output.stdout @@ -308,7 +313,6 @@ def parse_ls_output(ls_output, dir_path=''): from test_utils.filesystem.file import File, FsItem from test_utils.filesystem.directory import Directory from test_utils.filesystem.symlink import Symlink - if file_type == '-': fs_item = File(full_path) elif file_type == 'd': diff --git a/test_utils/filesystem/symlink.py b/test_utils/filesystem/symlink.py index e67906c..7765dc8 100644 --- a/test_utils/filesystem/symlink.py +++ b/test_utils/filesystem/symlink.py @@ -1,5 +1,6 @@ # # Copyright(c) 2019-2021 Intel Corporation +# Copyright(c) 2023 Huawei Technologies Co., Ltd. # SPDX-License-Identifier: BSD-3-Clause # @@ -9,6 +10,7 @@ from test_tools.fs_utils import ( create_directory, check_if_symlink_exists, check_if_directory_exists, + check_if_special_block_exist ) from test_utils.filesystem.file import File @@ -76,6 +78,11 @@ class Symlink(File): elif not create: raise FileNotFoundError("Requested symlink does not exist.") + is_special_block = check_if_special_block_exist(link_path) + if is_special_block: + if not target or readlink(link_path) == readlink(target): + return cls(link_path) + is_dir = check_if_directory_exists(link_path) if is_dir: raise IsADirectoryError(