test-api: reformat api files
Signed-off-by: Kamil Gierszewski <kamil.gierszewski@huawei.com>
This commit is contained in:
parent
077820f1c0
commit
d40e2a519d
@ -5,6 +5,7 @@
|
||||
#
|
||||
|
||||
from api.cas.casadm_parser import *
|
||||
from api.cas.core import Core
|
||||
from api.cas.dmesg import get_metadata_size_on_device
|
||||
from api.cas.statistics import CacheStats, IoClassStats
|
||||
from test_utils.os_utils import *
|
||||
@ -12,7 +13,7 @@ from test_utils.output import Output
|
||||
|
||||
|
||||
class Cache:
|
||||
def __init__(self, device: Device, cache_id: int = None):
|
||||
def __init__(self, device: Device, cache_id: int = None) -> None:
|
||||
self.cache_device = device
|
||||
self.cache_id = cache_id if cache_id else self.__get_cache_id()
|
||||
self.__cache_line_size = None
|
||||
@ -32,17 +33,17 @@ class Cache:
|
||||
def __get_cache_device_path(self) -> str:
|
||||
return self.cache_device.path if self.cache_device is not None else "-"
|
||||
|
||||
def get_core_devices(self):
|
||||
def get_core_devices(self) -> list:
|
||||
return get_cores(self.cache_id)
|
||||
|
||||
def get_cache_line_size(self):
|
||||
def get_cache_line_size(self) -> CacheLineSize:
|
||||
if self.__cache_line_size is None:
|
||||
stats = self.get_statistics()
|
||||
stats_line_size = stats.config_stats.cache_line_size
|
||||
self.__cache_line_size = CacheLineSize(stats_line_size)
|
||||
return self.__cache_line_size
|
||||
|
||||
def get_cleaning_policy(self):
|
||||
def get_cleaning_policy(self) -> CleaningPolicy:
|
||||
stats = self.get_statistics()
|
||||
cp = stats.config_stats.cleaning_policy
|
||||
return CleaningPolicy[cp]
|
||||
@ -58,7 +59,7 @@ class Cache:
|
||||
def get_occupancy(self):
|
||||
return self.get_statistics().usage_stats.occupancy
|
||||
|
||||
def get_status(self):
|
||||
def get_status(self) -> CacheStatus:
|
||||
status = (
|
||||
self.get_statistics(stat_filter=[StatsFilter.conf])
|
||||
.config_stats.status.replace(" ", "_")
|
||||
@ -67,25 +68,25 @@ class Cache:
|
||||
return CacheStatus[status]
|
||||
|
||||
@property
|
||||
def size(self):
|
||||
def size(self) -> Size:
|
||||
return self.get_statistics().config_stats.cache_size
|
||||
|
||||
def get_cache_mode(self):
|
||||
def get_cache_mode(self) -> CacheMode:
|
||||
return CacheMode[self.get_statistics().config_stats.write_policy.upper()]
|
||||
|
||||
def get_dirty_blocks(self):
|
||||
def get_dirty_blocks(self) -> Size:
|
||||
return self.get_statistics().usage_stats.dirty
|
||||
|
||||
def get_dirty_for(self):
|
||||
def get_dirty_for(self) -> timedelta:
|
||||
return self.get_statistics().config_stats.dirty_for
|
||||
|
||||
def get_clean_blocks(self):
|
||||
def get_clean_blocks(self) -> Size:
|
||||
return self.get_statistics().usage_stats.clean
|
||||
|
||||
def get_flush_parameters_alru(self):
|
||||
def get_flush_parameters_alru(self) -> FlushParametersAlru:
|
||||
return get_flush_parameters_alru(self.cache_id)
|
||||
|
||||
def get_flush_parameters_acp(self):
|
||||
def get_flush_parameters_acp(self) -> FlushParametersAcp:
|
||||
return get_flush_parameters_acp(self.cache_id)
|
||||
|
||||
# Casadm methods:
|
||||
@ -106,7 +107,7 @@ class Cache:
|
||||
io_class_id: int,
|
||||
stat_filter: List[StatsFilter] = None,
|
||||
percentage_val: bool = False,
|
||||
):
|
||||
) -> IoClassStats:
|
||||
return IoClassStats(
|
||||
cache_id=self.cache_id,
|
||||
filter=stat_filter,
|
||||
@ -115,39 +116,40 @@ class Cache:
|
||||
)
|
||||
|
||||
def flush_cache(self) -> Output:
|
||||
cmd_output = casadm.flush_cache(cache_id=self.cache_id)
|
||||
output = casadm.flush_cache(cache_id=self.cache_id)
|
||||
sync()
|
||||
return cmd_output
|
||||
return output
|
||||
|
||||
def purge_cache(self):
|
||||
casadm.purge_cache(cache_id=self.cache_id)
|
||||
def purge_cache(self) -> Output:
|
||||
output = casadm.purge_cache(cache_id=self.cache_id)
|
||||
sync()
|
||||
return output
|
||||
|
||||
def stop(self, no_data_flush: bool = False):
|
||||
def stop(self, no_data_flush: bool = False) -> Output:
|
||||
return casadm.stop_cache(self.cache_id, no_data_flush)
|
||||
|
||||
def add_core(self, core_dev, core_id: int = None):
|
||||
def add_core(self, core_dev, core_id: int = None) -> Core:
|
||||
return casadm.add_core(self, core_dev, core_id)
|
||||
|
||||
def remove_core(self, core_id: int, force: bool = False):
|
||||
def remove_core(self, core_id: int, force: bool = False) -> Output:
|
||||
return casadm.remove_core(self.cache_id, core_id, force)
|
||||
|
||||
def remove_inactive_core(self, core_id: int, force: bool = False):
|
||||
def remove_inactive_core(self, core_id: int, force: bool = False) -> Output:
|
||||
return casadm.remove_inactive(self.cache_id, core_id, force)
|
||||
|
||||
def reset_counters(self):
|
||||
def reset_counters(self) -> Output:
|
||||
return casadm.reset_counters(self.cache_id)
|
||||
|
||||
def set_cache_mode(self, cache_mode: CacheMode, flush=None):
|
||||
def set_cache_mode(self, cache_mode: CacheMode, flush=None) -> Output:
|
||||
return casadm.set_cache_mode(cache_mode, self.cache_id, flush)
|
||||
|
||||
def load_io_class(self, file_path: str):
|
||||
def load_io_class(self, file_path: str) -> Output:
|
||||
return casadm.load_io_classes(self.cache_id, file_path)
|
||||
|
||||
def list_io_classes(self):
|
||||
def list_io_classes(self) -> list:
|
||||
return get_io_class_list(self.cache_id)
|
||||
|
||||
def set_seq_cutoff_parameters(self, seq_cutoff_param: SeqCutOffParameters):
|
||||
def set_seq_cutoff_parameters(self, seq_cutoff_param: SeqCutOffParameters) -> Output:
|
||||
return casadm.set_param_cutoff(
|
||||
self.cache_id,
|
||||
threshold=seq_cutoff_param.threshold,
|
||||
@ -155,16 +157,16 @@ class Cache:
|
||||
promotion_count=seq_cutoff_param.promotion_count,
|
||||
)
|
||||
|
||||
def set_seq_cutoff_threshold(self, threshold: Size):
|
||||
def set_seq_cutoff_threshold(self, threshold: Size) -> Output:
|
||||
return casadm.set_param_cutoff(self.cache_id, threshold=threshold, policy=None)
|
||||
|
||||
def set_seq_cutoff_policy(self, policy: SeqCutOffPolicy):
|
||||
def set_seq_cutoff_policy(self, policy: SeqCutOffPolicy) -> Output:
|
||||
return casadm.set_param_cutoff(self.cache_id, threshold=None, policy=policy)
|
||||
|
||||
def set_cleaning_policy(self, cleaning_policy: CleaningPolicy):
|
||||
def set_cleaning_policy(self, cleaning_policy: CleaningPolicy) -> Output:
|
||||
return casadm.set_param_cleaning(self.cache_id, cleaning_policy)
|
||||
|
||||
def set_params_acp(self, acp_params: FlushParametersAcp):
|
||||
def set_params_acp(self, acp_params: FlushParametersAcp) -> Output:
|
||||
return casadm.set_param_cleaning_acp(
|
||||
self.cache_id,
|
||||
(
|
||||
@ -175,7 +177,7 @@ class Cache:
|
||||
int(acp_params.flush_max_buffers) if acp_params.flush_max_buffers else None,
|
||||
)
|
||||
|
||||
def set_params_alru(self, alru_params: FlushParametersAlru):
|
||||
def set_params_alru(self, alru_params: FlushParametersAlru) -> Output:
|
||||
return casadm.set_param_cleaning_alru(
|
||||
self.cache_id,
|
||||
(
|
||||
@ -196,17 +198,17 @@ class Cache:
|
||||
),
|
||||
)
|
||||
|
||||
def get_cache_config(self):
|
||||
def get_cache_config(self) -> CacheConfig:
|
||||
return CacheConfig(
|
||||
self.get_cache_line_size(),
|
||||
self.get_cache_mode(),
|
||||
self.get_cleaning_policy(),
|
||||
)
|
||||
|
||||
def standby_detach(self, shortcut: bool = False):
|
||||
def standby_detach(self, shortcut: bool = False) -> Output:
|
||||
return casadm.standby_detach_cache(cache_id=self.cache_id, shortcut=shortcut)
|
||||
|
||||
def standby_activate(self, device, shortcut: bool = False):
|
||||
def standby_activate(self, device, shortcut: bool = False) -> Output:
|
||||
return casadm.standby_activate_cache(
|
||||
cache_id=self.cache_id, cache_dev=device, shortcut=shortcut
|
||||
)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
@ -8,7 +9,12 @@ from datetime import timedelta
|
||||
from string import Template
|
||||
from textwrap import dedent
|
||||
|
||||
from test_tools.fs_utils import check_if_directory_exists, create_directory, write_file, remove
|
||||
from test_tools.fs_utils import (
|
||||
check_if_directory_exists,
|
||||
create_directory,
|
||||
write_file,
|
||||
remove,
|
||||
)
|
||||
from test_utils.systemd import reload_daemon
|
||||
|
||||
opencas_drop_in_directory = Path("/etc/systemd/system/open-cas.service.d/")
|
||||
|
@ -27,10 +27,6 @@ from test_utils.size import Size, Unit
|
||||
# casadm commands
|
||||
|
||||
|
||||
def help(shortcut: bool = False):
|
||||
return TestRun.executor.run(help_cmd(shortcut))
|
||||
|
||||
|
||||
def start_cache(
|
||||
cache_dev: Device,
|
||||
cache_mode: CacheMode = None,
|
||||
@ -40,7 +36,7 @@ def start_cache(
|
||||
load: bool = False,
|
||||
shortcut: bool = False,
|
||||
kernel_params: KernelParameters = KernelParameters(),
|
||||
):
|
||||
) -> Cache:
|
||||
if kernel_params != KernelParameters.read_current_settings():
|
||||
reload_kernel_module("cas_cache", kernel_params.get_parameter_dictionary())
|
||||
|
||||
@ -67,61 +63,33 @@ def start_cache(
|
||||
return Cache(cache_dev)
|
||||
|
||||
|
||||
def standby_init(
|
||||
cache_dev: Device,
|
||||
cache_id: int,
|
||||
cache_line_size: CacheLineSize,
|
||||
force: bool = False,
|
||||
shortcut: bool = False,
|
||||
kernel_params: KernelParameters = KernelParameters(),
|
||||
):
|
||||
if kernel_params != KernelParameters.read_current_settings():
|
||||
reload_kernel_module("cas_cache", kernel_params.get_parameter_dictionary())
|
||||
def load_cache(device: Device, shortcut: bool = False) -> Cache:
|
||||
output = TestRun.executor.run(load_cmd(cache_dev=device.path, shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to load cache.", output)
|
||||
return Cache(device)
|
||||
|
||||
_cache_line_size = (
|
||||
None
|
||||
if cache_line_size is None
|
||||
else str(int(cache_line_size.value.get_value(Unit.KibiByte)))
|
||||
)
|
||||
|
||||
def attach_cache(cache_id: int, device: [Device], force: bool, shortcut: bool = False) -> Output:
|
||||
cache_dev_paths = ",".join(str(devs_path.path) for devs_path in device)
|
||||
output = TestRun.executor.run(
|
||||
standby_init_cmd(
|
||||
cache_dev=cache_dev.path,
|
||||
cache_id=str(cache_id),
|
||||
cache_line_size=_cache_line_size,
|
||||
force=force,
|
||||
shortcut=shortcut,
|
||||
attach_cache_cmd(
|
||||
cache_dev=cache_dev_paths, cache_id=str(cache_id), force=force, shortcut=shortcut
|
||||
)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to init standby cache.", output)
|
||||
return Cache(cache_dev)
|
||||
|
||||
|
||||
def standby_load(cache_dev: Device, shortcut: bool = False):
|
||||
output = TestRun.executor.run(standby_load_cmd(cache_dev=cache_dev.path, shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to load standby cache.", output)
|
||||
return Cache(cache_dev)
|
||||
|
||||
|
||||
def standby_detach_cache(cache_id: int, shortcut: bool = False):
|
||||
output = TestRun.executor.run(standby_detach_cmd(cache_id=str(cache_id), shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to detach standby cache.", output)
|
||||
raise CmdException("Failed to attach cache.", output)
|
||||
return output
|
||||
|
||||
|
||||
def standby_activate_cache(cache_dev: Device, cache_id: int, shortcut: bool = False):
|
||||
output = TestRun.executor.run(
|
||||
standby_activate_cmd(cache_dev=cache_dev.path, cache_id=str(cache_id), shortcut=shortcut)
|
||||
)
|
||||
def detach_cache(cache_id: int, shortcut: bool = False) -> Output:
|
||||
output = TestRun.executor.run(detach_cache_cmd(cache_id=str(cache_id), shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to activate standby cache.", output)
|
||||
raise CmdException("Failed to detach cache.", output)
|
||||
return output
|
||||
|
||||
|
||||
def stop_cache(cache_id: int, no_data_flush: bool = False, shortcut: bool = False):
|
||||
def stop_cache(cache_id: int, no_data_flush: bool = False, shortcut: bool = False) -> Output:
|
||||
output = TestRun.executor.run(
|
||||
stop_cmd(cache_id=str(cache_id), no_data_flush=no_data_flush, shortcut=shortcut)
|
||||
)
|
||||
@ -130,250 +98,83 @@ def stop_cache(cache_id: int, no_data_flush: bool = False, shortcut: bool = Fals
|
||||
return output
|
||||
|
||||
|
||||
def add_core(cache: Cache, core_dev: Device, core_id: int = None, shortcut: bool = False):
|
||||
_core_id = None if core_id is None else str(core_id)
|
||||
output = TestRun.executor.run(
|
||||
add_core_cmd(
|
||||
cache_id=str(cache.cache_id),
|
||||
core_dev=core_dev.path,
|
||||
core_id=_core_id,
|
||||
shortcut=shortcut,
|
||||
)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to add core.", output)
|
||||
core = Core(core_dev.path, cache.cache_id)
|
||||
return core
|
||||
|
||||
|
||||
def remove_core(cache_id: int, core_id: int, force: bool = False, shortcut: bool = False):
|
||||
output = TestRun.executor.run(
|
||||
remove_core_cmd(
|
||||
cache_id=str(cache_id), core_id=str(core_id), force=force, shortcut=shortcut
|
||||
)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to remove core.", output)
|
||||
|
||||
|
||||
def remove_inactive(cache_id: int, core_id: int, force: bool = False, shortcut: bool = False):
|
||||
output = TestRun.executor.run(
|
||||
remove_inactive_cmd(
|
||||
cache_id=str(cache_id), core_id=str(core_id), force=force, shortcut=shortcut
|
||||
)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to remove inactive core.", output)
|
||||
|
||||
|
||||
def remove_detached(core_device: Device, shortcut: bool = False):
|
||||
output = TestRun.executor.run(
|
||||
remove_detached_cmd(core_device=core_device.path, shortcut=shortcut)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to remove detached core.", output)
|
||||
return output
|
||||
|
||||
|
||||
def try_add(core_device: Device, cache_id: int, core_id: int):
|
||||
output = TestRun.executor.run(script_try_add_cmd(str(cache_id), core_device.path, str(core_id)))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to execute try add script command.", output)
|
||||
return Core(core_device.path, cache_id)
|
||||
|
||||
|
||||
def purge_cache(cache_id: int):
|
||||
output = TestRun.executor.run(script_purge_cache_cmd(str(cache_id)))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Purge cache failed.", output)
|
||||
return output
|
||||
|
||||
|
||||
def purge_core(cache_id: int, core_id: int):
|
||||
output = TestRun.executor.run(script_purge_core_cmd(str(cache_id), str(core_id)))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Purge core failed.", output)
|
||||
return output
|
||||
|
||||
|
||||
def detach_core(cache_id: int, core_id: int):
|
||||
output = TestRun.executor.run(script_detach_core_cmd(str(cache_id), str(core_id)))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to execute detach core script command.", output)
|
||||
return output
|
||||
|
||||
|
||||
def remove_core_with_script_command(cache_id: int, core_id: int, no_flush: bool = False):
|
||||
output = TestRun.executor.run(script_remove_core_cmd(str(cache_id), str(core_id), no_flush))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to execute remove core script command.", output)
|
||||
return output
|
||||
|
||||
|
||||
def reset_counters(cache_id: int, core_id: int = None, shortcut: bool = False):
|
||||
_core_id = None if core_id is None else str(core_id)
|
||||
output = TestRun.executor.run(
|
||||
reset_counters_cmd(cache_id=str(cache_id), core_id=_core_id, shortcut=shortcut)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to reset counters.", output)
|
||||
return output
|
||||
|
||||
|
||||
def flush_cache(cache_id: int, shortcut: bool = False) -> Output:
|
||||
command = flush_cache_cmd(cache_id=str(cache_id), shortcut=shortcut)
|
||||
output = TestRun.executor.run(command)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Flushing cache failed.", output)
|
||||
return output
|
||||
|
||||
|
||||
def flush_core(
|
||||
cache_id: int, core_id: int, shortcut: bool = False
|
||||
def set_param_cutoff(
|
||||
cache_id: int,
|
||||
core_id: int = None,
|
||||
threshold: Size = None,
|
||||
policy: SeqCutOffPolicy = None,
|
||||
promotion_count: int = None,
|
||||
shortcut: bool = False,
|
||||
) -> Output:
|
||||
command = flush_core_cmd(
|
||||
_core_id = None if core_id is None else str(core_id)
|
||||
_threshold = None if threshold is None else str(int(threshold.get_value(Unit.KibiByte)))
|
||||
_policy = None if policy is None else policy.name
|
||||
_promotion_count = None if promotion_count is None else str(promotion_count)
|
||||
command = set_param_cutoff_cmd(
|
||||
cache_id=str(cache_id),
|
||||
core_id=str(core_id),
|
||||
core_id=_core_id,
|
||||
threshold=_threshold,
|
||||
policy=_policy,
|
||||
promotion_count=_promotion_count,
|
||||
shortcut=shortcut,
|
||||
)
|
||||
output = TestRun.executor.run(command)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Flushing core failed.", output)
|
||||
raise CmdException("Error while setting sequential cut-off params.", output)
|
||||
return output
|
||||
|
||||
|
||||
def load_cache(device: Device, shortcut: bool = False):
|
||||
output = TestRun.executor.run(load_cmd(cache_dev=device.path, shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to load cache.", output)
|
||||
return Cache(device)
|
||||
|
||||
|
||||
def list_caches(
|
||||
output_format: OutputFormat = None, by_id_path: bool = True, shortcut: bool = False
|
||||
):
|
||||
_output_format = None if output_format is None else output_format.name
|
||||
def set_param_cleaning(cache_id: int, policy: CleaningPolicy, shortcut: bool = False) -> Output:
|
||||
output = TestRun.executor.run(
|
||||
list_caches_cmd(output_format=_output_format, by_id_path=by_id_path, shortcut=shortcut)
|
||||
set_param_cleaning_cmd(cache_id=str(cache_id), policy=policy.name, shortcut=shortcut)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to list caches.", output)
|
||||
raise CmdException("Error while setting cleaning policy.", output)
|
||||
return output
|
||||
|
||||
|
||||
def print_version(output_format: OutputFormat = None, shortcut: bool = False):
|
||||
_output_format = None if output_format is None else output_format.name
|
||||
output = TestRun.executor.run(version_cmd(output_format=_output_format, shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to print version.", output)
|
||||
return output
|
||||
|
||||
|
||||
def zero_metadata(cache_dev: Device, force: bool = False, shortcut: bool = False):
|
||||
output = TestRun.executor.run(
|
||||
zero_metadata_cmd(cache_dev=cache_dev.path, force=force, shortcut=shortcut)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to wipe metadata.", output)
|
||||
return output
|
||||
|
||||
|
||||
def stop_all_caches():
|
||||
from .casadm_parser import get_caches
|
||||
|
||||
caches = get_caches()
|
||||
if not caches:
|
||||
return
|
||||
for cache in caches:
|
||||
stop_cache(cache_id=cache.cache_id)
|
||||
|
||||
|
||||
def remove_all_detached_cores():
|
||||
from api.cas import casadm_parser
|
||||
|
||||
devices = casadm_parser.get_cas_devices_dict()
|
||||
for dev in devices["core_pool"]:
|
||||
TestRun.executor.run(remove_detached_cmd(dev["device"]))
|
||||
|
||||
|
||||
def print_statistics(
|
||||
def set_param_cleaning_alru(
|
||||
cache_id: int,
|
||||
core_id: int = None,
|
||||
io_class_id: int = None,
|
||||
filter: List[StatsFilter] = None,
|
||||
output_format: OutputFormat = None,
|
||||
by_id_path: bool = True,
|
||||
wake_up: int = None,
|
||||
staleness_time: int = None,
|
||||
flush_max_buffers: int = None,
|
||||
activity_threshold: int = None,
|
||||
shortcut: bool = False,
|
||||
):
|
||||
_output_format = output_format.name if output_format else None
|
||||
_core_id = str(core_id) if core_id else None
|
||||
_io_class_id = str(io_class_id) if io_class_id else None
|
||||
if filter is None:
|
||||
_filter = filter
|
||||
else:
|
||||
names = (x.name for x in filter)
|
||||
_filter = ",".join(names)
|
||||
) -> Output:
|
||||
output = TestRun.executor.run(
|
||||
print_statistics_cmd(
|
||||
set_param_cleaning_alru_cmd(
|
||||
cache_id=str(cache_id),
|
||||
core_id=_core_id,
|
||||
io_class_id=_io_class_id,
|
||||
filter=_filter,
|
||||
output_format=_output_format,
|
||||
by_id_path=by_id_path,
|
||||
wake_up=str(wake_up),
|
||||
staleness_time=str(staleness_time),
|
||||
flush_max_buffers=str(flush_max_buffers),
|
||||
activity_threshold=str(activity_threshold),
|
||||
shortcut=shortcut,
|
||||
)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Printing statistics failed.", output)
|
||||
raise CmdException("Error while setting alru cleaning policy parameters.", output)
|
||||
return output
|
||||
|
||||
|
||||
def set_cache_mode(cache_mode: CacheMode, cache_id: int, flush=None, shortcut: bool = False):
|
||||
flush_cache = None
|
||||
if flush is True:
|
||||
flush_cache = "yes"
|
||||
elif flush is False:
|
||||
flush_cache = "no"
|
||||
|
||||
def set_param_cleaning_acp(
|
||||
cache_id: int, wake_up: int = None, flush_max_buffers: int = None, shortcut: bool = False
|
||||
) -> Output:
|
||||
output = TestRun.executor.run(
|
||||
set_cache_mode_cmd(
|
||||
cache_mode=cache_mode.name.lower(),
|
||||
set_param_cleaning_acp_cmd(
|
||||
cache_id=str(cache_id),
|
||||
flush_cache=flush_cache,
|
||||
wake_up=str(wake_up) if wake_up is not None else None,
|
||||
flush_max_buffers=str(flush_max_buffers) if flush_max_buffers else None,
|
||||
shortcut=shortcut,
|
||||
)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Set cache mode command failed.", output)
|
||||
return output
|
||||
|
||||
|
||||
def load_io_classes(cache_id: int, file: str, shortcut: bool = False):
|
||||
output = TestRun.executor.run(
|
||||
load_io_classes_cmd(cache_id=str(cache_id), file=file, shortcut=shortcut)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Load IO class command failed.", output)
|
||||
return output
|
||||
|
||||
|
||||
def list_io_classes(cache_id: int, output_format: OutputFormat, shortcut: bool = False):
|
||||
_output_format = None if output_format is None else output_format.name
|
||||
output = TestRun.executor.run(
|
||||
list_io_classes_cmd(cache_id=str(cache_id), output_format=_output_format, shortcut=shortcut)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("List IO class command failed.", output)
|
||||
raise CmdException("Error while setting acp cleaning policy parameters.", output)
|
||||
return output
|
||||
|
||||
|
||||
def get_param_cutoff(
|
||||
cache_id: int,
|
||||
core_id: int,
|
||||
output_format: OutputFormat = None,
|
||||
shortcut: bool = False,
|
||||
):
|
||||
cache_id: int, core_id: int, output_format: OutputFormat = None, shortcut: bool = False
|
||||
) -> Output:
|
||||
_output_format = None if output_format is None else output_format.name
|
||||
output = TestRun.executor.run(
|
||||
get_param_cutoff_cmd(
|
||||
@ -428,78 +229,299 @@ def get_param_cleaning_acp(
|
||||
return output
|
||||
|
||||
|
||||
def set_param_cutoff(
|
||||
def set_cache_mode(
|
||||
cache_mode: CacheMode, cache_id: int, flush=None, shortcut: bool = False
|
||||
) -> Output:
|
||||
flush_cache = None
|
||||
if flush is True:
|
||||
flush_cache = "yes"
|
||||
elif flush is False:
|
||||
flush_cache = "no"
|
||||
|
||||
output = TestRun.executor.run(
|
||||
set_cache_mode_cmd(
|
||||
cache_mode=cache_mode.name.lower(),
|
||||
cache_id=str(cache_id),
|
||||
flush_cache=flush_cache,
|
||||
shortcut=shortcut,
|
||||
)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Set cache mode command failed.", output)
|
||||
return output
|
||||
|
||||
|
||||
def add_core(cache: Cache, core_dev: Device, core_id: int = None, shortcut: bool = False) -> Core:
|
||||
_core_id = None if core_id is None else str(core_id)
|
||||
output = TestRun.executor.run(
|
||||
add_core_cmd(
|
||||
cache_id=str(cache.cache_id),
|
||||
core_dev=core_dev.path,
|
||||
core_id=_core_id,
|
||||
shortcut=shortcut,
|
||||
)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to add core.", output)
|
||||
return Core(core_dev.path, cache.cache_id)
|
||||
|
||||
|
||||
def remove_core(cache_id: int, core_id: int, force: bool = False, shortcut: bool = False) -> Output:
|
||||
output = TestRun.executor.run(
|
||||
remove_core_cmd(
|
||||
cache_id=str(cache_id), core_id=str(core_id), force=force, shortcut=shortcut
|
||||
)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to remove core.", output)
|
||||
return output
|
||||
|
||||
|
||||
def remove_inactive(
|
||||
cache_id: int, core_id: int, force: bool = False, shortcut: bool = False
|
||||
) -> Output:
|
||||
output = TestRun.executor.run(
|
||||
remove_inactive_cmd(
|
||||
cache_id=str(cache_id), core_id=str(core_id), force=force, shortcut=shortcut
|
||||
)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to remove inactive core.", output)
|
||||
return output
|
||||
|
||||
|
||||
def remove_detached(core_device: Device, shortcut: bool = False) -> Output:
|
||||
output = TestRun.executor.run(
|
||||
remove_detached_cmd(core_device=core_device.path, shortcut=shortcut)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to remove detached core.", output)
|
||||
return output
|
||||
|
||||
|
||||
def list_caches(
|
||||
output_format: OutputFormat = None, by_id_path: bool = True, shortcut: bool = False
|
||||
) -> Output:
|
||||
_output_format = None if output_format is None else output_format.name
|
||||
output = TestRun.executor.run(
|
||||
list_caches_cmd(output_format=_output_format, by_id_path=by_id_path, shortcut=shortcut)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to list caches.", output)
|
||||
return output
|
||||
|
||||
|
||||
def print_statistics(
|
||||
cache_id: int,
|
||||
core_id: int = None,
|
||||
threshold: Size = None,
|
||||
policy: SeqCutOffPolicy = None,
|
||||
promotion_count: int = None,
|
||||
io_class_id: int = None,
|
||||
filter: List[StatsFilter] = None,
|
||||
output_format: OutputFormat = None,
|
||||
by_id_path: bool = True,
|
||||
shortcut: bool = False,
|
||||
):
|
||||
) -> Output:
|
||||
_output_format = output_format.name if output_format else None
|
||||
_core_id = str(core_id) if core_id else None
|
||||
_io_class_id = str(io_class_id) if io_class_id else None
|
||||
if filter is None:
|
||||
_filter = filter
|
||||
else:
|
||||
names = (x.name for x in filter)
|
||||
_filter = ",".join(names)
|
||||
output = TestRun.executor.run(
|
||||
print_statistics_cmd(
|
||||
cache_id=str(cache_id),
|
||||
core_id=_core_id,
|
||||
io_class_id=_io_class_id,
|
||||
filter=_filter,
|
||||
output_format=_output_format,
|
||||
by_id_path=by_id_path,
|
||||
shortcut=shortcut,
|
||||
)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Printing statistics failed.", output)
|
||||
return output
|
||||
|
||||
|
||||
def reset_counters(cache_id: int, core_id: int = None, shortcut: bool = False) -> Output:
|
||||
_core_id = None if core_id is None else str(core_id)
|
||||
_threshold = None if threshold is None else str(int(threshold.get_value(Unit.KibiByte)))
|
||||
_policy = None if policy is None else policy.name
|
||||
_promotion_count = None if promotion_count is None else str(promotion_count)
|
||||
command = set_param_cutoff_cmd(
|
||||
cache_id=str(cache_id),
|
||||
core_id=_core_id,
|
||||
threshold=_threshold,
|
||||
policy=_policy,
|
||||
promotion_count=_promotion_count,
|
||||
shortcut=shortcut,
|
||||
output = TestRun.executor.run(
|
||||
reset_counters_cmd(cache_id=str(cache_id), core_id=_core_id, shortcut=shortcut)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to reset counters.", output)
|
||||
return output
|
||||
|
||||
|
||||
def flush_cache(cache_id: int, shortcut: bool = False) -> Output:
|
||||
command = flush_cache_cmd(cache_id=str(cache_id), shortcut=shortcut)
|
||||
output = TestRun.executor.run(command)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Flushing cache failed.", output)
|
||||
return output
|
||||
|
||||
|
||||
def flush_core(
|
||||
cache_id: int, core_id: int, shortcut: bool = False
|
||||
) -> Output:
|
||||
command = flush_core_cmd(
|
||||
cache_id=str(cache_id), core_id=str(core_id), shortcut=shortcut
|
||||
)
|
||||
output = TestRun.executor.run(command)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Error while setting sequential cut-off params.", output)
|
||||
raise CmdException("Flushing core failed.", output)
|
||||
return output
|
||||
|
||||
|
||||
def set_param_cleaning(cache_id: int, policy: CleaningPolicy, shortcut: bool = False):
|
||||
def load_io_classes(cache_id: int, file: str, shortcut: bool = False) -> Output:
|
||||
output = TestRun.executor.run(
|
||||
set_param_cleaning_cmd(cache_id=str(cache_id), policy=policy.name, shortcut=shortcut)
|
||||
load_io_classes_cmd(cache_id=str(cache_id), file=file, shortcut=shortcut)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Error while setting cleaning policy.", output)
|
||||
raise CmdException("Load IO class command failed.", output)
|
||||
return output
|
||||
|
||||
|
||||
def set_param_cleaning_alru(
|
||||
cache_id: int,
|
||||
wake_up: int = None,
|
||||
staleness_time: int = None,
|
||||
flush_max_buffers: int = None,
|
||||
activity_threshold: int = None,
|
||||
shortcut: bool = False,
|
||||
):
|
||||
def list_io_classes(cache_id: int, output_format: OutputFormat, shortcut: bool = False) -> Output:
|
||||
_output_format = None if output_format is None else output_format.name
|
||||
output = TestRun.executor.run(
|
||||
set_param_cleaning_alru_cmd(
|
||||
list_io_classes_cmd(cache_id=str(cache_id), output_format=_output_format, shortcut=shortcut)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("List IO class command failed.", output)
|
||||
return output
|
||||
|
||||
|
||||
def print_version(output_format: OutputFormat = None, shortcut: bool = False) -> Output:
|
||||
_output_format = None if output_format is None else output_format.name
|
||||
output = TestRun.executor.run(version_cmd(output_format=_output_format, shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to print version.", output)
|
||||
return output
|
||||
|
||||
|
||||
def help(shortcut: bool = False) -> Output:
|
||||
return TestRun.executor.run(help_cmd(shortcut))
|
||||
|
||||
|
||||
def standby_init(
|
||||
cache_dev: Device,
|
||||
cache_id: int,
|
||||
cache_line_size: CacheLineSize,
|
||||
force: bool = False,
|
||||
shortcut: bool = False,
|
||||
kernel_params: KernelParameters = KernelParameters(),
|
||||
) -> Cache:
|
||||
if kernel_params != KernelParameters.read_current_settings():
|
||||
reload_kernel_module("cas_cache", kernel_params.get_parameter_dictionary())
|
||||
|
||||
_cache_line_size = (
|
||||
None
|
||||
if cache_line_size is None
|
||||
else str(int(cache_line_size.value.get_value(Unit.KibiByte)))
|
||||
)
|
||||
|
||||
output = TestRun.executor.run(
|
||||
standby_init_cmd(
|
||||
cache_dev=cache_dev.path,
|
||||
cache_id=str(cache_id),
|
||||
wake_up=str(wake_up),
|
||||
staleness_time=str(staleness_time),
|
||||
flush_max_buffers=str(flush_max_buffers),
|
||||
activity_threshold=str(activity_threshold),
|
||||
cache_line_size=_cache_line_size,
|
||||
force=force,
|
||||
shortcut=shortcut,
|
||||
)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Error while setting alru cleaning policy parameters.", output)
|
||||
raise CmdException("Failed to init standby cache.", output)
|
||||
return Cache(cache_dev)
|
||||
|
||||
|
||||
def standby_load(cache_dev: Device, shortcut: bool = False) -> Cache:
|
||||
output = TestRun.executor.run(standby_load_cmd(cache_dev=cache_dev.path, shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to load standby cache.", output)
|
||||
return Cache(cache_dev)
|
||||
|
||||
|
||||
def standby_detach_cache(cache_id: int, shortcut: bool = False) -> Output:
|
||||
output = TestRun.executor.run(standby_detach_cmd(cache_id=str(cache_id), shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to detach standby cache.", output)
|
||||
return output
|
||||
|
||||
|
||||
def set_param_cleaning_acp(
|
||||
cache_id: int,
|
||||
wake_up: int = None,
|
||||
flush_max_buffers: int = None,
|
||||
shortcut: bool = False,
|
||||
):
|
||||
def standby_activate_cache(cache_dev: Device, cache_id: int, shortcut: bool = False) -> Output:
|
||||
output = TestRun.executor.run(
|
||||
set_param_cleaning_acp_cmd(
|
||||
cache_id=str(cache_id),
|
||||
wake_up=str(wake_up) if wake_up is not None else None,
|
||||
flush_max_buffers=str(flush_max_buffers) if flush_max_buffers else None,
|
||||
shortcut=shortcut,
|
||||
)
|
||||
standby_activate_cmd(cache_dev=cache_dev.path, cache_id=str(cache_id), shortcut=shortcut)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Error while setting acp cleaning policy parameters.", output)
|
||||
raise CmdException("Failed to activate standby cache.", output)
|
||||
return output
|
||||
|
||||
|
||||
def zero_metadata(cache_dev: Device, force: bool = False, shortcut: bool = False) -> Output:
|
||||
output = TestRun.executor.run(
|
||||
zero_metadata_cmd(cache_dev=cache_dev.path, force=force, shortcut=shortcut)
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to wipe metadata.", output)
|
||||
return output
|
||||
|
||||
|
||||
# script command
|
||||
|
||||
|
||||
def try_add(core_device: Device, cache_id: int, core_id: int) -> Core:
|
||||
output = TestRun.executor.run(script_try_add_cmd(str(cache_id), core_device.path, str(core_id)))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to execute try add script command.", output)
|
||||
return Core(core_device.path, cache_id)
|
||||
|
||||
|
||||
def purge_cache(cache_id: int) -> Output:
|
||||
output = TestRun.executor.run(script_purge_cache_cmd(str(cache_id)))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Purge cache failed.", output)
|
||||
return output
|
||||
|
||||
|
||||
def purge_core(cache_id: int, core_id: int) -> Output:
|
||||
output = TestRun.executor.run(script_purge_core_cmd(str(cache_id), str(core_id)))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Purge core failed.", output)
|
||||
return output
|
||||
|
||||
|
||||
def detach_core(cache_id: int, core_id: int) -> Output:
|
||||
output = TestRun.executor.run(script_detach_core_cmd(str(cache_id), str(core_id)))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to execute detach core script command.", output)
|
||||
return output
|
||||
|
||||
|
||||
def remove_core_with_script_command(cache_id: int, core_id: int, no_flush: bool = False) -> Output:
|
||||
output = TestRun.executor.run(script_remove_core_cmd(str(cache_id), str(core_id), no_flush))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to execute remove core script command.", output)
|
||||
return output
|
||||
|
||||
|
||||
# casadm custom commands
|
||||
|
||||
|
||||
def stop_all_caches() -> None:
|
||||
from .casadm_parser import get_caches
|
||||
|
||||
caches = get_caches()
|
||||
if not caches:
|
||||
return
|
||||
for cache in caches:
|
||||
stop_cache(cache_id=cache.cache_id)
|
||||
|
||||
|
||||
def remove_all_detached_cores() -> None:
|
||||
from api.cas import casadm_parser
|
||||
|
||||
devices = casadm_parser.get_cas_devices_dict()
|
||||
for dev in devices["core_pool"]:
|
||||
TestRun.executor.run(remove_detached_cmd(dev["device"]))
|
||||
|
@ -189,7 +189,7 @@ def get_casadm_version():
|
||||
return CasVersion.from_version_string(version_str)
|
||||
|
||||
|
||||
def get_io_class_list(cache_id: int):
|
||||
def get_io_class_list(cache_id: int) -> list:
|
||||
ret = []
|
||||
casadm_output = casadm.list_io_classes(cache_id, OutputFormat.csv).stdout.splitlines()
|
||||
casadm_output.pop(0) # Remove header
|
||||
@ -200,7 +200,7 @@ def get_io_class_list(cache_id: int):
|
||||
return ret
|
||||
|
||||
|
||||
def get_core_info_by_path(core_disk_path):
|
||||
def get_core_info_by_path(core_disk_path) -> dict | None:
|
||||
output = casadm.list_caches(OutputFormat.csv, by_id_path=True)
|
||||
reader = csv.DictReader(io.StringIO(output.stdout))
|
||||
for row in reader:
|
||||
|
@ -12,106 +12,6 @@ casadm_bin = "casadm"
|
||||
casctl = "casctl"
|
||||
|
||||
|
||||
def add_core_cmd(cache_id: str, core_dev: str, core_id: str = None, shortcut: bool = False) -> str:
|
||||
command = " -A " if shortcut else " --add-core"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
command += (" -d " if shortcut else " --core-device ") + core_dev
|
||||
if core_id:
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def script_try_add_cmd(cache_id: str, core_dev: str, core_id: str = None) -> str:
|
||||
command = " --script --add-core --try-add"
|
||||
command += " --cache-id " + cache_id
|
||||
if core_id:
|
||||
command += " --core-device " + core_dev
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def script_purge_cache_cmd(cache_id: str) -> str:
|
||||
command = "--script --purge-cache"
|
||||
command += " --cache-id " + cache_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def script_purge_core_cmd(cache_id: str, core_id: str) -> str:
|
||||
command = "--script --purge-core"
|
||||
command += " --cache-id " + cache_id
|
||||
command += " --core-id " + core_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def script_detach_core_cmd(cache_id: str, core_id: str) -> str:
|
||||
command = "--script --remove-core --detach"
|
||||
command += " --cache-id " + cache_id
|
||||
command += " --core-id " + core_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def script_remove_core_cmd(cache_id: str, core_id: str, no_flush: bool = False) -> str:
|
||||
command = "--script --remove-core"
|
||||
command += " --cache-id " + cache_id
|
||||
command += " --core-id " + core_id
|
||||
if no_flush:
|
||||
command += " --no-flush"
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def remove_core_cmd(
|
||||
cache_id: str, core_id: str, force: bool = False, shortcut: bool = False
|
||||
) -> str:
|
||||
command = " -R " if shortcut else " --remove-core"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
if force:
|
||||
command += " -f" if shortcut else " --force"
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def remove_inactive_cmd(
|
||||
cache_id: str, core_id: str, force: bool = False, shortcut: bool = False
|
||||
) -> str:
|
||||
command = " --remove-inactive"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
if force:
|
||||
command += " -f" if shortcut else " --force"
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def remove_detached_cmd(core_device: str, shortcut: bool = False) -> str:
|
||||
command = " --remove-detached"
|
||||
command += (" -d " if shortcut else " --device ") + core_device
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def help_cmd(shortcut: bool = False) -> str:
|
||||
command = " -H" if shortcut else " --help"
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def reset_counters_cmd(cache_id: str, core_id: str = None, shortcut: bool = False) -> str:
|
||||
command = " -Z" if shortcut else " --reset-counters"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
if core_id is not None:
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def flush_cache_cmd(cache_id: str, shortcut: bool = False) -> str:
|
||||
command = " -F" if shortcut else " --flush-cache"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def flush_core_cmd(cache_id: str, core_id: str, shortcut: bool = False) -> str:
|
||||
command = " -F" if shortcut else " --flush-cache"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def start_cmd(
|
||||
cache_dev: str,
|
||||
cache_mode: str = None,
|
||||
@ -136,73 +36,27 @@ def start_cmd(
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def standby_init_cmd(
|
||||
cache_dev: str,
|
||||
cache_id: str,
|
||||
cache_line_size: str,
|
||||
force: bool = False,
|
||||
shortcut: bool = False,
|
||||
def load_cmd(cache_dev: str, shortcut: bool = False) -> str:
|
||||
return start_cmd(cache_dev=cache_dev, load=True, shortcut=shortcut)
|
||||
|
||||
|
||||
def attach_cache_cmd(
|
||||
cache_dev: str, cache_id: str, force: bool = False, shortcut: bool = False
|
||||
) -> str:
|
||||
command = " --standby --init"
|
||||
command = " --attach-cache"
|
||||
command += (" -d " if shortcut else " --cache-device ") + cache_dev
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
command += (" -x " if shortcut else " --cache-line-size ") + cache_line_size
|
||||
if force:
|
||||
command += " -f" if shortcut else " --force"
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def standby_load_cmd(cache_dev: str, shortcut: bool = False) -> str:
|
||||
command = " --standby --load"
|
||||
command += (" -d " if shortcut else " --cache-device ") + cache_dev
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def standby_detach_cmd(cache_id: str, shortcut: bool = False) -> str:
|
||||
command = " --standby --detach"
|
||||
def detach_cache_cmd(cache_id: str, shortcut: bool = False) -> str:
|
||||
command = " --detach-cache"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def standby_activate_cmd(cache_dev: str, cache_id: str, shortcut: bool = False) -> str:
|
||||
command = " --standby --activate"
|
||||
command += (" -d " if shortcut else " --cache-device ") + cache_dev
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def print_statistics_cmd(
|
||||
cache_id: str,
|
||||
core_id: str = None,
|
||||
io_class_id: str = None,
|
||||
filter: str = None,
|
||||
output_format: str = None,
|
||||
by_id_path: bool = True,
|
||||
shortcut: bool = False,
|
||||
) -> str:
|
||||
command = " -P" if shortcut else " --stats"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
if core_id:
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
if io_class_id:
|
||||
command += (" -d " if shortcut else " --io-class-id ") + io_class_id
|
||||
if filter:
|
||||
command += (" -f " if shortcut else " --filter ") + filter
|
||||
if output_format:
|
||||
command += (" -o " if shortcut else " --output-format ") + output_format
|
||||
if by_id_path:
|
||||
command += " -b " if shortcut else " --by-id-path "
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def zero_metadata_cmd(cache_dev: str, force: bool = False, shortcut: bool = False) -> str:
|
||||
command = " --zero-metadata"
|
||||
command += (" -d " if shortcut else " --device ") + cache_dev
|
||||
if force:
|
||||
command += " -f" if shortcut else " --force"
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def stop_cmd(cache_id: str, no_data_flush: bool = False, shortcut: bool = False) -> str:
|
||||
command = " -T" if shortcut else " --stop-cache"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
@ -211,108 +65,6 @@ def stop_cmd(cache_id: str, no_data_flush: bool = False, shortcut: bool = False)
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def list_caches_cmd(
|
||||
output_format: str = None, by_id_path: bool = True, shortcut: bool = False
|
||||
) -> str:
|
||||
command = " -L" if shortcut else " --list-caches"
|
||||
if output_format:
|
||||
command += (" -o " if shortcut else " --output-format ") + output_format
|
||||
if by_id_path:
|
||||
command += " -b" if shortcut else " --by-id-path"
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def load_cmd(cache_dev: str, shortcut: bool = False) -> str:
|
||||
return start_cmd(cache_dev=cache_dev, load=True, shortcut=shortcut)
|
||||
|
||||
|
||||
def version_cmd(output_format: str = None, shortcut: bool = False) -> str:
|
||||
command = " -V" if shortcut else " --version"
|
||||
if output_format:
|
||||
command += (" -o " if shortcut else " --output-format ") + output_format
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def set_cache_mode_cmd(
|
||||
cache_mode: str, cache_id: str, flush_cache: str = None, shortcut: bool = False
|
||||
) -> str:
|
||||
command = (" -Q -c" if shortcut else " --set-cache-mode --cache-mode ") + cache_mode
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
if flush_cache:
|
||||
command += (" -f " if shortcut else " --flush-cache ") + flush_cache
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def load_io_classes_cmd(cache_id: str, file: str, shortcut: bool = False) -> str:
|
||||
command = " -C -C" if shortcut else " --io-class --load-config"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
command += (" -f " if shortcut else " --file ") + file
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def list_io_classes_cmd(cache_id: str, output_format: str, shortcut: bool = False) -> str:
|
||||
command = " -C -L" if shortcut else " --io-class --list"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
command += (" -o " if shortcut else " --output-format ") + output_format
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def _get_param_cmd(
|
||||
name: str,
|
||||
cache_id: str,
|
||||
output_format: str = None,
|
||||
shortcut: bool = False,
|
||||
) -> str:
|
||||
command = (" -G -n" if shortcut else " --get-param --name ") + name
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
if output_format:
|
||||
command += (" -o " if shortcut else " --output-format ") + output_format
|
||||
return command
|
||||
|
||||
|
||||
def get_param_cutoff_cmd(
|
||||
cache_id: str, core_id: str, output_format: str = None, shortcut: bool = False
|
||||
) -> str:
|
||||
name = "seq-cutoff"
|
||||
command = _get_param_cmd(
|
||||
name=name,
|
||||
cache_id=cache_id,
|
||||
core_id=core_id,
|
||||
output_format=output_format,
|
||||
shortcut=shortcut,
|
||||
)
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def get_param_cleaning_cmd(cache_id: str, output_format: str = None, shortcut: bool = False) -> str:
|
||||
name = "cleaning"
|
||||
command = _get_param_cmd(
|
||||
name=name, cache_id=cache_id, output_format=output_format, shortcut=shortcut
|
||||
)
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def get_param_cleaning_alru_cmd(
|
||||
cache_id: str, output_format: str = None, shortcut: bool = False
|
||||
) -> str:
|
||||
name = "cleaning-alru"
|
||||
command = _get_param_cmd(
|
||||
name=name, cache_id=cache_id, output_format=output_format, shortcut=shortcut
|
||||
)
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def get_param_cleaning_acp_cmd(
|
||||
cache_id: str, output_format: str = None, shortcut: bool = False
|
||||
) -> str:
|
||||
name = "cleaning-acp"
|
||||
command = _get_param_cmd(
|
||||
name=name, cache_id=cache_id, output_format=output_format, shortcut=shortcut
|
||||
)
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def _set_param_cmd(name: str, cache_id: str, shortcut: bool = False) -> str:
|
||||
command = (" X -n" if shortcut else " --set-param --name ") + name
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
@ -402,6 +154,237 @@ def set_param_cleaning_acp_cmd(
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def _get_param_cmd(
|
||||
name: str,
|
||||
cache_id: str,
|
||||
output_format: str = None,
|
||||
shortcut: bool = False,
|
||||
) -> str:
|
||||
command = (" -G -n" if shortcut else " --get-param --name ") + name
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
if output_format:
|
||||
command += (" -o " if shortcut else " --output-format ") + output_format
|
||||
return command
|
||||
|
||||
|
||||
def get_param_cutoff_cmd(
|
||||
cache_id: str, core_id: str, output_format: str = None, shortcut: bool = False
|
||||
) -> str:
|
||||
name = "seq-cutoff"
|
||||
command = _get_param_cmd(
|
||||
name=name,
|
||||
cache_id=cache_id,
|
||||
core_id=core_id,
|
||||
output_format=output_format,
|
||||
shortcut=shortcut,
|
||||
)
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def get_param_cleaning_cmd(cache_id: str, output_format: str = None, shortcut: bool = False) -> str:
|
||||
name = "cleaning"
|
||||
command = _get_param_cmd(
|
||||
name=name, cache_id=cache_id, output_format=output_format, shortcut=shortcut
|
||||
)
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def get_param_cleaning_alru_cmd(
|
||||
cache_id: str, output_format: str = None, shortcut: bool = False
|
||||
) -> str:
|
||||
name = "cleaning-alru"
|
||||
command = _get_param_cmd(
|
||||
name=name, cache_id=cache_id, output_format=output_format, shortcut=shortcut
|
||||
)
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def get_param_cleaning_acp_cmd(
|
||||
cache_id: str, output_format: str = None, shortcut: bool = False
|
||||
) -> str:
|
||||
name = "cleaning-acp"
|
||||
command = _get_param_cmd(
|
||||
name=name, cache_id=cache_id, output_format=output_format, shortcut=shortcut
|
||||
)
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def set_cache_mode_cmd(
|
||||
cache_mode: str, cache_id: str, flush_cache: str = None, shortcut: bool = False
|
||||
) -> str:
|
||||
command = (" -Q -c" if shortcut else " --set-cache-mode --cache-mode ") + cache_mode
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
if flush_cache:
|
||||
command += (" -f " if shortcut else " --flush-cache ") + flush_cache
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def add_core_cmd(cache_id: str, core_dev: str, core_id: str = None, shortcut: bool = False) -> str:
|
||||
command = " -A " if shortcut else " --add-core"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
command += (" -d " if shortcut else " --core-device ") + core_dev
|
||||
if core_id:
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def remove_core_cmd(
|
||||
cache_id: str, core_id: str, force: bool = False, shortcut: bool = False
|
||||
) -> str:
|
||||
command = " -R " if shortcut else " --remove-core"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
if force:
|
||||
command += " -f" if shortcut else " --force"
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def remove_inactive_cmd(
|
||||
cache_id: str, core_id: str, force: bool = False, shortcut: bool = False
|
||||
) -> str:
|
||||
command = " --remove-inactive"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
if force:
|
||||
command += " -f" if shortcut else " --force"
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def remove_detached_cmd(core_device: str, shortcut: bool = False) -> str:
|
||||
command = " --remove-detached"
|
||||
command += (" -d " if shortcut else " --device ") + core_device
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def list_caches_cmd(
|
||||
output_format: str = None, by_id_path: bool = True, shortcut: bool = False
|
||||
) -> str:
|
||||
command = " -L" if shortcut else " --list-caches"
|
||||
if output_format:
|
||||
command += (" -o " if shortcut else " --output-format ") + output_format
|
||||
if by_id_path:
|
||||
command += " -b" if shortcut else " --by-id-path"
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def print_statistics_cmd(
|
||||
cache_id: str,
|
||||
core_id: str = None,
|
||||
io_class_id: str = None,
|
||||
filter: str = None,
|
||||
output_format: str = None,
|
||||
by_id_path: bool = True,
|
||||
shortcut: bool = False,
|
||||
) -> str:
|
||||
command = " -P" if shortcut else " --stats"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
if core_id:
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
if io_class_id:
|
||||
command += (" -d " if shortcut else " --io-class-id ") + io_class_id
|
||||
if filter:
|
||||
command += (" -f " if shortcut else " --filter ") + filter
|
||||
if output_format:
|
||||
command += (" -o " if shortcut else " --output-format ") + output_format
|
||||
if by_id_path:
|
||||
command += " -b " if shortcut else " --by-id-path "
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def reset_counters_cmd(cache_id: str, core_id: str = None, shortcut: bool = False) -> str:
|
||||
command = " -Z" if shortcut else " --reset-counters"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
if core_id is not None:
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def flush_cache_cmd(cache_id: str, shortcut: bool = False) -> str:
|
||||
command = " -F" if shortcut else " --flush-cache"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def flush_core_cmd(cache_id: str, core_id: str, shortcut: bool = False) -> str:
|
||||
command = " -F" if shortcut else " --flush-cache"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def load_io_classes_cmd(cache_id: str, file: str, shortcut: bool = False) -> str:
|
||||
command = " -C -C" if shortcut else " --io-class --load-config"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
command += (" -f " if shortcut else " --file ") + file
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def list_io_classes_cmd(cache_id: str, output_format: str, shortcut: bool = False) -> str:
|
||||
command = " -C -L" if shortcut else " --io-class --list"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
command += (" -o " if shortcut else " --output-format ") + output_format
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def version_cmd(output_format: str = None, shortcut: bool = False) -> str:
|
||||
command = " -V" if shortcut else " --version"
|
||||
if output_format:
|
||||
command += (" -o " if shortcut else " --output-format ") + output_format
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def help_cmd(shortcut: bool = False) -> str:
|
||||
command = " -H" if shortcut else " --help"
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def standby_init_cmd(
|
||||
cache_dev: str,
|
||||
cache_id: str,
|
||||
cache_line_size: str,
|
||||
force: bool = False,
|
||||
shortcut: bool = False,
|
||||
) -> str:
|
||||
command = " --standby --init"
|
||||
command += (" -d " if shortcut else " --cache-device ") + cache_dev
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
command += (" -x " if shortcut else " --cache-line-size ") + cache_line_size
|
||||
if force:
|
||||
command += " -f" if shortcut else " --force"
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def standby_load_cmd(cache_dev: str, shortcut: bool = False) -> str:
|
||||
command = " --standby --load"
|
||||
command += (" -d " if shortcut else " --cache-device ") + cache_dev
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def standby_detach_cmd(cache_id: str, shortcut: bool = False) -> str:
|
||||
command = " --standby --detach"
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def standby_activate_cmd(cache_dev: str, cache_id: str, shortcut: bool = False) -> str:
|
||||
command = " --standby --activate"
|
||||
command += (" -d " if shortcut else " --cache-device ") + cache_dev
|
||||
command += (" -i " if shortcut else " --cache-id ") + cache_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def zero_metadata_cmd(cache_dev: str, force: bool = False, shortcut: bool = False) -> str:
|
||||
command = " --zero-metadata"
|
||||
command += (" -d " if shortcut else " --device ") + cache_dev
|
||||
if force:
|
||||
command += " -f" if shortcut else " --force"
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
# casctl command
|
||||
|
||||
|
||||
def ctl_help(shortcut: bool = False) -> str:
|
||||
command = " --help" if shortcut else " -h"
|
||||
return casctl + command
|
||||
@ -424,3 +407,43 @@ def ctl_init(force: bool = False) -> str:
|
||||
if force:
|
||||
command += " --force"
|
||||
return casctl + command
|
||||
|
||||
|
||||
# casadm script
|
||||
|
||||
|
||||
def script_try_add_cmd(cache_id: str, core_dev: str, core_id: str = None) -> str:
|
||||
command = " --script --add-core --try-add"
|
||||
command += " --cache-id " + cache_id
|
||||
if core_id:
|
||||
command += " --core-device " + core_dev
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def script_purge_cache_cmd(cache_id: str) -> str:
|
||||
command = "--script --purge-cache"
|
||||
command += " --cache-id " + cache_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def script_purge_core_cmd(cache_id: str, core_id: str) -> str:
|
||||
command = "--script --purge-core"
|
||||
command += " --cache-id " + cache_id
|
||||
command += " --core-id " + core_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def script_detach_core_cmd(cache_id: str, core_id: str) -> str:
|
||||
command = "--script --remove-core --detach"
|
||||
command += " --cache-id " + cache_id
|
||||
command += " --core-id " + core_id
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def script_remove_core_cmd(cache_id: str, core_id: str, no_flush: bool = False) -> str:
|
||||
command = "--script --remove-core"
|
||||
command += " --cache-id " + cache_id
|
||||
command += " --core-id " + core_id
|
||||
if no_flush:
|
||||
command += " --no-flush"
|
||||
return casadm_bin + command
|
||||
|
@ -34,137 +34,46 @@ casadm_help = [
|
||||
r"or go to support page \<https://open-cas\.github\.io\>\.",
|
||||
]
|
||||
|
||||
help_help = [r"Usage: casadm --help", r"Print help"]
|
||||
start_cache_help = [
|
||||
r"Usage: casadm --start-cache --cache-device \<DEVICE\> \[option\.\.\.\]",
|
||||
r"Start new cache instance or load using metadata",
|
||||
r"Options that are valid with --start-cache \(-S\) are:",
|
||||
r"-d --cache-device \<DEVICE\> Caching device to be used",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\> "
|
||||
r"\(if not provided, the first available number will be used\)",
|
||||
r"-l --load Load cache metadata from caching device "
|
||||
r"\(DANGEROUS - see manual or Admin Guide for details\)",
|
||||
r"-f --force Force the creation of cache instance",
|
||||
r"-c --cache-mode \<NAME\> Set cache mode from available: \{wt|wb|wa|pt|wo\} "
|
||||
r"Write-Through, Write-Back, Write-Around, Pass-Through, Write-Only; "
|
||||
r"without this parameter Write-Through will be set by default",
|
||||
r"-x --cache-line-size \<NUMBER\> Set cache line size in kibibytes: "
|
||||
r"\{4,8,16,32,64\}\[KiB\] \(default: 4\)",
|
||||
]
|
||||
|
||||
version_help = [
|
||||
r"Usage: casadm --version \[option\.\.\.\]",
|
||||
r"Print CAS version",
|
||||
r"Options that are valid with --version \(-V\) are:"
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
attach_cache_help = [
|
||||
r"Usage: casadm --attach-cache --cache-device \<DEVICE\> --cache-id \<ID\> \[option\.\.\.\]",
|
||||
r"Attach cache device",
|
||||
r"Options that are valid with --attach-cache are:",
|
||||
r"-d --cache-device \<DEVICE\> Caching device to be used",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\> "
|
||||
r"\(if not provided, the first available number will be used\)",
|
||||
r"-f --force Force attaching the cache device",
|
||||
]
|
||||
detach_cache_help = [
|
||||
r"Usage: casadm --detach-cache --cache-id \<ID\>",
|
||||
r"Detach cache device",
|
||||
r"Options that are valid with --detach-cache are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
]
|
||||
|
||||
|
||||
ioclass_help = [
|
||||
r"Usage: casadm --io-class \{--load-config|--list\}",
|
||||
r"Manage IO classes",
|
||||
r"Loads configuration for IO classes:",
|
||||
r"Usage: casadm --io-class --load-config --cache-id \<ID\> --file \<FILE\>",
|
||||
r"Options that are valid with --load-config \(-C\) are:",
|
||||
stop_cache_help = [
|
||||
r"Usage: casadm --stop-cache --cache-id \<ID\> \[option\.\.\.\]",
|
||||
r"Stop cache instance",
|
||||
r"Options that are valid with --stop-cache \(-T\) are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-f --file \<FILE\> Configuration file containing IO class definition",
|
||||
r"Lists currently configured IO classes:",
|
||||
r"Usage: casadm --io-class --list --cache-id \<ID\> \[option\.\.\.\]",
|
||||
r"Options that are valid with --list \(-L\) are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
]
|
||||
|
||||
flush_cache_help = [
|
||||
r"Usage: casadm --flush-cache --cache-id \<ID\>",
|
||||
r"Flush all dirty data from the caching device to core devices",
|
||||
r"Options that are valid with --flush-cache \(-F\) are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-j --core-id \[\<ID\>\] Identifier of core <0-4095> within given cache "
|
||||
r"instance",
|
||||
]
|
||||
|
||||
reset_counters_help = [
|
||||
r"Usage: casadm --reset-counters --cache-id \<ID\> \[option\.\.\.\]",
|
||||
r"Reset cache statistics for core device within cache instance",
|
||||
r"Options that are valid with --reset-counters \(-Z\) are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-j --core-id \<ID\> Identifier of core \<0-4095\> within given cache "
|
||||
r"instance\. If not specified, statistics are reset for all cores in cache instance\.",
|
||||
]
|
||||
|
||||
stats_help = [
|
||||
r"Usage: casadm --stats --cache-id \<ID\> \[option\.\.\.\]",
|
||||
r"Print statistics for cache instance",
|
||||
r"Options that are valid with --stats \(-P\) are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-j --core-id \<ID\> Limit display of core-specific statistics to only ones "
|
||||
r"pertaining to a specific core\. If this option is not given, casadm will display statistics "
|
||||
r"pertaining to all cores assigned to given cache instance\.",
|
||||
r"-d --io-class-id \[\<ID\>\] Display per IO class statistics",
|
||||
r"-f --filter \<FILTER-SPEC\> Apply filters from the following set: "
|
||||
r"\{all, conf, usage, req, blk, err\}",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
]
|
||||
|
||||
list_caches_help = [
|
||||
r"Usage: casadm --list-caches \[option\.\.\.\]",
|
||||
r"List all cache instances and core devices",
|
||||
r"Options that are valid with --list-caches \(-L\) are:",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
]
|
||||
|
||||
remove_detached_help = [
|
||||
r"Usage: casadm --remove-detached --device \<DEVICE\>",
|
||||
r"Remove core device from core pool",
|
||||
r"Options that are valid with --remove-detached are:",
|
||||
r"-d --device \<DEVICE\> Path to core device",
|
||||
]
|
||||
|
||||
remove_core_help = [
|
||||
r"Usage: casadm --remove-core --cache-id \<ID\> --core-id \<ID\> \[option\.\.\.\]",
|
||||
r"Remove active core device from cache instance",
|
||||
r"Options that are valid with --remove-core \(-R\) are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-j --core-id \<ID\> Identifier of core \<0-4095\> within given cache "
|
||||
r"instance",
|
||||
r"-f --force Force active core removal without data flush",
|
||||
]
|
||||
|
||||
add_core_help = [
|
||||
r"Usage: casadm --add-core --cache-id \<ID\> --core-device \<DEVICE\> \[option\.\.\.\]",
|
||||
r"Add core device to cache instance",
|
||||
r"Options that are valid with --add-core \(-A\) are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-j --core-id \<ID\> Identifier of core \<0-4095\> within given cache "
|
||||
r"instance",
|
||||
r"-d --core-device \<DEVICE\> Path to core device",
|
||||
]
|
||||
|
||||
set_cache_mode_help = [
|
||||
r"Usage: casadm --set-cache-mode --cache-mode \<NAME\> --cache-id \<ID\> \[option\.\.\.\]",
|
||||
r"Set cache mode",
|
||||
r"Options that are valid with --set-cache-mode \(-Q\) are:",
|
||||
r"-c --cache-mode \<NAME\> Cache mode\. Available cache modes: \{wt|wb|wa|pt|wo\}",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-f --flush-cache \<yes|no\> Flush all dirty data from cache before switching "
|
||||
r"to new mode\. Option is required when switching from Write-Back or Write-Only mode",
|
||||
]
|
||||
|
||||
get_params_help = [
|
||||
r"Usage: casadm --get-param --name \<NAME\>",
|
||||
r"Get various runtime parameters",
|
||||
r"Valid values of NAME are:",
|
||||
r"seq-cutoff - Sequential cutoff parameters",
|
||||
r"cleaning - Cleaning policy parameters",
|
||||
r"cleaning-alru - Cleaning policy ALRU parameters",
|
||||
r"cleaning-acp - Cleaning policy ACP parameters",
|
||||
r"promotion - Promotion policy parameters",
|
||||
r"promotion-nhit - Promotion policy NHIT parameters",
|
||||
r"Options that are valid with --get-param \(-G\) --name \(-n\) seq-cutoff are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-j --core-id \<ID\> Identifier of core \<0-4095\> within given cache "
|
||||
r"instance",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
r"Options that are valid with --get-param \(-G\) --name \(-n\) cleaning are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
r"Options that are valid with --get-param \(-G\) --name \(-n\) cleaning-alru are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
r"Options that are valid with --get-param \(-G\) --name \(-n\) cleaning-acp are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
r"Options that are valid with --get-param \(-G\) --name \(-n\) promotion are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
r"Options that are valid with --get-param \(-G\) --name \(-n\) promotion-nhit are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
r"-n --no-data-flush Do not flush dirty data \(may be dangerous\)",
|
||||
]
|
||||
|
||||
set_params_help = [
|
||||
@ -217,31 +126,157 @@ set_params_help = [
|
||||
]
|
||||
|
||||
|
||||
stop_cache_help = [
|
||||
r"Usage: casadm --stop-cache --cache-id \<ID\> \[option\.\.\.\]",
|
||||
r"Stop cache instance",
|
||||
r"Options that are valid with --stop-cache \(-T\) are:",
|
||||
get_params_help = [
|
||||
r"Usage: casadm --get-param --name \<NAME\>",
|
||||
r"Get various runtime parameters",
|
||||
r"Valid values of NAME are:",
|
||||
r"seq-cutoff - Sequential cutoff parameters",
|
||||
r"cleaning - Cleaning policy parameters",
|
||||
r"cleaning-alru - Cleaning policy ALRU parameters",
|
||||
r"cleaning-acp - Cleaning policy ACP parameters",
|
||||
r"promotion - Promotion policy parameters",
|
||||
r"promotion-nhit - Promotion policy NHIT parameters",
|
||||
r"Options that are valid with --get-param \(-G\) --name \(-n\) seq-cutoff are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-n --no-data-flush Do not flush dirty data \(may be dangerous\)",
|
||||
r"-j --core-id \<ID\> Identifier of core \<0-4095\> within given cache "
|
||||
r"instance",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
r"Options that are valid with --get-param \(-G\) --name \(-n\) cleaning are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
r"Options that are valid with --get-param \(-G\) --name \(-n\) cleaning-alru are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
r"Options that are valid with --get-param \(-G\) --name \(-n\) cleaning-acp are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
r"Options that are valid with --get-param \(-G\) --name \(-n\) promotion are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
r"Options that are valid with --get-param \(-G\) --name \(-n\) promotion-nhit are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
]
|
||||
|
||||
start_cache_help = [
|
||||
r"Usage: casadm --start-cache --cache-device \<DEVICE\> \[option\.\.\.\]",
|
||||
r"Start new cache instance or load using metadata",
|
||||
r"Options that are valid with --start-cache \(-S\) are:",
|
||||
r"-d --cache-device \<DEVICE\> Caching device to be used",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\> "
|
||||
r"\(if not provided, the first available number will be used\)",
|
||||
r"-l --load Load cache metadata from caching device "
|
||||
r"\(DANGEROUS - see manual or Admin Guide for details\)",
|
||||
r"-f --force Force the creation of cache instance",
|
||||
r"-c --cache-mode \<NAME\> Set cache mode from available: \{wt|wb|wa|pt|wo\} "
|
||||
r"Write-Through, Write-Back, Write-Around, Pass-Through, Write-Only; "
|
||||
r"without this parameter Write-Through will be set by default",
|
||||
r"-x --cache-line-size \<NUMBER\> Set cache line size in kibibytes: "
|
||||
r"\{4,8,16,32,64\}\[KiB\] \(default: 4\)",
|
||||
|
||||
set_cache_mode_help = [
|
||||
r"Usage: casadm --set-cache-mode --cache-mode \<NAME\> --cache-id \<ID\> \[option\.\.\.\]",
|
||||
r"Set cache mode",
|
||||
r"Options that are valid with --set-cache-mode \(-Q\) are:",
|
||||
r"-c --cache-mode \<NAME\> Cache mode\. Available cache modes: \{wt|wb|wa|pt|wo\}",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-f --flush-cache \<yes|no\> Flush all dirty data from cache before switching "
|
||||
r"to new mode\. Option is required when switching from Write-Back or Write-Only mode",
|
||||
]
|
||||
|
||||
|
||||
add_core_help = [
|
||||
r"Usage: casadm --add-core --cache-id \<ID\> --core-device \<DEVICE\> \[option\.\.\.\]",
|
||||
r"Add core device to cache instance",
|
||||
r"Options that are valid with --add-core \(-A\) are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-j --core-id \<ID\> Identifier of core \<0-4095\> within given cache "
|
||||
r"instance",
|
||||
r"-d --core-device \<DEVICE\> Path to core device",
|
||||
]
|
||||
|
||||
remove_core_help = [
|
||||
r"Usage: casadm --remove-core --cache-id \<ID\> --core-id \<ID\> \[option\.\.\.\]",
|
||||
r"Remove active core device from cache instance",
|
||||
r"Options that are valid with --remove-core \(-R\) are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-j --core-id \<ID\> Identifier of core \<0-4095\> within given cache "
|
||||
r"instance",
|
||||
r"-f --force Force active core removal without data flush",
|
||||
]
|
||||
|
||||
|
||||
remove_inactive_help = [
|
||||
r"casadm --remove-inactive --cache-id \<ID\> --core-id \<ID\> \[option\.\.\.\]",
|
||||
r"Remove inactive core device from cache instance",
|
||||
r"Options that are valid with --remove-inactive are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-j --core-id \<ID\> Identifier of core \<0-4095\> within given "
|
||||
r"cache instance",
|
||||
r"-f --force Force dirty inactive core removal",
|
||||
]
|
||||
|
||||
|
||||
remove_detached_help = [
|
||||
r"Usage: casadm --remove-detached --device \<DEVICE\>",
|
||||
r"Remove core device from core pool",
|
||||
r"Options that are valid with --remove-detached are:",
|
||||
r"-d --device \<DEVICE\> Path to core device",
|
||||
]
|
||||
|
||||
|
||||
list_caches_help = [
|
||||
r"Usage: casadm --list-caches \[option\.\.\.\]",
|
||||
r"List all cache instances and core devices",
|
||||
r"Options that are valid with --list-caches \(-L\) are:",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
]
|
||||
|
||||
stats_help = [
|
||||
r"Usage: casadm --stats --cache-id \<ID\> \[option\.\.\.\]",
|
||||
r"Print statistics for cache instance",
|
||||
r"Options that are valid with --stats \(-P\) are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-j --core-id \<ID\> Limit display of core-specific statistics to only ones "
|
||||
r"pertaining to a specific core\. If this option is not given, casadm will display statistics "
|
||||
r"pertaining to all cores assigned to given cache instance\.",
|
||||
r"-d --io-class-id \[\<ID\>\] Display per IO class statistics",
|
||||
r"-f --filter \<FILTER-SPEC\> Apply filters from the following set: "
|
||||
r"\{all, conf, usage, req, blk, err\}",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
]
|
||||
|
||||
|
||||
reset_counters_help = [
|
||||
r"Usage: casadm --reset-counters --cache-id \<ID\> \[option\.\.\.\]",
|
||||
r"Reset cache statistics for core device within cache instance",
|
||||
r"Options that are valid with --reset-counters \(-Z\) are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-j --core-id \<ID\> Identifier of core \<0-4095\> within given cache "
|
||||
r"instance\. If not specified, statistics are reset for all cores in cache instance\.",
|
||||
]
|
||||
|
||||
flush_cache_help = [
|
||||
r"Usage: casadm --flush-cache --cache-id \<ID\>",
|
||||
r"Flush all dirty data from the caching device to core devices",
|
||||
r"Options that are valid with --flush-cache \(-F\) are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-j --core-id \[\<ID\>\] Identifier of core <0-4095> within given cache "
|
||||
r"instance",
|
||||
]
|
||||
|
||||
|
||||
ioclass_help = [
|
||||
r"Usage: casadm --io-class \{--load-config|--list\}",
|
||||
r"Manage IO classes",
|
||||
r"Loads configuration for IO classes:",
|
||||
r"Usage: casadm --io-class --load-config --cache-id \<ID\> --file \<FILE\>",
|
||||
r"Options that are valid with --load-config \(-C\) are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-f --file \<FILE\> Configuration file containing IO class definition",
|
||||
r"Lists currently configured IO classes:",
|
||||
r"Usage: casadm --io-class --list --cache-id \<ID\> \[option\.\.\.\]",
|
||||
r"Options that are valid with --list \(-L\) are:",
|
||||
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
]
|
||||
|
||||
|
||||
version_help = [
|
||||
r"Usage: casadm --version \[option\.\.\.\]",
|
||||
r"Print CAS version",
|
||||
r"Options that are valid with --version \(-V\) are:"
|
||||
r"-o --output-format \<FORMAT\> Output format: \{table|csv\}",
|
||||
]
|
||||
|
||||
help_help = [r"Usage: casadm --help", r"Print help"]
|
||||
|
||||
|
||||
standby_help = [
|
||||
r"The command is not supported"
|
||||
]
|
||||
@ -254,7 +289,6 @@ zero_metadata_help = [
|
||||
r"-f --force Ignore potential dirty data on cache device",
|
||||
]
|
||||
|
||||
|
||||
unrecognized_stderr = [
|
||||
r"Unrecognized command -\S+",
|
||||
]
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2019-2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
@ -17,18 +18,24 @@ class InitConfig:
|
||||
self.cache_config_lines = []
|
||||
self.core_config_lines = []
|
||||
|
||||
def add_cache(self, cache_id, cache_device: Device,
|
||||
cache_mode: CacheMode = CacheMode.WT, extra_flags=""):
|
||||
def add_cache(
|
||||
self,
|
||||
cache_id,
|
||||
cache_device: Device,
|
||||
cache_mode: CacheMode = CacheMode.WT,
|
||||
extra_flags="",
|
||||
):
|
||||
self.cache_config_lines.append(
|
||||
CacheConfigLine(cache_id, cache_device, cache_mode, extra_flags))
|
||||
CacheConfigLine(cache_id, cache_device, cache_mode, extra_flags)
|
||||
)
|
||||
|
||||
def add_core(self, cache_id, core_id, core_device: Device, extra_flags=""):
|
||||
self.core_config_lines.append(CoreConfigLine(cache_id, core_id, core_device, extra_flags))
|
||||
|
||||
def remove_config_file(self):
|
||||
@staticmethod
|
||||
def remove_config_file():
|
||||
fs_utils.remove(opencas_conf_path, force=False)
|
||||
|
||||
|
||||
def save_config_file(self):
|
||||
config_lines = []
|
||||
InitConfig.create_default_init_config()
|
||||
@ -40,18 +47,20 @@ class InitConfig:
|
||||
config_lines.append(CoreConfigLine.header)
|
||||
for c in self.core_config_lines:
|
||||
config_lines.append(str(c))
|
||||
fs_utils.write_file(opencas_conf_path, '\n'.join(config_lines), False)
|
||||
fs_utils.write_file(opencas_conf_path, "\n".join(config_lines), False)
|
||||
|
||||
@classmethod
|
||||
def create_init_config_from_running_configuration(
|
||||
cls, cache_extra_flags="", core_extra_flags=""
|
||||
cls, cache_extra_flags="", core_extra_flags=""
|
||||
):
|
||||
init_conf = cls()
|
||||
for cache in casadm_parser.get_caches():
|
||||
init_conf.add_cache(cache.cache_id,
|
||||
cache.cache_device,
|
||||
cache.get_cache_mode(),
|
||||
cache_extra_flags)
|
||||
init_conf.add_cache(
|
||||
cache.cache_id,
|
||||
cache.cache_device,
|
||||
cache.get_cache_mode(),
|
||||
cache_extra_flags,
|
||||
)
|
||||
for core in casadm_parser.get_cores(cache.cache_id):
|
||||
init_conf.add_core(cache.cache_id, core.core_id, core.core_device, core_extra_flags)
|
||||
init_conf.save_config_file()
|
||||
@ -66,17 +75,20 @@ class InitConfig:
|
||||
class CacheConfigLine:
|
||||
header = "[caches]"
|
||||
|
||||
def __init__(self, cache_id, cache_device: Device,
|
||||
cache_mode: CacheMode, extra_flags=""):
|
||||
def __init__(self, cache_id, cache_device: Device, cache_mode: CacheMode, extra_flags=""):
|
||||
self.cache_id = cache_id
|
||||
self.cache_device = cache_device
|
||||
self.cache_mode = cache_mode
|
||||
self.extra_flags = extra_flags
|
||||
|
||||
def __str__(self):
|
||||
params = [str(self.cache_id), self.cache_device.path,
|
||||
self.cache_mode.name, self.extra_flags]
|
||||
return '\t'.join(params)
|
||||
params = [
|
||||
str(self.cache_id),
|
||||
self.cache_device.path,
|
||||
self.cache_mode.name,
|
||||
self.extra_flags,
|
||||
]
|
||||
return "\t".join(params)
|
||||
|
||||
|
||||
class CoreConfigLine:
|
||||
@ -89,6 +101,10 @@ class CoreConfigLine:
|
||||
self.extra_flags = extra_flags
|
||||
|
||||
def __str__(self):
|
||||
params = [str(self.cache_id), str(self.core_id),
|
||||
self.core_device.path, self.extra_flags]
|
||||
return '\t'.join(params)
|
||||
params = [
|
||||
str(self.cache_id),
|
||||
str(self.core_id),
|
||||
self.core_device.path,
|
||||
self.extra_flags,
|
||||
]
|
||||
return "\t".join(params)
|
||||
|
@ -22,27 +22,23 @@ def rsync_opencas_sources():
|
||||
# to make sure path ends with directory separator.
|
||||
# Needed for rsync to copy only contents of a directory
|
||||
# and not the directory itself.
|
||||
os.path.join(TestRun.usr.repo_dir, ''),
|
||||
os.path.join(TestRun.usr.working_dir, ''),
|
||||
os.path.join(TestRun.usr.repo_dir, ""),
|
||||
os.path.join(TestRun.usr.working_dir, ""),
|
||||
exclude_list=["test/functional/results/"],
|
||||
delete=True)
|
||||
delete=True,
|
||||
)
|
||||
|
||||
|
||||
def clean_opencas_repo():
|
||||
TestRun.LOGGER.info("Cleaning Open CAS repo")
|
||||
output = TestRun.executor.run(
|
||||
f"cd {TestRun.usr.working_dir} && "
|
||||
"make distclean")
|
||||
output = TestRun.executor.run(f"cd {TestRun.usr.working_dir} && " "make distclean")
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("make distclean command executed with nonzero status", output)
|
||||
|
||||
|
||||
def build_opencas():
|
||||
TestRun.LOGGER.info("Building Open CAS")
|
||||
output = TestRun.executor.run(
|
||||
f"cd {TestRun.usr.working_dir} && "
|
||||
"./configure && "
|
||||
"make -j")
|
||||
output = TestRun.executor.run(f"cd {TestRun.usr.working_dir} && " "./configure && " "make -j")
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Make command executed with nonzero status", output)
|
||||
|
||||
@ -54,8 +50,8 @@ def install_opencas(destdir: str = ""):
|
||||
destdir = os.path.join(TestRun.usr.working_dir, destdir)
|
||||
|
||||
output = TestRun.executor.run(
|
||||
f"cd {TestRun.usr.working_dir} && "
|
||||
f"make {'DESTDIR='+destdir if destdir else ''} install")
|
||||
f"cd {TestRun.usr.working_dir} && " f"make {'DESTDIR='+destdir if destdir else ''} install"
|
||||
)
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to install Open CAS", output)
|
||||
|
||||
@ -90,9 +86,7 @@ def uninstall_opencas():
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Open CAS is not properly installed", output)
|
||||
else:
|
||||
TestRun.executor.run(
|
||||
f"cd {TestRun.usr.working_dir} && "
|
||||
f"make uninstall")
|
||||
TestRun.executor.run(f"cd {TestRun.usr.working_dir} && " f"make uninstall")
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("There was an error during uninstall process", output)
|
||||
|
||||
|
@ -8,8 +8,8 @@ import functools
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
from datetime import timedelta
|
||||
|
||||
from datetime import timedelta
|
||||
from packaging import version
|
||||
|
||||
from core.test_run import TestRun
|
||||
@ -30,33 +30,49 @@ IO_CLASS_CONFIG_HEADER = "IO class id,IO class name,Eviction priority,Allocation
|
||||
|
||||
@functools.total_ordering
|
||||
class IoClass:
|
||||
def __init__(self, class_id: int, rule: str = '', priority: int = None,
|
||||
allocation: str = "1.00"):
|
||||
def __init__(
|
||||
self,
|
||||
class_id: int,
|
||||
rule: str = "",
|
||||
priority: int = None,
|
||||
allocation: str = "1.00",
|
||||
):
|
||||
self.id = class_id
|
||||
self.rule = rule
|
||||
self.priority = priority
|
||||
self.allocation = allocation
|
||||
|
||||
def __str__(self):
|
||||
return (f'{self.id},{self.rule},{"" if self.priority is None else self.priority}'
|
||||
f',{self.allocation}')
|
||||
return (
|
||||
f'{self.id},{self.rule},{"" if self.priority is None else self.priority}'
|
||||
f",{self.allocation}"
|
||||
)
|
||||
|
||||
def __eq__(self, other):
|
||||
return ((self.id, self.rule, self.priority, self.allocation)
|
||||
== (other.id, other.rule, other.priority, other.allocation))
|
||||
return (self.id, self.rule, self.priority, self.allocation) == (
|
||||
other.id,
|
||||
other.rule,
|
||||
other.priority,
|
||||
other.allocation,
|
||||
)
|
||||
|
||||
def __lt__(self, other):
|
||||
return ((self.id, self.rule, self.priority, self.allocation)
|
||||
< (other.id, other.rule, other.priority, other.allocation))
|
||||
return (self.id, self.rule, self.priority, self.allocation) < (
|
||||
other.id,
|
||||
other.rule,
|
||||
other.priority,
|
||||
other.allocation,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def from_string(ioclass_str: str):
|
||||
parts = [part.strip() for part in re.split('[,|]', ioclass_str.replace('║', ''))]
|
||||
parts = [part.strip() for part in re.split("[,|]", ioclass_str.replace("║", ""))]
|
||||
return IoClass(
|
||||
class_id=int(parts[0]),
|
||||
rule=parts[1],
|
||||
priority=int(parts[2]),
|
||||
allocation="%.2f" % float(parts[3]))
|
||||
allocation="%.2f" % float(parts[3]),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def list_to_csv(ioclass_list: [], add_default_rule: bool = True):
|
||||
@ -64,7 +80,7 @@ class IoClass:
|
||||
if add_default_rule and not len([c for c in list_copy if c.id == 0]):
|
||||
list_copy.insert(0, IoClass.default())
|
||||
list_copy.insert(0, IO_CLASS_CONFIG_HEADER)
|
||||
return '\n'.join(str(c) for c in list_copy)
|
||||
return "\n".join(str(c) for c in list_copy)
|
||||
|
||||
@staticmethod
|
||||
def csv_to_list(csv: str):
|
||||
@ -76,12 +92,15 @@ class IoClass:
|
||||
return ioclass_list
|
||||
|
||||
@staticmethod
|
||||
def save_list_to_config_file(ioclass_list: [],
|
||||
add_default_rule: bool = True,
|
||||
ioclass_config_path: str = default_config_file_path):
|
||||
def save_list_to_config_file(
|
||||
ioclass_list: [],
|
||||
add_default_rule: bool = True,
|
||||
ioclass_config_path: str = default_config_file_path,
|
||||
):
|
||||
TestRun.LOGGER.info(f"Creating config file {ioclass_config_path}")
|
||||
fs_utils.write_file(ioclass_config_path,
|
||||
IoClass.list_to_csv(ioclass_list, add_default_rule))
|
||||
fs_utils.write_file(
|
||||
ioclass_config_path, IoClass.list_to_csv(ioclass_list, add_default_rule)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def default(priority=DEFAULT_IO_CLASS_PRIORITY, allocation="1.00"):
|
||||
@ -93,12 +112,12 @@ class IoClass:
|
||||
"id": "IO class id",
|
||||
"name": "IO class name",
|
||||
"eviction_prio": "Eviction priority",
|
||||
"allocation": "Allocation"
|
||||
"allocation": "Allocation",
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def default_header():
|
||||
return ','.join(IoClass.default_header_dict().values())
|
||||
return ",".join(IoClass.default_header_dict().values())
|
||||
|
||||
@staticmethod
|
||||
def compare_ioclass_lists(list1: [], list2: []):
|
||||
@ -106,18 +125,37 @@ class IoClass:
|
||||
|
||||
@staticmethod
|
||||
def generate_random_ioclass_list(count: int, max_priority: int = MAX_IO_CLASS_PRIORITY):
|
||||
random_list = [IoClass.default(priority=random.randint(0, max_priority),
|
||||
allocation=f"{random.randint(0, 100) / 100:0.2f}")]
|
||||
random_list = [
|
||||
IoClass.default(
|
||||
priority=random.randint(0, max_priority),
|
||||
allocation=f"{random.randint(0, 100) / 100:0.2f}",
|
||||
)
|
||||
]
|
||||
for i in range(1, count):
|
||||
random_list.append(IoClass(i, priority=random.randint(0, max_priority),
|
||||
allocation=f"{random.randint(0, 100) / 100:0.2f}")
|
||||
.set_random_rule())
|
||||
random_list.append(
|
||||
IoClass(
|
||||
i,
|
||||
priority=random.randint(0, max_priority),
|
||||
allocation=f"{random.randint(0, 100) / 100:0.2f}",
|
||||
).set_random_rule()
|
||||
)
|
||||
return random_list
|
||||
|
||||
def set_random_rule(self):
|
||||
rules = ["metadata", "direct", "file_size", "directory", "io_class",
|
||||
"extension", "file_name_prefix", "lba", "pid", "process_name",
|
||||
"file_offset", "request_size"]
|
||||
rules = [
|
||||
"metadata",
|
||||
"direct",
|
||||
"file_size",
|
||||
"directory",
|
||||
"io_class",
|
||||
"extension",
|
||||
"file_name_prefix",
|
||||
"lba",
|
||||
"pid",
|
||||
"process_name",
|
||||
"file_offset",
|
||||
"request_size",
|
||||
]
|
||||
if os_utils.get_kernel_version() >= version.Version("4.13"):
|
||||
rules.append("wlth")
|
||||
|
||||
@ -128,7 +166,7 @@ class IoClass:
|
||||
@staticmethod
|
||||
def add_random_params(rule: str):
|
||||
if rule == "directory":
|
||||
allowed_chars = string.ascii_letters + string.digits + '/'
|
||||
allowed_chars = string.ascii_letters + string.digits + "/"
|
||||
rule += f":/{random_string(random.randint(1, 40), allowed_chars)}"
|
||||
elif rule in ["file_size", "lba", "pid", "file_offset", "request_size", "wlth"]:
|
||||
rule += f":{Operator(random.randrange(len(Operator))).name}:{random.randrange(1000000)}"
|
||||
@ -151,12 +189,10 @@ class Operator(enum.Enum):
|
||||
|
||||
# TODO: replace below methods with methods using IoClass
|
||||
def create_ioclass_config(
|
||||
add_default_rule: bool = True, ioclass_config_path: str = default_config_file_path
|
||||
add_default_rule: bool = True, ioclass_config_path: str = default_config_file_path
|
||||
):
|
||||
TestRun.LOGGER.info(f"Creating config file {ioclass_config_path}")
|
||||
output = TestRun.executor.run(
|
||||
f'echo {IO_CLASS_CONFIG_HEADER} > {ioclass_config_path}'
|
||||
)
|
||||
output = TestRun.executor.run(f"echo {IO_CLASS_CONFIG_HEADER} > {ioclass_config_path}")
|
||||
if output.exit_code != 0:
|
||||
raise Exception(
|
||||
"Failed to create ioclass config file. "
|
||||
@ -180,26 +216,21 @@ def remove_ioclass_config(ioclass_config_path: str = default_config_file_path):
|
||||
output = TestRun.executor.run(f"rm -f {ioclass_config_path}")
|
||||
if output.exit_code != 0:
|
||||
raise Exception(
|
||||
"Failed to remove config file. "
|
||||
+ f"stdout: {output.stdout} \n stderr :{output.stderr}"
|
||||
"Failed to remove config file. " + f"stdout: {output.stdout} \n stderr :{output.stderr}"
|
||||
)
|
||||
|
||||
|
||||
def add_ioclass(
|
||||
ioclass_id: int,
|
||||
rule: str,
|
||||
eviction_priority: int,
|
||||
allocation,
|
||||
ioclass_config_path: str = default_config_file_path,
|
||||
ioclass_id: int,
|
||||
rule: str,
|
||||
eviction_priority: int,
|
||||
allocation,
|
||||
ioclass_config_path: str = default_config_file_path,
|
||||
):
|
||||
new_ioclass = f"{ioclass_id},{rule},{eviction_priority},{allocation}"
|
||||
TestRun.LOGGER.info(
|
||||
f"Adding rule {new_ioclass} " + f"to config file {ioclass_config_path}"
|
||||
)
|
||||
TestRun.LOGGER.info(f"Adding rule {new_ioclass} " + f"to config file {ioclass_config_path}")
|
||||
|
||||
output = TestRun.executor.run(
|
||||
f'echo "{new_ioclass}" >> {ioclass_config_path}'
|
||||
)
|
||||
output = TestRun.executor.run(f'echo "{new_ioclass}" >> {ioclass_config_path}')
|
||||
if output.exit_code != 0:
|
||||
raise Exception(
|
||||
"Failed to append ioclass to config file. "
|
||||
@ -225,9 +256,7 @@ def get_ioclass(ioclass_id: int, ioclass_config_path: str = default_config_file_
|
||||
return ioclass
|
||||
|
||||
|
||||
def remove_ioclass(
|
||||
ioclass_id: int, ioclass_config_path: str = default_config_file_path
|
||||
):
|
||||
def remove_ioclass(ioclass_id: int, ioclass_config_path: str = default_config_file_path):
|
||||
TestRun.LOGGER.info(
|
||||
f"Removing rule no.{ioclass_id} " + f"from config file {ioclass_config_path}"
|
||||
)
|
||||
@ -243,9 +272,7 @@ def remove_ioclass(
|
||||
|
||||
# First line in valid config file is always a header, not a rule - it is
|
||||
# already extracted above
|
||||
new_ioclass_config = [
|
||||
x for x in old_ioclass_config[1:] if int(x.split(",")[0]) != ioclass_id
|
||||
]
|
||||
new_ioclass_config = [x for x in old_ioclass_config[1:] if int(x.split(",")[0]) != ioclass_id]
|
||||
|
||||
new_ioclass_config.insert(0, config_header)
|
||||
|
||||
@ -255,9 +282,7 @@ def remove_ioclass(
|
||||
)
|
||||
|
||||
new_ioclass_config_str = "\n".join(new_ioclass_config)
|
||||
output = TestRun.executor.run(
|
||||
f'echo "{new_ioclass_config_str}" > {ioclass_config_path}'
|
||||
)
|
||||
output = TestRun.executor.run(f'echo "{new_ioclass_config_str}" > {ioclass_config_path}')
|
||||
if output.exit_code != 0:
|
||||
raise Exception(
|
||||
"Failed to save new ioclass config. "
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
@ -31,8 +32,8 @@ def check_progress_bar(command: str, progress_bar_expected: bool = True):
|
||||
|
||||
percentage = 0
|
||||
while True:
|
||||
output = stdout.channel.recv(1024).decode('utf-8')
|
||||
search = re.search(r'\d+.\d+', output)
|
||||
output = stdout.channel.recv(1024).decode("utf-8")
|
||||
search = re.search(r"\d+.\d+", output)
|
||||
last_percentage = percentage
|
||||
if search:
|
||||
TestRun.LOGGER.info(output)
|
||||
|
@ -20,23 +20,25 @@ class CasVersion:
|
||||
self.base = f"{self.main}.{self.major}.{self.minor}"
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.main}.{self.major}.{self.minor}.{self.pr}" \
|
||||
f"{'.' + self.type if self.type is not None else ''}"
|
||||
return (
|
||||
f"{self.main}.{self.major}.{self.minor}.{self.pr}"
|
||||
f"{'.' + self.type if self.type is not None else ''}"
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return str(self)
|
||||
|
||||
@classmethod
|
||||
def from_git_tag(cls, version_tag):
|
||||
m = re.fullmatch(r'v([0-9]+)\.([0-9]+)\.?([0-9]?)', "v20.3")
|
||||
m = re.fullmatch(r"v([0-9]+)\.([0-9]+)\.?([0-9]?)", "v20.3")
|
||||
main, major, minor = m.groups()
|
||||
if not minor:
|
||||
minor = '0'
|
||||
minor = "0"
|
||||
return cls(main, major, minor, 0, "master")
|
||||
|
||||
@classmethod
|
||||
def from_version_string(cls, version_string):
|
||||
return cls(*version_string.split('.'))
|
||||
return cls(*version_string.split("."))
|
||||
|
||||
|
||||
def get_available_cas_versions():
|
||||
|
Loading…
Reference in New Issue
Block a user