Merge ~mpontillo/maas:replicate-search-paths-on-interface--bug-1771885 into maas:master

Proposed by Mike Pontillo on 2018-07-12
Status: Merged
Approved by: Mike Pontillo on 2018-07-12
Approved revision: 55b08879703c27ab5721a8f92a6e83d1fefab969
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~mpontillo/maas:replicate-search-paths-on-interface--bug-1771885
Merge into: maas:master
Diff against target: 162 lines (+32/-18)
2 files modified
src/maasserver/preseed_network.py (+11/-7)
src/maasserver/tests/test_preseed_network.py (+21/-11)
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) 2018-07-12 Approve on 2018-07-12
MAAS Lander unittests Pending
Review via email: mp+349442@code.launchpad.net

Commit message

LP: #1771885 - Replicate DNS search paths per-interface in v1 preseed YAML

To post a comment you must log in.
Andres Rodriguez (andreserl) wrote :

lgtm!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/preseed_network.py b/src/maasserver/preseed_network.py
2index 4a2d323..1c448fb 100644
3--- a/src/maasserver/preseed_network.py
4+++ b/src/maasserver/preseed_network.py
5@@ -257,6 +257,8 @@ class InterfaceConfiguration:
6 len(subnet.dns_servers) > 0):
7 v1_subnet_operation["dns_nameservers"] = (
8 subnet.dns_servers)
9+ v1_subnet_operation["dns_search"] = (
10+ self.node_config.default_search_list)
11 if "nameservers" not in v2_config:
12 v2_config["nameservers"] = v2_nameservers
13 # XXX should also support search paths.
14@@ -462,9 +464,17 @@ class NodeNetworkConfiguration:
15 self.v2_bridges = {}
16 self.gateway_ipv4_set = False
17 self.gateway_ipv6_set = False
18+
19 # The default value is False: expected keys are 4 and 6.
20 self.addr_family_present = defaultdict(bool)
21
22+ # Ensure the machine's primary domain always comes first in the list.
23+ self.default_search_list = [self.node.domain.name] + [
24+ name
25+ for name in sorted(get_dns_search_paths())
26+ if name != self.node.domain.name
27+ ]
28+
29 self.gateways = self.node.get_default_gateways()
30 if self.gateways.ipv4 is not None:
31 dest_ip = self.gateways.ipv4.gateway_ip
32@@ -506,16 +516,10 @@ class NodeNetworkConfiguration:
33 default_dns_servers = self.node.get_default_dns_servers(
34 ipv4=self.addr_family_present[4], ipv6=self.addr_family_present[6],
35 default_region_ip=default_source_ip)
36- # Ensure the machine's primary domain always comes first in the list.
37- search_list = [self.node.domain.name] + [
38- name
39- for name in sorted(get_dns_search_paths())
40- if name != self.node.domain.name
41- ]
42 self.v1_config.append({
43 "type": "nameserver",
44 "address": default_dns_servers,
45- "search": search_list,
46+ "search": self.default_search_list,
47 })
48 if version == 1:
49 network_config = {
50diff --git a/src/maasserver/tests/test_preseed_network.py b/src/maasserver/tests/test_preseed_network.py
51index 2992b0c..13d11b1 100644
52--- a/src/maasserver/tests/test_preseed_network.py
53+++ b/src/maasserver/tests/test_preseed_network.py
54@@ -213,6 +213,10 @@ class AssertNetworkConfigMixin:
55 ret += " dns_nameservers:\n"
56 for dns_server in subnet.dns_servers:
57 ret += " - %s\n" % dns_server
58+ ret += " dns_search:\n"
59+ for domain in self.get_dns_search_list(
60+ node.domain.name):
61+ ret += " - %s\n" % domain
62 dhcp_types = set()
63 for dhcp_ip in iface.ip_addresses.filter(
64 alloc_type=IPADDRESS_TYPE.DHCP):
65@@ -230,18 +234,22 @@ class AssertNetworkConfigMixin:
66 ret += " - type: dhcp6\n"
67 return ret
68
69- def collectDNSConfig(self, node, ipv4=True, ipv6=True):
70+ def collect_dns_config(self, node, ipv4=True, ipv6=True):
71 config = "- type: nameserver\n address: %s\n search:\n" % (
72 repr(node.get_default_dns_servers(ipv4=ipv4, ipv6=ipv6)))
73 domain_name = node.domain.name
74- dns_searches = [domain_name] + [
75- name
76- for name in sorted(get_dns_search_paths())
77- if name != domain_name]
78+ dns_searches = self.get_dns_search_list(domain_name)
79 for dns_name in dns_searches:
80 config += " - %s\n" % dns_name
81 return config
82
83+ def get_dns_search_list(self, domain_name):
84+ return [domain_name] + [
85+ name
86+ for name in sorted(get_dns_search_paths())
87+ if name != domain_name
88+ ]
89+
90
91 class TestSingleAddrFamilyLayout(MAASServerTestCase, AssertNetworkConfigMixin):
92
93@@ -277,7 +285,7 @@ class TestSingleAddrFamilyLayout(MAASServerTestCase, AssertNetworkConfigMixin):
94 sip.save()
95 factory.make_Interface(node=node)
96 net_config = self.collect_interface_config(node)
97- net_config += self.collectDNSConfig(
98+ net_config += self.collect_dns_config(
99 node, ipv4=(self.version == 4), ipv6=(self.version == 6))
100 config = compose_curtin_network_config(node)
101 self.assertNetworkConfig(net_config, config)
102@@ -311,7 +319,7 @@ class TestSimpleNetworkLayout(MAASServerTestCase, AssertNetworkConfigMixin):
103 sip.save()
104 factory.make_Interface(node=node)
105 net_config = self.collect_interface_config(node)
106- net_config += self.collectDNSConfig(node)
107+ net_config += self.collect_dns_config(node)
108 config = compose_curtin_network_config(node)
109 self.assertNetworkConfig(net_config, config)
110
111@@ -335,7 +343,7 @@ class TestBondNetworkLayout(MAASServerTestCase, AssertNetworkConfigMixin):
112 subnet=bond_iface.vlan.subnet_set.first())
113 net_config = self.collect_interface_config(node, filter="physical")
114 net_config += self.collect_interface_config(node, filter="bond")
115- net_config += self.collectDNSConfig(node)
116+ net_config += self.collect_dns_config(node)
117 config = compose_curtin_network_config(node)
118 self.assertNetworkConfig(net_config, config)
119
120@@ -352,7 +360,7 @@ class TestVLANNetworkLayout(MAASServerTestCase, AssertNetworkConfigMixin):
121 factory.make_StaticIPAddress(interface=vlan_iface, subnet=subnet)
122 net_config = self.collect_interface_config(node, filter="physical")
123 net_config += self.collect_interface_config(node, filter="vlan")
124- net_config += self.collectDNSConfig(node)
125+ net_config += self.collect_dns_config(node)
126 config = compose_curtin_network_config(node)
127 self.assertNetworkConfig(net_config, config)
128
129@@ -379,7 +387,7 @@ class TestVLANOnBondNetworkLayout(MAASServerTestCase,
130 net_config = self.collect_interface_config(node, filter="physical")
131 net_config += self.collect_interface_config(node, filter="bond")
132 net_config += self.collect_interface_config(node, filter="vlan")
133- net_config += self.collectDNSConfig(node)
134+ net_config += self.collect_dns_config(node)
135 config = compose_curtin_network_config(node)
136 self.assertNetworkConfig(net_config, config)
137
138@@ -438,7 +446,7 @@ class TestBridgeNetworkLayout(MAASServerTestCase, AssertNetworkConfigMixin):
139 subnet=bridge_iface.vlan.subnet_set.first())
140 net_config = self.collect_interface_config(node, filter="physical")
141 net_config += self.collect_interface_config(node, filter="bridge")
142- net_config += self.collectDNSConfig(node)
143+ net_config += self.collect_dns_config(node)
144 config = compose_curtin_network_config(node)
145 self.assertNetworkConfig(net_config, config)
146
147@@ -965,6 +973,7 @@ class TestNetplan(MAASServerTestCase):
148 'subnets': [{
149 'address': '10.0.0.4/24',
150 'dns_nameservers': ['10.0.0.2'],
151+ 'dns_search': ['maas'],
152 'gateway': '10.0.0.1',
153 'type': 'static',
154 }],
155@@ -978,6 +987,7 @@ class TestNetplan(MAASServerTestCase):
156 'subnets': [{
157 'address': '10.0.1.4/24',
158 'dns_nameservers': ['10.0.1.2'],
159+ 'dns_search': ['maas'],
160 'type': 'static',
161 }],
162 'type': 'physical'

Subscribers

People subscribed via source and target branches

to all changes: