Skip to content

Commit

Permalink
test-api: fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Gierszewski committed Aug 14, 2024
1 parent 39caada commit e0aab0e
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 103 deletions.
29 changes: 10 additions & 19 deletions test/functional/api/cas/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
),
)
Expand Down
78 changes: 35 additions & 43 deletions test/functional/api/cas/casadm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)
)
Expand All @@ -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,
)
)
Expand All @@ -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),
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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(),
Expand All @@ -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),
Expand Down Expand Up @@ -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)
)
Expand All @@ -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:
Expand All @@ -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)
)
Expand All @@ -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)
Expand All @@ -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)
)
Expand All @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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"]))
7 changes: 4 additions & 3 deletions test/functional/api/cas/casadm_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 4 additions & 4 deletions test/functional/api/cas/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test/functional/api/cas/cli_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
4 changes: 2 additions & 2 deletions test/functional/api/cas/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions test/functional/api/cas/dmesg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading

0 comments on commit e0aab0e

Please sign in to comment.