Skip to content

Commit

Permalink
test-framework: add null blk
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Gierszewski <[email protected]>
  • Loading branch information
Kamil Gierszewski authored and katlapinka committed Sep 16, 2024
1 parent 42ebe34 commit 1e82bd6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
51 changes: 51 additions & 0 deletions storage_devices/nullblk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#

from core.test_run import TestRun
from storage_devices.device import Device
from test_tools.fs_utils import ls, parse_ls_output
from test_utils.os_utils import (
unload_kernel_module,
is_kernel_module_loaded,
ModuleRemoveMethod,
reload_kernel_module,
)


class NullBlk(Device):
_module = "null_blk"

@classmethod
def create(
cls, completion_nsec: int = 10000, size_gb: int = 250, nr_devices: int = 1, bs: int = 512
):
TestRun.LOGGER.info("Configure null_blk...")
params = {
"completion_nsec": str(completion_nsec),
"gb": str(size_gb),
"nr_devices": str(nr_devices),
"bs": str(bs),
}

reload_kernel_module(cls._module, params)
return cls.list()

@classmethod
def remove_all(cls):
if not is_kernel_module_loaded(cls._module):
return
TestRun.LOGGER.info("Removing null_blk ")
unload_kernel_module(module_name=cls._module, unload_method=ModuleRemoveMethod.modprobe)

@classmethod
def list(cls):
return [cls(null_blk.full_path) for null_blk in cls._list_devices()]

@staticmethod
def _list_devices():
ls_output = ls(f"/dev/nullb*")
if "No such file or directory" in ls_output:
return []
return parse_ls_output(ls_output)
4 changes: 0 additions & 4 deletions test_tools/fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ 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

Expand Down
11 changes: 2 additions & 9 deletions test_utils/filesystem/symlink.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# Copyright(c) 2023 Huawei Technologies Co., Ltd.
# Copyright(c) 2023-2024 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#

Expand All @@ -9,8 +9,7 @@
readlink,
create_directory,
check_if_symlink_exists,
check_if_directory_exists,
check_if_special_block_exist
check_if_directory_exists
)
from test_utils.filesystem.file import File

Expand Down Expand Up @@ -77,12 +76,6 @@ def get_symlink(cls, link_path: str, target: str = None, create: bool = False):
raise FileExistsError("Existing symlink points to a different target.")
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(
Expand Down

0 comments on commit 1e82bd6

Please sign in to comment.