From 56b9ec1794ea3162d1231b1935198f0372196ad7 Mon Sep 17 00:00:00 2001 From: Michal Rakowski Date: Wed, 6 Nov 2019 12:41:47 +0100 Subject: [PATCH] tests: sequential cut off related methods fixup Signed-off-by: Michal Rakowski --- test/functional/api/cas/cache.py | 14 ++++++++++++-- test/functional/api/cas/cache_config.py | 9 +++++++++ test/functional/api/cas/casadm.py | 13 ++++--------- test/functional/api/cas/casadm_parser.py | 5 +++-- test/functional/api/cas/cli.py | 6 +++--- test/functional/api/cas/core.py | 23 +++++++++++++++++++++-- 6 files changed, 52 insertions(+), 18 deletions(-) diff --git a/test/functional/api/cas/cache.py b/test/functional/api/cas/cache.py index acb89aa..f9b27e2 100644 --- a/test/functional/api/cas/cache.py +++ b/test/functional/api/cas/cache.py @@ -123,8 +123,18 @@ class Cache: def set_seq_cutoff_parameters(self, seq_cutoff_param: SeqCutOffParameters): return casadm.set_param_cutoff(self.cache_id, - seq_cutoff_param.threshold, - seq_cutoff_param.policy) + threshold=seq_cutoff_param.threshold, + policy=seq_cutoff_param.policy) + + def set_seq_cutoff_threshold(self, threshold: Size): + return casadm.set_param_cutoff(self.cache_id, + threshold=threshold, + policy=None) + + def set_seq_cutoff_policy(self, policy: SeqCutOffPolicy): + return casadm.set_param_cutoff(self.cache_id, + threshold=None, + policy=policy) def set_cleaning_policy(self, cleaning_policy: CleaningPolicy): return casadm.set_param_cleaning(self.cache_id, cleaning_policy) diff --git a/test/functional/api/cas/cache_config.py b/test/functional/api/cas/cache_config.py index 8d028f0..b3c0266 100644 --- a/test/functional/api/cas/cache_config.py +++ b/test/functional/api/cas/cache_config.py @@ -32,6 +32,14 @@ class SeqCutOffPolicy(Enum): never = 2 DEFAULT = full + @classmethod + def from_name(cls, name): + for policy, policy_name in SeqCutOffPolicy.__members__.items(): + if name == policy: + return policy_name + + raise ValueError(f"{name} is not a valid sequential cut off name") + class EvictionPolicy(Enum): lru = 0 @@ -106,6 +114,7 @@ class SeqCutOffParameters: seq_cut_off_params = SeqCutOffParameters() seq_cut_off_params.policy = SeqCutOffPolicy.full seq_cut_off_params.threshold = Size(1024, Unit.KibiByte) + return seq_cut_off_params # TODO: Use case for this will be to iterate over configurations (kernel params such as diff --git a/test/functional/api/cas/casadm.py b/test/functional/api/cas/casadm.py index cd70ac8..720cc0a 100644 --- a/test/functional/api/cas/casadm.py +++ b/test/functional/api/cas/casadm.py @@ -254,15 +254,10 @@ def get_param_cleaning_acp(cache_id: int, output_format: OutputFormat = None, def set_param_cutoff(cache_id: int, core_id: int = None, threshold: Size = None, policy: SeqCutOffPolicy = None): - _threshold = None if threshold is None else threshold.get_value(Unit.KibiByte) - if core_id is None: - command = set_param_cutoff_cmd( - cache_id=str(cache_id), threshold=_threshold, - policy=policy.name) - else: - command = set_param_cutoff_cmd( - cache_id=str(cache_id), core_id=str(core_id), - threshold=_threshold, policy=policy.name) + _threshold = None if threshold is None else int(threshold.get_value(Unit.KibiByte)) + command = set_param_cutoff_cmd( + cache_id=cache_id, core_id=core_id, + threshold=_threshold, policy=policy) output = TestRun.executor.run(command) if output.exit_code != 0: raise Exception( diff --git a/test/functional/api/cas/casadm_parser.py b/test/functional/api/cas/casadm_parser.py index ca9a3b2..03f86d9 100644 --- a/test/functional/api/cas/casadm_parser.py +++ b/test/functional/api/cas/casadm_parser.py @@ -198,9 +198,10 @@ def get_seq_cut_off_parameters(cache_id: int, core_id: int): seq_cut_off_params = SeqCutOffParameters() for line in casadm_output: if 'threshold' in line: - seq_cut_off_params.threshold = line.split(',')[1] + seq_cut_off_params.threshold = Size(int(line.split(',')[1]), Unit.KibiByte) if 'policy' in line: - seq_cut_off_params.policy = SeqCutOffPolicy(line.split(',')[1]) + seq_cut_off_params.policy = SeqCutOffPolicy.from_name(line.split(',')[1]) + return seq_cut_off_params def get_casadm_version(): diff --git a/test/functional/api/cas/cli.py b/test/functional/api/cas/cli.py index 8abf909..a29838d 100644 --- a/test/functional/api/cas/cli.py +++ b/test/functional/api/cas/cli.py @@ -190,11 +190,11 @@ def set_param_cutoff_cmd(cache_id: str, core_id: str = None, threshold: str = No policy: str = None, shortcut: bool = False): add_params = "" if core_id is not None: - add_params += (" -j " if shortcut else " --core-id ") + core_id + add_params += (" -j " if shortcut else " --core-id ") + str(core_id) if threshold is not None: - add_params += (" -t " if shortcut else " --threshold ") + threshold + add_params += (" -t " if shortcut else " --threshold ") + str(threshold) if policy is not None: - add_params += (" -p " if shortcut else " --policy ") + policy + add_params += (" -p " if shortcut else " --policy ") + policy.name return _set_param_cmd(namespace="seq-cutoff", cache_id=cache_id, additional_params=add_params, shortcut=shortcut) diff --git a/test/functional/api/cas/core.py b/test/functional/api/cas/core.py index bb08324..325e017 100644 --- a/test/functional/api/cas/core.py +++ b/test/functional/api/cas/core.py @@ -17,6 +17,9 @@ class CoreStatus(Enum): detached = 3 +SEQ_CUTOFF_THRESHOLD_MAX = 4194181 + + class Core(Device): def __init__(self, core_device: str, cache_id: int): self.core_device = Device(core_device) @@ -54,6 +57,12 @@ class Core(Device): def get_seq_cut_off_parameters(self): return get_seq_cut_off_parameters(self.cache_id, self.core_id) + def get_seq_cut_off_policy(self): + return get_seq_cut_off_parameters(self.cache_id, self.core_id).policy + + def get_seq_cut_off_threshold(self): + return get_seq_cut_off_parameters(self.cache_id, self.core_id).threshold + def get_dirty_blocks(self): return self.get_core_statistics()["dirty"] @@ -77,5 +86,15 @@ class Core(Device): assert self.get_dirty_blocks().get_value(Unit.Blocks4096) == 0 def set_seq_cutoff_parameters(self, seq_cutoff_param: SeqCutOffParameters): - casadm.set_param_cutoff(self.cache_id, self.core_id, - seq_cutoff_param.threshold, seq_cutoff_param.policy) + return casadm.set_param_cutoff(self.cache_id, self.core_id, + seq_cutoff_param.threshold, seq_cutoff_param.policy) + + def set_seq_cutoff_threshold(self, threshold: Size): + return casadm.set_param_cutoff(self.cache_id, self.core_id, + threshold=threshold, + policy=None) + + def set_seq_cutoff_policy(self, policy: SeqCutOffPolicy): + return casadm.set_param_cutoff(self.cache_id, self.core_id, + threshold=None, + policy=policy)