WIP: Refactor service config to be more DRY

Signed-off-by: Vitaliy Potyarkin <v.potyarkin@yadro.com>
This commit is contained in:
Vitaliy Potyarkin 2025-05-13 12:00:04 +03:00
parent 1b4bb29662
commit 4c4520f81f
2 changed files with 56 additions and 57 deletions

View file

@ -81,6 +81,14 @@ class Component(Enum):
def __len__(self):
return len(self.value)
@classmethod
def is_valid(cls, value):
try:
cls(value)
return True
except ValueError:
return False
@pytest.fixture(scope=_SCOPE)
def _deployment(_deployment_dir) -> dict:

View file

@ -14,7 +14,7 @@ from frostfs_testlib.storage.cluster import Cluster, ClusterNode
from frostfs_testlib.storage.dataclasses.wallet import WalletInfo
from .container import ContainerizedService # TODO: move fixtures into testlib
from .fixtures import _new_wallet, _wallet_public_key
from .fixtures import Component, _new_wallet, _wallet_public_key
def dynamic_hosting_config(**fixtures) -> dict[str, Any]:
@ -43,63 +43,54 @@ def _host_config(name: str, containers: list, fixtures: Mapping[str, Any]) -> No
"services": [],
"clis": [],
}
if not Component.is_valid(name):
return
if name == "storage":
for index, container in enumerate(containers):
host = _from_template(host_template)
host["services"].append(
{
"name": f"frostfs-storage_{index:02}",
"attributes": {
"control_endpoint": f"{container.ip}:8801",
"endpoint_data0": f"{container.ip}:8802",
"endpoint_prometheus": f"{container.ip}:9090",
"wallet_config": container.wallet_config,
"wallet_password": container.config["node"]["wallet"]["password"],
"wallet_path": container.config["node"]["wallet"]["path"],
},
}
)
host["attributes"]["component_tests_container"] = container
host["address"] = container.ip
host["hostname"] = container.name
yield host
elif name == "neogo":
for index, container in enumerate(containers):
host = _from_template(host_template)
host["services"].append(
{
"name": f"neo-go_{index:02}",
"attributes": {
"endpoint_internal0": f"http://{container.ip}:30333",
"endpoint_prometheus": f"{container.ip}:20001",
"wallet_config": container.wallet_config,
"wallet_password": container.config["ApplicationConfiguration"]["Consensus"]["UnlockWallet"]["Password"],
"wallet_path": container.config["ApplicationConfiguration"]["Consensus"]["UnlockWallet"]["Path"],
},
}
)
host["attributes"]["component_tests_container"] = container
host["address"] = container.ip
host["hostname"] = container.name
yield host
elif name == "innerring":
for index, container in enumerate(containers):
host = _from_template(host_template)
host["services"].append(
{
"name": f"frostfs-ir_{index:02}",
"attributes": {
"wallet_config": container.wallet_config,
"wallet_password": container.config["wallet"]["password"],
"wallet_path": container.config["wallet"]["path"],
},
}
)
host["attributes"]["component_tests_container"] = container
host["address"] = container.ip
host["hostname"] = container.name
yield host
for index, container in enumerate(containers):
host = _from_template(host_template)
host["services"].append(_service_config(**locals()))
host["attributes"]["component_tests_container"] = container
host["address"] = container.ip
host["hostname"] = container.name
yield host
def _service_config(name, index, container, **kw):
match name:
case "storage":
return {
"name": f"frostfs-storage_{index:02}",
"attributes": {
"control_endpoint": f"{container.ip}:8801",
"endpoint_data0": f"{container.ip}:8802",
"endpoint_prometheus": f"{container.ip}:9090",
"wallet_config": container.wallet_config,
"wallet_password": container.config["node"]["wallet"]["password"],
"wallet_path": container.config["node"]["wallet"]["path"],
},
}
case "neogo":
return {
"name": f"neo-go_{index:02}",
"attributes": {
"endpoint_internal0": f"http://{container.ip}:30333",
"endpoint_prometheus": f"{container.ip}:20001",
"wallet_config": container.wallet_config,
"wallet_password": container.config["ApplicationConfiguration"]["Consensus"]["UnlockWallet"]["Password"],
"wallet_path": container.config["ApplicationConfiguration"]["Consensus"]["UnlockWallet"]["Path"],
},
}
case "innerring":
return {
"name": f"frostfs-ir_{index:02}",
"attributes": {
"wallet_config": container.wallet_config,
"wallet_password": container.config["wallet"]["password"],
"wallet_path": container.config["wallet"]["path"],
},
}
case _:
raise NotImplementedError(f"service config not implemented: {name}")
def _from_template(template: Mapping[str, Any]) -> Mapping[str, Any]: