Merge lp:~andreserl/maas/refactor_debconf_selections_preseed into lp:~maas-committers/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-committers/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

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
=== modified file 'contrib/preseeds_v2/curtin_userdata'
--- contrib/preseeds_v2/curtin_userdata 2017-02-24 03:57:02 +0000
+++ contrib/preseeds_v2/curtin_userdata 2017-03-02 02:03:28 +0000
@@ -1,9 +1,4 @@
1#cloud-config1#cloud-config
2debconf_selections:
3 maas: |
4 {{for line in str(curtin_preseed).splitlines()}}
5 {{line}}
6 {{endfor}}
7{{if third_party_drivers and driver}}2{{if third_party_drivers and driver}}
8early_commands:3early_commands:
9 {{py: key_string = ''.join(['\\x%x' % x for x in driver['key_binary']])}}4 {{py: key_string = ''.join(['\\x%x' % x for x in driver['key_binary']])}}
105
=== modified file 'contrib/preseeds_v2/curtin_userdata_centos'
--- contrib/preseeds_v2/curtin_userdata_centos 2016-12-07 09:25:19 +0000
+++ contrib/preseeds_v2/curtin_userdata_centos 2017-03-02 02:03:28 +0000
@@ -1,9 +1,3 @@
1#cloud-config1#cloud-config
2debconf_selections:
3 maas: |
4 {{for line in str(curtin_preseed).splitlines()}}
5 {{line}}
6 {{endfor}}
7
8late_commands:2late_commands:
9 maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null']3 maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null']
104
=== modified file 'contrib/preseeds_v2/curtin_userdata_suse'
--- contrib/preseeds_v2/curtin_userdata_suse 2016-12-07 09:25:19 +0000
+++ contrib/preseeds_v2/curtin_userdata_suse 2017-03-02 02:03:28 +0000
@@ -1,9 +1,3 @@
1#cloud-config1#cloud-config
2debconf_selections:
3 maas: |
4 {{for line in str(curtin_preseed).splitlines()}}
5 {{line}}
6 {{endfor}}
7
8late_commands:2late_commands:
9 maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null']3 maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null']
104
=== modified file 'contrib/preseeds_v2/curtin_userdata_windows'
--- contrib/preseeds_v2/curtin_userdata_windows 2016-12-07 09:25:19 +0000
+++ contrib/preseeds_v2/curtin_userdata_windows 2017-03-02 02:03:28 +0000
@@ -1,10 +1,4 @@
1#cloud-config1#cloud-config
2debconf_selections:
3 maas: |
4 {{for line in str(curtin_preseed).splitlines()}}
5 {{line}}
6 {{endfor}}
7
8late_commands:2late_commands:
9 maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null']3 maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null']
104
115
=== modified file 'src/maasserver/preseed.py'
--- src/maasserver/preseed.py 2017-03-02 00:22:23 +0000
+++ src/maasserver/preseed.py 2017-03-02 02:03:28 +0000
@@ -298,6 +298,7 @@
298def get_curtin_yaml_config(node):298def get_curtin_yaml_config(node):
299 """Return the curtin configration for the node."""299 """Return the curtin configration for the node."""
300 main_config = get_curtin_config(node)300 main_config = get_curtin_config(node)
301 cloud_config = compose_curtin_cloud_config(node)
301 archive_config = compose_curtin_archive_config(node)302 archive_config = compose_curtin_archive_config(node)
302 reporter_config = compose_curtin_maas_reporter(node)303 reporter_config = compose_curtin_maas_reporter(node)
303 swap_config = compose_curtin_swap_preseed(node)304 swap_config = compose_curtin_swap_preseed(node)
@@ -328,7 +329,8 @@
328329
329 return (330 return (
330 storage_config + [main_config] + archive_config + reporter_config +331 storage_config + [main_config] + archive_config + reporter_config +
331 network_config + swap_config + kernel_config + verbose_config)332 network_config + swap_config + kernel_config + verbose_config +
333 cloud_config)
332334
333335
334def get_curtin_merged_config(node):336def get_curtin_merged_config(node):
@@ -428,11 +430,10 @@
428 context.update(430 context.update(
429 get_node_preseed_context(431 get_node_preseed_context(
430 node, osystem, series, rack_controller=rack_controller))432 node, osystem, series, rack_controller=rack_controller))
431 context.update(get_curtin_context(node, rack_controller=rack_controller))
432 deprecated_context_variables = [433 deprecated_context_variables = [
433 'main_archive_hostname', 'main_archive_directory',434 'main_archive_hostname', 'main_archive_directory',
434 'ports_archive_hostname', 'ports_archive_directory',435 'ports_archive_hostname', 'ports_archive_directory',
435 'enable_http_proxy', 'http_proxy']436 'enable_http_proxy', 'http_proxy', 'curtin_preseed']
436 deprecated_config_variables = []437 deprecated_config_variables = []
437 for var in deprecated_context_variables:438 for var in deprecated_context_variables:
438 if var not in context:439 if var not in context:
@@ -449,6 +450,9 @@
449 if 'apt_mirrors' in config:450 if 'apt_mirrors' in config:
450 deprecated_config_variables.append('apt_mirrors')451 deprecated_config_variables.append('apt_mirrors')
451 del config['apt_mirrors']452 del config['apt_mirrors']
453 if 'debconf_selections' in config:
454 deprecated_config_variables.append('debconf_selections')
455 del config['debconf_selections']
452 if deprecated_context_variables:456 if deprecated_context_variables:
453 log.warn(457 log.warn(
454 "WARNING: '%s' contains deprecated preseed "458 "WARNING: '%s' contains deprecated preseed "
@@ -466,20 +470,23 @@
466 return yaml.safe_dump(config)470 return yaml.safe_dump(config)
467471
468472
469def get_curtin_context(node, rack_controller=None):473def compose_curtin_cloud_config(node, rack_controller=None):
470 """Return the curtin-specific context dictionary to be used to render474 """Return the curtin preseed for configuring a node's cloud-init cloud
471 user-data templates.475 config.
472476
473 :param node: The node for which to generate the user-data.477 This returns the cloud-init cloud config configuration required for that
474 :rtype: dict.478 is applied to the installed node.
475 """479 """
476 token = NodeKey.objects.get_token_for_node(node)480 token = NodeKey.objects.get_token_for_node(node)
477 if rack_controller is None:481 if rack_controller is None:
478 rack_controller = node.get_boot_rack_controller()482 rack_controller = node.get_boot_rack_controller()
479 base_url = rack_controller.url483 base_url = rack_controller.url
480 return {484 config = {
481 'curtin_preseed': compose_cloud_init_preseed(node, token, base_url)485 'debconf_selections:': {
486 'maas': compose_cloud_init_preseed(node, token, base_url)
487 }
482 }488 }
489 return [yaml.safe_dump(config)]
483490
484491
485def get_preseed_type_for(node):492def get_preseed_type_for(node):
@@ -781,6 +788,7 @@
781 'ports_archive_directory': ports_archive_directory,788 'ports_archive_directory': ports_archive_directory,
782 'enable_http_proxy': Config.objects.get_config('enable_http_proxy'),789 'enable_http_proxy': Config.objects.get_config('enable_http_proxy'),
783 'http_proxy': Config.objects.get_config('http_proxy'),790 'http_proxy': Config.objects.get_config('http_proxy'),
791 'curtin_preseed': '',
784 }792 }
785793
786794
787795
=== modified file 'src/maasserver/tests/test_preseed.py'
--- src/maasserver/tests/test_preseed.py 2017-03-02 00:22:23 +0000
+++ src/maasserver/tests/test_preseed.py 2017-03-02 02:03:28 +0000
@@ -37,6 +37,7 @@
37)37)
38from maasserver.preseed import (38from maasserver.preseed import (
39 compose_curtin_archive_config,39 compose_curtin_archive_config,
40 compose_curtin_cloud_config,
40 compose_curtin_kernel_preseed,41 compose_curtin_kernel_preseed,
41 compose_curtin_maas_reporter,42 compose_curtin_maas_reporter,
42 compose_curtin_swap_preseed,43 compose_curtin_swap_preseed,
@@ -46,7 +47,6 @@
46 curtin_maas_reporter,47 curtin_maas_reporter,
47 GENERIC_FILENAME,48 GENERIC_FILENAME,
48 get_curtin_config,49 get_curtin_config,
49 get_curtin_context,
50 get_curtin_image,50 get_curtin_image,
51 get_curtin_installer_url,51 get_curtin_installer_url,
52 get_curtin_merged_config,52 get_curtin_merged_config,
@@ -474,7 +474,7 @@
474 self.assertItemsEqual(474 self.assertItemsEqual(
475 ['main_archive_hostname', 'main_archive_directory',475 ['main_archive_hostname', 'main_archive_directory',
476 'ports_archive_hostname', 'ports_archive_directory',476 'ports_archive_hostname', 'ports_archive_directory',
477 'enable_http_proxy', 'http_proxy'477 'enable_http_proxy', 'http_proxy', 'curtin_preseed',
478 ],478 ],
479 context.keys())479 context.keys())
480480
@@ -934,7 +934,7 @@
934 config = get_curtin_config(node)934 config = get_curtin_config(node)
935 self.assertThat(935 self.assertThat(
936 config,936 config,
937 Contains("debconf_selections:"))937 Contains("late_commands:"))
938 self.assertThat(config, Not(Contains('mode: reboot')))938 self.assertThat(config, Not(Contains('mode: reboot')))
939939
940 def test_get_curtin_config_removes_power_state(self):940 def test_get_curtin_config_removes_power_state(self):
@@ -999,7 +999,6 @@
999 "%smetadata/latest/by-id/%s/" % (999 "%smetadata/latest/by-id/%s/" % (
1000 primary_rack.url, node.system_id),1000 primary_rack.url, node.system_id),
1001 yaml_conf['late_commands']['maas'][2])1001 yaml_conf['late_commands']['maas'][2])
1002 self.assertTrue('debconf_selections' in yaml_conf)
10031002
1004 def test_get_curtin_config_with_ipv6_rack_url(self):1003 def test_get_curtin_config_with_ipv6_rack_url(self):
1005 primary_rack = self.rpc_rack_controller1004 primary_rack = self.rpc_rack_controller
@@ -1014,7 +1013,6 @@
1014 "%smetadata/latest/by-id/%s/" % (1013 "%smetadata/latest/by-id/%s/" % (
1015 primary_rack.url, node.system_id),1014 primary_rack.url, node.system_id),
1016 yaml_conf['late_commands']['maas'][2])1015 yaml_conf['late_commands']['maas'][2])
1017 self.assertTrue('debconf_selections' in yaml_conf)
10181016
1019 def test_get_curtin_config_with_name_rack_url(self):1017 def test_get_curtin_config_with_name_rack_url(self):
1020 primary_rack = self.rpc_rack_controller1018 primary_rack = self.rpc_rack_controller
@@ -1029,7 +1027,6 @@
1029 "%smetadata/latest/by-id/%s/" % (1027 "%smetadata/latest/by-id/%s/" % (
1030 primary_rack.url, node.system_id),1028 primary_rack.url, node.system_id),
1031 yaml_conf['late_commands']['maas'][2])1029 yaml_conf['late_commands']['maas'][2])
1032 self.assertTrue('debconf_selections' in yaml_conf)
10331030
1034 def test_get_curtin_config_with_quote_rack_url(self):1031 def test_get_curtin_config_with_quote_rack_url(self):
1035 primary_rack = self.rpc_rack_controller1032 primary_rack = self.rpc_rack_controller
@@ -1043,7 +1040,6 @@
1043 self.assertEqual(1040 self.assertEqual(
1044 "%smetadata/latest/by-id/%s/" % (primary_rack.url, node.system_id),1041 "%smetadata/latest/by-id/%s/" % (primary_rack.url, node.system_id),
1045 yaml_conf['late_commands']['maas'][2])1042 yaml_conf['late_commands']['maas'][2])
1046 self.assertTrue('debconf_selections' in yaml_conf)
10471043
1048 def make_fastpath_node(self, main_arch=None):1044 def make_fastpath_node(self, main_arch=None):
1049 """Return a `Node`, with FPI enabled, and the given main architecture.1045 """Return a `Node`, with FPI enabled, and the given main architecture.
@@ -1363,12 +1359,14 @@
1363 archive.url,1359 archive.url,
1364 self.extract_archive_setting(userdata[0]))1360 self.extract_archive_setting(userdata[0]))
13651361
1366 def test_get_curtin_context(self):1362 def test_compose_curtin_cloud_config_debconf_selections(self):
1367 node = factory.make_Node_with_Interface_on_Subnet(1363 node = factory.make_Node_with_Interface_on_Subnet(
1368 primary_rack=self.rpc_rack_controller)1364 primary_rack=self.rpc_rack_controller)
1369 context = get_curtin_context(node)1365 config = compose_curtin_cloud_config(
1370 self.assertItemsEqual(['curtin_preseed'], context.keys())1366 node=node)
1371 self.assertIn('cloud-init', context['curtin_preseed'])1367 self.assertThat(
1368 config[0],
1369 Contains("debconf_selections:"))
13721370
1373 def test_get_curtin_image_calls_get_boot_images_for(self):1371 def test_get_curtin_image_calls_get_boot_images_for(self):
1374 osystem = factory.make_name('os')1372 osystem = factory.make_name('os')