1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-30 20:28:08 +00:00

Prevent locked nodes to be deleted. Fixes https://github.com/GNS3/gns3-gui/issues/2764

This commit is contained in:
grossmj 2019-04-10 15:43:51 +07:00
parent 4d222ddc0a
commit 2af9c9c8ec
3 changed files with 23 additions and 1 deletions

View File

@ -567,6 +567,8 @@ class Project:
@open_required @open_required
async def delete_node(self, node_id): async def delete_node(self, node_id):
node = self.get_node(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) await self.__delete_node_links(node)
self.remove_allocated_node_name(node.name) self.remove_allocated_node_name(node.name)
del self._nodes[node.id] del self._nodes[node.id]

View File

@ -189,7 +189,8 @@ class NodeHandler:
status_codes={ status_codes={
204: "Instance deleted", 204: "Instance deleted",
400: "Invalid request", 400: "Invalid request",
404: "Instance doesn't exist" 404: "Instance doesn't exist",
409: "Cannot delete locked node"
}, },
description="Delete a node instance") description="Delete a node instance")
async def delete(request, response): async def delete(request, response):

View File

@ -257,6 +257,25 @@ def test_delete_node(async_run, controller):
project.emit_notification.assert_any_call("node.deleted", node.__json__()) 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): def test_delete_node_delete_link(async_run, controller):
""" """
Delete a node delete all the node connected Delete a node delete all the node connected