Merge lp:~andreserl/maas/lp1646955 into lp:~maas-committers/maas/trunk

Proposed by Andres Rodriguez
Status: Merged
Merged at revision: 5603
Proposed branch: lp:~andreserl/maas/lp1646955
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 162 lines (+102/-1)
2 files modified
src/maasserver/preseed.py (+57/-1)
src/maasserver/tests/test_preseed.py (+45/-0)
To merge this branch: bzr merge lp:~andreserl/maas/lp1646955
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Blake Rouse (community) Approve
Review via email: mp+312851@code.launchpad.net

Commit message

Re-add deprecated variables to the curtin preseed context so that MAAS doesn't fail rendering on machine deployment, causing machines to fail to deploy.

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Some minor nits below.

Revision history for this message
Gavin Panella (allenap) :
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Also missing commit message.

review: Needs Fixing
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good.

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (33.0 KiB)

The attempt to merge lp:~andreserl/maas/lp1646955 into lp:maas failed. Below is the output from the failed tests.

Hit:1 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:3 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:4 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Fetched 306 kB in 0s (612 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
    --no-install-recommends install apache2 archdetect-deb authbind avahi-utils bash bind9 bind9utils build-essential bzr bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools git gjs ipython isc-dhcp-common isc-dhcp-server libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libnss-wrapper libpq-dev make nodejs-legacy npm postgresql pxelinux python3-all python3-apt python3-attr python3-bson python3-convoy python3-crochet python3-cssselect python3-curtin python3-dev python3-distro-info python3-django python3-django-nose python3-django-piston3 python3-dnspython python3-docutils python3-formencode python3-hivex python3-httplib2 python3-jinja2 python3-jsonschema python3-lxml python3-netaddr python3-netifaces python3-novaclient python3-oauth python3-oauthlib python3-openssl python3-paramiko python3-petname python3-pexpect python3-psycopg2 python3-pyinotify python3-pyparsing python3-pyvmomi python3-requests python3-seamicroclient python3-setuptools python3-simplestreams python3-sphinx python3-tempita python3-twisted python3-txtftp python3-tz python3-yaml python3-zope.interface python-bson python-crochet python-django python-django-piston python-djorm-ext-pgarray python-formencode python-lxml python-netaddr python-netifaces python-pocket-lint python-psycopg2 python-simplejson python-tempita python-twisted python-yaml socat syslinux-common tgt ubuntu-cloudimage-keyring wget xvfb
Reading package lists...
Building dependency tree...
Reading state information...
authbind is already the newest version (2.1.1+nmu1).
avahi-utils is already the newest version (0.6.32~rc+dfsg-1ubuntu2).
build-essential is already the newest version (12.1ubuntu2).
debhelper is already the newest version (9.20160115ubuntu3).
distro-info is already the newest version (0.14build1).
git is already the newest version (1:2.7.4-0ubuntu1).
libjs-angularjs is already the newest version (1.2.28-1ubuntu2).
libjs-jquery is already the newest version (1.11.3+dfsg-4).
libjs-yui3-full is already the newest version (3.5.1-1ubuntu3).
libjs-yui3-min is already the newest version (3.5.1-1ubuntu3).
make is already the newest version (4.1-6).
postgresql is already the newest version (9.5+173).
pxelinux is already the newest version (3:6.03+dfsg-11ubuntu1).
python-formencode is already the newest version (1.3.0-0ubuntu5).
python-lxml is already the newest version (3.5.0-1build1).
python-netaddr is already the newest version (0.7.18-1).
python-netifaces is already the newest version (0.10.4-0.1build2).
python-psycopg2 is...

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

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Andres Rodriguez (andreserl) :
review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (1.6 MiB)

The attempt to merge lp:~andreserl/maas/lp1646955 into lp:maas failed. Below is the output from the failed tests.

Hit:1 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:3 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:4 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Fetched 306 kB in 2s (124 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
    --no-install-recommends install apache2 archdetect-deb authbind avahi-utils bash bind9 bind9utils build-essential bzr bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools git gjs ipython isc-dhcp-common isc-dhcp-server libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libnss-wrapper libpq-dev make nodejs-legacy npm postgresql pxelinux python3-all python3-apt python3-attr python3-bson python3-convoy python3-crochet python3-cssselect python3-curtin python3-dev python3-distro-info python3-django python3-django-nose python3-django-piston3 python3-dnspython python3-docutils python3-formencode python3-hivex python3-httplib2 python3-jinja2 python3-jsonschema python3-lxml python3-netaddr python3-netifaces python3-novaclient python3-oauth python3-oauthlib python3-openssl python3-paramiko python3-petname python3-pexpect python3-psycopg2 python3-pyinotify python3-pyparsing python3-pyvmomi python3-requests python3-seamicroclient python3-setuptools python3-simplestreams python3-sphinx python3-tempita python3-twisted python3-txtftp python3-tz python3-yaml python3-zope.interface python-bson python-crochet python-django python-django-piston python-djorm-ext-pgarray python-formencode python-lxml python-netaddr python-netifaces python-pocket-lint python-psycopg2 python-simplejson python-tempita python-twisted python-yaml socat syslinux-common tgt ubuntu-cloudimage-keyring wget xvfb
Reading package lists...
Building dependency tree...
Reading state information...
authbind is already the newest version (2.1.1+nmu1).
avahi-utils is already the newest version (0.6.32~rc+dfsg-1ubuntu2).
build-essential is already the newest version (12.1ubuntu2).
debhelper is already the newest version (9.20160115ubuntu3).
distro-info is already the newest version (0.14build1).
git is already the newest version (1:2.7.4-0ubuntu1).
libjs-angularjs is already the newest version (1.2.28-1ubuntu2).
libjs-jquery is already the newest version (1.11.3+dfsg-4).
libjs-yui3-full is already the newest version (3.5.1-1ubuntu3).
libjs-yui3-min is already the newest version (3.5.1-1ubuntu3).
make is already the newest version (4.1-6).
postgresql is already the newest version (9.5+173).
pxelinux is already the newest version (3:6.03+dfsg-11ubuntu1).
python-formencode is already the newest version (1.3.0-0ubuntu5).
python-lxml is already the newest version (3.5.0-1build1).
python-netaddr is already the newest version (0.7.18-1).
python-netifaces is already the newest version (0.10.4-0.1build2).
python-psycopg2 is...

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

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Andres Rodriguez (andreserl) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/preseed.py'
2--- src/maasserver/preseed.py 2016-12-08 09:10:54 +0000
3+++ src/maasserver/preseed.py 2016-12-12 17:30:38 +0000
4@@ -62,7 +62,10 @@
5 from metadataserver.models import NodeKey
6 from metadataserver.user_data.snippets import get_snippet_context
7 from provisioningserver.drivers.osystem.ubuntu import UbuntuOS
8-from provisioningserver.logger import get_maas_logger
9+from provisioningserver.logger import (
10+ get_maas_logger,
11+ LegacyLogger,
12+)
13 from provisioningserver.rpc.exceptions import NoConnectionsAvailable
14 from provisioningserver.utils import typed
15 from provisioningserver.utils.url import compose_URL
16@@ -72,6 +75,8 @@
17
18 maaslog = get_maas_logger("preseed")
19
20+log = LegacyLogger()
21+
22 GENERIC_FILENAME = 'generic'
23
24
25@@ -417,9 +422,36 @@
26 get_node_preseed_context(
27 node, osystem, series, rack_controller=rack_controller))
28 context.update(get_curtin_context(node, rack_controller=rack_controller))
29+ deprecated_context_variables = [
30+ 'main_archive_hostname', 'main_archive_directory',
31+ 'ports_archive_hostname', 'ports_archive_directory',
32+ 'enable_http_proxy', 'http_proxy']
33+ deprecated_config_variables = []
34+ for var in deprecated_context_variables:
35+ if var not in context:
36+ deprecated_context_variables.remove(var)
37+ context.update(get_node_deprecated_preseed_context())
38 config = yaml.load(template.substitute(**context))
39+ # Remove deprecated config from the curtin preseed.
40 if 'power_state' in config:
41 del config['power_state']
42+ deprecated_config_variables.append('power_state')
43+ if 'apt_proxy' in config:
44+ deprecated_config_variables.append('apt_proxy')
45+ del config['apt_proxy']
46+ if 'apt_mirrors' in config:
47+ deprecated_config_variables.append('apt_mirrors')
48+ del config['apt_mirrors']
49+ if deprecated_context_variables:
50+ log.warn(
51+ "WARNING: '%s' contains deprecated preseed "
52+ "variables. Please remove - %s" % (
53+ template.name, ",".join(deprecated_context_variables)))
54+ if deprecated_config_variables:
55+ log.warn(
56+ "WARNING: '%s' contains deprecated preseed "
57+ "configuration. Please remove - %s" % (
58+ template.name, ",".join(deprecated_config_variables)))
59 # Precise does not support cloud-init performing the reboot, so curtin
60 # must have this statement.
61 if node.distro_series == "precise":
62@@ -721,6 +753,30 @@
63 }
64
65
66+def get_node_deprecated_preseed_context():
67+ """Return the node-dependent context dictionary to be used to render
68+ preseed template. This includes all the context variables that have
69+ been deprecated, but allows for backwards compatibility for those
70+ preseeds that still contain old variables.
71+
72+ :return: The context dictionary.
73+ :rtype: dict.
74+ """
75+ main_archive_hostname, main_archive_directory = get_netloc_and_path(
76+ PackageRepository.get_main_archive().url)
77+ ports_archive_hostname, ports_archive_directory = get_netloc_and_path(
78+ PackageRepository.get_ports_archive().url)
79+
80+ return {
81+ 'main_archive_hostname': main_archive_hostname,
82+ 'main_archive_directory': main_archive_directory,
83+ 'ports_archive_hostname': ports_archive_hostname,
84+ 'ports_archive_directory': ports_archive_directory,
85+ 'enable_http_proxy': Config.objects.get_config('enable_http_proxy'),
86+ 'http_proxy': Config.objects.get_config('http_proxy'),
87+ }
88+
89+
90 def render_enlistment_preseed(
91 prefix, osystem='', release='', rack_controller=None):
92 """Return the enlistment preseed.
93
94=== modified file 'src/maasserver/tests/test_preseed.py'
95--- src/maasserver/tests/test_preseed.py 2016-12-08 09:10:54 +0000
96+++ src/maasserver/tests/test_preseed.py 2016-12-12 17:30:38 +0000
97@@ -54,6 +54,7 @@
98 get_enlist_preseed,
99 get_enlist_userdata,
100 get_netloc_and_path,
101+ get_node_deprecated_preseed_context,
102 get_node_preseed_context,
103 get_preseed,
104 get_preseed_context,
105@@ -460,6 +461,23 @@
106 context)
107
108
109+class TestNodeDeprecatedPreseedContext(
110+ PreseedRPCMixin, BootImageHelperMixin, MAASTransactionServerTestCase):
111+ """Test for `get_node_deprecated_preseed_context`."""
112+
113+ def test_get_node_deprecated_preseed_context_contains_keys(self):
114+ node = factory.make_Node_with_Interface_on_Subnet(
115+ primary_rack=self.rpc_rack_controller)
116+ self.configure_get_boot_images_for_node(node, 'install')
117+ context = get_node_deprecated_preseed_context()
118+ self.assertItemsEqual(
119+ ['main_archive_hostname', 'main_archive_directory',
120+ 'ports_archive_hostname', 'ports_archive_directory',
121+ 'enable_http_proxy', 'http_proxy'
122+ ],
123+ context)
124+
125+
126 class TestNodePreseedContext(
127 PreseedRPCMixin, BootImageHelperMixin, MAASTransactionServerTestCase):
128 """Tests for `get_node_preseed_context`."""
129@@ -880,6 +898,33 @@
130 config = get_curtin_config(node)
131 self.assertThat(config, Not(Contains('mode: reboot')))
132
133+ def test_get_curtin_config_removes_apt_mirrors(self):
134+ node = factory.make_Node_with_Interface_on_Subnet(
135+ primary_rack=self.rpc_rack_controller)
136+ self.configure_get_boot_images_for_node(node, 'xinstall')
137+ apt_mirrors_template = dedent("""\
138+ apt_mirrors:
139+ ubuntu_archive:
140+ ubuntu_security:
141+ """)
142+ self.patch(preseed_module, "get_preseed_template").return_value = (
143+ factory.make_name("filename"), apt_mirrors_template)
144+ config = get_curtin_config(node)
145+ self.assertThat(config, Not(Contains('ubuntu_archive')))
146+ self.assertThat(config, Not(Contains('ubuntu_security')))
147+
148+ def test_get_curtin_config_removes_apt_proxy(self):
149+ node = factory.make_Node_with_Interface_on_Subnet(
150+ primary_rack=self.rpc_rack_controller)
151+ self.configure_get_boot_images_for_node(node, 'xinstall')
152+ apt_proxy_template = dedent("""\
153+ apt_proxy: http://127.0.0.1:8000/
154+ """)
155+ self.patch(preseed_module, "get_preseed_template").return_value = (
156+ factory.make_name("filename"), apt_proxy_template)
157+ config = get_curtin_config(node)
158+ self.assertThat(config, Not(Contains('127.0.0.1')))
159+
160 def test_get_curtin_config_contains_reboot_for_precise(self):
161 node = factory.make_Node_with_Interface_on_Subnet(
162 primary_rack=self.rpc_rack_controller)