Fix imports
Signed-off-by: Katarzyna Treder <katarzyna.treder@h-partners.com>
This commit is contained in:
@@ -3,31 +3,32 @@
|
||||
# Copyright(c) 2023-2024 Huawei Technologies Co., Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
import posixpath
|
||||
|
||||
import test_tools.fs_tools
|
||||
from core.test_run import TestRun
|
||||
from test_tools import disk_tools, fs_tools
|
||||
from test_tools.disk_tools import get_sysfs_path
|
||||
from test_tools.fs_tools import get_device_filesystem_type
|
||||
from test_tools import disk_tools
|
||||
from test_tools.disk_tools import get_sysfs_path, validate_dev_path, get_size
|
||||
from test_tools.fs_tools import (get_device_filesystem_type, Filesystem, wipefs,
|
||||
readlink, write_file, mkfs, ls, parse_ls_output)
|
||||
from test_utils.io_stats import IoStats
|
||||
from type_def.size import Size, Unit
|
||||
|
||||
|
||||
class Device:
|
||||
def __init__(self, path):
|
||||
disk_tools.validate_dev_path(path)
|
||||
validate_dev_path(path)
|
||||
self.path = path
|
||||
self.size = Size(disk_tools.get_size(self.get_device_id()), Unit.Byte)
|
||||
self.size = Size(get_size(self.get_device_id()), Unit.Byte)
|
||||
self.filesystem = get_device_filesystem_type(self.get_device_id())
|
||||
self.mount_point = None
|
||||
|
||||
def create_filesystem(self, fs_type: test_tools.fs_tools.Filesystem, force=True, blocksize=None):
|
||||
test_tools.fs_tools.create_filesystem(self, fs_type, force, blocksize)
|
||||
def create_filesystem(self, fs_type: Filesystem, force=True, blocksize=None):
|
||||
mkfs(self, fs_type, force, blocksize)
|
||||
self.filesystem = fs_type
|
||||
|
||||
def wipe_filesystem(self, force=True):
|
||||
test_tools.fs_tools.wipe_filesystem(self, force)
|
||||
wipefs(self, force)
|
||||
self.filesystem = None
|
||||
|
||||
def is_mounted(self):
|
||||
@@ -36,7 +37,7 @@ class Device:
|
||||
return False
|
||||
else:
|
||||
mount_point_line = output.stdout.split('\n')[1]
|
||||
device_path = fs_tools.readlink(self.path)
|
||||
device_path = readlink(self.path)
|
||||
self.mount_point = mount_point_line[0:mount_point_line.find(device_path)].strip()
|
||||
return True
|
||||
|
||||
@@ -58,27 +59,26 @@ class Device:
|
||||
return next(i for i in items if i.full_path.startswith(directory))
|
||||
|
||||
def get_device_id(self):
|
||||
return fs_tools.readlink(self.path).split('/')[-1]
|
||||
return readlink(self.path).split('/')[-1]
|
||||
|
||||
def get_all_device_links(self, directory: str):
|
||||
from test_tools import fs_tools
|
||||
output = fs_tools.ls(f"$(find -L {directory} -samefile {self.path})")
|
||||
return fs_tools.parse_ls_output(output, self.path)
|
||||
output = ls(f"$(find -L {directory} -samefile {self.path})")
|
||||
return parse_ls_output(output, self.path)
|
||||
|
||||
def get_io_stats(self):
|
||||
return IoStats.get_io_stats(self.get_device_id())
|
||||
|
||||
def get_sysfs_property(self, property_name):
|
||||
path = posixpath.join(disk_tools.get_sysfs_path(self.get_device_id()),
|
||||
path = posixpath.join(get_sysfs_path(self.get_device_id()),
|
||||
"queue", property_name)
|
||||
return TestRun.executor.run_expect_success(f"cat {path}").stdout
|
||||
|
||||
def set_sysfs_property(self, property_name, value):
|
||||
TestRun.LOGGER.info(
|
||||
f"Setting {property_name} for device {self.get_device_id()} to {value}.")
|
||||
path = posixpath.join(disk_tools.get_sysfs_path(self.get_device_id()), "queue",
|
||||
path = posixpath.join(get_sysfs_path(self.get_device_id()), "queue",
|
||||
property_name)
|
||||
fs_tools.write_file(path, str(value))
|
||||
write_file(path, str(value))
|
||||
|
||||
def set_max_io_size(self, new_max_io_size: Size):
|
||||
self.set_sysfs_property("max_sectors_kb",
|
||||
|
@@ -10,13 +10,14 @@ import re
|
||||
from datetime import timedelta
|
||||
from enum import IntEnum
|
||||
|
||||
import test_tools.fs_tools
|
||||
from core.test_run import TestRun
|
||||
from storage_devices.device import Device
|
||||
from test_tools import disk_tools, fs_tools, nvme_cli
|
||||
from test_tools.common.wait import wait
|
||||
from connection.utils.output import Output
|
||||
from storage_devices.device import Device
|
||||
from test_tools import disk_tools, nvme_cli
|
||||
from test_tools.common.wait import wait
|
||||
from test_tools.disk_finder import get_block_devices_list, resolve_to_by_id_link
|
||||
from test_tools.disk_tools import PartitionTable
|
||||
from test_tools.fs_tools import readlink, is_mounted, ls_item, parse_ls_output
|
||||
from type_def.size import Unit
|
||||
|
||||
|
||||
@@ -138,7 +139,7 @@ class Disk(Device):
|
||||
)
|
||||
return recognized_types[0]
|
||||
|
||||
def create_partitions(self, sizes: [], partition_table_type=disk_tools.PartitionTable.gpt):
|
||||
def create_partitions(self, sizes: [], partition_table_type=PartitionTable.gpt):
|
||||
disk_tools.create_partitions(self, sizes, partition_table_type)
|
||||
|
||||
def remove_partition(self, part):
|
||||
@@ -148,12 +149,12 @@ class Disk(Device):
|
||||
|
||||
def umount_all_partitions(self):
|
||||
TestRun.LOGGER.info(f"Unmounting all partitions from: {self.path}")
|
||||
cmd = f"umount -l {fs_tools.readlink(self.path)}*?"
|
||||
cmd = f"umount -l {readlink(self.path)}*?"
|
||||
TestRun.executor.run(cmd)
|
||||
|
||||
def remove_partitions(self):
|
||||
for part in self.partitions:
|
||||
if test_tools.fs_tools.is_mounted(part.path):
|
||||
if is_mounted(part.path):
|
||||
part.unmount()
|
||||
if disk_tools.remove_partitions(self):
|
||||
self.partitions.clear()
|
||||
@@ -163,8 +164,8 @@ class Disk(Device):
|
||||
serial_numbers = Disk.get_all_serial_numbers()
|
||||
return self.serial_number in serial_numbers
|
||||
elif self.path:
|
||||
output = fs_tools.ls_item(f"{self.path}")
|
||||
return fs_tools.parse_ls_output(output)[0] is not None
|
||||
output = ls_item(f"{self.path}")
|
||||
return parse_ls_output(output)[0] is not None
|
||||
raise Exception("Couldn't check if device is detected by the system")
|
||||
|
||||
def wait_for_plug_status(self, should_be_visible):
|
||||
@@ -290,8 +291,8 @@ class NvmeDisk(Disk):
|
||||
base = f"/sys/block/{device_id}/device"
|
||||
for suffix in ["/remove", "/device/remove"]:
|
||||
try:
|
||||
output = fs_tools.ls_item(base + suffix)
|
||||
fs_tools.parse_ls_output(output)[0]
|
||||
output = ls_item(base + suffix)
|
||||
parse_ls_output(output)[0]
|
||||
except TypeError:
|
||||
continue
|
||||
return base + suffix
|
||||
@@ -346,8 +347,8 @@ class SataDisk(Disk):
|
||||
@staticmethod
|
||||
def get_sysfs_addr(device_id):
|
||||
ls_command = f"$(find -H /sys/devices/ -name {device_id} -type d)"
|
||||
output = fs_tools.ls_item(f"{ls_command}")
|
||||
sysfs_addr = fs_tools.parse_ls_output(output)[0]
|
||||
output = ls_item(ls_command)
|
||||
sysfs_addr = parse_ls_output(output)[0]
|
||||
if not sysfs_addr:
|
||||
raise Exception(f"Failed to find sysfs address: ls -l {ls_command}")
|
||||
return sysfs_addr.full_path
|
||||
@@ -413,8 +414,8 @@ class VirtioDisk(Disk):
|
||||
@staticmethod
|
||||
def get_sysfs_addr(device_id: str) -> str:
|
||||
ls_command = f"$(find -H /sys/devices/ -name {device_id} -type d)"
|
||||
output = fs_tools.ls_item(f"{ls_command}")
|
||||
sysfs_addr = fs_tools.parse_ls_output(output)[0]
|
||||
output = ls_item(ls_command)
|
||||
sysfs_addr = parse_ls_output(output)[0]
|
||||
if not sysfs_addr:
|
||||
raise Exception(f"Failed to find sysfs address: ls -l {ls_command}")
|
||||
|
||||
|
@@ -4,13 +4,13 @@
|
||||
#
|
||||
|
||||
from storage_devices.device import Device
|
||||
from test_tools import disk_tools
|
||||
from test_tools.disk_tools import get_partition_path
|
||||
from type_def.size import Size
|
||||
|
||||
|
||||
class Partition(Device):
|
||||
def __init__(self, parent_dev, type, number, begin: Size, end: Size):
|
||||
Device.__init__(self, disk_tools.get_partition_path(parent_dev.path, number))
|
||||
Device.__init__(self, get_partition_path(parent_dev.path, number))
|
||||
self.number = number
|
||||
self.parent_device = parent_dev
|
||||
self.type = type
|
||||
|
@@ -2,6 +2,7 @@
|
||||
# Copyright(c) 2020-2021 Intel Corporation
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
import threading
|
||||
from enum import IntEnum, Enum
|
||||
|
||||
|
@@ -7,7 +7,7 @@ import posixpath
|
||||
|
||||
from core.test_run import TestRun
|
||||
from storage_devices.device import Device
|
||||
from test_tools import disk_tools
|
||||
from test_tools.disk_tools import get_size
|
||||
from test_tools.fs_tools import ls, parse_ls_output
|
||||
from test_utils.filesystem.symlink import Symlink
|
||||
from test_tools.os_tools import reload_kernel_module, unload_kernel_module, is_kernel_module_loaded
|
||||
@@ -68,7 +68,7 @@ class RamDisk(Device):
|
||||
ram_disks = cls._list_devices()
|
||||
return (
|
||||
len(ram_disks) >= disk_count
|
||||
and Size(disk_tools.get_size(ram_disks[0].name), Unit.Byte).align_down(Unit.MiB.value)
|
||||
and Size(get_size(ram_disks[0].name), Unit.Byte).align_down(Unit.MiB.value)
|
||||
== disk_size.align_down(Unit.MiB.value)
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user