mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-19 12:45:19 +02:00
fix: roll back a node update the compute refused
A compute 409 (for instance "must be stopped to change the console type to vnc") left every value that had already been applied locally on the controller node, because the update loop sets them before the PUT. Nothing was dumped at that point, but project.dump() serializes the whole topology: the next successful change anywhere in the project wrote the refused values to disk, and the next project open recreated the node with them — this time accepted by a stopped node. A refused change silently landed later. Restore the applied properties, the node properties, custom adapters, missing images and the derived ports before re-raising, the way the degraded-image create() path already cleans up after its own failure.
This commit is contained in:
2 files changed
+44
No files matched your search
@@ -811,6 +811,36 @@ async def test_update_properties(node, compute, controller):
|
||||
# controller._notification.emit.assert_called_with("node.updated", node_notif)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_rolls_back_when_compute_refuses(node, compute, project, controller):
|
||||
"""
|
||||
Values applied locally before the PUT must be rolled back when the compute
|
||||
refuses the update: kept in memory they describe a node the compute never
|
||||
accepted, and the next project dump persists them — the refused change
|
||||
would then silently land the next time the node is created.
|
||||
"""
|
||||
|
||||
async def resp(*args, **kwargs):
|
||||
raise ComputeConflictError(
|
||||
f"/projects/{project.id}/vpcs/nodes/{node.id}",
|
||||
{"message": '"demo" must be stopped to change the console type to telnet'},
|
||||
)
|
||||
|
||||
compute.put = AsyncioMagicMock(side_effect=resp)
|
||||
controller._notification = AsyncioMagicMock()
|
||||
project.dump = MagicMock()
|
||||
old_json = node.asdict()
|
||||
|
||||
with pytest.raises(ComputeConflictError):
|
||||
await node.update(x=42, console_type="telnet", name="renamed", properties={"startup_script": "changed"})
|
||||
|
||||
assert node.name == "demo"
|
||||
assert node.console_type == "vnc"
|
||||
assert node.properties == {"startup_script": "echo test"}
|
||||
assert node.asdict() == old_json
|
||||
assert not project.dump.called
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_only_controller(node, compute):
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user