frostfs-testlib/src/frostfs_testlib/storage/service_registry.py
Andrey Berezin 997e768e92 Move shared code to testlib
Signed-off-by: Andrey Berezin <a.berezin@yadro.com>
2023-05-14 13:43:59 +03:00

21 lines
780 B
Python

from frostfs_testlib.storage.dataclasses.node_base import NodeBase, NodeClassDict, ServiceClass
class ServiceRegistry:
_class_mapping: dict[str, NodeClassDict] = {}
def get_entry(self, service_type: type[ServiceClass]) -> NodeClassDict:
key = service_type.__name__
if key not in self._class_mapping:
raise RuntimeError(
f"Unregistered service type requested: {key}. At this moment registered services are: {self._class_mapping.keys()}"
)
return self._class_mapping[key]
def register_service(self, service_name: str, service_class: type[NodeBase]):
self._class_mapping[service_class.__name__] = {
"cls": service_class,
"hosting_service_name": service_name,
}