Minor fixes in CAS API

Signed-off-by: Jan Musial <jan.musial@intel.com>
This commit is contained in:
Jan Musial 2019-12-06 15:11:36 +01:00
parent 9cabf06ed4
commit 3908ab261b
4 changed files with 22 additions and 8 deletions

View File

@ -14,8 +14,8 @@ from api.cas.statistics import CacheStats, IoClassStats
class Cache: class Cache:
def __init__(self, device_system_path): def __init__(self, device: Device):
self.cache_device = Device(device_system_path) self.cache_device = device
self.cache_id = int(self.__get_cache_id()) self.cache_id = int(self.__get_cache_id())
self.__cache_line_size = None self.__cache_line_size = None
self.__metadata_mode = None self.__metadata_mode = None
@ -36,7 +36,7 @@ class Cache:
if self.__cache_line_size is None: if self.__cache_line_size is None:
stats = self.get_statistics() stats = self.get_statistics()
stats_line_size = stats.config_stats.cache_line_size 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 return self.__cache_line_size
def get_cleaning_policy(self): def get_cleaning_policy(self):
@ -69,6 +69,10 @@ class Cache:
status = self.get_statistics().config_stats.status.replace(' ', '_').lower() status = self.get_statistics().config_stats.status.replace(' ', '_').lower()
return CacheStatus[status] return CacheStatus[status]
@property
def size(self):
return self.get_statistics().config_stats.cache_size
def get_cache_mode(self): def get_cache_mode(self):
return CacheMode[self.get_statistics().config_stats.write_policy.upper()] return CacheMode[self.get_statistics().config_stats.write_policy.upper()]

View File

@ -9,7 +9,7 @@ from test_utils.size import Size, Unit
from datetime import timedelta from datetime import timedelta
class CacheLineSize(IntEnum): class CacheLineSize(Enum):
LINE_4KiB = Size(4, Unit.KibiByte) LINE_4KiB = Size(4, Unit.KibiByte)
LINE_8KiB = Size(8, Unit.KibiByte) LINE_8KiB = Size(8, Unit.KibiByte)
LINE_16KiB = Size(16, Unit.KibiByte) LINE_16KiB = Size(16, Unit.KibiByte)
@ -17,6 +17,9 @@ class CacheLineSize(IntEnum):
LINE_64KiB = Size(64, Unit.KibiByte) LINE_64KiB = Size(64, Unit.KibiByte)
DEFAULT = LINE_4KiB DEFAULT = LINE_4KiB
def __int__(self):
return int(self.value.get_value())
class CacheMode(Enum): class CacheMode(Enum):
WT = "Write-Through" WT = "Write-Through"

View File

@ -27,7 +27,7 @@ def start_cache(cache_dev: Device, cache_mode: CacheMode = None,
cache_line_size: CacheLineSize = None, cache_id: int = None, cache_line_size: CacheLineSize = None, cache_id: int = None,
force: bool = False, load: bool = False, shortcut: bool = False): force: bool = False, load: bool = False, shortcut: bool = False):
_cache_line_size = None if cache_line_size is None else str( _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_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_mode = None if cache_mode is None else cache_mode.name.lower()
output = TestRun.executor.run(start_cmd( 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)) cache_id=_cache_id, force=force, load=load, shortcut=shortcut))
if output.exit_code != 0: if output.exit_code != 0:
raise CmdException("Failed to start cache.", output) 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): 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)) load_cmd(cache_dev=device.system_path, shortcut=shortcut))
if output.exit_code != 0: if output.exit_code != 0:
raise CmdException("Failed to load cache.", output) 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): def list_caches(output_format: OutputFormat = None, shortcut: bool = False):

View File

@ -6,6 +6,11 @@ import csv
import json import json
import re 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 datetime import timedelta
from typing import List 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: for line in lines:
args = line.split(',') args = line.split(',')
if args[0] == "cache": if args[0] == "cache":
current_cache = Cache(args[2]) current_cache = Cache(Device(args[2]))
caches_list.append(current_cache) caches_list.append(current_cache)
return caches_list return caches_list