forked from TrueCloudLab/frostfs-testlib
65 lines
1.7 KiB
Python
65 lines
1.7 KiB
Python
from abc import ABC, abstractmethod
|
|
from typing import Any
|
|
|
|
|
|
class ServiceConfigurationYml(ABC):
|
|
"""
|
|
Class to manipulate yml configuration for service
|
|
"""
|
|
|
|
def _find_option(self, key: str, data: dict):
|
|
tree = key.split(":")
|
|
current = data
|
|
for node in tree:
|
|
if isinstance(current, list) and len(current) - 1 >= int(node):
|
|
current = current[int(node)]
|
|
continue
|
|
|
|
if node not in current:
|
|
return None
|
|
|
|
current = current[node]
|
|
|
|
return current
|
|
|
|
def _set_option(self, key: str, value: Any, data: dict):
|
|
tree = key.split(":")
|
|
current = data
|
|
for node in tree[:-1]:
|
|
if isinstance(current, list) and len(current) - 1 >= int(node):
|
|
current = current[int(node)]
|
|
continue
|
|
|
|
if node not in current:
|
|
current[node] = {}
|
|
|
|
current = current[node]
|
|
|
|
current[tree[-1]] = value
|
|
|
|
@abstractmethod
|
|
def get(self, key: str) -> str:
|
|
"""
|
|
Get parameter value from current configuration
|
|
|
|
Args:
|
|
key: key of the parameter in yaml format like 'storage:shard:default:resync_metabase'
|
|
|
|
Returns:
|
|
value of the parameter
|
|
"""
|
|
|
|
@abstractmethod
|
|
def set(self, values: dict[str, Any]):
|
|
"""
|
|
Sets parameters to configuration
|
|
|
|
Args:
|
|
values: dict where key is the key of the parameter in yaml format like 'storage:shard:default:resync_metabase' and value is the value of the option to set
|
|
"""
|
|
|
|
@abstractmethod
|
|
def revert(self):
|
|
"""
|
|
Revert changes
|
|
"""
|