feat: expand domain schema and seed profiles
This commit is contained in:
+40
-29
@@ -1,40 +1,51 @@
|
||||
"""Deterministic seed profile tests."""
|
||||
|
||||
from app.simulation.seed import small_profile, stable_id
|
||||
import pytest
|
||||
|
||||
from app.simulation.seed import build_profile, large_profile, small_profile, stable_id
|
||||
|
||||
|
||||
def test_small_profile_has_stable_logical_state() -> None:
|
||||
def test_small_profile_matches_required_logical_shape() -> None:
|
||||
first = small_profile()
|
||||
second = small_profile()
|
||||
|
||||
assert first == second
|
||||
assert first.logical_state() == {
|
||||
"profile": "small",
|
||||
"nodes": [
|
||||
{"name": "pve1", "status": "online"},
|
||||
{"name": "pve2", "status": "online"},
|
||||
],
|
||||
"resources": [
|
||||
{
|
||||
"kind": "qemu",
|
||||
"external_id": "100",
|
||||
"node": "pve1",
|
||||
"state": {"name": "demo", "status": "stopped"},
|
||||
},
|
||||
{
|
||||
"kind": "qemu",
|
||||
"external_id": "101",
|
||||
"node": "pve1",
|
||||
"state": {"name": "worker", "status": "stopped"},
|
||||
},
|
||||
{
|
||||
"kind": "storage",
|
||||
"external_id": "local",
|
||||
"node": "pve1",
|
||||
"state": {"content": ["iso", "backup"]},
|
||||
},
|
||||
],
|
||||
}
|
||||
state = first.logical_state()
|
||||
assert state == second.logical_state()
|
||||
assert state["nodes"] == [{"name": "pve1", "status": "online"}]
|
||||
resources = state["resources"]
|
||||
assert isinstance(resources, list)
|
||||
assert [resource["kind"] for resource in resources].count("qemu") == 2
|
||||
assert [resource["kind"] for resource in resources].count("lxc") == 1
|
||||
assert [resource["kind"] for resource in resources].count("storage") == 2
|
||||
tasks = state["tasks"]
|
||||
assert isinstance(tasks, list)
|
||||
assert len(tasks) == 2
|
||||
|
||||
|
||||
def test_medium_and_fault_profiles_are_deterministic() -> None:
|
||||
medium = build_profile("medium")
|
||||
assert len(medium.nodes) == 3
|
||||
assert sum(resource.kind == "qemu" for resource in medium.resources) == 50
|
||||
assert sum(resource.kind == "lxc" for resource in medium.resources) == 20
|
||||
assert build_profile("ha-demo") == build_profile("ha-demo")
|
||||
broken = build_profile("broken-storage")
|
||||
assert any(resource.state.get("status") == "offline" for resource in broken.resources)
|
||||
|
||||
|
||||
def test_large_profile_is_configurable_and_stable() -> None:
|
||||
first = large_profile(node_count=4, resource_count=1_000)
|
||||
second = large_profile(node_count=4, resource_count=1_000)
|
||||
assert first == second
|
||||
assert len(first.nodes) == 4
|
||||
assert len(first.resources) == 1_000
|
||||
|
||||
|
||||
def test_profile_validation() -> None:
|
||||
with pytest.raises(ValueError, match="unknown seed profile"):
|
||||
build_profile("missing")
|
||||
with pytest.raises(ValueError, match="positive"):
|
||||
large_profile(node_count=0, resource_count=1)
|
||||
|
||||
|
||||
def test_stable_ids_are_namespaced_and_repeatable() -> None:
|
||||
|
||||
Reference in New Issue
Block a user