mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 03:08:14 +00:00
Prevent locked nodes to be deleted. Fixes https://github.com/GNS3/gns3-gui/issues/2764
This commit is contained in:
parent
4d222ddc0a
commit
2af9c9c8ec
@ -567,6 +567,8 @@ class Project:
|
||||
@open_required
|
||||
async def delete_node(self, node_id):
|
||||
node = self.get_node(node_id)
|
||||
if node.locked:
|
||||
raise aiohttp.web.HTTPConflict(text="Node {} cannot be deleted because it is locked".format(node.name))
|
||||
await self.__delete_node_links(node)
|
||||
self.remove_allocated_node_name(node.name)
|
||||
del self._nodes[node.id]
|
||||
|
@ -189,7 +189,8 @@ class NodeHandler:
|
||||
status_codes={
|
||||
204: "Instance deleted",
|
||||
400: "Invalid request",
|
||||
404: "Instance doesn't exist"
|
||||
404: "Instance doesn't exist",
|
||||
409: "Cannot delete locked node"
|
||||
},
|
||||
description="Delete a node instance")
|
||||
async def delete(request, response):
|
||||
|
@ -257,6 +257,25 @@ def test_delete_node(async_run, controller):
|
||||
project.emit_notification.assert_any_call("node.deleted", node.__json__())
|
||||
|
||||
|
||||
def test_delete_locked_node(async_run, controller):
|
||||
"""
|
||||
For a local server we send the project path
|
||||
"""
|
||||
compute = MagicMock()
|
||||
project = Project(controller=controller, name="Test")
|
||||
project.emit_notification = MagicMock()
|
||||
|
||||
response = MagicMock()
|
||||
response.json = {"console": 2048}
|
||||
compute.post = AsyncioMagicMock(return_value=response)
|
||||
|
||||
node = async_run(project.add_node(compute, "test", None, node_type="vpcs", properties={"startup_config": "test.cfg"}))
|
||||
assert node.id in project._nodes
|
||||
node.locked = True
|
||||
with pytest.raises(aiohttp.web_exceptions.HTTPConflict):
|
||||
async_run(project.delete_node(node.id))
|
||||
|
||||
|
||||
def test_delete_node_delete_link(async_run, controller):
|
||||
"""
|
||||
Delete a node delete all the node connected
|
||||
|
Loading…
Reference in New Issue
Block a user