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

Strip space from all nodes names

Fix #727
This commit is contained in:
Julien Duponchelle 2016-10-18 11:11:45 +02:00
parent a8ffaa9cb5
commit dd849f7945
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 19 additions and 0 deletions

View File

@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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

View File

@ -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"