mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-23 06:15:13 +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
@@ -14,6 +14,8 @@
|
||||
# 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 pytest
|
||||
|
||||
from gns3server.utils import hostname
|
||||
|
||||
|
||||
@@ -118,3 +120,20 @@ def test_rfc1123_conversion_hostname_with_all_numeric_tld_replaced():
|
||||
|
||||
def rfc1123_hostname_with_multiple_consecutive_invalid_characters():
|
||||
assert hostname.to_rfc1123_hostname("hostname!!!.example..com") == "hostname---.example.com"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"name,node_type,expected",
|
||||
[
|
||||
("MikroTik CCR1072-1G-8S+", "qemu", "MikroTikCCR1072-1G-8S"),
|
||||
("MikroTik RB450G", "qemu", "MikroTikRB450G"),
|
||||
("Cisco IOSv 15.9", "qemu", "CiscoIOSv15.9"),
|
||||
("ubuntu:22.04", "docker", "ubuntu-22.04"),
|
||||
("IOU L2 15.2", "iou", "IOUL215-2"),
|
||||
("c7200+", "dynamips", "c7200"),
|
||||
("PC 1+", "vpcs", "PC1+"),
|
||||
("+++", "qemu", "qemu"),
|
||||
],
|
||||
)
|
||||
def test_template_name_to_node_name(name, node_type, expected):
|
||||
assert hostname.template_name_to_node_name(name, node_type) == expected
|
||||
Reference in new issue
Block a user