Merge lp:~rvb/maas/templ-back-bug-1439366 into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 3765
Proposed branch: lp:~rvb/maas/templ-back-bug-1439366
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 211 lines (+104/-7)
3 files modified
docs/development/preseeds.rst (+19/-2)
src/maasserver/preseed.py (+32/-0)
src/maasserver/tests/test_preseed.py (+53/-5)
To merge this branch: bzr merge lp:~rvb/maas/templ-back-bug-1439366
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+255177@code.launchpad.net

Commit message

Add backward-compatibility fix to support templates created for earlier versions of MAAS when Ubuntu was the only OS supported.

Description of the change

This cannot "clash" since none of the architectures that MAAS support as a name that is the same as an OS name.

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

Overall looks good. Don't really like that its needed, but code wise it should work.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'docs/development/preseeds.rst'
2--- docs/development/preseeds.rst 2015-02-13 09:06:14 +0000
3+++ docs/development/preseeds.rst 2015-04-03 11:47:12 +0000
4@@ -75,8 +75,25 @@
5 {prefix}
6 'generic'
7
8-``prefix`` is either empty or one of ``enlist``, ``enlist_userdata``,
9-``commissioning``, ``curtin``, ``curtin_userdata`` or ``preseed_master``.
10+ Note: in order to be backward-compatible with earlier versions of MAAS that
11+ only supported the Ubuntu OS, if the node OS is Ubuntu paths without the
12+ {osystem} are also tried:
13+ {prefix}_{osystem}_{node_arch}_{node_subarch}_{release}_{node_name}
14+ {prefix}_{node_arch}_{node_subarch}_{release}_{node_name}
15+ {prefix}_{osystem}_{node_arch}_{node_subarch}_{release}
16+ {prefix}_{node_arch}_{node_subarch}_{release}
17+ {prefix}_{osystem}_{node_arch}_{node_subarch}
18+ {prefix}_{node_arch}_{node_subarch}
19+ {prefix}_{osystem}_{node_arch}
20+ {prefix}_{node_arch}
21+ {prefix}_{osystem}
22+ {prefix}
23+ 'generic'
24+
25+``prefix`` is either empty (in which case the following underscore is also
26+ommitted: e.g. {osystem}_{node_arch}_{node_subarch}_{release}) or one of
27+``enlist``, ``enlist_userdata``, ``commissioning``, ``curtin``,
28+``curtin_userdata`` or ``preseed_master``.
29
30 As you can see this mechanism is also used to calculate the base preseeds for
31 all of installation, enlistment and commissioning. It allows end users to
32
33=== modified file 'src/maasserver/preseed.py'
34--- src/maasserver/preseed.py 2015-03-25 15:33:23 +0000
35+++ src/maasserver/preseed.py 2015-04-03 11:47:12 +0000
36@@ -60,6 +60,7 @@
37 from metadataserver.models import NodeKey
38 from metadataserver.user_data.snippets import get_snippet_context
39 from netaddr import IPAddress
40+from provisioningserver.drivers.osystem.ubuntu import UbuntuOS
41 from provisioningserver.rpc.exceptions import NoConnectionsAvailable
42 from provisioningserver.utils import locate_config
43 from provisioningserver.utils.fs import read_text_file
44@@ -408,6 +409,9 @@
45 osystem=node.get_osystem(), release=node.get_distro_series())
46
47
48+UBUNTU_NAME = UbuntuOS().name
49+
50+
51 def get_preseed_filenames(node, prefix='', osystem='', release='',
52 default=False):
53 """List possible preseed template filenames for the given node.
54@@ -435,11 +439,29 @@
55 {prefix}_{osystem}
56 {prefix}
57 'generic'
58+
59+ Note: in order to be backward-compatible with earlier versions of MAAS that
60+ only supported the Ubuntu OS, if the node OS is Ubuntu paths without the
61+ {osystem} are also tried:
62+ {prefix}_{osystem}_{node_arch}_{node_subarch}_{release}_{node_name}
63+ {prefix}_{node_arch}_{node_subarch}_{release}_{node_name}
64+ {prefix}_{osystem}_{node_arch}_{node_subarch}_{release}
65+ {prefix}_{node_arch}_{node_subarch}_{release}
66+ {prefix}_{osystem}_{node_arch}_{node_subarch}
67+ {prefix}_{node_arch}_{node_subarch}
68+ {prefix}_{osystem}_{node_arch}
69+ {prefix}_{node_arch}
70+ {prefix}_{osystem}
71+ {prefix}
72+ 'generic'
73 """
74 elements = []
75 # Add prefix.
76 if prefix != '':
77 elements.append(prefix)
78+ has_prefix = True
79+ else:
80+ has_prefix = False
81 # Add osystem
82 elements.append(osystem)
83 # Add architecture/sub-architecture.
84@@ -453,6 +475,16 @@
85 elements.append(node.hostname)
86 while elements:
87 yield compose_filename(elements)
88+ # Backward-compatibility fix for 1439366: also generate a filename
89+ # with the 'osystem' omitted when deploying with Ubuntu.
90+ if osystem == UBUNTU_NAME:
91+ should_emit = (
92+ (not has_prefix and len(elements) > 1) or
93+ (has_prefix and len(elements) > 2))
94+ if should_emit:
95+ cutoff = 1 if has_prefix else 0
96+ yield compose_filename(
97+ elements[:cutoff] + elements[cutoff + 1:])
98 elements.pop()
99 if default:
100 yield GENERIC_FILENAME
101
102=== modified file 'src/maasserver/tests/test_preseed.py'
103--- src/maasserver/tests/test_preseed.py 2015-03-25 15:33:23 +0000
104+++ src/maasserver/tests/test_preseed.py 2015-04-03 11:47:12 +0000
105@@ -76,6 +76,7 @@
106 from maastesting.matchers import MockCalledOnceWith
107 from metadataserver.models import NodeKey
108 from mock import ANY
109+from provisioningserver.drivers.osystem.ubuntu import UbuntuOS
110 from provisioningserver.rpc.exceptions import NoConnectionsAvailable
111 from provisioningserver.utils import locate_config
112 from provisioningserver.utils.enum import map_enum
113@@ -145,7 +146,7 @@
114 class TestGetPreseedFilenames(MAASServerTestCase):
115 """Tests for `get_preseed_filenames`."""
116
117- def test_get_preseed_filenames_returns_filenames(self):
118+ def test__returns_filenames(self):
119 hostname = factory.make_string()
120 prefix = factory.make_string()
121 osystem = factory.make_string()
122@@ -166,7 +167,7 @@
123 list(get_preseed_filenames(
124 node, prefix, osystem, release, default=True)))
125
126- def test_get_preseed_filenames_if_node_is_None(self):
127+ def test__returns_limited_filenames_if_node_is_None(self):
128 osystem = factory.make_string()
129 release = factory.make_string()
130 prefix = factory.make_string()
131@@ -178,7 +179,7 @@
132 ],
133 list(get_preseed_filenames(None, prefix, osystem, release)))
134
135- def test_get_preseed_filenames_supports_empty_prefix(self):
136+ def test__supports_empty_prefix(self):
137 hostname = factory.make_string()
138 osystem = factory.make_string()
139 release = factory.make_string()
140@@ -194,7 +195,7 @@
141 ],
142 list(get_preseed_filenames(node, '', osystem, release)))
143
144- def test_get_preseed_filenames_returns_list_without_default(self):
145+ def test__returns_list_without_default(self):
146 # If default=False is passed to get_preseed_filenames, the
147 # returned list won't include the default template name as a
148 # last resort template.
149@@ -207,7 +208,7 @@
150 list(get_preseed_filenames(
151 node, prefix, release, default=True))[-1])
152
153- def test_get_preseed_filenames_returns_list_with_default(self):
154+ def test__returns_list_with_default(self):
155 # If default=True is passed to get_preseed_filenames, the
156 # returned list will include the default template name as a
157 # last resort template.
158@@ -220,6 +221,53 @@
159 list(get_preseed_filenames(
160 node, prefix, release, default=False))[-1])
161
162+ def test__returns_backward_compatible_name_for_ubuntu_without_prefix(self):
163+ # If the OS is Ubuntu, also include backward-compatible filenames.
164+ # See bug 1439366 for details.
165+ hostname = factory.make_string()
166+ osystem = UbuntuOS().name
167+ release = factory.make_string()
168+ node = factory.make_Node(hostname=hostname)
169+ arch, subarch = node.architecture.split('/')
170+ self.assertSequenceEqual(
171+ [
172+ '%s_%s_%s_%s_%s' % (osystem, arch, subarch, release, hostname),
173+ '%s_%s_%s_%s' % (arch, subarch, release, hostname),
174+ '%s_%s_%s_%s' % (osystem, arch, subarch, release),
175+ '%s_%s_%s' % (arch, subarch, release),
176+ '%s_%s_%s' % (osystem, arch, subarch),
177+ '%s_%s' % (arch, subarch),
178+ '%s_%s' % (osystem, arch),
179+ '%s' % (arch),
180+ '%s' % osystem,
181+ ],
182+ list(get_preseed_filenames(node, '', osystem, release)))
183+
184+ def test__returns_backward_compatible_name_for_ubuntu_with_prefix(self):
185+ # If the OS is Ubuntu, also include backward-compatible filenames.
186+ # See bug 1439366 for details.
187+ hostname = factory.make_string()
188+ osystem = UbuntuOS().name
189+ release = factory.make_string()
190+ node = factory.make_Node(hostname=hostname)
191+ arch, subarch = node.architecture.split('/')
192+ prefix = factory.make_string()
193+ self.assertSequenceEqual(
194+ [
195+ '%s_%s_%s_%s_%s_%s' % (
196+ prefix, osystem, arch, subarch, release, hostname),
197+ '%s_%s_%s_%s_%s' % (prefix, arch, subarch, release, hostname),
198+ '%s_%s_%s_%s_%s' % (prefix, osystem, arch, subarch, release),
199+ '%s_%s_%s_%s' % (prefix, arch, subarch, release),
200+ '%s_%s_%s_%s' % (prefix, osystem, arch, subarch),
201+ '%s_%s_%s' % (prefix, arch, subarch),
202+ '%s_%s_%s' % (prefix, osystem, arch),
203+ '%s_%s' % (prefix, arch),
204+ '%s_%s' % (prefix, osystem),
205+ '%s' % prefix,
206+ ],
207+ list(get_preseed_filenames(node, prefix, osystem, release)))
208+
209
210 class TestConfiguration(MAASServerTestCase):
211 """Test for correct configuration of the preseed component."""