test-framework: Add nullblock to test-framework

Signed-off-by: Kamil Gierszewski <kamil.gierszewski@huawei.com>
This commit is contained in:
Kamil Gierszewski 2023-11-14 16:23:45 +01:00
parent d62106e850
commit 83e8064bfb
No known key found for this signature in database
3 changed files with 21 additions and 3 deletions

View File

@ -1,5 +1,6 @@
# #
# Copyright(c) 2019-2022 Intel Corporation # Copyright(c) 2019-2022 Intel Corporation
# Copyright(c) 2023 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# #
@ -375,7 +376,13 @@ def _is_by_id_path(path: str):
def _is_dev_path_whitelisted(path: str): def _is_dev_path_whitelisted(path: str):
"""check if given path is whitelisted""" """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: for whitelisted_path in whitelisted_paths:
if re.search(whitelisted_path, path) is not None: if re.search(whitelisted_path, path) is not None:

View File

@ -1,5 +1,6 @@
# #
# Copyright(c) 2019-2022 Intel Corporation # Copyright(c) 2019-2022 Intel Corporation
# Copyright(c) 2023 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause # 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 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): def check_if_symlink_exists(path):
return TestRun.executor.run(f"test -L \"{path}\"").exit_code == 0 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=''): def ls(path, options=''):
default_options = "-lA --time-style=+'%Y-%m-%d %H:%M:%S'" default_options = "-lA --time-style=+'%Y-%m-%d %H:%M:%S'"
output = TestRun.executor.run( output = TestRun.executor.run(
f"ls {default_options} {options} \"{path}\"") f"ls {default_options} {options} {path}")
return output.stdout 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.file import File, FsItem
from test_utils.filesystem.directory import Directory from test_utils.filesystem.directory import Directory
from test_utils.filesystem.symlink import Symlink from test_utils.filesystem.symlink import Symlink
if file_type == '-': if file_type == '-':
fs_item = File(full_path) fs_item = File(full_path)
elif file_type == 'd': elif file_type == 'd':

View File

@ -1,5 +1,6 @@
# #
# Copyright(c) 2019-2021 Intel Corporation # Copyright(c) 2019-2021 Intel Corporation
# Copyright(c) 2023 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# #
@ -9,6 +10,7 @@ from test_tools.fs_utils import (
create_directory, create_directory,
check_if_symlink_exists, check_if_symlink_exists,
check_if_directory_exists, check_if_directory_exists,
check_if_special_block_exist
) )
from test_utils.filesystem.file import File from test_utils.filesystem.file import File
@ -76,6 +78,11 @@ class Symlink(File):
elif not create: elif not create:
raise FileNotFoundError("Requested symlink does not exist.") 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) is_dir = check_if_directory_exists(link_path)
if is_dir: if is_dir:
raise IsADirectoryError( raise IsADirectoryError(