mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-20 13:15:14 +02:00
fix(controller): make node names from template names valid hostnames
Creating a node from a template whose name has characters invalid in a hostname, such as "MikroTik CCR1072-1G-8S+", failed on the compute with "'MikroTikCCR1072-1G-8S+-1' is an invalid name to create a Qemu node": the template name was only stripped of spaces. Replace the other invalid characters by hyphens, following the rules the compute validates node names with (RFC 1123 for Qemu and Docker, IOS for Dynamips and IOU), as project import already does for existing nodes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b9cf9158ca
commit
dd69a01fba
4 files changed
+69
-1
No files matched your search
@@ -253,6 +253,35 @@ async def test_add_node_from_template_seeds_default_credentials(controller):
|
||||
assert "default_password" not in node.properties
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_node_from_template_name_invalid_in_hostname(controller):
|
||||
"""
|
||||
A template name with characters invalid in a hostname (e.g. "+" in a model name)
|
||||
gives node names the compute accepts.
|
||||
"""
|
||||
|
||||
compute = MagicMock()
|
||||
compute.id = "local"
|
||||
controller._computes["local"] = compute
|
||||
project = Project(controller=controller, name="Test")
|
||||
project.emit_notification = MagicMock()
|
||||
|
||||
response = MagicMock()
|
||||
response.json = {"console": 2048}
|
||||
compute.post = AsyncioMagicMock(return_value=response)
|
||||
|
||||
template = {
|
||||
"name": "MikroTik CCR1072-1G-8S+",
|
||||
"template_type": "qemu",
|
||||
"compute_id": "local",
|
||||
"default_name_format": "{name}-{0}",
|
||||
"properties": {},
|
||||
}
|
||||
|
||||
node = await project.add_node_from_template(template)
|
||||
assert node.name == "MikroTikCCR1072-1G-8S-1"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_node_non_local(controller):
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user