test-api: reformat api files
Signed-off-by: Kamil Gierszewski <kamil.gierszewski@huawei.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2019-2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
@@ -17,18 +18,24 @@ class InitConfig:
|
||||
self.cache_config_lines = []
|
||||
self.core_config_lines = []
|
||||
|
||||
def add_cache(self, cache_id, cache_device: Device,
|
||||
cache_mode: CacheMode = CacheMode.WT, extra_flags=""):
|
||||
def add_cache(
|
||||
self,
|
||||
cache_id,
|
||||
cache_device: Device,
|
||||
cache_mode: CacheMode = CacheMode.WT,
|
||||
extra_flags="",
|
||||
):
|
||||
self.cache_config_lines.append(
|
||||
CacheConfigLine(cache_id, cache_device, cache_mode, extra_flags))
|
||||
CacheConfigLine(cache_id, cache_device, cache_mode, extra_flags)
|
||||
)
|
||||
|
||||
def add_core(self, cache_id, core_id, core_device: Device, extra_flags=""):
|
||||
self.core_config_lines.append(CoreConfigLine(cache_id, core_id, core_device, extra_flags))
|
||||
|
||||
def remove_config_file(self):
|
||||
@staticmethod
|
||||
def remove_config_file():
|
||||
fs_utils.remove(opencas_conf_path, force=False)
|
||||
|
||||
|
||||
def save_config_file(self):
|
||||
config_lines = []
|
||||
InitConfig.create_default_init_config()
|
||||
@@ -40,18 +47,20 @@ class InitConfig:
|
||||
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)
|
||||
fs_utils.write_file(opencas_conf_path, "\n".join(config_lines), False)
|
||||
|
||||
@classmethod
|
||||
def create_init_config_from_running_configuration(
|
||||
cls, cache_extra_flags="", core_extra_flags=""
|
||||
cls, cache_extra_flags="", core_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(),
|
||||
cache_extra_flags)
|
||||
init_conf.add_cache(
|
||||
cache.cache_id,
|
||||
cache.cache_device,
|
||||
cache.get_cache_mode(),
|
||||
cache_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, core_extra_flags)
|
||||
init_conf.save_config_file()
|
||||
@@ -66,17 +75,20 @@ class InitConfig:
|
||||
class CacheConfigLine:
|
||||
header = "[caches]"
|
||||
|
||||
def __init__(self, cache_id, cache_device: Device,
|
||||
cache_mode: CacheMode, extra_flags=""):
|
||||
def __init__(self, cache_id, cache_device: Device, cache_mode: CacheMode, extra_flags=""):
|
||||
self.cache_id = cache_id
|
||||
self.cache_device = cache_device
|
||||
self.cache_mode = cache_mode
|
||||
self.extra_flags = extra_flags
|
||||
|
||||
def __str__(self):
|
||||
params = [str(self.cache_id), self.cache_device.path,
|
||||
self.cache_mode.name, self.extra_flags]
|
||||
return '\t'.join(params)
|
||||
params = [
|
||||
str(self.cache_id),
|
||||
self.cache_device.path,
|
||||
self.cache_mode.name,
|
||||
self.extra_flags,
|
||||
]
|
||||
return "\t".join(params)
|
||||
|
||||
|
||||
class CoreConfigLine:
|
||||
@@ -89,6 +101,10 @@ class CoreConfigLine:
|
||||
self.extra_flags = extra_flags
|
||||
|
||||
def __str__(self):
|
||||
params = [str(self.cache_id), str(self.core_id),
|
||||
self.core_device.path, self.extra_flags]
|
||||
return '\t'.join(params)
|
||||
params = [
|
||||
str(self.cache_id),
|
||||
str(self.core_id),
|
||||
self.core_device.path,
|
||||
self.extra_flags,
|
||||
]
|
||||
return "\t".join(params)
|
||||
|
||||
Reference in New Issue
Block a user