From 3908ab261ba9f180be37e6c35e6ac091d949f58d Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Fri, 6 Dec 2019 15:11:36 +0100 Subject: [PATCH] Minor fixes in CAS API Signed-off-by: Jan Musial --- test/functional/api/cas/cache.py | 10 +++++++--- test/functional/api/cas/cache_config.py | 5 ++++- test/functional/api/cas/casadm.py | 8 +++++--- test/functional/api/cas/casadm_parser.py | 7 ++++++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/test/functional/api/cas/cache.py b/test/functional/api/cas/cache.py index bc224ae..eb0ab27 100644 --- a/test/functional/api/cas/cache.py +++ b/test/functional/api/cas/cache.py @@ -14,8 +14,8 @@ from api.cas.statistics import CacheStats, IoClassStats class Cache: - def __init__(self, device_system_path): - self.cache_device = Device(device_system_path) + def __init__(self, device: Device): + self.cache_device = device self.cache_id = int(self.__get_cache_id()) self.__cache_line_size = None self.__metadata_mode = None @@ -36,7 +36,7 @@ class Cache: 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.get_value(Unit.Byte)) + self.__cache_line_size = CacheLineSize(stats_line_size) return self.__cache_line_size def get_cleaning_policy(self): @@ -69,6 +69,10 @@ class Cache: status = self.get_statistics().config_stats.status.replace(' ', '_').lower() return CacheStatus[status] + @property + def size(self): + return self.get_statistics().config_stats.cache_size + def get_cache_mode(self): return CacheMode[self.get_statistics().config_stats.write_policy.upper()] diff --git a/test/functional/api/cas/cache_config.py b/test/functional/api/cas/cache_config.py index a7aed8f..5aa3965 100644 --- a/test/functional/api/cas/cache_config.py +++ b/test/functional/api/cas/cache_config.py @@ -9,7 +9,7 @@ from test_utils.size import Size, Unit from datetime import timedelta -class CacheLineSize(IntEnum): +class CacheLineSize(Enum): LINE_4KiB = Size(4, Unit.KibiByte) LINE_8KiB = Size(8, Unit.KibiByte) LINE_16KiB = Size(16, Unit.KibiByte) @@ -17,6 +17,9 @@ class CacheLineSize(IntEnum): LINE_64KiB = Size(64, Unit.KibiByte) DEFAULT = LINE_4KiB + def __int__(self): + return int(self.value.get_value()) + class CacheMode(Enum): WT = "Write-Through" diff --git a/test/functional/api/cas/casadm.py b/test/functional/api/cas/casadm.py index ae943b5..b7d1bae 100644 --- a/test/functional/api/cas/casadm.py +++ b/test/functional/api/cas/casadm.py @@ -27,7 +27,7 @@ def start_cache(cache_dev: Device, cache_mode: CacheMode = None, cache_line_size: CacheLineSize = None, cache_id: int = None, force: bool = False, load: bool = False, shortcut: bool = False): _cache_line_size = None if cache_line_size is None else str( - CacheLineSize.get_value(Unit.KibiByte)) + int(cache_line_size.value.get_value(Unit.KibiByte))) _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() output = TestRun.executor.run(start_cmd( @@ -35,7 +35,8 @@ def start_cache(cache_dev: Device, cache_mode: CacheMode = None, cache_id=_cache_id, force=force, load=load, shortcut=shortcut)) if output.exit_code != 0: raise CmdException("Failed to start cache.", output) - return Cache(cache_dev.system_path) + + return Cache(cache_dev) def stop_cache(cache_id: int, no_data_flush: bool = False, shortcut: bool = False): @@ -97,7 +98,8 @@ def load_cache(device: Device, shortcut: bool = False): load_cmd(cache_dev=device.system_path, shortcut=shortcut)) if output.exit_code != 0: raise CmdException("Failed to load cache.", output) - return Cache(device.system_path) + + return Cache(device) def list_caches(output_format: OutputFormat = None, shortcut: bool = False): diff --git a/test/functional/api/cas/casadm_parser.py b/test/functional/api/cas/casadm_parser.py index 65c0cd2..c608e95 100644 --- a/test/functional/api/cas/casadm_parser.py +++ b/test/functional/api/cas/casadm_parser.py @@ -6,6 +6,11 @@ import csv import json import re +from api.cas import casadm +from test_utils.size import parse_unit +from storage_devices.device import Device +from api.cas.cache_config import * +from api.cas.casadm_params import * from datetime import timedelta from typing import List @@ -151,7 +156,7 @@ def get_caches(): # This method does not return inactive or detached CAS device for line in lines: args = line.split(',') if args[0] == "cache": - current_cache = Cache(args[2]) + current_cache = Cache(Device(args[2])) caches_list.append(current_cache) return caches_list