sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #08978
[Merge] ~lloydwaltersj/maas:backport-1807725-3.2 into maas:3.2
Jack Lloyd-Walters has proposed merging ~lloydwaltersj/maas:backport-1807725-3.2 into maas:3.2.
Commit message:
backport 1807725
Requested reviews:
MAAS Maintainers (maas-maintainers)
Related bugs:
Bug #1807725 in MAAS: "Machine interfaces allow '_' character, results on a interface based domain breaking bind (as it doesn't allow it for the host part)."
https://bugs.launchpad.net/maas/+bug/1807725
For more details, see:
https://code.launchpad.net/~lloydwaltersj/maas/+git/maas/+merge/444180
--
Your team MAAS Committers is subscribed to branch maas:3.2.
diff --git a/src/maasserver/models/staticipaddress.py b/src/maasserver/models/staticipaddress.py
index 469e405..57d1c46 100644
--- a/src/maasserver/models/staticipaddress.py
+++ b/src/maasserver/models/staticipaddress.py
@@ -50,7 +50,7 @@ from maasserver.models.domain import Domain
from maasserver.models.subnet import Subnet
from maasserver.models.timestampedmodel import TimestampedModel
from maasserver.utils import orm
-from maasserver.utils.dns import get_ip_based_hostname
+from maasserver.utils.dns import get_ip_based_hostname, get_iface_based_hostname
from provisioningserver.utils.enum import map_enum_reverse
_mapping_base_fields = (
@@ -755,7 +755,8 @@ class StaticIPAddressManager(Manager):
# node, then consider adding the IP.
if result.assigned or not assigned_ips[result.fqdn]:
if result.ip not in mapping[result.fqdn].ips:
- entry = mapping[f"{result.iface_name}.{result.fqdn}"]
+ fqdn = "{}.{}".format(get_iface_based_hostname(result.iface_name), result.fqdn)
+ entry = mapping[fqdn]
entry.node_type = result.node_type
entry.system_id = result.system_id
if result.user_id is not None:
diff --git a/src/maasserver/models/tests/test_staticipaddress.py b/src/maasserver/models/tests/test_staticipaddress.py
index 6ec2ec7..77c8b72 100644
--- a/src/maasserver/models/tests/test_staticipaddress.py
+++ b/src/maasserver/models/tests/test_staticipaddress.py
@@ -50,7 +50,7 @@ from maasserver.testing.testcase import (
MAASTransactionServerTestCase,
)
from maasserver.utils import orm
-from maasserver.utils.dns import get_ip_based_hostname
+from maasserver.utils.dns import get_ip_based_hostname, get_iface_based_hostname
from maasserver.utils.orm import reload_object, transactional
from maasserver.websockets.base import dehydrate_datetime
@@ -482,6 +482,46 @@ class TestStaticIPAddressManagerMapping(MAASServerTestCase):
),
}
self.assertEqual(expected, mapping)
+
+ def test_get_hostname_ip_mapping_sanitized_iface_name(self):
+ hostname = factory.make_name("hostname")
+ domainname = factory.make_name("domain")
+ factory.make_Domain(name=domainname)
+ full_hostname = f"{hostname}.{domainname}"
+ subnet = factory.make_Subnet()
+ node = factory.make_Node_with_Interface_on_Subnet(
+ extra_ifnames=["eth_1"],
+ hostname=full_hostname,
+ interface_count=2,
+ subnet=subnet,
+ )
+ boot_interface = node.get_boot_interface()
+ staticip = factory.make_StaticIPAddress(
+ alloc_type=IPADDRESS_TYPE.STICKY,
+ ip=factory.pick_ip_in_Subnet(subnet),
+ subnet=subnet,
+ interface=boot_interface,
+ )
+ iface2 = node.current_config.interface_set.exclude(
+ id=boot_interface.id
+ ).first()
+ sip2 = factory.make_StaticIPAddress(
+ alloc_type=IPADDRESS_TYPE.STICKY,
+ ip=factory.pick_ip_in_Subnet(subnet),
+ subnet=subnet,
+ interface=iface2,
+ )
+ mapping = StaticIPAddress.objects.get_hostname_ip_mapping(subnet)
+ sanitized_if2name = get_iface_name_based_hostname(iface2.name)
+ expected = {
+ full_hostname: HostnameIPMapping(
+ node.system_id, 30, {staticip.ip}, node.node_type
+ ),
+ "%s.%s"
+ % (sanitized_if2name, full_hostname): HostnameIPMapping(
+ node.system_id, 30, {sip2.ip}, node.node_type
+ ),
+ }
def make_mapping(self, node, raw_ttl=False):
if raw_ttl or node.address_ttl is not None:
diff --git a/src/maasserver/utils/dns.py b/src/maasserver/utils/dns.py
index 0c8cde5..3448901 100644
--- a/src/maasserver/utils/dns.py
+++ b/src/maasserver/utils/dns.py
@@ -90,6 +90,15 @@ def get_ip_based_hostname(ip):
hostname = str(IPAddress(ip).ipv6()).replace(":", "-")
return hostname
+def get_iface_name_based_hostname(iface_name):
+ """Given the specified interface name, creates an automatically generated
+ hostname by converting the '_' characters in it to '-' characters.
+
+ :param iface_name: Input value for the interface name.
+ """
+ hostname = iface_name.replace("_", "-")
+ return hostname
+
def validate_url(url, schemes=("http", "https")):
"""Validator for URLs.
diff --git a/src/maasserver/utils/tests/test_dns.py b/src/maasserver/utils/tests/test_dns.py
index e6be8ab..641cd1d 100644
--- a/src/maasserver/utils/tests/test_dns.py
+++ b/src/maasserver/utils/tests/test_dns.py
@@ -9,6 +9,7 @@ from testtools.matchers import Equals, HasLength
from maasserver.utils.dns import (
get_ip_based_hostname,
+ get_iface_name_based_hostname,
validate_domain_name,
validate_hostname,
validate_url,
@@ -244,3 +245,10 @@ class TestIpBasedHostnameGenerator(MAASTestCase):
get_ip_based_hostname("2001:67c:1562::15"),
Equals("2001-67c-1562--15"),
)
+
+class TestIfaceBasedHostnameGenerator(MAASTestCase):
+ def test_interface_name_changed(self):
+ self.assertEqual(get_iface_name_based_hostname("eth_0"), "eth-0")
+
+ def test_interface_name_unchanged(self):
+ self.assertEqual(get_iface_name_based_hostname("eth0"), "eth0")
\ No newline at end of file
Follow ups