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: 138 lines (+73/-3)
4 files modified
src/maasserver/models/staticipaddress.py (+9/-2)
src/maasserver/models/tests/test_staticipaddress.py (+45/-1)
src/maasserver/utils/dns.py (+10/-0)
src/maasserver/utils/tests/test_dns.py (+9/-0)
Reviewer Review Type Date Requested Status
Björn Tillenius Approve
MAAS Lander Approve
Review via email: mp+439150@code.launchpad.net

This proposal supersedes a proposal from 2023-03-16.

This proposal has been superseded by a proposal from 2023-04-25.

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

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
Revision history for this message
MAAS Lander (maas-lander) wrote : Posted in a previous version of this proposal

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/1549/consoleText
COMMIT: a3337f142376a14d3b1b300033e176fbadfbbbff

review: Needs Fixing
Revision history for this message
Alexsander de Souza (alexsander-souza) wrote : Posted in a previous version of this proposal

jenkins: !test

Revision history for this message
MAAS Lander (maas-lander) wrote : Posted in a previous version of this proposal

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

STATUS: SUCCESS
COMMIT: a3337f142376a14d3b1b300033e176fbadfbbbff

review: Approve
Revision history for this message
Thorsten Merten (thorsten-merten) wrote : Posted in a previous version of this proposal

Thanks for the MP! This would fix the DNS resolution.

While we are at it, I have the feeling that a dot in the interface name (.) is also a bit weird to be taken over to a hostname as a dot has its own semantics in DNS.

Finally, it might be confusing to the user if we replace characters "at random" without a warning in the UI or the CLI in case that the interface name will be used as the host name.

We will need to check with UX before merging.

Revision history for this message
Björn Tillenius (bjornt) wrote : Posted in a previous version of this proposal

I think the patch looks fine as it is. Could you please add a test for this, though?

review: Needs Information
Revision history for this message
Tiago Pasqualini da Silva (tiago.pasqualini) wrote : Posted in a previous version of this proposal

Added the tests, please let me know if that looks fine.

Revision history for this message
MAAS Lander (maas-lander) wrote : Posted in a previous version of this proposal

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/2161/consoleText
COMMIT: f2d97c69435a5968daf6ab84d0e6e39f80ac1c50

review: Needs Fixing
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: SUCCESS
COMMIT: d3af9741abe27a7d675ce530f6f1dccb3a604ee6

review: Approve
Revision history for this message
Mauricio Faria de Oliveira (mfo) wrote :

Hi Björn,

Friendly follow-up, if you have a chance to review the tests added.

Thanks!

Revision history for this message
Alberto Donato (ack) :
Revision history for this message
Björn Tillenius (bjornt) wrote :

Thanks, it looks good now, except for Alberto's comment, which should be trivial to fix.

review: Approve
Revision history for this message
Tiago Pasqualini da Silva (tiago.pasqualini) wrote :

Hi Björn, you approved it but left a comment. Do you want me to fix that or it is good as is?

I'm fine either way, it's a simple method replace.

Revision history for this message
Adam Collard (adam-collard) wrote :

> Hi Björn, you approved it but left a comment. Do you want me to fix that or it
> is good as is?
>
> I'm fine either way, it's a simple method replace.

Please fix it - we do not want to add any more assertThat()s to MAAS

Unmerged commits

daf5370... 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
diff --git a/src/maasserver/models/staticipaddress.py b/src/maasserver/models/staticipaddress.py
index b5794a1..81c7a82 100644
--- a/src/maasserver/models/staticipaddress.py
+++ b/src/maasserver/models/staticipaddress.py
@@ -52,7 +52,10 @@ from maasserver.models.domain import Domain
52from maasserver.models.subnet import Subnet52from maasserver.models.subnet import Subnet
53from maasserver.models.timestampedmodel import TimestampedModel53from maasserver.models.timestampedmodel import TimestampedModel
54from maasserver.utils import orm54from maasserver.utils import orm
55from maasserver.utils.dns import get_ip_based_hostname55from maasserver.utils.dns import (
56 get_iface_name_based_hostname,
57 get_ip_based_hostname,
58)
56from provisioningserver.utils.enum import map_enum_reverse59from provisioningserver.utils.enum import map_enum_reverse
5760
58StaticIPAddress = TypeVar("StaticIPAddress")61StaticIPAddress = TypeVar("StaticIPAddress")
@@ -841,7 +844,11 @@ class StaticIPAddressManager(Manager):
841 # node, then consider adding the IP.844 # node, then consider adding the IP.
842 if result.assigned or not assigned_ips[result.fqdn]:845 if result.assigned or not assigned_ips[result.fqdn]:
843 if result.ip not in mapping[result.fqdn].ips:846 if result.ip not in mapping[result.fqdn].ips:
844 entry = mapping[f"{result.iface_name}.{result.fqdn}"]847 fqdn = "{}.{}".format(
848 get_iface_name_based_hostname(result.iface_name),
849 result.fqdn,
850 )
851 entry = mapping[fqdn]
845 entry.node_type = result.node_type852 entry.node_type = result.node_type
846 entry.system_id = result.system_id853 entry.system_id = result.system_id
847 if result.user_id is not None:854 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 ee9c08a..08cdff1 100644
--- a/src/maasserver/models/tests/test_staticipaddress.py
+++ b/src/maasserver/models/tests/test_staticipaddress.py
@@ -50,7 +50,10 @@ from maasserver.testing.testcase import (
50 MAASTransactionServerTestCase,50 MAASTransactionServerTestCase,
51)51)
52from maasserver.utils import orm52from maasserver.utils import orm
53from maasserver.utils.dns import get_ip_based_hostname53from maasserver.utils.dns import (
54 get_iface_name_based_hostname,
55 get_ip_based_hostname,
56)
54from maasserver.utils.orm import reload_object, transactional57from maasserver.utils.orm import reload_object, transactional
55from maasserver.websockets.base import dehydrate_datetime58from maasserver.websockets.base import dehydrate_datetime
5659
@@ -483,6 +486,47 @@ class TestStaticIPAddressManagerMapping(MAASServerTestCase):
483 }486 }
484 self.assertEqual(expected, mapping)487 self.assertEqual(expected, mapping)
485488
489 def test_get_hostname_ip_mapping_sanitized_iface_name(self):
490 hostname = factory.make_name("hostname")
491 domainname = factory.make_name("domain")
492 factory.make_Domain(name=domainname)
493 full_hostname = f"{hostname}.{domainname}"
494 subnet = factory.make_Subnet()
495 node = factory.make_Node_with_Interface_on_Subnet(
496 extra_ifnames=["eth_1"],
497 hostname=full_hostname,
498 interface_count=2,
499 subnet=subnet,
500 )
501 boot_interface = node.get_boot_interface()
502 staticip = factory.make_StaticIPAddress(
503 alloc_type=IPADDRESS_TYPE.STICKY,
504 ip=factory.pick_ip_in_Subnet(subnet),
505 subnet=subnet,
506 interface=boot_interface,
507 )
508 iface2 = node.current_config.interface_set.exclude(
509 id=boot_interface.id
510 ).first()
511 sip2 = factory.make_StaticIPAddress(
512 alloc_type=IPADDRESS_TYPE.STICKY,
513 ip=factory.pick_ip_in_Subnet(subnet),
514 subnet=subnet,
515 interface=iface2,
516 )
517 mapping = StaticIPAddress.objects.get_hostname_ip_mapping(subnet)
518 sanitized_if2name = get_iface_name_based_hostname(iface2.name)
519 expected = {
520 full_hostname: HostnameIPMapping(
521 node.system_id, 30, {staticip.ip}, node.node_type
522 ),
523 "%s.%s"
524 % (sanitized_if2name, full_hostname): HostnameIPMapping(
525 node.system_id, 30, {sip2.ip}, node.node_type
526 ),
527 }
528 self.assertEqual(expected, mapping)
529
486 def make_mapping(self, node, raw_ttl=False):530 def make_mapping(self, node, raw_ttl=False):
487 if raw_ttl or node.address_ttl is not None:531 if raw_ttl or node.address_ttl is not None:
488 ttl = node.address_ttl532 ttl = node.address_ttl
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):
91 return hostname91 return hostname
9292
9393
94def get_iface_name_based_hostname(iface_name):
95 """Given the specified interface name, creates an automatically generated
96 hostname by converting the '_' characters in it to '-' characters.
97
98 :param iface_name: Input value for the interface name.
99 """
100 hostname = iface_name.replace("_", "-")
101 return hostname
102
103
94def validate_url(url, schemes=("http", "https")):104def validate_url(url, schemes=("http", "https")):
95 """Validator for URLs.105 """Validator for URLs.
96106
diff --git a/src/maasserver/utils/tests/test_dns.py b/src/maasserver/utils/tests/test_dns.py
index e6be8ab..41cfe80 100644
--- a/src/maasserver/utils/tests/test_dns.py
+++ b/src/maasserver/utils/tests/test_dns.py
@@ -8,6 +8,7 @@ from django.core.validators import URLValidator
8from testtools.matchers import Equals, HasLength8from testtools.matchers import Equals, HasLength
99
10from maasserver.utils.dns import (10from maasserver.utils.dns import (
11 get_iface_name_based_hostname,
11 get_ip_based_hostname,12 get_ip_based_hostname,
12 validate_domain_name,13 validate_domain_name,
13 validate_hostname,14 validate_hostname,
@@ -244,3 +245,11 @@ class TestIpBasedHostnameGenerator(MAASTestCase):
244 get_ip_based_hostname("2001:67c:1562::15"),245 get_ip_based_hostname("2001:67c:1562::15"),
245 Equals("2001-67c-1562--15"),246 Equals("2001-67c-1562--15"),
246 )247 )
248
249
250class TestIfaceBasedHostnameGenerator(MAASTestCase):
251 def test_interface_name_changed(self):
252 self.assertEqual(get_iface_name_based_hostname("eth_0"), "eth-0")
253
254 def test_interface_name_unchanged(self):
255 self.assertEqual(get_iface_name_based_hostname("eth0"), "eth0")

Subscribers

People subscribed via source and target branches