diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index 25205441..f4913d1b 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import re import os import json import uuid @@ -282,6 +283,7 @@ 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 diff --git a/tests/controller/test_project.py b/tests/controller/test_project.py index 4024e944..1fec7320 100644 --- a/tests/controller/test_project.py +++ b/tests/controller/test_project.py @@ -539,3 +539,20 @@ def test_suspend_all(project, async_run): compute.post = AsyncioMagicMock() async_run(project.suspend_all()) assert len(compute.post.call_args_list) == 10 + + +def test_node_name(project, async_run): + compute = MagicMock() + compute.id = "local" + response = MagicMock() + response.json = {"console": 2048} + compute.post = AsyncioMagicMock(return_value=response) + + node = async_run(project.add_node(compute, "test-{0}", None, node_type="vpcs", properties={"startup_config": "test.cfg"})) + assert node.name == "test-1" + node = async_run(project.add_node(compute, "test-{0}", None, node_type="vpcs", properties={"startup_config": "test.cfg"})) + assert node.name == "test-2" + node = async_run(project.add_node(compute, "hello world-{0}", None, node_type="vpcs", properties={"startup_config": "test.cfg"})) + assert node.name == "helloworld-1" + node = async_run(project.add_node(compute, "hello world-{0}", None, node_type="vpcs", properties={"startup_config": "test.cfg"})) + assert node.name == "helloworld-2"