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

Proposed by Tiago Pasqualini da Silva
Status: Superseded
Proposed branch: ~tiago.pasqualini/maas:lp1807725
Merge into: maas:master
Diff against target: 49 lines (+19/-2)
2 files modified
src/maasserver/models/staticipaddress.py (+9/-2)
src/maasserver/utils/dns.py (+10/-0)
Reviewer Review Type Date Requested Status
MAAS Lander Needs Fixing
MAAS Maintainers Pending
Review via email: mp+434000@code.launchpad.net

This proposal has been superseded by a proposal from 2022-12-02.

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1807725 lp:~tiago.pasqualini/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/1547/consoleText
COMMIT: d5b537062408b0f05dbbe98bc95f21e4d542ca41

review: Needs Fixing

Unmerged commits

a3337f1... by Tiago Pasqualini da Silva

Fix incorrect hostname from interface name

MAAS currently creates a DNS record for each interface in a host
by simply using its interface name. Whenever an interface has the
'_' character, the code uses it anyway, which is currently breaking
bind as this character is not allowed on domain names.
This patch fixes that by verifying it and replacing the incorrect
character.

LP: #1807725

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/models/staticipaddress.py b/src/maasserver/models/staticipaddress.py
2index b5794a1..81c7a82 100644
3--- a/src/maasserver/models/staticipaddress.py
4+++ b/src/maasserver/models/staticipaddress.py
5@@ -52,7 +52,10 @@ from maasserver.models.domain import Domain
6 from maasserver.models.subnet import Subnet
7 from maasserver.models.timestampedmodel import TimestampedModel
8 from maasserver.utils import orm
9-from maasserver.utils.dns import get_ip_based_hostname
10+from maasserver.utils.dns import (
11+ get_iface_name_based_hostname,
12+ get_ip_based_hostname,
13+)
14 from provisioningserver.utils.enum import map_enum_reverse
15
16 StaticIPAddress = TypeVar("StaticIPAddress")
17@@ -841,7 +844,11 @@ class StaticIPAddressManager(Manager):
18 # node, then consider adding the IP.
19 if result.assigned or not assigned_ips[result.fqdn]:
20 if result.ip not in mapping[result.fqdn].ips:
21- entry = mapping[f"{result.iface_name}.{result.fqdn}"]
22+ fqdn = "{}.{}".format(
23+ get_iface_name_based_hostname(result.iface_name),
24+ result.fqdn,
25+ )
26+ entry = mapping[fqdn]
27 entry.node_type = result.node_type
28 entry.system_id = result.system_id
29 if result.user_id is not None:
30diff --git a/src/maasserver/utils/dns.py b/src/maasserver/utils/dns.py
31index 0c8cde5..76f553a 100644
32--- a/src/maasserver/utils/dns.py
33+++ b/src/maasserver/utils/dns.py
34@@ -91,6 +91,16 @@ def get_ip_based_hostname(ip):
35 return hostname
36
37
38+def get_iface_name_based_hostname(iface_name):
39+ """Given the specified interface name, creates an automatically generated
40+ hostname by converting the '_' characters in it to '-' characters.
41+
42+ :param iface_name: Input value for the interface name.
43+ """
44+ hostname = iface_name.replace("_", "-")
45+ return hostname
46+
47+
48 def validate_url(url, schemes=("http", "https")):
49 """Validator for URLs.
50

Subscribers

People subscribed via source and target branches