From 283b08c2a1f1e15795e94d563d0ca45d9f2e0c63 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 27 Jul 2017 16:06:52 +0200 Subject: [PATCH] Fix naming of node with a number in the name Fix #1149 --- gns3server/controller/project.py | 3 ++- tests/controller/test_project.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index f7179c2b..6801cb01 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -368,7 +368,8 @@ class Project: if base_name is None: return None base_name = re.sub(r"[ ]", "", base_name) - base_name = re.sub(r"[0-9]+$", "{0}", base_name) + if base_name in self._allocated_node_names: + base_name = re.sub(r"[0-9]+$", "{0}", 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 diff --git a/tests/controller/test_project.py b/tests/controller/test_project.py index bbc0a5f7..1fd54d47 100644 --- a/tests/controller/test_project.py +++ b/tests/controller/test_project.py @@ -602,6 +602,9 @@ def test_node_name(project, async_run): node = async_run(project.add_node(compute, "VPCS-1", None, node_type="vpcs", properties={"startup_config": "test.cfg"})) assert node.name == "VPCS-2" + node = async_run(project.add_node(compute, "R3", None, node_type="vpcs", properties={"startup_config": "test.cfg"})) + assert node.name == "R3" + def test_add_iou_node_and_check_if_gets_application_id(project, async_run): compute = MagicMock()