Create init config class representation
This commit is contained in:
parent
e435f3017a
commit
53664937ba
2
ocf
2
ocf
@ -1 +1 @@
|
||||
Subproject commit 1ec0a5c053c2e5fb1d502b0aa052030838011278
|
||||
Subproject commit ce28c71475756cae0abe698039c187b645c029d1
|
2
test/functional/.gitignore
vendored
2
test/functional/.gitignore
vendored
@ -1,3 +1,3 @@
|
||||
plugins/
|
||||
lib/external_plugins
|
||||
results/
|
||||
config/dut_config.yml
|
||||
|
@ -12,40 +12,54 @@ from test_tools import fs_utils
|
||||
opencas_conf_path = "/etc/opencas/opencas.conf"
|
||||
|
||||
|
||||
def create_init_config_from_running_configuration(load: bool = None, extra_flags=""):
|
||||
cache_lines = []
|
||||
core_lines = []
|
||||
for cache in casadm_parser.get_caches():
|
||||
cache_lines.append(CacheConfigLine(cache.cache_id,
|
||||
cache.cache_device,
|
||||
cache.get_cache_mode(),
|
||||
load,
|
||||
extra_flags))
|
||||
for core in casadm_parser.get_cores(cache.cache_id):
|
||||
core_lines.append(CoreConfigLine(cache.cache_id,
|
||||
core.core_id,
|
||||
core.core_device))
|
||||
config_lines = []
|
||||
create_default_init_config()
|
||||
if len(cache_lines) > 0:
|
||||
config_lines.append(CacheConfigLine.header)
|
||||
for c in cache_lines:
|
||||
config_lines.append(str(c))
|
||||
if len(core_lines) > 0:
|
||||
config_lines.append(CoreConfigLine.header)
|
||||
for c in core_lines:
|
||||
config_lines.append(str(c))
|
||||
fs_utils.write_file(opencas_conf_path, '\n'.join(config_lines), False)
|
||||
class InitConfig:
|
||||
def __init__(self):
|
||||
self.cache_config_lines = []
|
||||
self.core_config_lines = []
|
||||
|
||||
def add_cache(self, cache_id, cache_device: Device,
|
||||
cache_mode: CacheMode = CacheMode.WT, load=None, extra_flags=""):
|
||||
self.cache_config_lines.append(
|
||||
CacheConfigLine(cache_id, cache_device, cache_mode, load, extra_flags))
|
||||
|
||||
def create_default_init_config():
|
||||
cas_version = casadm_parser.get_casadm_version()
|
||||
fs_utils.write_file(opencas_conf_path,
|
||||
f"version={'.'.join(str(x) for x in cas_version.release[0:3])}")
|
||||
def add_core(self, cache_id, core_id, core_device: Device):
|
||||
self.core_config_lines.append(CoreConfigLine(cache_id, core_id, core_device))
|
||||
|
||||
def save_config_file(self):
|
||||
config_lines = []
|
||||
InitConfig.create_default_init_config()
|
||||
if self.cache_config_lines:
|
||||
config_lines.append(CacheConfigLine.header)
|
||||
for c in self.cache_config_lines:
|
||||
config_lines.append(str(c))
|
||||
if self.core_config_lines:
|
||||
config_lines.append(CoreConfigLine.header)
|
||||
for c in self.core_config_lines:
|
||||
config_lines.append(str(c))
|
||||
fs_utils.write_file(opencas_conf_path, '\n'.join(config_lines), False)
|
||||
|
||||
@classmethod
|
||||
def create_init_config_from_running_configuration(cls, load: bool = None, extra_flags=""):
|
||||
init_conf = cls()
|
||||
for cache in casadm_parser.get_caches():
|
||||
init_conf.add_cache(cache.cache_id,
|
||||
cache.cache_device,
|
||||
cache.get_cache_mode(),
|
||||
load,
|
||||
extra_flags)
|
||||
for core in casadm_parser.get_cores(cache.cache_id):
|
||||
init_conf.add_core(cache.cache_id, core.core_id, core.core_device)
|
||||
init_conf.save_config_file()
|
||||
return init_conf
|
||||
|
||||
@classmethod
|
||||
def create_default_init_config(cls):
|
||||
cas_version = casadm_parser.get_casadm_version()
|
||||
fs_utils.write_file(opencas_conf_path,
|
||||
f"version={'.'.join(str(x) for x in cas_version.release[0:3])}")
|
||||
|
||||
|
||||
class CacheConfigLine:
|
||||
|
||||
header = "[caches]"
|
||||
|
||||
def __init__(self, cache_id, cache_device: Device,
|
||||
@ -69,7 +83,6 @@ class CacheConfigLine:
|
||||
|
||||
|
||||
class CoreConfigLine:
|
||||
|
||||
header = "[cores]"
|
||||
|
||||
def __init__(self, cache_id, core_id, core_device: Device):
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 4b4c66db919bb44bba06de5998e2e81517c7ea4b
|
||||
Subproject commit 1c2adf303c58bfe1e6d37b3648eae7d9d18af671
|
@ -96,8 +96,8 @@ def pytest_runtest_teardown():
|
||||
unmount_cas_devices()
|
||||
casadm.remove_all_detached_cores()
|
||||
casadm.stop_all_caches()
|
||||
from api.cas import init_config
|
||||
init_config.create_default_init_config()
|
||||
from api.cas.init_config import InitConfig
|
||||
InitConfig.create_default_init_config()
|
||||
DeviceMapper.remove_all()
|
||||
except Exception as ex:
|
||||
TestRun.LOGGER.warning(f"Exception occured during platform cleanup.\n"
|
||||
@ -156,8 +156,8 @@ def base_prepare(item):
|
||||
|
||||
if installer.check_if_installed():
|
||||
try:
|
||||
from api.cas import init_config
|
||||
init_config.create_default_init_config()
|
||||
from api.cas.init_config import InitConfig
|
||||
InitConfig.create_default_init_config()
|
||||
unmount_cas_devices()
|
||||
casadm.stop_all_caches()
|
||||
casadm.remove_all_detached_cores()
|
||||
|
@ -7,8 +7,9 @@ import time
|
||||
|
||||
import pytest
|
||||
|
||||
from api.cas import casadm, casctl, casadm_parser, init_config, cas_module
|
||||
from api.cas import casadm, casctl, casadm_parser, cas_module
|
||||
from api.cas.cache_config import CacheMode
|
||||
from api.cas.init_config import InitConfig
|
||||
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
|
||||
from core.test_run import TestRun
|
||||
from test_tools import fs_utils
|
||||
@ -84,7 +85,7 @@ def test_stress_service(cache_mode):
|
||||
f"Stop and start CAS service {iterations_per_config} times."):
|
||||
with TestRun.step(
|
||||
"Create CAS init config based on current running CAS configuration."):
|
||||
init_config.create_init_config_from_running_configuration()
|
||||
InitConfig.create_init_config_from_running_configuration()
|
||||
with TestRun.step("Stop CAS service."):
|
||||
casctl.stop()
|
||||
with TestRun.step("Check if service stopped successfully."):
|
||||
@ -105,7 +106,7 @@ def test_stress_service(cache_mode):
|
||||
|
||||
with TestRun.step("Stop caches and create default init config file."):
|
||||
casadm.stop_all_caches()
|
||||
init_config.create_default_init_config()
|
||||
InitConfig.create_default_init_config()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("cache_mode", CacheMode)
|
||||
|
Loading…
Reference in New Issue
Block a user