MAS-WP-0007 is finished. power.sh scales the MX and statute together and records the power annotation. apply.sh keeps an off facility off. The live facility was annotated power=on and was not restarted. Assistant: grok Assistant-Session: 01a198fa-fd27-7e41-a0a2-57355c3e4efd
74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
"""MAS facility power render (MAS-WP-0007). No cluster."""
|
|
|
|
import importlib.util
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
_spec = importlib.util.spec_from_file_location(
|
|
"facility", ROOT / "deploy/railiance/facility.py"
|
|
)
|
|
_facility = importlib.util.module_from_spec(_spec)
|
|
_spec.loader.exec_module(_facility)
|
|
render = _facility.render
|
|
MANIFEST = (ROOT / "deploy/railiance/manifests.yaml").read_text()
|
|
POWER = (ROOT / "deploy/railiance/power.sh").read_text()
|
|
APPLY = (ROOT / "deploy/railiance/apply.sh").read_text()
|
|
IMAGE = "docker.io/library/mas-live:v0.2-480e69a"
|
|
DURABLE = (
|
|
"kind: PersistentVolumeClaim",
|
|
"name: mas-evidence",
|
|
"name: mas-smtp",
|
|
"kind: Ingress",
|
|
"kind: ExternalSecret",
|
|
"name: mas-relay",
|
|
)
|
|
|
|
|
|
def docs(text):
|
|
return text.split("\n---\n")
|
|
|
|
|
|
def deployment(text, name):
|
|
for doc in docs(text):
|
|
if doc.startswith("apiVersion: apps/v1") and f"\n name: {name}\n" in doc:
|
|
return doc
|
|
raise AssertionError(name)
|
|
|
|
|
|
def test_off_stops_both_deployments_and_keeps_durable_objects():
|
|
rendered = render(MANIFEST, IMAGE, "off")
|
|
assert rendered.count("\n replicas: 0\n") == 2
|
|
assert "replicas: 1" not in rendered
|
|
for name in ("mas-mx", "mas-statute"):
|
|
assert "\n replicas: 0\n" in deployment(rendered, name)
|
|
for marker in DURABLE:
|
|
assert marker in rendered
|
|
assert f"image: {IMAGE}" in rendered
|
|
assert "image: IMAGE" not in rendered
|
|
|
|
|
|
def test_on_leaves_one_replica_each():
|
|
rendered = render(MANIFEST, IMAGE, "on")
|
|
assert rendered.count("\n replicas: 1\n") == 2
|
|
assert "replicas: 0" not in rendered
|
|
for marker in DURABLE:
|
|
assert marker in rendered
|
|
|
|
|
|
def test_render_rejects_unknown_power_and_a_blank_image():
|
|
with pytest.raises(ValueError):
|
|
render(MANIFEST, IMAGE, "standby")
|
|
with pytest.raises(ValueError):
|
|
render(MANIFEST, "mas live", "on")
|
|
|
|
|
|
def test_operator_command_does_not_delete_durable_objects():
|
|
assert POWER.startswith("#!/bin/bash\n")
|
|
for script in (POWER, APPLY):
|
|
assert "kubectl delete" not in script
|
|
assert "delete namespace" not in script
|
|
assert "mas-mx" in POWER and "mas-statute" in POWER
|
|
assert "mas.coulomb.social/power" in POWER
|
|
assert "facility.py render" in APPLY
|