[test] Add unit tests for ACP and ALRU cleaning policy parameters
- Add tests for wake-up and flush-max-buffers parameter validation - Test parameter boundary values and error conditions - Cover parameter parsing from configuration strings - Verify set_param_cleaning_policy commands construction - Test proper handling of different cleaning policies in configure_cache These tests ensure the proper validation and handling of cleaning policy parameters introduced in the previous commits.
This commit was merged in pull request #1.
This commit is contained in:
@@ -219,6 +219,9 @@ class cas_config(object):
|
||||
if not stat.S_ISBLK(mode):
|
||||
raise ValueError(f'{path} is not block device')
|
||||
|
||||
def __str__(self):
|
||||
return f"cas_config(caches={[str(cache) for cache in self.caches.values()]}, cores={[str(core) for core in self.cores]}, version_tag={self.version_tag})"
|
||||
|
||||
class cache_config(object):
|
||||
def __init__(self, cache_id, device, cache_mode, **params):
|
||||
self.cache_id = int(cache_id)
|
||||
@@ -227,6 +230,9 @@ class cas_config(object):
|
||||
self.params = params
|
||||
self.cores = dict()
|
||||
|
||||
def __str__(self):
|
||||
return f"cache_config(cache_id={self.cache_id}, device={self.device}, cache_mode={self.cache_mode}, params={self.params}, cores={self.cores})"
|
||||
|
||||
@classmethod
|
||||
def from_line(cls, line, allow_incomplete=False):
|
||||
values = line.split()
|
||||
@@ -278,9 +284,9 @@ class cas_config(object):
|
||||
self.check_lazy_startup_valid(param_value)
|
||||
elif param_name == "target_failover_state":
|
||||
self.check_failover_state_valid(param_value)
|
||||
elif param_name == "wake-up":
|
||||
elif param_name == "wake_up":
|
||||
self.check_wake_up_valid(param_value)
|
||||
elif param_name == "flush-max-buffers":
|
||||
elif param_name == "flush_max_buffers":
|
||||
self.check_flush_max_buffers_valid(param_value)
|
||||
else:
|
||||
raise ValueError(f'{param_name} is invalid parameter name')
|
||||
@@ -332,24 +338,24 @@ class cas_config(object):
|
||||
if self.params.get("cleaning_policy") == "acp":
|
||||
if not wake_up.isdigit():
|
||||
raise ValueError(f"{wake_up} is invalid wake-up value for acp cleaning policy")
|
||||
if int(wake_up) not in range(0, 10000):
|
||||
if int(wake_up) not in range(0, 10001):
|
||||
raise ValueError(f"{wake_up} is invalid wake-up value for acp cleaning policy")
|
||||
elif self.params.get("cleaning_policy") == "alru":
|
||||
if not wake_up.isdigit():
|
||||
raise ValueError(f"{wake_up} is invalid wake-up value for alru cleaning policy")
|
||||
if int(wake_up) not in range(0, 3600):
|
||||
if int(wake_up) not in range(0, 3601):
|
||||
raise ValueError(f"{wake_up} is invalid wake-up value for alru cleaning policy")
|
||||
|
||||
def check_flush_max_buffers_valid(self, flush_max_buffers):
|
||||
if self.params.get("cleaning_policy") == "acp":
|
||||
if not flush_max_buffers.isdigit():
|
||||
raise ValueError(f"{flush_max_buffers} is invalid flush-max-buffers value for acp cleaning policy")
|
||||
if int(flush_max_buffers) not in range(1, 10000):
|
||||
if int(flush_max_buffers) not in range(1, 10001):
|
||||
raise ValueError(f"{flush_max_buffers} is invalid flush-max-buffers value for acp cleaning policy")
|
||||
elif self.params.get("cleaning_policy") == "alru":
|
||||
if not flush_max_buffers.isdigit():
|
||||
raise ValueError(f"{flush_max_buffers} is invalid flush-max-buffers value for alru cleaning policy")
|
||||
if int(flush_max_buffers) not in range(1, 10000):
|
||||
if int(flush_max_buffers) not in range(1, 10001):
|
||||
raise ValueError(f"{flush_max_buffers} is invalid flush-max-buffers value for alru cleaning policy")
|
||||
def check_recursive(self):
|
||||
if not self.device.startswith('/dev/cas'):
|
||||
@@ -387,6 +393,9 @@ class cas_config(object):
|
||||
self.device = path
|
||||
self.params = params
|
||||
|
||||
def __str__(self):
|
||||
return f"core_config(cache_id={self.cache_id}, core_id={self.core_id}, device={self.device}, params={self.params})"
|
||||
|
||||
@classmethod
|
||||
def from_line(cls, line, allow_incomplete=False):
|
||||
values = line.split()
|
||||
@@ -646,12 +655,12 @@ def configure_cache(cache):
|
||||
)
|
||||
|
||||
|
||||
def add_core(core, attach):
|
||||
def add_core(core, try_add):
|
||||
casadm.add_core(
|
||||
device=core.device,
|
||||
cache_id=core.cache_id,
|
||||
core_id=core.core_id,
|
||||
try_add=attach)
|
||||
try_add=try_add)
|
||||
|
||||
# Another helper functions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user