From d74769c8248e899590e2a24cb892cf69e06b53b1 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 18 Jan 2017 18:28:50 +0100 Subject: [PATCH] Fix duplicate node names Fix https://github.com/GNS3/gns3-gui/issues/1796 --- gns3server/controller/project.py | 15 +-------------- tests/controller/test_node.py | 4 ++++ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index 22f68867..24614236 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -286,7 +286,6 @@ class Project: if base_name is None: return None base_name = re.sub(r"[ ]", "", base_name) - self.remove_allocated_node_name(base_name) if '{0}' in base_name or '{id}' in base_name: # base name is a template, replace {0} or {id} by an unique identifier for number in range(1, 1000000): @@ -306,22 +305,10 @@ class Project: return name raise aiohttp.web.HTTPConflict(text="A node name could not be allocated (node limit reached?)") - def has_allocated_node_name(self, name): - """ - Returns either a node name is already allocated or not. - - :param name: node name - - :returns: boolean - """ - - if name in self._allocated_node_names: - return True - return False - def update_node_name(self, node, new_name): if new_name and node.name != new_name: + self.remove_allocated_node_name(node.name) return self.update_allocated_node_name(new_name) return new_name diff --git a/tests/controller/test_node.py b/tests/controller/test_node.py index 7ccc1b89..f3b6e55a 100644 --- a/tests/controller/test_node.py +++ b/tests/controller/test_node.py @@ -76,6 +76,10 @@ def test_name(compute, project): properties={"startup_script": "echo test"}) assert node.name == "PC2" + # If we change the name to a name already used we patch the name to a free + node.name == "PC1" + assert node.name == "PC2" + def test_eq(compute, project, node, controller): assert node == Node(project, compute, "demo1", node_id=node.id, node_type="qemu")