← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~tiago.pasqualini/maas:lp1807725 into maas:master

 

Tiago Pasqualini da Silva has proposed merging ~tiago.pasqualini/maas:lp1807725 into maas:master.

Requested reviews:
  MAAS Maintainers (maas-maintainers)
Related bugs:
  Bug #1807725 in MAAS: "[2.5] 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/~tiago.pasqualini/maas/+git/maas/+merge/434000
-- 
Your team MAAS Committers is subscribed to branch maas:master.
diff --git a/src/maasserver/models/staticipaddress.py b/src/maasserver/models/staticipaddress.py
index b5794a1..131f868 100644
--- a/src/maasserver/models/staticipaddress.py
+++ b/src/maasserver/models/staticipaddress.py
@@ -52,7 +52,10 @@ 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_name_based_hostname,
+)
 from provisioningserver.utils.enum import map_enum_reverse
 
 StaticIPAddress = TypeVar("StaticIPAddress")
@@ -841,7 +844,11 @@ 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_name_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/utils/dns.py b/src/maasserver/utils/dns.py
index 0c8cde5..76f553a 100644
--- a/src/maasserver/utils/dns.py
+++ b/src/maasserver/utils/dns.py
@@ -91,6 +91,16 @@ def get_ip_based_hostname(ip):
     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.
 

Follow ups