From 061af38b5a1c518087fc378354211e92133b5f64 Mon Sep 17 00:00:00 2001 From: grossmj Date: Thu, 23 Nov 2017 11:19:41 +0700 Subject: [PATCH] Make sure connected links are removed when a node is deleted. --- gns3server/compute/base_manager.py | 6 ++++-- gns3server/controller/project.py | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/gns3server/compute/base_manager.py b/gns3server/compute/base_manager.py index d233fb8d..59e9c90a 100644 --- a/gns3server/compute/base_manager.py +++ b/gns3server/compute/base_manager.py @@ -335,8 +335,10 @@ class BaseManager: :returns: Node instance """ - node = yield from self.close_node(node_id) - node.project.emit("node.deleted", node) + try: + node = yield from self.close_node(node_id) + finally: + node.project.emit("node.deleted", node) yield from node.project.remove_node(node) if node.id in self._nodes: del self._nodes[node.id] diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index ef8934ee..6c99431b 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -474,7 +474,7 @@ class Project: """ for link in list(self._links.values()): if node in link.nodes: - yield from self.delete_link(link.id) + yield from self.delete_link(link.id, force_delete=True) @open_required @asyncio.coroutine @@ -565,10 +565,14 @@ class Project: @open_required @asyncio.coroutine - def delete_link(self, link_id): + def delete_link(self, link_id, force_delete=False): link = self.get_link(link_id) del self._links[link.id] - yield from link.delete() + try: + yield from link.delete() + except Exception: + if force_delete is False: + raise self.dump() self.controller.notification.emit("link.deleted", link.__json__()) @@ -789,7 +793,7 @@ class Project: yield from link.add_node(node, node_link["adapter_number"], node_link["port_number"], label=node_link.get("label"), dump=False) if len(link.nodes) != 2: # a link should have 2 attached nodes, this can happen with corrupted projects - yield from self.delete_link(link.id) + yield from self.delete_link(link.id, force_delete=True) for drawing_data in topology.get("drawings", []): yield from self.add_drawing(dump=False, **drawing_data)