Merge ~ddstreet/maas:lp1896684 into maas:master

Proposed by Dan Streetman
Status: Merged
Approved by: Lee Trager
Approved revision: b60e8e96657ffce7939970ad8a911042888114cc
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ddstreet/maas:lp1896684
Merge into: maas:master
Diff against target: 364 lines (+158/-43)
6 files modified
src/maasserver/dhcp.py (+13/-1)
src/maasserver/models/node.py (+6/-11)
src/maasserver/models/tests/test_node.py (+20/-0)
src/maasserver/preseed_network.py (+26/-21)
src/maasserver/tests/test_dhcp.py (+44/-10)
src/maasserver/tests/test_preseed_network.py (+49/-0)
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
MAAS Lander Approve
Dan Streetman (community) Needs Resubmitting
Review via email: mp+391198@code.launchpad.net

Commit message

LP: #1896684 - If no subnet gateway, only use in-subnet dns addresses

If DHCP is not providing any gateway, it should not provide any
DNS server addresses that aren't directly reachable.

Similarly, if the network preseed is not configuring any gateway,
it should not provide per-interface DNS server addresses, nor default
dns server addresses, that aren't directly reachable.

Only apply rack DNS server address if subnet.allow_dns == True

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

UNIT TESTS
-b lp1896684 lp:~ddstreet/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8418/console
COMMIT: 69acdb0067cf0a7159a34678f824f59651750e5b

review: Needs Fixing
Revision history for this message
Dan Streetman (ddstreet) wrote :

> STATUS: FAILED
> LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8418/console

I'm not able to access this CI test system to see the logs.

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1896684 lp:~ddstreet/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8419/console
COMMIT: 99132e5871c0a99448db0db8ad59cb612c7f1b2b

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1896684 lp:~ddstreet/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: fdc4a764ddd43050b749df10a2a749437146ba3c

review: Approve
Revision history for this message
Lee Trager (ltrager) wrote :

Thanks for finding and fixing this!

This seems to fix the bug for static IP address, have you tested DHCP? Looking at the code[1] I think its correct but it would be good to verify. Couple of other things

1. This needs commit message to land. It should start with "LP: #1896684 - "
2. Unit tests need to be added to ensure we don't regress this.
3. One comment inline below.

[1] https://git.launchpad.net/maas/tree/src/maasserver/dhcp.py#n420

review: Needs Fixing
~ddstreet/maas:lp1896684 updated
bae3958... by Dan Streetman

LP: #1896684 - If no subnet gateway, only use in-subnet dns addresses

If DHCP is not providing any gateway, it should not provide any
DNS server addresses that aren't directly reachable.

Similarly, if the network preseed is not configuring any gateway,
it should not provide per-interface DNS server addresses, nor default
dns server addresses, that aren't directly reachable.

Revision history for this message
Dan Streetman (ddstreet) wrote :

> Thanks for finding and fixing this!
>
> This seems to fix the bug for static IP address, have you tested DHCP? Looking
> at the code[1] I think its correct but it would be good to verify.

It does look like it needed a change, i included that in the latest patch

> Couple of
> other things
>
> 1. This needs commit message to land. It should start with "LP: #1896684 - "

ok, done

> 2. Unit tests need to be added to ensure we don't regress this.

if these changes look ok to you, i'll work on adding unit tests for them

> 3. One comment inline below.

response inline (with the old diff) - basically i'm confused as to why there's a in-vlan restriction but no in-subnet restriction, without a gateway (or defined route) a node can't access a separate subnet, even if it's in the same vlan. and with a gateway (or defined route), there's no need for the separate subnet to be in the same vlan.

>
>
> [1] https://git.launchpad.net/maas/tree/src/maasserver/dhcp.py#n420

Revision history for this message
Dan Streetman (ddstreet) :
review: Needs Resubmitting
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1896684 lp:~ddstreet/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8426/console
COMMIT: f5485d47b0aef19c9454d1d62d265a28fbdef0d5

review: Needs Fixing
Revision history for this message
Lee Trager (ltrager) wrote :

That looks good but this still needs unit tests. Also LaunchPad requires the commit message be added on LaunchPad, it doesn't automatically take whats in git.

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1896684 lp:~ddstreet/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8438/console
COMMIT: 692f3ca6b93e20fcb26c5c9f4e083b3afe86bd19

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1896684 lp:~ddstreet/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8440/console
COMMIT: 44003e8d41e36812a7b4b0df45650e494c809f69

review: Needs Fixing
~ddstreet/maas:lp1896684 updated
b60e8e9... by Dan Streetman

add unit tests

Revision history for this message
Dan Streetman (ddstreet) wrote :

updated commits, and added test cases...let's see if it passes jenkins

review: Needs Resubmitting
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1896684 lp:~ddstreet/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8450/console
COMMIT: d74a74e14352697d4bab6e799546978c991e3663

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1896684 lp:~ddstreet/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8451/console
COMMIT: 82b401ad22dd3298d69eb00a2934c2979e07af09

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1896684 lp:~ddstreet/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 5e806d38e90f341cc86acb4bb89974b84c63124e

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1896684 lp:~ddstreet/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: b60e8e96657ffce7939970ad8a911042888114cc

review: Approve
Revision history for this message
Lee Trager (ltrager) wrote :

LGTM! Thanks for the fix!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/maasserver/dhcp.py b/src/maasserver/dhcp.py
index 848ff1b..05e9f7a 100644
--- a/src/maasserver/dhcp.py
+++ b/src/maasserver/dhcp.py
@@ -438,7 +438,15 @@ def make_subnet_config(
438 dns_servers = []438 dns_servers = []
439 if subnet.allow_dns and default_dns_servers:439 if subnet.allow_dns and default_dns_servers:
440 # If the MAAS DNS server is enabled make sure that is used first.440 # If the MAAS DNS server is enabled make sure that is used first.
441 dns_servers += default_dns_servers441 if subnet.gateway_ip:
442 dns_servers += default_dns_servers
443 else:
444 # if there is no gateway, only provide in-subnet dns servers
445 dns_servers += [
446 ipaddress
447 for ipaddress in default_dns_servers
448 if ipaddress in ip_network
449 ]
442 if subnet.dns_servers:450 if subnet.dns_servers:
443 # Add DNS user defined DNS servers451 # Add DNS user defined DNS servers
444 dns_servers += [IPAddress(server) for server in subnet.dns_servers]452 dns_servers += [IPAddress(server) for server in subnet.dns_servers]
@@ -557,6 +565,10 @@ def get_default_dns_servers(rack_controller, subnet, use_rack_proxy=True):
557 :param use_rack_proxy: Whether to proxy DNS through the rack controller565 :param use_rack_proxy: Whether to proxy DNS through the rack controller
558 or not.566 or not.
559 """567 """
568 if not subnet.allow_dns:
569 # This subnet isn't allowed to use region or rack addresses for dns
570 return []
571
560 ip_version = subnet.get_ip_version()572 ip_version = subnet.get_ip_version()
561 default_region_ip = get_source_address(subnet.get_ipnetwork())573 default_region_ip = get_source_address(subnet.get_ipnetwork())
562 try:574 try:
diff --git a/src/maasserver/models/node.py b/src/maasserver/models/node.py
index d3e40c2..4882eec 100644
--- a/src/maasserver/models/node.py
+++ b/src/maasserver/models/node.py
@@ -4937,6 +4937,8 @@ class Node(CleanSave, TimestampedModel):
4937 if ipv4 and gateways.ipv4 is not None:4937 if ipv4 and gateways.ipv4 is not None:
4938 subnet = Subnet.objects.get(id=gateways.ipv4.subnet_id)4938 subnet = Subnet.objects.get(id=gateways.ipv4.subnet_id)
4939 if subnet.dns_servers:4939 if subnet.dns_servers:
4940 if not subnet.allow_dns:
4941 return subnet.dns_servers
4940 rack_dns = []4942 rack_dns = []
4941 for rack in {4943 for rack in {
4942 self.get_boot_primary_rack_controller(),4944 self.get_boot_primary_rack_controller(),
@@ -4963,6 +4965,8 @@ class Node(CleanSave, TimestampedModel):
4963 if ipv6 and gateways.ipv6 is not None:4965 if ipv6 and gateways.ipv6 is not None:
4964 subnet = Subnet.objects.get(id=gateways.ipv6.subnet_id)4966 subnet = Subnet.objects.get(id=gateways.ipv6.subnet_id)
4965 if subnet.dns_servers:4967 if subnet.dns_servers:
4968 if not subnet.allow_dns:
4969 return subnet.dns_servers
4966 rack_dns = []4970 rack_dns = []
4967 for rack in {4971 for rack in {
4968 self.get_boot_primary_rack_controller(),4972 self.get_boot_primary_rack_controller(),
@@ -5009,18 +5013,9 @@ class Node(CleanSave, TimestampedModel):
5009 if filtered_addresses:5013 if filtered_addresses:
5010 routable_addrs_map[node] = filtered_addresses5014 routable_addrs_map[node] = filtered_addresses
50115015
5012 # No default gateway subnet has specific DNS servers defined, so
5013 # use MAAS for the default DNS server.
5014 if gateways.ipv4 is None and gateways.ipv6 is None:5016 if gateways.ipv4 is None and gateways.ipv6 is None:
5015 # If there are no default gateways, the default is the MAAS5017 # node with no gateway can only use routable addrs
5016 # region IP address.5018 maas_dns_servers = []
5017 maas_dns_servers = get_dns_server_addresses(
5018 rack_controller=self.get_boot_rack_controller(),
5019 ipv4=ipv4,
5020 ipv6=ipv6,
5021 include_alternates=True,
5022 default_region_ip=default_region_ip,
5023 )
5024 routable_addrs_map = {5019 routable_addrs_map = {
5025 node: [5020 node: [
5026 address5021 address
diff --git a/src/maasserver/models/tests/test_node.py b/src/maasserver/models/tests/test_node.py
index 33339a7..b6ac6a4 100644
--- a/src/maasserver/models/tests/test_node.py
+++ b/src/maasserver/models/tests/test_node.py
@@ -8203,6 +8203,26 @@ class TestGetDefaultDNSServers(MAASServerTestCase):
8203 node.get_default_dns_servers(), [ipv6_subnet_dns]8203 node.get_default_dns_servers(), [ipv6_subnet_dns]
8204 )8204 )
82058205
8206 def test_ignores_other_unroutable_rack_controllers_ipv4(self):
8207 # Regression test for LP:1896684
8208 rack_v4, rack_v6, node = self.make_Node_with_RackController(
8209 ipv4=True, ipv4_gateway=False, ipv6=False, ipv6_gateway=False
8210 )
8211 vlan = node.boot_interface.vlan
8212 rack = vlan.primary_rack
8213 rackif = rack.interface_set.first()
8214 rack_ips = [rack_v4]
8215 for _ in range(3):
8216 subnet = factory.make_Subnet(vlan=vlan, version=4)
8217 ip = factory.make_StaticIPAddress(subnet=subnet, interface=rackif)
8218 rack_ips.append(ip.ip)
8219 rack.save()
8220 resolve_hostname = self.patch(server_address, "resolve_hostname")
8221 resolve_hostname.side_effect = lambda hostname, version: set(
8222 map(IPAddress, rack_ips)
8223 )
8224 self.assertItemsEqual(node.get_default_dns_servers(), [rack_v4])
8225
82068226
8207class TestNode_Start(MAASTransactionServerTestCase):8227class TestNode_Start(MAASTransactionServerTestCase):
8208 """Tests for Node.start()."""8228 """Tests for Node.start()."""
diff --git a/src/maasserver/preseed_network.py b/src/maasserver/preseed_network.py
index 8188603..395f3b3 100644
--- a/src/maasserver/preseed_network.py
+++ b/src/maasserver/preseed_network.py
@@ -373,32 +373,37 @@ class InterfaceConfiguration:
373 if "addresses" not in v2_nameservers:373 if "addresses" not in v2_nameservers:
374 v2_nameservers["addresses"] = []374 v2_nameservers["addresses"] = []
375375
376 for ip in StaticIPAddress.objects.filter(376 if subnet.allow_dns:
377 interface__node__in=[377 for ip in StaticIPAddress.objects.filter(
378 subnet.vlan.primary_rack,378 interface__node__in=[
379 subnet.vlan.secondary_rack,379 subnet.vlan.primary_rack,
380 ],380 subnet.vlan.secondary_rack,
381 subnet__vlan=subnet.vlan,381 ],
382 alloc_type__in=[382 subnet__vlan=subnet.vlan,
383 IPADDRESS_TYPE.AUTO,383 alloc_type__in=[
384 IPADDRESS_TYPE.STICKY,384 IPADDRESS_TYPE.AUTO,
385 ],385 IPADDRESS_TYPE.STICKY,
386 ).exclude(ip=None):386 ],
387 if (387 ).exclude(ip=None):
388 IPAddress(ip.get_ip()).version388 if ip.ip in v2_nameservers["addresses"]:
389 == subnet.get_ip_version()389 continue
390 and ip.get_ip() not in v2_nameservers["addresses"]390 ip_address = IPAddress(ip.ip)
391 ):391 if ip_address.version != subnet.get_ip_version():
392 continue
393 if not subnet.gateway_ip:
394 if ip_address not in subnet.get_ipnetwork():
395 # without gateway, only use in-subnet addrs
396 continue
392 v1_subnet_operation["dns_nameservers"].append(397 v1_subnet_operation["dns_nameservers"].append(
393 ip.ip398 ip.ip
394 )399 )
395 v2_nameservers["addresses"].append(ip.ip)400 v2_nameservers["addresses"].append(ip.ip)
396401
397 if subnet.dns_servers:402 for ip in subnet.dns_servers:
398 v1_subnet_operation[403 if ip in v2_nameservers["addresses"]:
399 "dns_nameservers"404 continue
400 ] += subnet.dns_servers405 v1_subnet_operation["dns_nameservers"].append(ip)
401 v2_nameservers["addresses"] += subnet.dns_servers406 v2_nameservers["addresses"].append(ip)
402407
403 if len(matching_subnet_routes) > 0 and version == 1:408 if len(matching_subnet_routes) > 0 and version == 1:
404 # For the v1 YAML, the list of routes is rendered409 # For the v1 YAML, the list of routes is rendered
diff --git a/src/maasserver/tests/test_dhcp.py b/src/maasserver/tests/test_dhcp.py
index d53f8bb..f445146 100644
--- a/src/maasserver/tests/test_dhcp.py
+++ b/src/maasserver/tests/test_dhcp.py
@@ -1158,7 +1158,7 @@ class TestMakeSubnetConfig(MAASServerTestCase):
1158 config = dhcp.make_subnet_config(1158 config = dhcp.make_subnet_config(
1159 rack_controller,1159 rack_controller,
1160 subnet,1160 subnet,
1161 [factory.make_name("dns")],1161 [factory.make_ipv4_address()],
1162 [factory.make_name("ntp")],1162 [factory.make_name("ntp")],
1163 default_domain,1163 default_domain,
1164 search_list=default_domain.name,1164 search_list=default_domain.name,
@@ -1457,7 +1457,7 @@ class TestMakeSubnetConfig(MAASServerTestCase):
1457 config = dhcp.make_subnet_config(1457 config = dhcp.make_subnet_config(
1458 rack_controller,1458 rack_controller,
1459 subnet,1459 subnet,
1460 [factory.make_name("dns")],1460 [factory.make_ipv4_address()],
1461 [factory.make_name("ntp")],1461 [factory.make_name("ntp")],
1462 default_domain,1462 default_domain,
1463 )1463 )
@@ -1474,7 +1474,7 @@ class TestMakeSubnetConfig(MAASServerTestCase):
1474 config = dhcp.make_subnet_config(1474 config = dhcp.make_subnet_config(
1475 rack_controller,1475 rack_controller,
1476 subnet,1476 subnet,
1477 [factory.make_name("dns")],1477 [factory.make_ipv4_address()],
1478 [factory.make_name("ntp")],1478 [factory.make_name("ntp")],
1479 default_domain,1479 default_domain,
1480 )1480 )
@@ -1495,7 +1495,7 @@ class TestMakeSubnetConfig(MAASServerTestCase):
1495 config = dhcp.make_subnet_config(1495 config = dhcp.make_subnet_config(
1496 rack_controller,1496 rack_controller,
1497 subnet,1497 subnet,
1498 [factory.make_name("dns")],1498 [factory.make_ipv4_address()],
1499 [factory.make_name("ntp")],1499 [factory.make_name("ntp")],
1500 default_domain,1500 default_domain,
1501 )1501 )
@@ -1518,7 +1518,7 @@ class TestMakeSubnetConfig(MAASServerTestCase):
1518 config = dhcp.make_subnet_config(1518 config = dhcp.make_subnet_config(
1519 rack_controller,1519 rack_controller,
1520 subnet,1520 subnet,
1521 [factory.make_name("dns")],1521 [factory.make_ipv4_address()],
1522 [factory.make_name("ntp")],1522 [factory.make_name("ntp")],
1523 default_domain,1523 default_domain,
1524 search_list=search_list,1524 search_list=search_list,
@@ -1546,7 +1546,7 @@ class TestMakeSubnetConfig(MAASServerTestCase):
1546 config = dhcp.make_subnet_config(1546 config = dhcp.make_subnet_config(
1547 rack_controller,1547 rack_controller,
1548 subnet,1548 subnet,
1549 [factory.make_name("dns")],1549 [factory.make_ipv6_address()],
1550 [factory.make_name("ntp")],1550 [factory.make_name("ntp")],
1551 default_domain,1551 default_domain,
1552 search_list=search_list,1552 search_list=search_list,
@@ -1581,7 +1581,7 @@ class TestMakeSubnetConfig(MAASServerTestCase):
1581 config = dhcp.make_subnet_config(1581 config = dhcp.make_subnet_config(
1582 rack_controller,1582 rack_controller,
1583 subnet,1583 subnet,
1584 [factory.make_name("dns")],1584 [factory.make_ipv4_address()],
1585 [factory.make_name("ntp")],1585 [factory.make_name("ntp")],
1586 default_domain,1586 default_domain,
1587 )1587 )
@@ -1609,7 +1609,7 @@ class TestMakeSubnetConfig(MAASServerTestCase):
1609 config = dhcp.make_subnet_config(1609 config = dhcp.make_subnet_config(
1610 rack_controller,1610 rack_controller,
1611 subnet,1611 subnet,
1612 [factory.make_name("dns")],1612 [factory.make_ipv4_address()],
1613 [factory.make_name("ntp")],1613 [factory.make_name("ntp")],
1614 default_domain,1614 default_domain,
1615 failover_peer=failover_peer,1615 failover_peer=failover_peer,
@@ -1643,7 +1643,7 @@ class TestMakeSubnetConfig(MAASServerTestCase):
1643 config = dhcp.make_subnet_config(1643 config = dhcp.make_subnet_config(
1644 rack_controller,1644 rack_controller,
1645 subnet,1645 subnet,
1646 [factory.make_name("dns")],1646 [factory.make_ipv4_address()],
1647 [factory.make_name("ntp")],1647 [factory.make_name("ntp")],
1648 default_domain,1648 default_domain,
1649 )1649 )
@@ -1664,7 +1664,7 @@ class TestMakeSubnetConfig(MAASServerTestCase):
1664 config = dhcp.make_subnet_config(1664 config = dhcp.make_subnet_config(
1665 rack_controller,1665 rack_controller,
1666 subnet,1666 subnet,
1667 [factory.make_name("dns")],1667 [factory.make_ipv4_address()],
1668 [factory.make_name("ntp")],1668 [factory.make_name("ntp")],
1669 default_domain,1669 default_domain,
1670 subnets_dhcp_snippets=dhcp_snippets,1670 subnets_dhcp_snippets=dhcp_snippets,
@@ -1681,6 +1681,40 @@ class TestMakeSubnetConfig(MAASServerTestCase):
1681 config["dhcp_snippets"],1681 config["dhcp_snippets"],
1682 )1682 )
16831683
1684 def test_subnet_without_gateway_restricts_nameservers(self):
1685 network1 = IPNetwork("10.9.8.0/24")
1686 network2 = IPNetwork("10.9.9.0/24")
1687 rackip1 = "10.9.8.1"
1688 rackip2 = "10.9.9.1"
1689 rack_controller = factory.make_RackController(interface=False)
1690 vlan = factory.make_VLAN()
1691 subnet1 = factory.make_Subnet(cidr=str(network1.cidr), vlan=vlan)
1692 subnet2 = factory.make_Subnet(
1693 cidr=str(network2.cidr), vlan=vlan, gateway_ip=None
1694 )
1695 factory.make_Interface(
1696 INTERFACE_TYPE.PHYSICAL, vlan=vlan, node=rack_controller
1697 )
1698 default_domain = Domain.objects.get_default_domain()
1699 config = dhcp.make_subnet_config(
1700 rack_controller,
1701 subnet1,
1702 [rackip1, rackip2],
1703 [factory.make_name("ntp")],
1704 default_domain,
1705 )
1706 self.assertIn(rackip1, config["dns_servers"])
1707 self.assertIn(rackip2, config["dns_servers"])
1708 config = dhcp.make_subnet_config(
1709 rack_controller,
1710 subnet2,
1711 [rackip1, rackip2],
1712 [factory.make_name("ntp")],
1713 default_domain,
1714 )
1715 self.assertNotIn(rackip1, config["dns_servers"])
1716 self.assertIn(rackip2, config["dns_servers"])
1717
16841718
1685class TestMakeHostsForSubnet(MAASServerTestCase):1719class TestMakeHostsForSubnet(MAASServerTestCase):
1686 def tests__returns_defined_hosts(self):1720 def tests__returns_defined_hosts(self):
diff --git a/src/maasserver/tests/test_preseed_network.py b/src/maasserver/tests/test_preseed_network.py
index c19283a..279c203 100644
--- a/src/maasserver/tests/test_preseed_network.py
+++ b/src/maasserver/tests/test_preseed_network.py
@@ -1761,6 +1761,55 @@ class TestNetplan(MAASServerTestCase):
1761 v2["network"]["ethernets"][iface.name]["nameservers"],1761 v2["network"]["ethernets"][iface.name]["nameservers"],
1762 )1762 )
17631763
1764 def test_allow_dns_false_does_not_include_rack_controllers(self):
1765 # Regression test for LP:1896684
1766 vlan = factory.make_VLAN()
1767 nameserver = "1.1.1.1"
1768 subnet = factory.make_Subnet(
1769 dns_servers=[nameserver], vlan=vlan, allow_dns=False
1770 )
1771 rack = factory.make_RackController(subnet=subnet)
1772 rack_iface = rack.interface_set.first()
1773 factory.make_StaticIPAddress(subnet=subnet, interface=rack_iface)
1774 vlan.primary_rack = rack
1775 vlan.save()
1776 node = factory.make_Node_with_Interface_on_Subnet(
1777 status=NODE_STATUS.DEPLOYING, subnet=subnet
1778 )
1779 iface = node.interface_set.first()
1780 factory.make_StaticIPAddress(subnet=subnet, interface=iface)
1781 v2 = self._render_netplan_dict(node)
1782 self.assertDictEqual(
1783 {"search": ["maas"], "addresses": [nameserver]},
1784 v2["network"]["ethernets"][iface.name]["nameservers"],
1785 )
1786
1787 def test_no_gateway_does_not_include_unroutable_controllers(self):
1788 # Regression test for LP:1896684
1789 vlan = factory.make_VLAN()
1790 subnet1 = factory.make_Subnet(
1791 dns_servers=[], vlan=vlan, version=4, gateway_ip=None
1792 )
1793 subnet2 = factory.make_Subnet(dns_servers=[], vlan=vlan, version=4)
1794 rack = factory.make_RackController(subnet=subnet1)
1795 rack_iface = rack.interface_set.first()
1796 rack_ip1 = factory.make_StaticIPAddress(
1797 subnet=subnet1, interface=rack_iface
1798 )
1799 factory.make_StaticIPAddress(subnet=subnet2, interface=rack_iface)
1800 vlan.primary_rack = rack
1801 vlan.save()
1802 node = factory.make_Node_with_Interface_on_Subnet(
1803 status=NODE_STATUS.DEPLOYING, subnet=subnet1
1804 )
1805 iface = node.interface_set.first()
1806 factory.make_StaticIPAddress(subnet=subnet1, interface=iface)
1807 v2 = self._render_netplan_dict(node)
1808 self.assertDictEqual(
1809 {"search": ["maas"], "addresses": [rack_ip1.ip]},
1810 v2["network"]["ethernets"][iface.name]["nameservers"],
1811 )
1812
1764 def test_commissioning_dhcp_config(self):1813 def test_commissioning_dhcp_config(self):
1765 # Verifies dhcp config is given when commissioning has run1814 # Verifies dhcp config is given when commissioning has run
1766 # or just run and no AUTOIP has been acquired.1815 # or just run and no AUTOIP has been acquired.

Subscribers

People subscribed via source and target branches