Compare commits

..

1 Commits

Author SHA1 Message Date
0ce2e344b0 [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.
2025-04-16 18:48:47 +08:00
3 changed files with 33 additions and 26 deletions

7
README-TD.md Normal file
View File

@ -0,0 +1,7 @@
# Test Cas_Config
```
python3 -m venv test_env
source test_env/bin/activate
pip3 install pytest
pytest test/utils_tests/opencas-py-tests/test_cas_config_01.py -vv
```

View File

@ -482,24 +482,24 @@ def test_cas_config_from_file_insert_cache_insert_core_to_file(
"cleaning_policy,wake_up,flush_max_buffers,expected_exception",
[
("acp", "100", "500", None), # Valid normal values
("acp", "0", "1", None), # Boundary value test
("acp", "9999", "9999", None), # Boundary value test
("acp", "0", "1", None), # Boundary value test - min
("acp", "10000", "9999", None), # Boundary value test - max
("acp", "-1", "500", ValueError), # Invalid wake_up value
("acp", "10000", "500", ValueError), # Out of range wake_up value
("acp", "10001", "500", ValueError), # Out of range wake_up value
("acp", "abc", "500", ValueError), # Non-numeric wake_up value
("acp", "100", "0", ValueError), # Invalid flush_max_buffers value
("acp", "100", "10000", ValueError), # Out of range flush_max_buffers value
("acp", "100", "10001", ValueError), # Out of range flush_max_buffers value
("acp", "100", "abc", ValueError), # Non-numeric flush_max_buffers value
("alru", "100", "500", None), # Valid normal values
("alru", "0", "1", None), # Boundary value test
("alru", "3599", "9999", None), # Boundary value test
("alru", "0", "1", None), # Boundary value test - min
("alru", "3599", "10000", None), # Boundary value test - max
("alru", "-1", "500", ValueError), # Invalid wake_up value
("alru", "3600", "500", ValueError), # Out of range wake_up value
("alru", "3601", "500", ValueError), # Out of range wake_up value
("alru", "abc", "500", ValueError), # Non-numeric wake_up value
("alru", "100", "0", ValueError), # Invalid flush_max_buffers value
("alru", "100", "10000", ValueError), # Out of range flush_max_buffers value
("alru", "100", "10001", ValueError), # Out of range flush_max_buffers value
("alru", "100", "abc", ValueError), # Non-numeric flush_max_buffers value
("nop", "100", "500", ValueError), # Testing parameters for unsupported cleaning policy
("nop", "100", "500", None), # Testing parameters for unsupported cleaning policy
],
)
def test_cache_config_cleaning_policy_parameters(cleaning_policy, wake_up, flush_max_buffers, expected_exception):
@ -507,8 +507,8 @@ def test_cache_config_cleaning_policy_parameters(cleaning_policy, wake_up, flush
cache = opencas.cas_config.cache_config(1, "/dev/dummy", "WT", cleaning_policy=cleaning_policy)
# Add test parameters
cache.params["wake-up"] = wake_up
cache.params["flush-max-buffers"] = flush_max_buffers
cache.params["wake_up"] = wake_up
cache.params["flush_max_buffers"] = flush_max_buffers
if expected_exception:
with pytest.raises(expected_exception):
@ -525,23 +525,23 @@ def test_cache_config_cleaning_policy_parameters(cleaning_policy, wake_up, flush
[
("1 /dev/dummy WT cleaning_policy=acp,wake_up=100,flush_max_buffers=500", None),
("1 /dev/dummy WT cleaning_policy=alru,wake_up=60,flush_max_buffers=100", None),
("1 /dev/dummy WT cleaning_policy=acp,wake_up=10000,flush_max_buffers=500", ValueError),
("1 /dev/dummy WT cleaning_policy=acp,wake_up=10001,flush_max_buffers=500", ValueError),
("1 /dev/dummy WT cleaning_policy=acp,wake_up=100,flush_max_buffers=0", ValueError),
("1 /dev/dummy WT cleaning_policy=alru,wake_up=3600,flush_max_buffers=100", ValueError),
("1 /dev/dummy WT cleaning_policy=alru,wake_up=100,flush_max_buffers=10000", ValueError),
("1 /dev/dummy WT cleaning_policy=nop,wake_up=100,flush_max_buffers=500", ValueError),
("1 /dev/dummy WT cleaning_policy=alru,wake_up=3601,flush_max_buffers=100", ValueError),
("1 /dev/dummy WT cleaning_policy=alru,wake_up=100,flush_max_buffers=10001", ValueError),
("1 /dev/dummy WT cleaning_policy=nop,wake_up=100,flush_max_buffers=500", None),
],
)
def test_cache_config_from_line_with_cleaning_parameters(cache_config_str, exception):
"""Test parsing cache configuration with cleaning policy parameters from config line"""
if exception:
with pytest.raises(exception):
cache = opencas.cas_config.cache_config.from_line(cache_config_str)
cache = opencas.cas_config.cache_config.from_line(cache_config_str, True)
else:
cache = opencas.cas_config.cache_config.from_line(cache_config_str)
assert cache.params.get("cleaning_policy") in ["acp", "alru"]
assert "wake-up" in cache.params
assert "flush-max-buffers" in cache.params
cache = opencas.cas_config.cache_config.from_line(cache_config_str, True)
assert cache.params.get("cleaning_policy") in ["acp", "alru", "nop"]
assert "wake_up" in cache.params
assert "flush_max_buffers" in cache.params
@patch("opencas.casadm.run_cmd")

View File

@ -278,9 +278,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 +332,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'):