diff --git a/test/functional/api/cas/cache.py b/test/functional/api/cas/cache.py index c670a6a9d..99ae20345 100644 --- a/test/functional/api/cas/cache.py +++ b/test/functional/api/cas/cache.py @@ -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 @@ 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 @@ def __get_cache_id(self) -> int: 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 @@ def get_metadata_size_on_disk(self) -> Size: 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 @@ def get_status(self): 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 @@ def get_io_class_statistics( 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 @@ def get_io_class_statistics( ) 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 @@ def set_seq_cutoff_parameters(self, seq_cutoff_param: SeqCutOffParameters): 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 @@ def set_params_acp(self, acp_params: FlushParametersAcp): 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 @@ def set_params_alru(self, alru_params: FlushParametersAlru): ), ) - 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 ) diff --git a/test/functional/api/cas/cas_service.py b/test/functional/api/cas/cas_service.py index 18004ade9..cc167c064 100644 --- a/test/functional/api/cas/cas_service.py +++ b/test/functional/api/cas/cas_service.py @@ -8,7 +8,12 @@ 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/") diff --git a/test/functional/api/cas/casadm.py b/test/functional/api/cas/casadm.py index 5657bea35..34cd66d93 100644 --- a/test/functional/api/cas/casadm.py +++ b/test/functional/api/cas/casadm.py @@ -27,10 +27,6 @@ # 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,191 +63,245 @@ 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) + raise CmdException("Failed to attach cache.", output) + return output -def standby_load(cache_dev: Device, shortcut: bool = False): - output = TestRun.executor.run(standby_load_cmd(cache_dev=cache_dev.path, 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 load standby cache.", output) - return Cache(cache_dev) + raise CmdException("Failed to detach cache.", output) + return output -def standby_detach_cache(cache_id: int, shortcut: bool = False): - output = TestRun.executor.run(standby_detach_cmd(cache_id=str(cache_id), shortcut=shortcut)) +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) + ) if output.exit_code != 0: - raise CmdException("Failed to detach standby cache.", output) + raise CmdException("Failed to stop 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 set_param_cutoff( + cache_id: int, + core_id: int = None, + threshold: Size = None, + policy: SeqCutOffPolicy = None, + promotion_count: 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(command) if output.exit_code != 0: - raise CmdException("Failed to activate standby cache.", output) + raise CmdException("Error while setting sequential cut-off params.", output) return output -def stop_cache(cache_id: int, no_data_flush: bool = False, shortcut: bool = False): +def set_param_cleaning(cache_id: int, policy: CleaningPolicy, shortcut: bool = False) -> Output: output = TestRun.executor.run( - stop_cmd(cache_id=str(cache_id), no_data_flush=no_data_flush, 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 stop cache.", output) + raise CmdException("Error while setting cleaning policy.", output) 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) +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, +) -> Output: output = TestRun.executor.run( - add_core_cmd( - cache_id=str(cache.cache_id), - core_dev=core_dev.path, - core_id=_core_id, + set_param_cleaning_alru_cmd( + 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), shortcut=shortcut, ) ) if output.exit_code != 0: - raise CmdException("Failed to add core.", output) - core = Core(core_dev.path, cache.cache_id) - return core + raise CmdException("Error while setting alru cleaning policy parameters.", output) + return output -def remove_core(cache_id: int, core_id: int, force: bool = False, shortcut: bool = False): +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( - remove_core_cmd( - cache_id=str(cache_id), core_id=str(core_id), force=force, shortcut=shortcut + 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, ) ) if output.exit_code != 0: - raise CmdException("Failed to remove core.", output) + raise CmdException("Error while setting acp cleaning policy parameters.", output) + return output -def remove_inactive(cache_id: int, core_id: int, force: bool = False, shortcut: bool = False): +def get_param_cutoff( + 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( - remove_inactive_cmd( - cache_id=str(cache_id), core_id=str(core_id), force=force, shortcut=shortcut + get_param_cutoff_cmd( + cache_id=str(cache_id), + core_id=str(core_id), + output_format=_output_format, + shortcut=shortcut, ) ) if output.exit_code != 0: - raise CmdException("Failed to remove inactive core.", output) + raise CmdException("Getting sequential cutoff params failed.", output) + return output -def remove_detached(core_device: Device, shortcut: bool = False): +def get_param_cleaning(cache_id: int, output_format: OutputFormat = None, shortcut: bool = False): + _output_format = None if output_format is None else output_format.name output = TestRun.executor.run( - remove_detached_cmd(core_device=core_device.path, shortcut=shortcut) + get_param_cleaning_cmd( + cache_id=str(cache_id), output_format=_output_format, shortcut=shortcut + ) ) if output.exit_code != 0: - raise CmdException("Failed to remove detached core.", output) + raise CmdException("Getting cleaning policy params failed.", 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))) +def get_param_cleaning_alru( + cache_id: int, output_format: OutputFormat = None, shortcut: bool = False +): + _output_format = None if output_format is None else output_format.name + output = TestRun.executor.run( + get_param_cleaning_alru_cmd( + cache_id=str(cache_id), output_format=_output_format, shortcut=shortcut + ) + ) if output.exit_code != 0: - raise CmdException("Purge cache failed.", output) + raise CmdException("Getting alru cleaning policy params 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))) +def get_param_cleaning_acp( + cache_id: int, output_format: OutputFormat = None, shortcut: bool = False +): + _output_format = None if output_format is None else output_format.name + output = TestRun.executor.run( + get_param_cleaning_acp_cmd( + cache_id=str(cache_id), output_format=_output_format, shortcut=shortcut + ) + ) if output.exit_code != 0: - raise CmdException("Purge core failed.", output) + raise CmdException("Getting acp cleaning policy params 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 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" -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)) + 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("Failed to execute remove core script command.", output) + raise CmdException("Set cache mode command failed.", output) return output -def reset_counters(cache_id: int, core_id: int = None, shortcut: bool = False): +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( - reset_counters_cmd(cache_id=str(cache_id), core_id=_core_id, shortcut=shortcut) + 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 reset counters.", output) - return output + raise CmdException("Failed to add core.", output) + return Core(core_dev.path, cache.cache_id) -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) +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("Flushing cache failed.", output) + raise CmdException("Failed to remove core.", output) return output -def flush_core( - cache_id: int, core_id: int, shortcut: bool = False +def remove_inactive( + cache_id: int, core_id: int, force: bool = False, shortcut: bool = False ) -> Output: - command = flush_core_cmd( - cache_id=str(cache_id), - core_id=str(core_id), - shortcut=shortcut, + output = TestRun.executor.run( + remove_inactive_cmd( + cache_id=str(cache_id), core_id=str(core_id), force=force, shortcut=shortcut + ) ) - output = TestRun.executor.run(command) if output.exit_code != 0: - raise CmdException("Flushing core failed.", output) + raise CmdException("Failed to remove inactive core.", output) return output -def load_cache(device: Device, shortcut: bool = False): - output = TestRun.executor.run(load_cmd(cache_dev=device.path, shortcut=shortcut)) +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 load cache.", output) - return Cache(device) + 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) @@ -261,41 +311,6 @@ def list_caches( 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( cache_id: int, core_id: int = None, @@ -304,7 +319,7 @@ def print_statistics( 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 @@ -329,27 +344,37 @@ def print_statistics( 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 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) 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, - ) + reset_counters_cmd(cache_id=str(cache_id), core_id=_core_id, shortcut=shortcut) ) if output.exit_code != 0: - raise CmdException("Set cache mode command failed.", output) + 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("Flushing core failed.", output) return output -def load_io_classes(cache_id: int, file: str, shortcut: bool = False): +def load_io_classes(cache_id: int, file: str, shortcut: bool = False) -> Output: output = TestRun.executor.run( load_io_classes_cmd(cache_id=str(cache_id), file=file, shortcut=shortcut) ) @@ -358,7 +383,7 @@ def load_io_classes(cache_id: int, file: str, shortcut: bool = False): return output -def list_io_classes(cache_id: int, output_format: OutputFormat, 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( list_io_classes_cmd(cache_id=str(cache_id), output_format=_output_format, shortcut=shortcut) @@ -368,138 +393,135 @@ def list_io_classes(cache_id: int, output_format: OutputFormat, shortcut: bool = return output -def get_param_cutoff( +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, - core_id: int, - output_format: OutputFormat = None, + cache_line_size: CacheLineSize, + force: bool = False, shortcut: bool = False, -): - _output_format = None if output_format is None else output_format.name + 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( - get_param_cutoff_cmd( + standby_init_cmd( + cache_dev=cache_dev.path, cache_id=str(cache_id), - core_id=str(core_id), - output_format=_output_format, + cache_line_size=_cache_line_size, + force=force, shortcut=shortcut, ) ) if output.exit_code != 0: - raise CmdException("Getting sequential cutoff params failed.", output) - return output + raise CmdException("Failed to init standby cache.", output) + return Cache(cache_dev) -def get_param_cleaning(cache_id: int, output_format: OutputFormat = None, shortcut: bool = False): - _output_format = None if output_format is None else output_format.name - output = TestRun.executor.run( - get_param_cleaning_cmd( - cache_id=str(cache_id), output_format=_output_format, shortcut=shortcut - ) - ) +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("Getting cleaning policy params failed.", output) + 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 get_param_cleaning_alru( - cache_id: int, output_format: OutputFormat = None, shortcut: bool = False -): - _output_format = None if output_format is None else output_format.name +def standby_activate_cache(cache_dev: Device, cache_id: int, shortcut: bool = False) -> Output: output = TestRun.executor.run( - get_param_cleaning_alru_cmd( - cache_id=str(cache_id), output_format=_output_format, shortcut=shortcut - ) + standby_activate_cmd(cache_dev=cache_dev.path, cache_id=str(cache_id), shortcut=shortcut) ) if output.exit_code != 0: - raise CmdException("Getting alru cleaning policy params failed.", output) + raise CmdException("Failed to activate standby cache.", output) return output -def get_param_cleaning_acp( - cache_id: int, output_format: OutputFormat = None, shortcut: bool = False -): - _output_format = None if output_format is None else output_format.name +def zero_metadata(cache_dev: Device, force: bool = False, shortcut: bool = False) -> Output: output = TestRun.executor.run( - get_param_cleaning_acp_cmd( - cache_id=str(cache_id), output_format=_output_format, shortcut=shortcut - ) + zero_metadata_cmd(cache_dev=cache_dev.path, force=force, shortcut=shortcut) ) if output.exit_code != 0: - raise CmdException("Getting acp cleaning policy params failed.", output) + raise CmdException("Failed to wipe metadata.", output) return output -def set_param_cutoff( - cache_id: int, - core_id: int = None, - threshold: Size = None, - policy: SeqCutOffPolicy = None, - promotion_count: int = None, - shortcut: bool = False, -): - _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(command) +# 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("Error while setting sequential cut-off params.", output) + 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 set_param_cleaning(cache_id: int, policy: CleaningPolicy, shortcut: bool = False): - output = TestRun.executor.run( - set_param_cleaning_cmd(cache_id=str(cache_id), policy=policy.name, shortcut=shortcut) - ) +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("Error while setting cleaning policy.", output) + raise CmdException("Purge core 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, -): - output = TestRun.executor.run( - set_param_cleaning_alru_cmd( - 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), - shortcut=shortcut, - ) - ) +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("Error while setting alru cleaning policy parameters.", output) + raise CmdException("Failed to execute detach core script command.", output) return output -def set_param_cleaning_acp( - cache_id: int, - wake_up: int = None, - flush_max_buffers: int = None, - shortcut: bool = False, -): - 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, - ) - ) +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("Error while setting acp cleaning policy parameters.", output) + 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"])) diff --git a/test/functional/api/cas/casadm_parser.py b/test/functional/api/cas/casadm_parser.py index 8bcd59f67..04b226c98 100644 --- a/test/functional/api/cas/casadm_parser.py +++ b/test/functional/api/cas/casadm_parser.py @@ -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: diff --git a/test/functional/api/cas/cli.py b/test/functional/api/cas/cli.py index d186c719c..94eb7e39a 100644 --- a/test/functional/api/cas/cli.py +++ b/test/functional/api/cas/cli.py @@ -12,106 +12,6 @@ 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,124 +36,121 @@ 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 +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_detach_cmd(cache_id: str, shortcut: bool = False) -> str: - command = " --standby --detach" +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 + if no_data_flush: + command += " --no-data-flush" 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 +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 - return casadm_bin + command + return command -def print_statistics_cmd( +def set_param_cutoff_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, + threshold: str = None, + policy: str = None, + promotion_count: str = None, shortcut: bool = False, ) -> str: - command = " -P" if shortcut else " --stats" - command += (" -i " if shortcut else " --cache-id ") + cache_id + name = "seq-cutoff" + command = _set_param_cmd(name=name, cache_id=cache_id, shortcut=shortcut) 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" + if threshold: + command += (" -t " if shortcut else " --threshold ") + threshold + if policy: + command += (" -p " if shortcut else " --policy ") + policy + if promotion_count: + command += " --promotion-count " + promotion_count 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 - if no_data_flush: - command += " --no-data-flush" +def set_param_promotion_cmd(cache_id: str, policy: str, shortcut: bool = False) -> str: + name = "promotion" + command = _set_param_cmd(name=name, cache_id=cache_id, shortcut=shortcut) + command += (" -p " if shortcut else " --policy ") + policy return casadm_bin + command -def list_caches_cmd( - output_format: str = None, by_id_path: bool = True, shortcut: bool = False +def set_param_promotion_nhit_cmd( + cache_id: str, threshold: str = None, trigger: str = None, 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" + name = "promotion-nhit" + command = _set_param_cmd(name=name, cache_id=cache_id, shortcut=shortcut) + if threshold: + command += (" -t " if shortcut else " --threshold ") + threshold + if trigger is not None: + command += (" -o " if shortcut else " --trigger ") + trigger 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 +def set_param_cleaning_cmd(cache_id: str, policy: str, shortcut: bool = False) -> str: + name = "cleaning" + command = _set_param_cmd(name=name, cache_id=cache_id, shortcut=shortcut) + command += (" -p " if shortcut else " --policy ") + policy return casadm_bin + command -def set_cache_mode_cmd( - cache_mode: str, cache_id: str, flush_cache: str = None, shortcut: bool = False +def set_param_cleaning_alru_cmd( + cache_id: str, + wake_up: str = None, + staleness_time: str = None, + flush_max_buffers: str = None, + activity_threshold: 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 + name = "cleaning-alru" + command = _set_param_cmd(name=name, cache_id=cache_id, shortcut=shortcut) + if wake_up: + command += (" -w " if shortcut else " --wake-up ") + wake_up + if staleness_time: + command += (" -s " if shortcut else " --staleness-time ") + staleness_time + if flush_max_buffers: + command += (" -b " if shortcut else " --flush-max-buffers ") + flush_max_buffers + if activity_threshold: + command += (" -t " if shortcut else " --activity-threshold ") + activity_threshold 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 +def set_param_cleaning_acp_cmd( + cache_id: str, + wake_up: str = None, + flush_max_buffers: str = None, + shortcut: bool = False, +) -> str: + name = "cleaning-acp" + command = _set_param_cmd(name=name, cache_id=cache_id, shortcut=shortcut) + if wake_up is not None: + command += (" -w " if shortcut else " --wake-up ") + wake_up + if flush_max_buffers is not None: + command += (" -b " if shortcut else " --flush-max-buffers ") + flush_max_buffers return casadm_bin + command @@ -313,95 +210,181 @@ def get_param_cleaning_acp_cmd( 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 +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 - return command + if flush_cache: + command += (" -f " if shortcut else " --flush-cache ") + flush_cache + return casadm_bin + command -def set_param_cutoff_cmd( - cache_id: str, - core_id: str = None, - threshold: str = None, - policy: str = None, - promotion_count: str = None, - shortcut: bool = False, -) -> str: - name = "seq-cutoff" - command = _set_param_cmd(name=name, cache_id=cache_id, shortcut=shortcut) +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 - if threshold: - command += (" -t " if shortcut else " --threshold ") + threshold - if policy: - command += (" -p " if shortcut else " --policy ") + policy - if promotion_count: - command += " --promotion-count " + promotion_count return casadm_bin + command -def set_param_promotion_cmd(cache_id: str, policy: str, shortcut: bool = False) -> str: - name = "promotion" - command = _set_param_cmd(name=name, cache_id=cache_id, shortcut=shortcut) - command += (" -p " if shortcut else " --policy ") + policy +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 set_param_promotion_nhit_cmd( - cache_id: str, threshold: str = None, trigger: str = None, shortcut: bool = False +def remove_inactive_cmd( + cache_id: str, core_id: str, force: bool = False, shortcut: bool = False ) -> str: - name = "promotion-nhit" - command = _set_param_cmd(name=name, cache_id=cache_id, shortcut=shortcut) - if threshold: - command += (" -t " if shortcut else " --threshold ") + threshold - if trigger is not None: - command += (" -o " if shortcut else " --trigger ") + trigger + 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 set_param_cleaning_cmd(cache_id: str, policy: str, shortcut: bool = False) -> str: - name = "cleaning" - command = _set_param_cmd(name=name, cache_id=cache_id, shortcut=shortcut) - command += (" -p " if shortcut else " --policy ") + policy +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 set_param_cleaning_alru_cmd( +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, - wake_up: str = None, - staleness_time: str = None, - flush_max_buffers: str = None, - activity_threshold: str = None, + 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: - name = "cleaning-alru" - command = _set_param_cmd(name=name, cache_id=cache_id, shortcut=shortcut) - if wake_up: - command += (" -w " if shortcut else " --wake-up ") + wake_up - if staleness_time: - command += (" -s " if shortcut else " --staleness-time ") + staleness_time - if flush_max_buffers: - command += (" -b " if shortcut else " --flush-max-buffers ") + flush_max_buffers - if activity_threshold: - command += (" -t " if shortcut else " --activity-threshold ") + activity_threshold + 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 set_param_cleaning_acp_cmd( +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, - wake_up: str = None, - flush_max_buffers: str = None, + cache_line_size: str, + force: bool = False, shortcut: bool = False, ) -> str: - name = "cleaning-acp" - command = _set_param_cmd(name=name, cache_id=cache_id, shortcut=shortcut) - if wake_up is not None: - command += (" -w " if shortcut else " --wake-up ") + wake_up - if flush_max_buffers is not None: - command += (" -b " if shortcut else " --flush-max-buffers ") + flush_max_buffers + 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 diff --git a/test/functional/api/cas/cli_help_messages.py b/test/functional/api/cas/cli_help_messages.py index ec9d30225..1875bcf8f 100644 --- a/test/functional/api/cas/cli_help_messages.py +++ b/test/functional/api/cas/cli_help_messages.py @@ -1,5 +1,6 @@ # # Copyright(c) 2020-2022 Intel Corporation +# Copyright(c) 2024 Huawei Technologies Co., Ltd. # SPDX-License-Identifier: BSD-3-Clause # @@ -34,137 +35,46 @@ r"or go to support page \\.", ] -help_help = [r"Usage: casadm --help", r"Print help"] - -version_help = [ - r"Usage: casadm --version \[option\.\.\.\]", - r"Print CAS version", - r"Options that are valid with --version \(-V\) are:" - r"-o --output-format \ Output format: \{table|csv\}", -] - - -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 \ --file \", - r"Options that are valid with --load-config \(-C\) are:", - r"-i --cache-id \ Identifier of cache instance \<1-16384\>", - r"-f --file \ Configuration file containing IO class definition", - r"Lists currently configured IO classes:", - r"Usage: casadm --io-class --list --cache-id \ \[option\.\.\.\]", - r"Options that are valid with --list \(-L\) are:", - r"-i --cache-id \ Identifier of cache instance \<1-16384\>", - r"-o --output-format \ Output format: \{table|csv\}", -] - -flush_cache_help = [ - r"Usage: casadm --flush-cache --cache-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 \ Identifier of cache instance \<1-16384\>", - r"-j --core-id \[\\] Identifier of core <0-4095> within given cache " - r"instance", -] - -reset_counters_help = [ - r"Usage: casadm --reset-counters --cache-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 \ Identifier of cache instance \<1-16384\>", - r"-j --core-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 \ \[option\.\.\.\]", - r"Print statistics for cache instance", - r"Options that are valid with --stats \(-P\) are:", - r"-i --cache-id \ Identifier of cache instance \<1-16384\>", - r"-j --core-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 \[\\] Display per IO class statistics", - r"-f --filter \ Apply filters from the following set: " - r"\{all, conf, usage, req, blk, err\}", - r"-o --output-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 \ Output format: \{table|csv\}", -] - -remove_detached_help = [ - r"Usage: casadm --remove-detached --device \", - r"Remove core device from core pool", - r"Options that are valid with --remove-detached are:", - r"-d --device \ Path to core device", +start_cache_help = [ + r"Usage: casadm --start-cache --cache-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 \ Caching device to be used", + r"-i --cache-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 \ 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 \ Set cache line size in kibibytes: " + r"\{4,8,16,32,64\}\[KiB\] \(default: 4\)", ] -remove_core_help = [ - r"Usage: casadm --remove-core --cache-id \ --core-id \ \[option\.\.\.\]", - r"Remove active core device from cache instance", - r"Options that are valid with --remove-core \(-R\) are:", - r"-i --cache-id \ Identifier of cache instance \<1-16384\>", - r"-j --core-id \ Identifier of core \<0-4095\> within given cache " - r"instance", - r"-f --force Force active core removal without data flush", +attach_cache_help = [ + r"Usage: casadm --attach-cache --cache-device \ --cache-id \ \[option\.\.\.\]", + r"Attach cache device", + r"Options that are valid with --attach-cache are:", + r"-d --cache-device \ Caching device to be used", + r"-i --cache-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", ] - -add_core_help = [ - r"Usage: casadm --add-core --cache-id \ --core-device \ \[option\.\.\.\]", - r"Add core device to cache instance", - r"Options that are valid with --add-core \(-A\) are:", +detach_cache_help = [ + r"Usage: casadm --detach-cache --cache-id \", + r"Detach cache device", + r"Options that are valid with --detach-cache are:", r"-i --cache-id \ Identifier of cache instance \<1-16384\>", - r"-j --core-id \ Identifier of core \<0-4095\> within given cache " - r"instance", - r"-d --core-device \ Path to core device", ] -set_cache_mode_help = [ - r"Usage: casadm --set-cache-mode --cache-mode \ --cache-id \ \[option\.\.\.\]", - r"Set cache mode", - r"Options that are valid with --set-cache-mode \(-Q\) are:", - r"-c --cache-mode \ Cache mode\. Available cache modes: \{wt|wb|wa|pt|wo\}", - r"-i --cache-id \ Identifier of cache instance \<1-16384\>", - r"-f --flush-cache \ 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 \", - 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 \ Identifier of cache instance \<1-16384\>", - r"-j --core-id \ Identifier of core \<0-4095\> within given cache " - r"instance", - r"-o --output-format \ Output format: \{table|csv\}", - r"Options that are valid with --get-param \(-G\) --name \(-n\) cleaning are:", - r"-i --cache-id \ Identifier of cache instance \<1-16384\>", - r"-o --output-format \ Output format: \{table|csv\}", - r"Options that are valid with --get-param \(-G\) --name \(-n\) cleaning-alru are:", - r"-i --cache-id \ Identifier of cache instance \<1-16384\>", - r"-o --output-format \ Output format: \{table|csv\}", - r"Options that are valid with --get-param \(-G\) --name \(-n\) cleaning-acp are:", - r"-i --cache-id \ Identifier of cache instance \<1-16384\>", - r"-o --output-format \ Output format: \{table|csv\}", - r"Options that are valid with --get-param \(-G\) --name \(-n\) promotion are:", - r"-i --cache-id \ Identifier of cache instance \<1-16384\>", - r"-o --output-format \ Output format: \{table|csv\}", - r"Options that are valid with --get-param \(-G\) --name \(-n\) promotion-nhit are:", +stop_cache_help = [ + r"Usage: casadm --stop-cache --cache-id \ \[option\.\.\.\]", + r"Stop cache instance", + r"Options that are valid with --stop-cache \(-T\) are:", r"-i --cache-id \ Identifier of cache instance \<1-16384\>", - r"-o --output-format \ Output format: \{table|csv\}", + r"-n --no-data-flush Do not flush dirty data \(may be dangerous\)", ] set_params_help = [ @@ -217,31 +127,157 @@ ] -stop_cache_help = [ - r"Usage: casadm --stop-cache --cache-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 \", + 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 \ Identifier of cache instance \<1-16384\>", - r"-n --no-data-flush Do not flush dirty data \(may be dangerous\)", + r"-j --core-id \ Identifier of core \<0-4095\> within given cache " + r"instance", + r"-o --output-format \ Output format: \{table|csv\}", + r"Options that are valid with --get-param \(-G\) --name \(-n\) cleaning are:", + r"-i --cache-id \ Identifier of cache instance \<1-16384\>", + r"-o --output-format \ Output format: \{table|csv\}", + r"Options that are valid with --get-param \(-G\) --name \(-n\) cleaning-alru are:", + r"-i --cache-id \ Identifier of cache instance \<1-16384\>", + r"-o --output-format \ Output format: \{table|csv\}", + r"Options that are valid with --get-param \(-G\) --name \(-n\) cleaning-acp are:", + r"-i --cache-id \ Identifier of cache instance \<1-16384\>", + r"-o --output-format \ Output format: \{table|csv\}", + r"Options that are valid with --get-param \(-G\) --name \(-n\) promotion are:", + r"-i --cache-id \ Identifier of cache instance \<1-16384\>", + r"-o --output-format \ Output format: \{table|csv\}", + r"Options that are valid with --get-param \(-G\) --name \(-n\) promotion-nhit are:", + r"-i --cache-id \ Identifier of cache instance \<1-16384\>", + r"-o --output-format \ Output format: \{table|csv\}", ] -start_cache_help = [ - r"Usage: casadm --start-cache --cache-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 \ Caching device to be used", - r"-i --cache-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 \ 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 \ 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 \ --cache-id \ \[option\.\.\.\]", + r"Set cache mode", + r"Options that are valid with --set-cache-mode \(-Q\) are:", + r"-c --cache-mode \ Cache mode\. Available cache modes: \{wt|wb|wa|pt|wo\}", + r"-i --cache-id \ Identifier of cache instance \<1-16384\>", + r"-f --flush-cache \ 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 \ --core-device \ \[option\.\.\.\]", + r"Add core device to cache instance", + r"Options that are valid with --add-core \(-A\) are:", + r"-i --cache-id \ Identifier of cache instance \<1-16384\>", + r"-j --core-id \ Identifier of core \<0-4095\> within given cache " + r"instance", + r"-d --core-device \ Path to core device", ] +remove_core_help = [ + r"Usage: casadm --remove-core --cache-id \ --core-id \ \[option\.\.\.\]", + r"Remove active core device from cache instance", + r"Options that are valid with --remove-core \(-R\) are:", + r"-i --cache-id \ Identifier of cache instance \<1-16384\>", + r"-j --core-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 \ --core-id \ \[option\.\.\.\]", + r"Remove inactive core device from cache instance", + r"Options that are valid with --remove-inactive are:", + r"-i --cache-id \ Identifier of cache instance \<1-16384\>", + r"-j --core-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 \", + r"Remove core device from core pool", + r"Options that are valid with --remove-detached are:", + r"-d --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 \ Output format: \{table|csv\}", +] + +stats_help = [ + r"Usage: casadm --stats --cache-id \ \[option\.\.\.\]", + r"Print statistics for cache instance", + r"Options that are valid with --stats \(-P\) are:", + r"-i --cache-id \ Identifier of cache instance \<1-16384\>", + r"-j --core-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 \[\\] Display per IO class statistics", + r"-f --filter \ Apply filters from the following set: " + r"\{all, conf, usage, req, blk, err\}", + r"-o --output-format \ Output format: \{table|csv\}", +] + + +reset_counters_help = [ + r"Usage: casadm --reset-counters --cache-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 \ Identifier of cache instance \<1-16384\>", + r"-j --core-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 \", + 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 \ Identifier of cache instance \<1-16384\>", + r"-j --core-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 \ --file \", + r"Options that are valid with --load-config \(-C\) are:", + r"-i --cache-id \ Identifier of cache instance \<1-16384\>", + r"-f --file \ Configuration file containing IO class definition", + r"Lists currently configured IO classes:", + r"Usage: casadm --io-class --list --cache-id \ \[option\.\.\.\]", + r"Options that are valid with --list \(-L\) are:", + r"-i --cache-id \ Identifier of cache instance \<1-16384\>", + r"-o --output-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 \ Output format: \{table|csv\}", +] + +help_help = [r"Usage: casadm --help", r"Print help"] + + standby_help = [ r"Usage: casadm --standby \{--init|--load|--detach|--activate\}", r"Manage failover standby", @@ -277,7 +313,6 @@ r"-f --force Ignore potential dirty data on cache device", ] - unrecognized_stderr = [ r"Unrecognized command -\S+", ] diff --git a/test/functional/api/cas/init_config.py b/test/functional/api/cas/init_config.py index c68b4121b..3418a6f97 100644 --- a/test/functional/api/cas/init_config.py +++ b/test/functional/api/cas/init_config.py @@ -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 @@ def __init__(self): 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 @@ def save_config_file(self): 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 @@ def create_default_init_config(cls): 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 @@ def __init__(self, cache_id, core_id, core_device: Device, extra_flags=""): 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) diff --git a/test/functional/api/cas/installer.py b/test/functional/api/cas/installer.py index a161a8713..27862d971 100644 --- a/test/functional/api/cas/installer.py +++ b/test/functional/api/cas/installer.py @@ -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) diff --git a/test/functional/api/cas/ioclass_config.py b/test/functional/api/cas/ioclass_config.py index 7f3c0d048..0806dffaa 100644 --- a/test/functional/api/cas/ioclass_config.py +++ b/test/functional/api/cas/ioclass_config.py @@ -8,8 +8,8 @@ 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 @@ @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 @@ def list_to_csv(ioclass_list: [], add_default_rule: bool = True): 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 @@ def csv_to_list(csv: str): 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 @@ def default_header_dict(): "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 @@ def compare_ioclass_lists(list1: [], list2: []): @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 @@ def set_random_rule(self): @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. " diff --git a/test/functional/api/cas/progress_bar.py b/test/functional/api/cas/progress_bar.py index 77cf6140d..a8aefd0ba 100644 --- a/test/functional/api/cas/progress_bar.py +++ b/test/functional/api/cas/progress_bar.py @@ -31,8 +31,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) diff --git a/test/functional/api/cas/version.py b/test/functional/api/cas/version.py index 9ede4c4bd..ce163bcba 100644 --- a/test/functional/api/cas/version.py +++ b/test/functional/api/cas/version.py @@ -20,23 +20,25 @@ def __init__(self, main, major, minor, pr, release_type=None): 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():