feat(host): emit steps during initialize_instance
This commit is contained in:
parent
700b5be6f8
commit
d977098344
2 changed files with 18 additions and 0 deletions
|
|
@ -32,6 +32,7 @@ def initialize_instance(
|
|||
root = get_left4me_root() if root is None else Path(root)
|
||||
spec = load_spec(spec_path)
|
||||
|
||||
_emit_step("creating instance directories...", on_stdout, passthrough)
|
||||
instance_dir = root / "instances" / name
|
||||
runtime_dir = root / "runtime" / name
|
||||
(runtime_dir / "upper").mkdir(parents=True, exist_ok=True)
|
||||
|
|
@ -42,6 +43,7 @@ def initialize_instance(
|
|||
lowerdirs = [str(overlay_path(overlay, root=root)) for overlay in spec.overlays]
|
||||
lowerdirs.append(str(root / "installation"))
|
||||
|
||||
_emit_step("writing instance.env...", on_stdout, passthrough)
|
||||
instance_env = "\n".join(
|
||||
[
|
||||
f"L4D2_PORT={spec.port}",
|
||||
|
|
@ -51,8 +53,10 @@ def initialize_instance(
|
|||
) + "\n"
|
||||
(instance_dir / "instance.env").write_text(instance_env)
|
||||
|
||||
_emit_step("writing server.cfg...", on_stdout, passthrough)
|
||||
server_cfg = "\n".join(spec.config) if spec.config else ""
|
||||
(instance_dir / "server.cfg").write_text(server_cfg)
|
||||
_emit_step("initialization complete.", on_stdout, passthrough)
|
||||
|
||||
|
||||
def _load_instance_env(path: Path) -> dict[str, str]:
|
||||
|
|
|
|||
|
|
@ -51,3 +51,17 @@ def test_emit_step_uses_passthrough_stdout(monkeypatch) -> None:
|
|||
def test_emit_step_does_nothing_if_no_target() -> None:
|
||||
_emit_step("silent step", on_stdout=None, passthrough=False)
|
||||
|
||||
|
||||
def test_initialize_instance_emits_steps(tmp_path: Path) -> None:
|
||||
spec = tmp_path / "spec.yaml"
|
||||
spec.write_text("port: 27015\noverlays: [standard]\n")
|
||||
|
||||
steps: list[str] = []
|
||||
initialize_instance("alpha", spec, root=tmp_path, on_stdout=steps.append)
|
||||
|
||||
assert steps == [
|
||||
"Step: creating instance directories...",
|
||||
"Step: writing instance.env...",
|
||||
"Step: writing server.cfg...",
|
||||
"Step: initialization complete.",
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in a new issue