Merge lp:~andreserl/maas/refactor_debconf_selections_preseed into lp:maas/trunk

Proposed by Andres Rodriguez
Status: Rejected
Rejected by: MAAS Lander
Proposed branch: lp:~andreserl/maas/refactor_debconf_selections_preseed
Merge into: lp:maas/trunk
Diff against target: 229 lines (+27/-44)
6 files modified
contrib/preseeds_v2/curtin_userdata (+0/-5)
contrib/preseeds_v2/curtin_userdata_centos (+0/-6)
contrib/preseeds_v2/curtin_userdata_suse (+0/-6)
contrib/preseeds_v2/curtin_userdata_windows (+0/-6)
src/maasserver/preseed.py (+18/-10)
src/maasserver/tests/test_preseed.py (+9/-11)
To merge this branch: bzr merge lp:~andreserl/maas/refactor_debconf_selections_preseed
Reviewer Review Type Date Requested Status
MAAS Maintainers Pending
Review via email: mp+318702@code.launchpad.net

Commit message

Refactor the way Cloud Init configuration (cloudconfig) for debconf selections is inserted into the curtin preseed.

Description of the change

Ubuntu requires to insert Cloud Config (in the curtin preseed) for the deployed node's cloud-init configuration. This allows cloud init in the deployed node to read user-data from the local system and perform system configuration on first boot.

This refactor injects in a better way that allows this to be expanded and support Ubuntu Core, provided that Ubuntu Core will ignore debconf_selections, but will still require 'cloudconfig'. A branch will follow adding such cloud-config.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good. Just one comment about compatibility.

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

Transitioned to Git.

lp:maas has now moved from Bzr to Git.
Please propose your branches with Launchpad using Git.

git clone https://git.launchpad.net/maas

Unmerged revisions

5771. By Andres Rodriguez on 2017-03-02

Refactor how we obtain debconf selections to not do it in the preseed. This is in preparation to supporting Ubuntu Core, as it makes it easier to add curtin config. Ubuntu Core will ignore debconf selections, but requires cloudconfig to be sent instead.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'contrib/preseeds_v2/curtin_userdata'
2--- contrib/preseeds_v2/curtin_userdata 2017-02-24 03:57:02 +0000
3+++ contrib/preseeds_v2/curtin_userdata 2017-03-02 02:03:28 +0000
4@@ -1,9 +1,4 @@
5 #cloud-config
6-debconf_selections:
7- maas: |
8- {{for line in str(curtin_preseed).splitlines()}}
9- {{line}}
10- {{endfor}}
11 {{if third_party_drivers and driver}}
12 early_commands:
13 {{py: key_string = ''.join(['\\x%x' % x for x in driver['key_binary']])}}
14
15=== modified file 'contrib/preseeds_v2/curtin_userdata_centos'
16--- contrib/preseeds_v2/curtin_userdata_centos 2016-12-07 09:25:19 +0000
17+++ contrib/preseeds_v2/curtin_userdata_centos 2017-03-02 02:03:28 +0000
18@@ -1,9 +1,3 @@
19 #cloud-config
20-debconf_selections:
21- maas: |
22- {{for line in str(curtin_preseed).splitlines()}}
23- {{line}}
24- {{endfor}}
25-
26 late_commands:
27 maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null']
28
29=== modified file 'contrib/preseeds_v2/curtin_userdata_suse'
30--- contrib/preseeds_v2/curtin_userdata_suse 2016-12-07 09:25:19 +0000
31+++ contrib/preseeds_v2/curtin_userdata_suse 2017-03-02 02:03:28 +0000
32@@ -1,9 +1,3 @@
33 #cloud-config
34-debconf_selections:
35- maas: |
36- {{for line in str(curtin_preseed).splitlines()}}
37- {{line}}
38- {{endfor}}
39-
40 late_commands:
41 maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null']
42
43=== modified file 'contrib/preseeds_v2/curtin_userdata_windows'
44--- contrib/preseeds_v2/curtin_userdata_windows 2016-12-07 09:25:19 +0000
45+++ contrib/preseeds_v2/curtin_userdata_windows 2017-03-02 02:03:28 +0000
46@@ -1,10 +1,4 @@
47 #cloud-config
48-debconf_selections:
49- maas: |
50- {{for line in str(curtin_preseed).splitlines()}}
51- {{line}}
52- {{endfor}}
53-
54 late_commands:
55 maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null']
56
57
58=== modified file 'src/maasserver/preseed.py'
59--- src/maasserver/preseed.py 2017-03-02 00:22:23 +0000
60+++ src/maasserver/preseed.py 2017-03-02 02:03:28 +0000
61@@ -298,6 +298,7 @@
62 def get_curtin_yaml_config(node):
63 """Return the curtin configration for the node."""
64 main_config = get_curtin_config(node)
65+ cloud_config = compose_curtin_cloud_config(node)
66 archive_config = compose_curtin_archive_config(node)
67 reporter_config = compose_curtin_maas_reporter(node)
68 swap_config = compose_curtin_swap_preseed(node)
69@@ -328,7 +329,8 @@
70
71 return (
72 storage_config + [main_config] + archive_config + reporter_config +
73- network_config + swap_config + kernel_config + verbose_config)
74+ network_config + swap_config + kernel_config + verbose_config +
75+ cloud_config)
76
77
78 def get_curtin_merged_config(node):
79@@ -428,11 +430,10 @@
80 context.update(
81 get_node_preseed_context(
82 node, osystem, series, rack_controller=rack_controller))
83- context.update(get_curtin_context(node, rack_controller=rack_controller))
84 deprecated_context_variables = [
85 'main_archive_hostname', 'main_archive_directory',
86 'ports_archive_hostname', 'ports_archive_directory',
87- 'enable_http_proxy', 'http_proxy']
88+ 'enable_http_proxy', 'http_proxy', 'curtin_preseed']
89 deprecated_config_variables = []
90 for var in deprecated_context_variables:
91 if var not in context:
92@@ -449,6 +450,9 @@
93 if 'apt_mirrors' in config:
94 deprecated_config_variables.append('apt_mirrors')
95 del config['apt_mirrors']
96+ if 'debconf_selections' in config:
97+ deprecated_config_variables.append('debconf_selections')
98+ del config['debconf_selections']
99 if deprecated_context_variables:
100 log.warn(
101 "WARNING: '%s' contains deprecated preseed "
102@@ -466,20 +470,23 @@
103 return yaml.safe_dump(config)
104
105
106-def get_curtin_context(node, rack_controller=None):
107- """Return the curtin-specific context dictionary to be used to render
108- user-data templates.
109+def compose_curtin_cloud_config(node, rack_controller=None):
110+ """Return the curtin preseed for configuring a node's cloud-init cloud
111+ config.
112
113- :param node: The node for which to generate the user-data.
114- :rtype: dict.
115+ This returns the cloud-init cloud config configuration required for that
116+ is applied to the installed node.
117 """
118 token = NodeKey.objects.get_token_for_node(node)
119 if rack_controller is None:
120 rack_controller = node.get_boot_rack_controller()
121 base_url = rack_controller.url
122- return {
123- 'curtin_preseed': compose_cloud_init_preseed(node, token, base_url)
124+ config = {
125+ 'debconf_selections:': {
126+ 'maas': compose_cloud_init_preseed(node, token, base_url)
127+ }
128 }
129+ return [yaml.safe_dump(config)]
130
131
132 def get_preseed_type_for(node):
133@@ -781,6 +788,7 @@
134 'ports_archive_directory': ports_archive_directory,
135 'enable_http_proxy': Config.objects.get_config('enable_http_proxy'),
136 'http_proxy': Config.objects.get_config('http_proxy'),
137+ 'curtin_preseed': '',
138 }
139
140
141
142=== modified file 'src/maasserver/tests/test_preseed.py'
143--- src/maasserver/tests/test_preseed.py 2017-03-02 00:22:23 +0000
144+++ src/maasserver/tests/test_preseed.py 2017-03-02 02:03:28 +0000
145@@ -37,6 +37,7 @@
146 )
147 from maasserver.preseed import (
148 compose_curtin_archive_config,
149+ compose_curtin_cloud_config,
150 compose_curtin_kernel_preseed,
151 compose_curtin_maas_reporter,
152 compose_curtin_swap_preseed,
153@@ -46,7 +47,6 @@
154 curtin_maas_reporter,
155 GENERIC_FILENAME,
156 get_curtin_config,
157- get_curtin_context,
158 get_curtin_image,
159 get_curtin_installer_url,
160 get_curtin_merged_config,
161@@ -474,7 +474,7 @@
162 self.assertItemsEqual(
163 ['main_archive_hostname', 'main_archive_directory',
164 'ports_archive_hostname', 'ports_archive_directory',
165- 'enable_http_proxy', 'http_proxy'
166+ 'enable_http_proxy', 'http_proxy', 'curtin_preseed',
167 ],
168 context.keys())
169
170@@ -934,7 +934,7 @@
171 config = get_curtin_config(node)
172 self.assertThat(
173 config,
174- Contains("debconf_selections:"))
175+ Contains("late_commands:"))
176 self.assertThat(config, Not(Contains('mode: reboot')))
177
178 def test_get_curtin_config_removes_power_state(self):
179@@ -999,7 +999,6 @@
180 "%smetadata/latest/by-id/%s/" % (
181 primary_rack.url, node.system_id),
182 yaml_conf['late_commands']['maas'][2])
183- self.assertTrue('debconf_selections' in yaml_conf)
184
185 def test_get_curtin_config_with_ipv6_rack_url(self):
186 primary_rack = self.rpc_rack_controller
187@@ -1014,7 +1013,6 @@
188 "%smetadata/latest/by-id/%s/" % (
189 primary_rack.url, node.system_id),
190 yaml_conf['late_commands']['maas'][2])
191- self.assertTrue('debconf_selections' in yaml_conf)
192
193 def test_get_curtin_config_with_name_rack_url(self):
194 primary_rack = self.rpc_rack_controller
195@@ -1029,7 +1027,6 @@
196 "%smetadata/latest/by-id/%s/" % (
197 primary_rack.url, node.system_id),
198 yaml_conf['late_commands']['maas'][2])
199- self.assertTrue('debconf_selections' in yaml_conf)
200
201 def test_get_curtin_config_with_quote_rack_url(self):
202 primary_rack = self.rpc_rack_controller
203@@ -1043,7 +1040,6 @@
204 self.assertEqual(
205 "%smetadata/latest/by-id/%s/" % (primary_rack.url, node.system_id),
206 yaml_conf['late_commands']['maas'][2])
207- self.assertTrue('debconf_selections' in yaml_conf)
208
209 def make_fastpath_node(self, main_arch=None):
210 """Return a `Node`, with FPI enabled, and the given main architecture.
211@@ -1363,12 +1359,14 @@
212 archive.url,
213 self.extract_archive_setting(userdata[0]))
214
215- def test_get_curtin_context(self):
216+ def test_compose_curtin_cloud_config_debconf_selections(self):
217 node = factory.make_Node_with_Interface_on_Subnet(
218 primary_rack=self.rpc_rack_controller)
219- context = get_curtin_context(node)
220- self.assertItemsEqual(['curtin_preseed'], context.keys())
221- self.assertIn('cloud-init', context['curtin_preseed'])
222+ config = compose_curtin_cloud_config(
223+ node=node)
224+ self.assertThat(
225+ config[0],
226+ Contains("debconf_selections:"))
227
228 def test_get_curtin_image_calls_get_boot_images_for(self):
229 osystem = factory.make_name('os')