Merge lp:~blake-rouse/maas/fix-startup-and-list-archs into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 2872
Proposed branch: lp:~blake-rouse/maas/fix-startup-and-list-archs
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 268 lines (+58/-74)
4 files modified
src/maasserver/forms.py (+4/-13)
src/maasserver/start_up.py (+8/-11)
src/maasserver/tests/test_forms_helpers.py (+17/-22)
src/maasserver/tests/test_start_up.py (+29/-28)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-startup-and-list-archs
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+232602@code.launchpad.net

Commit message

Fix start_up to use BootResource instead of BootImage. Fix list_all_usable_architectures to use BootResource instead of BootImage.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Looks good. Just a couple of comments on wording.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/forms.py'
2--- src/maasserver/forms.py 2014-09-01 12:18:51 +0000
3+++ src/maasserver/forms.py 2014-09-02 13:12:22 +0000
4@@ -98,7 +98,6 @@
5 list_commisioning_choices,
6 )
7 from maasserver.models import (
8- BootImage,
9 BootResource,
10 BootResourceFile,
11 BootResourceSet,
12@@ -212,19 +211,11 @@
13 def list_all_usable_architectures():
14 """Return all architectures that can be used for nodes.
15
16- These are the architectures for which any nodegroup has the boot images
17- required to commission and install nodes.
18+ These are the architectures for which any boot resource exists. Now that
19+ all clusters sync from the region, all cluster support the same
20+ architectures.
21 """
22- # The Node edit form offers all usable architectures as options for the
23- # architecture field. Not all of these may be available in the node's
24- # nodegroup, but to represent that accurately in the UI would depend on
25- # the currently selected nodegroup. Narrowing the options down further
26- # would have to happen browser-side.
27- architectures = set()
28- for nodegroup in NodeGroup.objects.all():
29- architectures = architectures.union(
30- BootImage.objects.get_usable_architectures(nodegroup))
31- return sorted(architectures)
32+ return sorted(BootResource.objects.get_usable_architectures())
33
34
35 def list_architecture_choices(architectures):
36
37=== modified file 'src/maasserver/start_up.py'
38--- src/maasserver/start_up.py 2014-08-29 20:14:16 +0000
39+++ src/maasserver/start_up.py 2014-09-02 13:12:22 +0000
40@@ -35,7 +35,7 @@
41 from maasserver.enum import COMPONENT
42 from maasserver.fields import register_mac_type
43 from maasserver.models import (
44- BootImage,
45+ BootResource,
46 NodeGroup,
47 )
48 from provisioningserver.upgrade_cluster import create_gnupg_home
49@@ -65,17 +65,14 @@
50 post_start_up()
51
52
53-def update_import_script_error():
54+def update_boot_resource_error():
55 import_script = COMPONENT.IMPORT_PXE_FILES
56- have_boot_images = BootImage.objects.all().exists()
57- if not have_boot_images and get_persistent_error(import_script) is None:
58+ have_resources = BootResource.objects.all().exists()
59+ if not have_resources and get_persistent_error(import_script) is None:
60 warning = dedent("""\
61- The region controller does not know whether any boot images have
62- been imported yet. If this message does not disappear in 5
63- minutes, there may be a communication problem between the region
64- worker process and the region controller. Check the region
65- worker's logs for signs that it was unable to report to the MAAS
66- API.
67+ The region controller does not have any boot images available.
68+ Nodes will not be able to provision without boot images. Start
69+ the boot images import process to resolve this issue.
70 """)
71 register_persistent_error(import_script, warning)
72
73@@ -101,7 +98,7 @@
74 write_full_dns_config(reload_retry=True)
75
76 # Check whether we have boot images yet.
77- update_import_script_error()
78+ update_boot_resource_error()
79
80
81 def post_start_up():
82
83=== modified file 'src/maasserver/tests/test_forms_helpers.py'
84--- src/maasserver/tests/test_forms_helpers.py 2014-08-26 08:07:48 +0000
85+++ src/maasserver/tests/test_forms_helpers.py 2014-09-02 13:12:22 +0000
86@@ -14,7 +14,10 @@
87 __metaclass__ = type
88 __all__ = []
89
90-from maasserver.enum import NODE_STATUS
91+from maasserver.enum import (
92+ BOOT_RESOURCE_TYPE,
93+ NODE_STATUS,
94+ )
95 from maasserver.forms import (
96 AdminNodeForm,
97 AdminNodeWithMACAddressesForm,
98@@ -38,30 +41,22 @@
99
100 class TestHelpers(MAASServerTestCase):
101
102- def make_usable_boot_images(self, nodegroup=None, osystem=None,
103- arch=None, subarchitecture=None, release=None):
104- """Create a set of boot images, so the architecture becomes "usable".
105+ def make_usable_boot_resource(self, arch=None, subarch=None):
106+ """Create a set of boot resources, so the architecture becomes usable.
107
108- This will make the images' architecture show up in the list of usable
109- architecture.
110+ This will make the resources' architecture show up in the list of
111+ usable architecture.
112
113 Nothing is returned.
114 """
115- if nodegroup is None:
116- nodegroup = factory.make_node_group()
117- if osystem is None:
118- osystem = factory.make_name('os')
119 if arch is None:
120 arch = factory.make_name('arch')
121- if subarchitecture is None:
122- subarchitecture = factory.make_name('subarch')
123- if release is None:
124- release = factory.make_name('release')
125+ if subarch is None:
126+ subarch = factory.make_name('subarch')
127 for purpose in ['install', 'commissioning']:
128- factory.make_boot_image(
129- nodegroup=nodegroup, osystem=osystem, architecture=arch,
130- subarchitecture=subarchitecture, release=release,
131- purpose=purpose)
132+ architecture = '%s/%s' % (arch, subarch)
133+ factory.make_usable_boot_resource(
134+ rtype=BOOT_RESOURCE_TYPE.SYNCED, architecture=architecture)
135
136 def test_initialize_node_group_leaves_nodegroup_reference_intact(self):
137 preselected_nodegroup = factory.make_node_group()
138@@ -88,7 +83,7 @@
139 (factory.make_name('arch'), factory.make_name('subarch'))
140 for _ in range(3)]
141 for arch, subarch in arches:
142- self.make_usable_boot_images(arch=arch, subarchitecture=subarch)
143+ self.make_usable_boot_resource(arch=arch, subarch=subarch)
144 expected = [
145 "%s/%s" % (arch, subarch) for arch, subarch in arches]
146 self.assertItemsEqual(expected, list_all_usable_architectures())
147@@ -98,7 +93,7 @@
148 (factory.make_name('arch'), factory.make_name('subarch'))
149 for _ in range(3)]
150 for arch, subarch in arches:
151- self.make_usable_boot_images(arch=arch, subarchitecture=subarch)
152+ self.make_usable_boot_resource(arch=arch, subarch=subarch)
153 expected = [
154 "%s/%s" % (arch, subarch) for arch, subarch in arches]
155 self.assertEqual(sorted(expected), list_all_usable_architectures())
156@@ -106,8 +101,8 @@
157 def test_list_all_usable_architectures_returns_no_duplicates(self):
158 arch = factory.make_name('arch')
159 subarch = factory.make_name('subarch')
160- self.make_usable_boot_images(arch=arch, subarchitecture=subarch)
161- self.make_usable_boot_images(arch=arch, subarchitecture=subarch)
162+ self.make_usable_boot_resource(arch=arch, subarch=subarch)
163+ self.make_usable_boot_resource(arch=arch, subarch=subarch)
164 self.assertEqual(
165 ["%s/%s" % (arch, subarch)], list_all_usable_architectures())
166
167
168=== modified file 'src/maasserver/tests/test_start_up.py'
169--- src/maasserver/tests/test_start_up.py 2014-08-26 17:50:29 +0000
170+++ src/maasserver/tests/test_start_up.py 2014-09-02 13:12:22 +0000
171@@ -28,7 +28,6 @@
172 NODEGROUP_STATUS,
173 )
174 from maasserver.models import (
175- BootImage,
176 BootSource,
177 NodeGroup,
178 )
179@@ -37,11 +36,20 @@
180 from maasserver.testing.testcase import MAASServerTestCase
181 from maastesting.celery import CeleryFixture
182 from maastesting.fakemethod import FakeMethod
183-from maastesting.matchers import MockCalledOnceWith
184-from mock import Mock
185+from maastesting.matchers import (
186+ MockCalledOnceWith,
187+ MockCalledWith,
188+ )
189+from mock import (
190+ ANY,
191+ Mock,
192+ )
193 from provisioningserver import tasks
194 from testresources import FixtureResource
195-from testtools.matchers import HasLength
196+from testtools.matchers import (
197+ HasLength,
198+ Not,
199+ )
200
201
202 class LockChecker:
203@@ -122,48 +130,41 @@
204 start_up.inner_start_up()
205 self.assertThat(BootSource.objects.all(), HasLength(1))
206
207- def test__warns_about_missing_boot_images(self):
208- # If no boot images have been registered yet, that may mean that
209- # the import script has not been successfully run yet, or that
210- # the master worker is having trouble reporting its images. And
211- # so start_up registers a persistent warning about this.
212- BootImage.objects.all().delete()
213+ def test__warns_about_missing_boot_resources(self):
214+ # If no boot resources have been created, then the user has not
215+ # performed the import process.
216 discard_persistent_error(COMPONENT.IMPORT_PXE_FILES)
217 recorder = self.patch(start_up, 'register_persistent_error')
218
219 start_up.inner_start_up()
220
221- self.assertIn(
222- COMPONENT.IMPORT_PXE_FILES,
223- [args[0][0] for args in recorder.call_args_list])
224+ self.assertThat(
225+ recorder,
226+ MockCalledWith(COMPONENT.IMPORT_PXE_FILES, ANY))
227
228- def test__does_not_warn_if_boot_images_are_known(self):
229- # If boot images are known, there is no warning about the import
230- # script.
231- factory.make_boot_image()
232+ def test__does_not_warn_if_boot_resources_are_known(self):
233+ # If boot resources are known, there is no warning.
234+ factory.make_boot_resource()
235 recorder = self.patch(start_up, 'register_persistent_error')
236
237 start_up.inner_start_up()
238
239- self.assertNotIn(
240- COMPONENT.IMPORT_PXE_FILES,
241- [args[0][0] for args in recorder.call_args_list])
242+ self.assertThat(
243+ recorder,
244+ Not(MockCalledWith(COMPONENT.IMPORT_PXE_FILES, ANY)))
245
246 def test__does_not_warn_if_already_warning(self):
247- # If there already is a warning about missing boot images, it is
248- # based on more precise knowledge of whether we ever heard from
249- # the region worker at all. It will not be replaced by a less
250- # knowledgeable warning.
251- BootImage.objects.all().delete()
252+ # If there already is a warning about missing boot resources, it will
253+ # not be replaced.
254 register_persistent_error(
255 COMPONENT.IMPORT_PXE_FILES, factory.make_string())
256 recorder = self.patch(start_up, 'register_persistent_error')
257
258 start_up.inner_start_up()
259
260- self.assertNotIn(
261- COMPONENT.IMPORT_PXE_FILES,
262- [args[0][0] for args in recorder.call_args_list])
263+ self.assertThat(
264+ recorder,
265+ Not(MockCalledWith(COMPONENT.IMPORT_PXE_FILES, ANY)))
266
267
268 class TestPostStartUp(MAASServerTestCase):