You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/engine/tests/test_app_durable_admission.py

48 lines
2.0 KiB
Python

"""An unstarted local admission failure must not leave durable uncertainty."""
import asyncio
from contextlib import contextmanager
from test_engine_coordination import local_backends, prepare_hosts, request, running_engine # noqa: F401
from virsh_panel.coordination import current_execution
from virsh_panel.resource_locks import ResourceLockRegistry, ResourceLockTimeout
def test_rescue_template_local_lock_timeout_releases_durable_claim(tmp_path, monkeypatch):
original_hold = ResourceLockRegistry.hold
observed = []
@contextmanager
def injected_timeout(self, resources, *, timeout=5.0):
keys = tuple(resources)
if any(key.startswith("rescue-template:") for key in keys):
execution = current_execution()
assert execution is not None
assert set(keys).issubset(execution.claim.resources)
row = execution.coordinator.snapshot()[execution.claim.token]
assert row["state"] == "active"
observed.append(execution.claim.token)
raise ResourceLockTimeout("injected before template work")
with original_hold(self, keys, timeout=timeout):
yield
monkeypatch.setattr(ResourceLockRegistry, "hold", injected_timeout)
async def run():
async with running_engine(tmp_path) as (engine, _store, services):
await prepare_hosts(engine, "host-a")
services["host-a"].calls.clear()
baseline = engine.coordinator.snapshot()
status, body = await request(
engine, "DELETE",
"/internal/v1/hosts/host-a/rescue-templates/" + "a" * 32,
operation_id="template-local-admission-timeout",
)
assert status == 409, body
assert observed, "the failure must occur inside a durable resource claim"
assert engine.coordinator.snapshot() == baseline
assert services["host-a"].calls == []
assert engine.coordinator.operation_claim("template-local-admission-timeout") is None
asyncio.run(run())