Refactor disk tools and fs tools
Signed-off-by: Katarzyna Treder <katarzyna.treder@h-partners.com>
This commit is contained in:
@@ -5,27 +5,29 @@
|
||||
#
|
||||
import posixpath
|
||||
|
||||
import test_tools.fs_tools
|
||||
from core.test_run import TestRun
|
||||
from test_tools import disk_utils, fs_utils
|
||||
from test_tools.disk_utils import get_device_filesystem_type, get_sysfs_path
|
||||
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_utils.io_stats import IoStats
|
||||
from type_def.size import Size, Unit
|
||||
|
||||
|
||||
class Device:
|
||||
def __init__(self, path):
|
||||
disk_utils.validate_dev_path(path)
|
||||
disk_tools.validate_dev_path(path)
|
||||
self.path = path
|
||||
self.size = Size(disk_utils.get_size(self.get_device_id()), Unit.Byte)
|
||||
self.size = Size(disk_tools.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: disk_utils.Filesystem, force=True, blocksize=None):
|
||||
disk_utils.create_filesystem(self, fs_type, force, blocksize)
|
||||
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)
|
||||
self.filesystem = fs_type
|
||||
|
||||
def wipe_filesystem(self, force=True):
|
||||
disk_utils.wipe_filesystem(self, force)
|
||||
test_tools.fs_tools.wipe_filesystem(self, force)
|
||||
self.filesystem = None
|
||||
|
||||
def is_mounted(self):
|
||||
@@ -34,13 +36,13 @@ class Device:
|
||||
return False
|
||||
else:
|
||||
mount_point_line = output.stdout.split('\n')[1]
|
||||
device_path = fs_utils.readlink(self.path)
|
||||
device_path = fs_tools.readlink(self.path)
|
||||
self.mount_point = mount_point_line[0:mount_point_line.find(device_path)].strip()
|
||||
return True
|
||||
|
||||
def mount(self, mount_point, options: [str] = None):
|
||||
if not self.is_mounted():
|
||||
if disk_utils.mount(self, mount_point, options):
|
||||
if disk_tools.mount(self, mount_point, options):
|
||||
self.mount_point = mount_point
|
||||
else:
|
||||
raise Exception(f"Device is already mounted! Actual mount point: {self.mount_point}")
|
||||
@@ -48,7 +50,7 @@ class Device:
|
||||
def unmount(self):
|
||||
if not self.is_mounted():
|
||||
TestRun.LOGGER.info("Device is not mounted.")
|
||||
elif disk_utils.unmount(self):
|
||||
elif disk_tools.unmount(self):
|
||||
self.mount_point = None
|
||||
|
||||
def get_device_link(self, directory: str):
|
||||
@@ -56,27 +58,27 @@ class Device:
|
||||
return next(i for i in items if i.full_path.startswith(directory))
|
||||
|
||||
def get_device_id(self):
|
||||
return fs_utils.readlink(self.path).split('/')[-1]
|
||||
return fs_tools.readlink(self.path).split('/')[-1]
|
||||
|
||||
def get_all_device_links(self, directory: str):
|
||||
from test_tools import fs_utils
|
||||
output = fs_utils.ls(f"$(find -L {directory} -samefile {self.path})")
|
||||
return fs_utils.parse_ls_output(output, self.path)
|
||||
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)
|
||||
|
||||
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_utils.get_sysfs_path(self.get_device_id()),
|
||||
path = posixpath.join(disk_tools.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_utils.get_sysfs_path(self.get_device_id()), "queue",
|
||||
path = posixpath.join(disk_tools.get_sysfs_path(self.get_device_id()), "queue",
|
||||
property_name)
|
||||
fs_utils.write_file(path, str(value))
|
||||
fs_tools.write_file(path, str(value))
|
||||
|
||||
def set_max_io_size(self, new_max_io_size: Size):
|
||||
self.set_sysfs_property("max_sectors_kb",
|
||||
|
@@ -10,9 +10,10 @@ 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_utils, fs_utils, nvme_cli
|
||||
from test_tools import disk_tools, fs_tools, nvme_cli
|
||||
from test_tools.common.wait import wait
|
||||
from connection.utils.output import Output
|
||||
from test_tools.disk_finder import get_block_devices_list, resolve_to_by_id_link
|
||||
@@ -137,24 +138,24 @@ class Disk(Device):
|
||||
)
|
||||
return recognized_types[0]
|
||||
|
||||
def create_partitions(self, sizes: [], partition_table_type=disk_utils.PartitionTable.gpt):
|
||||
disk_utils.create_partitions(self, sizes, partition_table_type)
|
||||
def create_partitions(self, sizes: [], partition_table_type=disk_tools.PartitionTable.gpt):
|
||||
disk_tools.create_partitions(self, sizes, partition_table_type)
|
||||
|
||||
def remove_partition(self, part):
|
||||
part_number = int(part.path.split("part")[1])
|
||||
disk_utils.remove_parition(self, part_number)
|
||||
disk_tools.remove_parition(self, part_number)
|
||||
self.partitions.remove(part)
|
||||
|
||||
def umount_all_partitions(self):
|
||||
TestRun.LOGGER.info(f"Unmounting all partitions from: {self.path}")
|
||||
cmd = f"umount -l {fs_utils.readlink(self.path)}*?"
|
||||
cmd = f"umount -l {fs_tools.readlink(self.path)}*?"
|
||||
TestRun.executor.run(cmd)
|
||||
|
||||
def remove_partitions(self):
|
||||
for part in self.partitions:
|
||||
if part.is_mounted():
|
||||
if test_tools.fs_tools.is_mounted(part.path):
|
||||
part.unmount()
|
||||
if disk_utils.remove_partitions(self):
|
||||
if disk_tools.remove_partitions(self):
|
||||
self.partitions.clear()
|
||||
|
||||
def is_detected(self):
|
||||
@@ -162,8 +163,8 @@ class Disk(Device):
|
||||
serial_numbers = Disk.get_all_serial_numbers()
|
||||
return self.serial_number in serial_numbers
|
||||
elif self.path:
|
||||
output = fs_utils.ls_item(f"{self.path}")
|
||||
return fs_utils.parse_ls_output(output)[0] is not None
|
||||
output = fs_tools.ls_item(f"{self.path}")
|
||||
return fs_tools.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):
|
||||
@@ -289,8 +290,8 @@ class NvmeDisk(Disk):
|
||||
base = f"/sys/block/{device_id}/device"
|
||||
for suffix in ["/remove", "/device/remove"]:
|
||||
try:
|
||||
output = fs_utils.ls_item(base + suffix)
|
||||
fs_utils.parse_ls_output(output)[0]
|
||||
output = fs_tools.ls_item(base + suffix)
|
||||
fs_tools.parse_ls_output(output)[0]
|
||||
except TypeError:
|
||||
continue
|
||||
return base + suffix
|
||||
@@ -345,8 +346,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_utils.ls_item(f"{ls_command}")
|
||||
sysfs_addr = fs_utils.parse_ls_output(output)[0]
|
||||
output = fs_tools.ls_item(f"{ls_command}")
|
||||
sysfs_addr = fs_tools.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
|
||||
@@ -412,8 +413,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_utils.ls_item(f"{ls_command}")
|
||||
sysfs_addr = fs_utils.parse_ls_output(output)[0]
|
||||
output = fs_tools.ls_item(f"{ls_command}")
|
||||
sysfs_addr = fs_tools.parse_ls_output(output)[0]
|
||||
if not sysfs_addr:
|
||||
raise Exception(f"Failed to find sysfs address: ls -l {ls_command}")
|
||||
|
||||
|
@@ -10,7 +10,7 @@ from typing import Union
|
||||
from core.test_run import TestRun
|
||||
from storage_devices.device import Device
|
||||
from storage_devices.disk import Disk
|
||||
from test_tools.fs_utils import readlink
|
||||
from test_tools.fs_tools import readlink
|
||||
from test_tools.disk_finder import resolve_to_by_id_link, get_system_disks
|
||||
from test_utils.filesystem.symlink import Symlink
|
||||
from type_def.size import Size
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
from core.test_run import TestRun
|
||||
from storage_devices.device import Device
|
||||
from test_tools.fs_utils import ls, parse_ls_output
|
||||
from test_tools.fs_tools import ls, parse_ls_output
|
||||
from test_tools.os_tools import (
|
||||
unload_kernel_module,
|
||||
is_kernel_module_loaded,
|
||||
|
@@ -4,13 +4,13 @@
|
||||
#
|
||||
|
||||
from storage_devices.device import Device
|
||||
from test_tools import disk_utils
|
||||
from test_tools import disk_tools
|
||||
from type_def.size import Size
|
||||
|
||||
|
||||
class Partition(Device):
|
||||
def __init__(self, parent_dev, type, number, begin: Size, end: Size):
|
||||
Device.__init__(self, disk_utils.get_partition_path(parent_dev.path, number))
|
||||
Device.__init__(self, disk_tools.get_partition_path(parent_dev.path, number))
|
||||
self.number = number
|
||||
self.parent_device = parent_dev
|
||||
self.type = type
|
||||
|
@@ -8,7 +8,7 @@ from enum import IntEnum, Enum
|
||||
from core.test_run import TestRun
|
||||
from storage_devices.device import Device
|
||||
from storage_devices.disk import Disk
|
||||
from test_tools.fs_utils import readlink
|
||||
from test_tools.fs_tools import readlink
|
||||
from test_tools.mdadm import Mdadm
|
||||
from test_tools.disk_finder import resolve_to_by_id_link
|
||||
from type_def.size import Size, Unit
|
||||
|
@@ -7,8 +7,8 @@ import posixpath
|
||||
|
||||
from core.test_run import TestRun
|
||||
from storage_devices.device import Device
|
||||
from test_tools import disk_utils
|
||||
from test_tools.fs_utils import ls, parse_ls_output
|
||||
from test_tools import disk_tools
|
||||
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
|
||||
from type_def.size import Size, Unit
|
||||
@@ -68,7 +68,7 @@ class RamDisk(Device):
|
||||
ram_disks = cls._list_devices()
|
||||
return (
|
||||
len(ram_disks) >= disk_count
|
||||
and Size(disk_utils.get_size(ram_disks[0].name), Unit.Byte).align_down(Unit.MiB.value)
|
||||
and Size(disk_tools.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