fix: release consumed restore references and explain deletion protection [skip ci]
This commit is contained in:
@@ -145,6 +145,105 @@ def test_delete_restore_reference_protected(service):
|
||||
service.process_one()
|
||||
assert service.operation(delete)["status"] == "FAILED"
|
||||
assert service.operation(delete)["error"]["code"] == "CONFLICT"
|
||||
assert (
|
||||
service.operation(delete)["error"]["details"]["reason"]
|
||||
== "RESTORE_IMAGE_PROTECTED"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("automatic", [True, False])
|
||||
def test_completed_restore_consumes_self_reference(client, service, automatic):
|
||||
display = submit(service, 60, True)
|
||||
service.process_one()
|
||||
service.sync()
|
||||
if automatic:
|
||||
expired(service, display)
|
||||
service.expire()
|
||||
else:
|
||||
service.submit("restore", {}, "living-room", "admin", "restore-test")
|
||||
service.process_one()
|
||||
service.sync()
|
||||
assert service.state("living-room")["previous_image_id"] is None
|
||||
assert not client.get("/api/v1/devices/living-room").json()["can_restore"]
|
||||
delete = service.submit(
|
||||
"delete",
|
||||
{"image_id": 1, "confirm_current": True},
|
||||
"living-room",
|
||||
"admin",
|
||||
"delete-restored",
|
||||
)
|
||||
service.process_one()
|
||||
assert service.operation(delete)["status"] == "COMPLETED"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("via_delete", [False, True])
|
||||
def test_existing_self_reference_is_repaired(client, service, via_delete):
|
||||
service.state("living-room")
|
||||
service.db.execute(
|
||||
"UPDATE device_state SET previous_image_id=1,managed_image_id=1 WHERE device_id=?",
|
||||
("living-room",),
|
||||
)
|
||||
if via_delete:
|
||||
operation = service.submit(
|
||||
"delete",
|
||||
{"image_id": 1, "confirm_current": True},
|
||||
"living-room",
|
||||
"admin",
|
||||
"delete-stale-reference",
|
||||
)
|
||||
service.process_one()
|
||||
assert service.operation(operation)["status"] == "COMPLETED"
|
||||
else:
|
||||
assert not client.get("/api/v1/devices/living-room?refresh=true").json()[
|
||||
"can_restore"
|
||||
]
|
||||
assert service.state("living-room")["previous_image_id"] is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"protection",
|
||||
["override", "base", "unsynced", "unknown", "syncing", "other_previous"],
|
||||
)
|
||||
def test_self_reference_cleanup_preserves_real_restore_requirements(
|
||||
service, protection
|
||||
):
|
||||
service.state("living-room")
|
||||
service.db.execute(
|
||||
"UPDATE device_state SET previous_image_id=1,managed_image_id=1 WHERE device_id=?",
|
||||
("living-room",),
|
||||
)
|
||||
device = service.registry.get("living-room").device()
|
||||
if protection == "override":
|
||||
service.db.execute(
|
||||
"INSERT INTO overrides VALUES(?,?,?,?,?,?)",
|
||||
("active", "living-room", 1, 50, "2099-01-01", "2026-01-01"),
|
||||
)
|
||||
elif protection == "base":
|
||||
service.db.execute(
|
||||
"UPDATE device_state SET base_image_id=1 WHERE device_id=?",
|
||||
("living-room",),
|
||||
)
|
||||
elif protection == "unsynced":
|
||||
device = device.model_copy(
|
||||
update={
|
||||
"current_content": device.current_content.model_copy(
|
||||
update={"synced": False}
|
||||
)
|
||||
}
|
||||
)
|
||||
elif protection in ("unknown", "syncing"):
|
||||
operation = submit(service)
|
||||
service._start_write(operation)
|
||||
service.update(operation, protection.upper())
|
||||
else:
|
||||
service.db.execute(
|
||||
"UPDATE device_state SET previous_image_id=2 WHERE device_id=?",
|
||||
("living-room",),
|
||||
)
|
||||
service.clear_self_restore_reference("living-room", device)
|
||||
assert service.state("living-room")["previous_image_id"] == (
|
||||
2 if protection == "other_previous" else 1
|
||||
)
|
||||
|
||||
|
||||
def test_offline(service):
|
||||
|
||||
Reference in New Issue
Block a user