Refactor public API around environments
This commit is contained in:
parent
57dae52cc2
commit
5d5243df23
41 changed files with 1301 additions and 459 deletions
|
|
@ -27,7 +27,7 @@ def test_create_server_registers_vm_tools(tmp_path: Path) -> None:
|
|||
tool_names = asyncio.run(_run())
|
||||
assert "vm_create" in tool_names
|
||||
assert "vm_exec" in tool_names
|
||||
assert "vm_list_profiles" in tool_names
|
||||
assert "vm_list_environments" in tool_names
|
||||
assert "vm_network_info" in tool_names
|
||||
assert "vm_run" in tool_names
|
||||
assert "vm_status" in tool_names
|
||||
|
|
@ -54,7 +54,7 @@ def test_vm_run_round_trip(tmp_path: Path) -> None:
|
|||
await server.call_tool(
|
||||
"vm_run",
|
||||
{
|
||||
"profile": "debian-git",
|
||||
"environment": "debian:12",
|
||||
"command": "printf 'git version 2.0\\n'",
|
||||
"vcpu_count": 1,
|
||||
"mem_mib": 512,
|
||||
|
|
@ -95,19 +95,24 @@ def test_vm_tools_status_stop_delete_and_reap(tmp_path: Path) -> None:
|
|||
dict[str, Any],
|
||||
]:
|
||||
server = create_server(manager=manager)
|
||||
profiles_raw = await server.call_tool("vm_list_profiles", {})
|
||||
if not isinstance(profiles_raw, tuple) or len(profiles_raw) != 2:
|
||||
raise TypeError("unexpected profiles result")
|
||||
_, profiles_structured = profiles_raw
|
||||
if not isinstance(profiles_structured, dict):
|
||||
raise TypeError("profiles tool should return a dictionary")
|
||||
raw_profiles = profiles_structured.get("result")
|
||||
if not isinstance(raw_profiles, list):
|
||||
raise TypeError("profiles tool did not contain a result list")
|
||||
environments_raw = await server.call_tool("vm_list_environments", {})
|
||||
if not isinstance(environments_raw, tuple) or len(environments_raw) != 2:
|
||||
raise TypeError("unexpected environments result")
|
||||
_, environments_structured = environments_raw
|
||||
if not isinstance(environments_structured, dict):
|
||||
raise TypeError("environments tool should return a dictionary")
|
||||
raw_environments = environments_structured.get("result")
|
||||
if not isinstance(raw_environments, list):
|
||||
raise TypeError("environments tool did not contain a result list")
|
||||
created = _extract_structured(
|
||||
await server.call_tool(
|
||||
"vm_create",
|
||||
{"profile": "debian-base", "vcpu_count": 1, "mem_mib": 512, "ttl_seconds": 600},
|
||||
{
|
||||
"environment": "debian:12-base",
|
||||
"vcpu_count": 1,
|
||||
"mem_mib": 512,
|
||||
"ttl_seconds": 600,
|
||||
},
|
||||
)
|
||||
)
|
||||
vm_id = str(created["vm_id"])
|
||||
|
|
@ -120,7 +125,12 @@ def test_vm_tools_status_stop_delete_and_reap(tmp_path: Path) -> None:
|
|||
expiring = _extract_structured(
|
||||
await server.call_tool(
|
||||
"vm_create",
|
||||
{"profile": "debian-base", "vcpu_count": 1, "mem_mib": 512, "ttl_seconds": 1},
|
||||
{
|
||||
"environment": "debian:12-base",
|
||||
"vcpu_count": 1,
|
||||
"mem_mib": 512,
|
||||
"ttl_seconds": 1,
|
||||
},
|
||||
)
|
||||
)
|
||||
expiring_id = str(expiring["vm_id"])
|
||||
|
|
@ -131,16 +141,16 @@ def test_vm_tools_status_stop_delete_and_reap(tmp_path: Path) -> None:
|
|||
network,
|
||||
stopped,
|
||||
deleted,
|
||||
cast(list[dict[str, object]], raw_profiles),
|
||||
cast(list[dict[str, object]], raw_environments),
|
||||
reaped,
|
||||
)
|
||||
|
||||
status, network, stopped, deleted, profiles, reaped = asyncio.run(_run())
|
||||
status, network, stopped, deleted, environments, reaped = asyncio.run(_run())
|
||||
assert status["state"] == "started"
|
||||
assert network["network_enabled"] is False
|
||||
assert stopped["state"] == "stopped"
|
||||
assert bool(deleted["deleted"]) is True
|
||||
assert profiles[0]["name"] == "debian-base"
|
||||
assert environments[0]["name"] == "debian:12"
|
||||
assert int(reaped["count"]) == 1
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue