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): def __len__(self):
return len(self.value) return len(self.value)
@classmethod
def is_valid(cls, value):
try:
cls(value)
return True
except ValueError:
return False
@pytest.fixture(scope=_SCOPE) @pytest.fixture(scope=_SCOPE)
def _deployment(_deployment_dir) -> dict: 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 frostfs_testlib.storage.dataclasses.wallet import WalletInfo
from .container import ContainerizedService # TODO: move fixtures into testlib 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]: def dynamic_hosting_config(**fixtures) -> dict[str, Any]:
@ -43,12 +43,22 @@ def _host_config(name: str, containers: list, fixtures: Mapping[str, Any]) -> No
"services": [], "services": [],
"clis": [], "clis": [],
} }
if not Component.is_valid(name):
return
if name == "storage":
for index, container in enumerate(containers): for index, container in enumerate(containers):
host = _from_template(host_template) host = _from_template(host_template)
host["services"].append( 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}", "name": f"frostfs-storage_{index:02}",
"attributes": { "attributes": {
"control_endpoint": f"{container.ip}:8801", "control_endpoint": f"{container.ip}:8801",
@ -59,16 +69,8 @@ def _host_config(name: str, containers: list, fixtures: Mapping[str, Any]) -> No
"wallet_path": container.config["node"]["wallet"]["path"], "wallet_path": container.config["node"]["wallet"]["path"],
}, },
} }
) case "neogo":
host["attributes"]["component_tests_container"] = container return {
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}", "name": f"neo-go_{index:02}",
"attributes": { "attributes": {
"endpoint_internal0": f"http://{container.ip}:30333", "endpoint_internal0": f"http://{container.ip}:30333",
@ -78,16 +80,8 @@ def _host_config(name: str, containers: list, fixtures: Mapping[str, Any]) -> No
"wallet_path": container.config["ApplicationConfiguration"]["Consensus"]["UnlockWallet"]["Path"], "wallet_path": container.config["ApplicationConfiguration"]["Consensus"]["UnlockWallet"]["Path"],
}, },
} }
) case "innerring":
host["attributes"]["component_tests_container"] = container return {
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}", "name": f"frostfs-ir_{index:02}",
"attributes": { "attributes": {
"wallet_config": container.wallet_config, "wallet_config": container.wallet_config,
@ -95,11 +89,8 @@ def _host_config(name: str, containers: list, fixtures: Mapping[str, Any]) -> No
"wallet_path": container.config["wallet"]["path"], "wallet_path": container.config["wallet"]["path"],
}, },
} }
) case _:
host["attributes"]["component_tests_container"] = container raise NotImplementedError(f"service config not implemented: {name}")
host["address"] = container.ip
host["hostname"] = container.name
yield host
def _from_template(template: Mapping[str, Any]) -> Mapping[str, Any]: def _from_template(template: Mapping[str, Any]) -> Mapping[str, Any]: