cli: add tests for agebd service new
This commit is contained in:
+16
-16
@@ -1,5 +1,3 @@
|
||||
from typing import Any, Dict
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from config.paths import Paths
|
||||
@@ -8,6 +6,7 @@ from models import IocsOverview, MasterHLANames, MasterIocSubs, ServiceManagerUI
|
||||
|
||||
class ServicesContext(BaseModel):
|
||||
paths: Paths
|
||||
_write_paths: Paths | None = None
|
||||
|
||||
service_registry: ServiceRegistry
|
||||
master_hla_names: MasterHLANames
|
||||
@@ -15,6 +14,15 @@ class ServicesContext(BaseModel):
|
||||
master_ioc_subs: MasterIocSubs
|
||||
service_manager_ui: ServiceManagerUI
|
||||
|
||||
@property
|
||||
def write_paths(self) -> Paths:
|
||||
"""
|
||||
Mainly used to change the write location in tests
|
||||
"""
|
||||
if self._write_paths is None:
|
||||
return self.paths
|
||||
return self._write_paths
|
||||
|
||||
@classmethod
|
||||
def load_from_disk(cls, paths: Paths) -> "ServicesContext":
|
||||
return cls(
|
||||
@@ -27,7 +35,7 @@ class ServicesContext(BaseModel):
|
||||
)
|
||||
|
||||
def snapshot(self) -> "ServicesContext":
|
||||
"""Creates an in-memory backup of all configs for rollback."""
|
||||
"""Creates an backup of all configs for rollback."""
|
||||
return ServicesContext(
|
||||
paths=self.paths,
|
||||
service_registry=self.service_registry.model_copy(deep=True),
|
||||
@@ -37,18 +45,10 @@ class ServicesContext(BaseModel):
|
||||
service_manager_ui=self.service_manager_ui.model_copy(deep=True),
|
||||
)
|
||||
|
||||
def restore_snapshot(self, snapshot: Dict[str, Any]) -> None:
|
||||
"""Restores state from a backup dictionary."""
|
||||
self.service_registry = snapshot["service_registry"]
|
||||
self.master_hla_names = snapshot["master_hla_names"]
|
||||
self.iocs_overview = snapshot["iocs_overview"]
|
||||
self.master_ioc_subs = snapshot["master_ioc_subs"]
|
||||
self.service_manager_ui = snapshot["service_manager_ui"]
|
||||
|
||||
def write_all(self) -> None:
|
||||
"""Persists all modified objects to disk."""
|
||||
self.service_registry.write_to_file(self.paths.service_registry_file)
|
||||
self.master_hla_names.write_to_file(self.paths.master_hla_names_file)
|
||||
self.iocs_overview.write_to_file(self.paths.iocs_overview_filename)
|
||||
self.master_ioc_subs.write_to_file(self.paths.master_ioc_subs_file)
|
||||
self.service_manager_ui.write_to_file(self.paths.service_manager_ui_file)
|
||||
self.service_registry.write_to_file(self.write_paths.service_registry_file)
|
||||
self.master_hla_names.write_to_file(self.write_paths.master_hla_names_file)
|
||||
self.iocs_overview.write_to_file(self.write_paths.iocs_overview_filename)
|
||||
self.master_ioc_subs.write_to_file(self.write_paths.master_ioc_subs_file)
|
||||
self.service_manager_ui.write_to_file(self.write_paths.service_manager_ui_file)
|
||||
|
||||
Reference in New Issue
Block a user