diff --git a/test/functional/api/cas/cache.py b/test/functional/api/cas/cache.py index 99ae20345..8efd00119 100644 --- a/test/functional/api/cas/cache.py +++ b/test/functional/api/cas/cache.py @@ -7,7 +7,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 api.cas.statistics import CacheStats, CacheIoClassStats from test_utils.os_utils import * from test_utils.output import Output @@ -53,8 +53,7 @@ def get_metadata_size_in_ram(self) -> Size: return stats.config_stats.metadata_memory_footprint def get_metadata_size_on_disk(self) -> Size: - cache_name = f"cache{self.cache_id}" - return get_metadata_size_on_device(cache_name=cache_name) + return get_metadata_size_on_device(cache_id=self.cache_id) def get_occupancy(self): return self.get_statistics().usage_stats.occupancy @@ -104,11 +103,11 @@ def get_statistics( def get_io_class_statistics( self, - io_class_id: int, + io_class_id: int = None, stat_filter: List[StatsFilter] = None, percentage_val: bool = False, - ) -> IoClassStats: - return IoClassStats( + ) -> CacheIoClassStats: + return CacheIoClassStats( cache_id=self.cache_id, filter=stat_filter, io_class_id=io_class_id, @@ -169,31 +168,23 @@ def set_cleaning_policy(self, cleaning_policy: CleaningPolicy) -> Output: def set_params_acp(self, acp_params: FlushParametersAcp) -> Output: return casadm.set_param_cleaning_acp( self.cache_id, - ( - int(acp_params.wake_up_time.total_milliseconds()) - if acp_params.wake_up_time - else None - ), + int(acp_params.wake_up_time.total_milliseconds()) if acp_params.wake_up_time else None, int(acp_params.flush_max_buffers) if acp_params.flush_max_buffers else None, ) def set_params_alru(self, alru_params: FlushParametersAlru) -> Output: return casadm.set_param_cleaning_alru( self.cache_id, - ( - int(alru_params.wake_up_time.total_seconds()) - if alru_params.wake_up_time is not None - else None - ), + (int(alru_params.wake_up_time.total_seconds()) if alru_params.wake_up_time else None), ( int(alru_params.staleness_time.total_seconds()) - if alru_params.staleness_time is not None + if alru_params.staleness_time else None ), - (alru_params.flush_max_buffers if alru_params.flush_max_buffers is not None else None), + (alru_params.flush_max_buffers if alru_params.flush_max_buffers else None), ( int(alru_params.activity_threshold.total_milliseconds()) - if alru_params.activity_threshold is not None + if alru_params.activity_threshold else None ), ) diff --git a/test/functional/api/cas/casadm.py b/test/functional/api/cas/casadm.py index 34cd66d93..b0ce7ee67 100644 --- a/test/functional/api/cas/casadm.py +++ b/test/functional/api/cas/casadm.py @@ -41,12 +41,10 @@ def start_cache( 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))) + str(int(cache_line_size.value.get_value(Unit.KibiByte))) if cache_line_size else None ) - _cache_id = None if cache_id is None else str(cache_id) - _cache_mode = None if cache_mode is None else cache_mode.name.lower() + _cache_id = str(cache_id) if cache_id else None + _cache_mode = cache_mode.name.lower() if cache_mode else None output = TestRun.executor.run( start_cmd( cache_dev=cache_dev.path, @@ -141,13 +139,17 @@ def set_param_cleaning_alru( activity_threshold: int = None, shortcut: bool = False, ) -> Output: + _wake_up = str(wake_up) if wake_up else None + _staleness_time = str(staleness_time) if staleness_time else None + _flush_max_buffers = str(flush_max_buffers) if flush_max_buffers else None + _activity_threshold = str(activity_threshold) if activity_threshold else None 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), + wake_up=_wake_up, + staleness_time=_staleness_time, + flush_max_buffers=_flush_max_buffers, + activity_threshold=_activity_threshold, shortcut=shortcut, ) ) @@ -159,11 +161,13 @@ def set_param_cleaning_alru( def set_param_cleaning_acp( cache_id: int, wake_up: int = None, flush_max_buffers: int = None, shortcut: bool = False ) -> Output: + _wake_up = str(wake_up) if wake_up else None + _flush_max_buffers = str(flush_max_buffers) if flush_max_buffers else None 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, + wake_up=_wake_up, + flush_max_buffers=_flush_max_buffers, shortcut=shortcut, ) ) @@ -175,7 +179,7 @@ def set_param_cleaning_acp( 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_format = output_format.name if output_format else None output = TestRun.executor.run( get_param_cutoff_cmd( cache_id=str(cache_id), @@ -190,21 +194,21 @@ def get_param_cutoff( 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_format = output_format.name if output_format else None output = TestRun.executor.run( get_param_cleaning_cmd( cache_id=str(cache_id), output_format=_output_format, shortcut=shortcut ) ) if output.exit_code != 0: - raise CmdException("Getting cleaning policy params failed.", output) + raise CmdException("Getting cleaning policy failed.", 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 + _output_format = output_format.name if output_format else None output = TestRun.executor.run( get_param_cleaning_alru_cmd( cache_id=str(cache_id), output_format=_output_format, shortcut=shortcut @@ -218,7 +222,7 @@ def get_param_cleaning_alru( 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_format = output_format.name if output_format else None output = TestRun.executor.run( get_param_cleaning_acp_cmd( cache_id=str(cache_id), output_format=_output_format, shortcut=shortcut @@ -233,11 +237,8 @@ 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" - + if flush: + flush_cache = "yes" if flush else "no" output = TestRun.executor.run( set_cache_mode_cmd( cache_mode=cache_mode.name.lower(), @@ -252,7 +253,7 @@ def set_cache_mode( 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) + _core_id = str(core_id) if core_id else None output = TestRun.executor.run( add_core_cmd( cache_id=str(cache.cache_id), @@ -302,7 +303,7 @@ def remove_detached(core_device: Device, shortcut: bool = False) -> 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_format = output_format.name if output_format else None output = TestRun.executor.run( list_caches_cmd(output_format=_output_format, by_id_path=by_id_path, shortcut=shortcut) ) @@ -321,8 +322,8 @@ def print_statistics( 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 + _core_id = str(core_id) if core_id else None if filter is None: _filter = filter else: @@ -345,7 +346,7 @@ def print_statistics( 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) + _core_id = str(core_id) if core_id else None output = TestRun.executor.run( reset_counters_cmd(cache_id=str(cache_id), core_id=_core_id, shortcut=shortcut) ) @@ -362,12 +363,8 @@ def flush_cache(cache_id: int, shortcut: bool = False) -> 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 - ) +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) @@ -384,7 +381,7 @@ def load_io_classes(cache_id: int, file: str, shortcut: bool = False) -> Output: 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_format = output_format.name if output_format else None output = TestRun.executor.run( list_io_classes_cmd(cache_id=str(cache_id), output_format=_output_format, shortcut=shortcut) ) @@ -394,7 +391,7 @@ def list_io_classes(cache_id: int, output_format: OutputFormat, shortcut: bool = def print_version(output_format: OutputFormat = None, shortcut: bool = False) -> Output: - _output_format = None if output_format is None else output_format.name + _output_format = output_format.name if output_format else None output = TestRun.executor.run(version_cmd(output_format=_output_format, shortcut=shortcut)) if output.exit_code != 0: raise CmdException("Failed to print version.", output) @@ -415,12 +412,7 @@ def standby_init( ) -> 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))) - ) + _cache_line_size = str(int(cache_line_size.value.get_value(Unit.KibiByte))) output = TestRun.executor.run( standby_init_cmd( @@ -510,18 +502,18 @@ def remove_core_with_script_command(cache_id: int, core_id: int, no_flush: bool def stop_all_caches() -> None: - from .casadm_parser import get_caches + from api.cas.casadm_parser import get_caches caches = get_caches() if not caches: return for cache in caches: - stop_cache(cache_id=cache.cache_id) + stop_cache(cache_id=cache.cache_id, no_data_flush=True) def remove_all_detached_cores() -> None: - from api.cas import casadm_parser + from api.cas.casadm_parser import get_cas_devices_dict - devices = casadm_parser.get_cas_devices_dict() + devices = 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 04b226c98..33ba03fdd 100644 --- a/test/functional/api/cas/casadm_parser.py +++ b/test/functional/api/cas/casadm_parser.py @@ -75,13 +75,14 @@ def get_cas_devices_dict() -> dict: core_pool = False for device in device_list: if device["type"] == "cache": + cache_id = int(device["id"]) params = [ - ("id", int(device["id"])), + ("id", cache_id), ("device_path", device["disk"]), ("status", device["status"]), ] - devices["caches"][int(device["id"])] = dict([(key, value) for key, value in params]) - cache_id = int(device["id"]) + devices["caches"][cache_id] = dict([(key, value) for key, value in params]) + elif device["type"] == "core": params = [ ("cache_id", cache_id), diff --git a/test/functional/api/cas/cli.py b/test/functional/api/cas/cli.py index 94eb7e39a..864580ba6 100644 --- a/test/functional/api/cas/cli.py +++ b/test/functional/api/cas/cli.py @@ -421,27 +421,27 @@ def script_try_add_cmd(cache_id: str, core_dev: str, core_id: str = None) -> str def script_purge_cache_cmd(cache_id: str) -> str: - command = "--script --purge-cache" + 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 = " --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 = " --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 = " --script --remove-core" command += " --cache-id " + cache_id command += " --core-id " + core_id if no_flush: diff --git a/test/functional/api/cas/cli_messages.py b/test/functional/api/cas/cli_messages.py index 70e831261..9833aa8c9 100644 --- a/test/functional/api/cas/cli_messages.py +++ b/test/functional/api/cas/cli_messages.py @@ -138,7 +138,7 @@ ] mutually_exclusive_params_init = [ - r"Can\'t use \'load\' and \'init\' options simultaneously\n" r"Error during options handling" + r"Can\'t use \'load\' and \'init\' options simultaneously\n Error during options handling" ] mutually_exclusive_params_load = [ diff --git a/test/functional/api/cas/core.py b/test/functional/api/cas/core.py index 1b2e87d24..f5229137f 100644 --- a/test/functional/api/cas/core.py +++ b/test/functional/api/cas/core.py @@ -12,7 +12,7 @@ from api.cas.cache_config import SeqCutOffParameters, SeqCutOffPolicy from api.cas.casadm_params import StatsFilter from api.cas.casadm_parser import get_seq_cut_off_parameters, get_core_info_by_path -from api.cas.statistics import CoreStats, IoClassStats +from api.cas.statistics import CoreStats, CoreIoClassStats from core.test_run_utils import TestRun from storage_devices.device import Device from test_tools import fs_utils, disk_utils @@ -58,7 +58,7 @@ def get_io_class_statistics( stat_filter: List[StatsFilter] = None, percentage_val: bool = False, ): - return IoClassStats( + return CoreIoClassStats( cache_id=self.cache_id, filter=stat_filter, io_class_id=io_class_id, diff --git a/test/functional/api/cas/dmesg.py b/test/functional/api/cas/dmesg.py index f64f16756..7616ace1b 100644 --- a/test/functional/api/cas/dmesg.py +++ b/test/functional/api/cas/dmesg.py @@ -9,9 +9,10 @@ from test_utils.size import Size, Unit -def get_metadata_size_on_device(cache_name: str) -> Size: +def get_metadata_size_on_device(cache_id: int) -> Size: dmesg_reversed = list(reversed(get_dmesg().split("\n"))) - cache_dmesg = "\n".join(line for line in dmesg_reversed if cache_name in line) + cache_name = "cache" + str(cache_id) + cache_dmesg = "\n".join(line for line in dmesg_reversed if re.search(f"{cache_name}:", line)) try: return _get_metadata_info(dmesg=cache_dmesg, section_name="Metadata size on device") except ValueError: diff --git a/test/functional/api/cas/installer.py b/test/functional/api/cas/installer.py index 27862d971..3c6a5b06a 100644 --- a/test/functional/api/cas/installer.py +++ b/test/functional/api/cas/installer.py @@ -31,14 +31,14 @@ def rsync_opencas_sources(): 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) @@ -50,7 +50,7 @@ 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} && make {'DESTDIR='+destdir if destdir else ''} install" ) if output.exit_code != 0: raise CmdException("Failed to install Open CAS", output) @@ -86,7 +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} && 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 0806dffaa..bdf41c9a5 100644 --- a/test/functional/api/cas/ioclass_config.py +++ b/test/functional/api/cas/ioclass_config.py @@ -228,7 +228,7 @@ def add_ioclass( 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} to config file {ioclass_config_path}") output = TestRun.executor.run(f'echo "{new_ioclass}" >> {ioclass_config_path}') if output.exit_code != 0: @@ -239,9 +239,7 @@ def add_ioclass( def get_ioclass(ioclass_id: int, ioclass_config_path: str = default_config_file_path): - TestRun.LOGGER.info( - f"Retrieving rule no. {ioclass_id} " + f"from config file {ioclass_config_path}" - ) + TestRun.LOGGER.info(f"Retrieving rule no. {ioclass_id} from config file {ioclass_config_path}") output = TestRun.executor.run(f"cat {ioclass_config_path}") if output.exit_code != 0: raise Exception( @@ -257,9 +255,7 @@ def get_ioclass(ioclass_id: int, ioclass_config_path: str = default_config_file_ 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}" - ) + TestRun.LOGGER.info(f"Removing rule no.{ioclass_id} from config file {ioclass_config_path}") output = TestRun.executor.run(f"cat {ioclass_config_path}") if output.exit_code != 0: raise Exception( diff --git a/test/functional/api/cas/statistics.py b/test/functional/api/cas/statistics.py index 00abb720a..6641a3609 100644 --- a/test/functional/api/cas/statistics.py +++ b/test/functional/api/cas/statistics.py @@ -101,11 +101,6 @@ def __init__( ).stdout.splitlines() stat_keys, stat_values = csv.reader(csv_stats) - - # Unify names in block stats for core and cache: - # cache stats: Reads from core(s) - # core stats: Reads from core - stat_keys = [x.replace("(s)", "") for x in stat_keys] stats_dict = dict(zip(stat_keys, stat_values)) for filter in filters: @@ -133,12 +128,7 @@ def __eq__(self, other): ] -class IoClassStats: - def __str__(self): - # stats_list contains all Class.__str__ methods initialized in CacheStats - stats_list = [str(getattr(self, stats_item)) for stats_item in self.__dict__] - return "\n".join(stats_list) - +class CoreIoClassStats: def __init__( self, cache_id: int, @@ -147,7 +137,6 @@ def __init__( filter: List[StatsFilter] = None, percentage_val: bool = False, ): - if filter is None: filters = [ StatsFilter.conf, @@ -177,7 +166,7 @@ def __init__( for filter in filters: match filter: case StatsFilter.conf: - self.config_stats = IoClassConfigStats(stats_dict, percentage_val) + self.config_stats = IoClassConfigStats(stats_dict) case StatsFilter.usage: self.usage_stats = IoClassUsageStats(stats_dict, percentage_val) case StatsFilter.req: @@ -191,6 +180,28 @@ def __eq__(self, other): getattr(other, stats_item) for stats_item in other.__dict__ ] + def __str__(self): + # stats_list contains all Class.__str__ methods initialized in CacheStats + stats_list = [str(getattr(self, stats_item)) for stats_item in self.__dict__] + return "\n".join(stats_list) + + +class CacheIoClassStats(CoreIoClassStats): + def __init__( + self, + cache_id: int, + io_class_id: int, + filter: List[StatsFilter] = None, + percentage_val: bool = False, + ): + super().__init__( + cache_id=cache_id, + io_class_id=io_class_id, + core_id=None, + filter=filter, + percentage_val=percentage_val, + ) + class CacheConfigStats: def __init__(self, stats_dict): diff --git a/test/functional/tests/basic/start_cas.py b/test/functional/tests/basic/start_cas.py index 94d695b17..ed0136eee 100644 --- a/test/functional/tests/basic/start_cas.py +++ b/test/functional/tests/basic/start_cas.py @@ -1,5 +1,6 @@ # # Copyright(c) 2022 Intel Corporation +# Copyright(c) 2024 Huawei Technologies Co., Ltd. # SPDX-License-Identifier: BSD-3-Clause # @@ -23,7 +24,8 @@ def test_start_cache_add_core(): - Cache started successfully. - Core added successfully. """ - with TestRun.step("Prepare cache and core devices."): + + with TestRun.step("Prepare cache and core."): cache_dev = TestRun.disks["cache"] cache_dev.create_partitions([Size(500, Unit.MebiByte)]) core_dev = TestRun.disks["core"] diff --git a/test/functional/tests/io_class/io_class_common.py b/test/functional/tests/io_class/io_class_common.py index 405e1e858..80a70416d 100644 --- a/test/functional/tests/io_class/io_class_common.py +++ b/test/functional/tests/io_class/io_class_common.py @@ -26,8 +26,8 @@ def prepare( - cache_size=Size(10, Unit.GibiByte), - core_size=Size(40, Unit.GibiByte), + cache_size=Size(100, Unit.MebiByte), + core_size=Size(100, Unit.MebiByte), cache_mode=CacheMode.WB, cache_line_size=CacheLineSize.LINE_4KiB, default_allocation="0.00", @@ -49,11 +49,11 @@ def prepare( Udev.disable() TestRun.LOGGER.info(f"Setting cleaning policy to NOP") - casadm.set_param_cleaning(cache_id=cache.cache_id, policy=CleaningPolicy.nop) + # casadm.set_param_cleaning(cache_id=cache.cache_id, policy=CleaningPolicy.nop) TestRun.LOGGER.info(f"Adding core device") core = casadm.add_core(cache, core_dev=core_device) TestRun.LOGGER.info(f"Setting seq cutoff policy to never") - core.set_seq_cutoff_policy(SeqCutOffPolicy.never) + # core.set_seq_cutoff_policy(SeqCutOffPolicy.never) ioclass_config.create_ioclass_config( add_default_rule=False, ioclass_config_path=ioclass_config_path )