Merge lp:~ltrager/maas/lp1686169_2.1 into lp:maas/2.1
- lp1686169_2.1
- Merge into 2.1
Proposed by
Lee Trager
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Blake Rouse | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 5602 | ||||
Proposed branch: | lp:~ltrager/maas/lp1686169_2.1 | ||||
Merge into: | lp:maas/2.1 | ||||
Diff against target: |
652 lines (+253/-162) 5 files modified
Makefile (+2/-2) src/maasserver/bootresources.py (+2/-63) src/maasserver/tests/test_bootresources.py (+59/-86) src/provisioningserver/import_images/download_descriptions.py (+72/-0) src/provisioningserver/import_images/tests/test_download_descriptions.py (+118/-11) |
||||
To merge this branch: | bzr merge lp:~ltrager/maas/lp1686169_2.1 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Blake Rouse (community) | Approve | ||
Review via email: mp+323191@code.launchpad.net |
Commit message
Filter out unsupported products from BootSourceCache.
Description of the change
This prevents Ubuntu Core from being shown in the boot images page in MAAS 2.1
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Makefile' |
2 | --- Makefile 2016-10-17 06:38:56 +0000 |
3 | +++ Makefile 2017-04-26 00:29:21 +0000 |
4 | @@ -587,8 +587,8 @@ |
5 | # this. |
6 | |
7 | # Old names. |
8 | -PACKAGING := $(abspath ../packaging.trunk) |
9 | -PACKAGING_BRANCH := lp:~maas-maintainers/maas/packaging |
10 | +PACKAGING := $(abspath ../packaging.2.1) |
11 | +PACKAGING_BRANCH := lp:~maas-maintainers/maas/packaging-2.1 |
12 | |
13 | packaging-tree = $(PACKAGING) |
14 | packaging-branch = $(PACKAGING_BRANCH) |
15 | |
16 | === modified file 'src/maasserver/bootresources.py' |
17 | --- src/maasserver/bootresources.py 2016-10-28 15:58:32 +0000 |
18 | +++ src/maasserver/bootresources.py 2017-04-26 00:29:21 +0000 |
19 | @@ -18,7 +18,6 @@ |
20 | from datetime import timedelta |
21 | from operator import itemgetter |
22 | import os |
23 | -import re |
24 | from subprocess import CalledProcessError |
25 | from textwrap import dedent |
26 | import threading |
27 | @@ -81,6 +80,7 @@ |
28 | from provisioningserver.import_images.download_descriptions import ( |
29 | download_all_image_descriptions, |
30 | image_passes_filter, |
31 | + validate_product, |
32 | ) |
33 | from provisioningserver.import_images.helpers import ( |
34 | get_os_from_product, |
35 | @@ -1019,12 +1019,6 @@ |
36 | # will be downloaded from simplestreams. |
37 | 'max_items': 1, |
38 | }) |
39 | - # Compile a regex to validate bootloader product names. This only |
40 | - # allows V1 bootloaders. |
41 | - self.bootloader_regex = re.compile('.*:1:.*', re.IGNORECASE) |
42 | - # Compile a regex to validate Ubuntu product names. This only allows |
43 | - # V2 and V3 Ubuntu products. |
44 | - self.ubuntu_regex = re.compile('.*:v[23]:.*', re.IGNORECASE) |
45 | |
46 | def load_products(self, path=None, content_id=None): |
47 | """Overridable from `BasicMirrorWriter`.""" |
48 | @@ -1038,59 +1032,6 @@ |
49 | return self.product_mapping.contains( |
50 | sutil.products_exdata(src, pedigree)) |
51 | |
52 | - def _validate_ubuntu(self, data, product_name): |
53 | - osystem = data.get('os') |
54 | - if 'ubuntu' not in osystem.lower(): |
55 | - # It's not an Ubuntu product, nothing to validate. |
56 | - return True |
57 | - elif self.ubuntu_regex.search(product_name) is None: |
58 | - # Only insert v2 or v3 Ubuntu products. |
59 | - return False |
60 | - else: |
61 | - return True |
62 | - |
63 | - def _validate_bootloader(self, data, product_name): |
64 | - bootloader_type = data.get('bootloader-type') |
65 | - if bootloader_type is None: |
66 | - # It's not a bootloader, nothing to validate |
67 | - return True |
68 | - if self.bootloader_regex.search(product_name) is None: |
69 | - # Only insert V1 bootloaders from the stream |
70 | - return False |
71 | - # Validate MAAS supports the specific bootloader_type, os, arch |
72 | - # combination. |
73 | - SUPPORTED_BOOTLOADERS = { |
74 | - 'pxe': [ |
75 | - { |
76 | - 'os': 'pxelinux', |
77 | - 'arch': 'i386', |
78 | - } |
79 | - ], |
80 | - 'uefi': [ |
81 | - { |
82 | - 'os': 'grub-efi-signed', |
83 | - 'arch': 'amd64', |
84 | - }, |
85 | - { |
86 | - 'os': 'grub-efi', |
87 | - 'arch': 'arm64', |
88 | - } |
89 | - ], |
90 | - 'open-firmware': [ |
91 | - { |
92 | - 'os': 'grub-ieee1275', |
93 | - 'arch': 'ppc64el', |
94 | - } |
95 | - ], |
96 | - } |
97 | - for bootloader in SUPPORTED_BOOTLOADERS.get(bootloader_type, []): |
98 | - if ( |
99 | - data.get('os') == bootloader['os'] and |
100 | - data.get('arch') == bootloader['arch']): |
101 | - return True |
102 | - # Bootloader not supported, ignore |
103 | - return False |
104 | - |
105 | def insert_item(self, data, src, target, pedigree, contentsource): |
106 | """Overridable from `BasicMirrorWriter`.""" |
107 | item = sutil.products_exdata(src, pedigree) |
108 | @@ -1107,9 +1048,7 @@ |
109 | elif item['ftype'] not in dict(BOOT_RESOURCE_FILE_TYPE_CHOICES).keys(): |
110 | # Skip filetypes that we don't know about. |
111 | return |
112 | - elif not self._validate_ubuntu(item, product_name): |
113 | - return |
114 | - elif not self._validate_bootloader(item, product_name): |
115 | + elif not validate_product(item, product_name): |
116 | return |
117 | else: |
118 | self.store.insert(item, contentsource) |
119 | |
120 | === modified file 'src/maasserver/tests/test_bootresources.py' |
121 | --- src/maasserver/tests/test_bootresources.py 2016-10-12 15:26:17 +0000 |
122 | +++ src/maasserver/tests/test_bootresources.py 2017-04-26 00:29:21 +0000 |
123 | @@ -2103,7 +2103,7 @@ |
124 | class TestBootResourceRepoWriter(MAASServerTestCase): |
125 | """Tests for `BootResourceRepoWriter`.""" |
126 | |
127 | - def create_simplestream(self, ftypes, stream_version=None): |
128 | + def create_ubuntu_simplestream(self, ftypes, stream_version=None): |
129 | version = '16.04' |
130 | arch = 'amd64' |
131 | subarch = 'hwe-x' |
132 | @@ -2145,10 +2145,47 @@ |
133 | } |
134 | return src, product, version |
135 | |
136 | + def create_bootloader_simplestream(self, stream_version=None): |
137 | + if stream_version is None: |
138 | + stream_version = '1' |
139 | + product = ( |
140 | + 'com.ubuntu.maas:daily:%s:bootloader-download' % stream_version) |
141 | + version = datetime.now().date().strftime('%Y%m%d.0') |
142 | + versions = { |
143 | + version: { |
144 | + 'items': { |
145 | + BOOT_RESOURCE_FILE_TYPE.BOOTLOADER: { |
146 | + 'sha256': factory.make_name('sha256'), |
147 | + 'path': factory.make_name('path'), |
148 | + 'ftype': BOOT_RESOURCE_FILE_TYPE.BOOTLOADER, |
149 | + 'size': random.randint(0, 2**64), |
150 | + } |
151 | + } |
152 | + } |
153 | + } |
154 | + products = { |
155 | + product: { |
156 | + 'label': 'daily', |
157 | + 'os': 'grub-efi-signed', |
158 | + 'arch': 'amd64', |
159 | + 'bootloader-type': 'uefi', |
160 | + 'version': version, |
161 | + 'versions': versions, |
162 | + } |
163 | + } |
164 | + src = { |
165 | + 'datatype': 'image-downloads', |
166 | + 'format': 'products:1.0', |
167 | + 'updated': format_datetime(datetime.now()), |
168 | + 'products': products, |
169 | + 'content_id': 'com.ubuntu.maas:daily:1:bootloader-download' |
170 | + } |
171 | + return src, product, version |
172 | + |
173 | def test_insert_prefers_squashfs_over_root_image(self): |
174 | boot_resource_repo_writer = BootResourceRepoWriter( |
175 | BootResourceStore(), None) |
176 | - src, product, version = self.create_simplestream([ |
177 | + src, product, version = self.create_ubuntu_simplestream([ |
178 | BOOT_RESOURCE_FILE_TYPE.ROOT_IMAGE, |
179 | BOOT_RESOURCE_FILE_TYPE.SQUASHFS_IMAGE, |
180 | ]) |
181 | @@ -2162,7 +2199,7 @@ |
182 | def test_insert_allows_squashfs(self): |
183 | boot_resource_repo_writer = BootResourceRepoWriter( |
184 | BootResourceStore(), None) |
185 | - src, product, version = self.create_simplestream([ |
186 | + src, product, version = self.create_ubuntu_simplestream([ |
187 | BOOT_RESOURCE_FILE_TYPE.SQUASHFS_IMAGE, |
188 | ]) |
189 | data = src['products'][product]['versions'][version]['items'][ |
190 | @@ -2175,7 +2212,7 @@ |
191 | def test_insert_allows_root_image(self): |
192 | boot_resource_repo_writer = BootResourceRepoWriter( |
193 | BootResourceStore(), None) |
194 | - src, product, version = self.create_simplestream([ |
195 | + src, product, version = self.create_ubuntu_simplestream([ |
196 | BOOT_RESOURCE_FILE_TYPE.ROOT_IMAGE, |
197 | ]) |
198 | data = src['products'][product]['versions'][version]['items'][ |
199 | @@ -2188,9 +2225,7 @@ |
200 | def test_insert_allows_bootloader(self): |
201 | boot_resource_repo_writer = BootResourceRepoWriter( |
202 | BootResourceStore(), None) |
203 | - src, product, version = self.create_simplestream([ |
204 | - BOOT_RESOURCE_FILE_TYPE.BOOTLOADER, |
205 | - ]) |
206 | + src, product, version = self.create_bootloader_simplestream() |
207 | data = src['products'][product]['versions'][version]['items'][ |
208 | BOOT_RESOURCE_FILE_TYPE.BOOTLOADER] |
209 | pedigree = (product, version, BOOT_RESOURCE_FILE_TYPE.BOOTLOADER) |
210 | @@ -2201,7 +2236,7 @@ |
211 | def test_insert_allows_archive_tar_xz(self): |
212 | boot_resource_repo_writer = BootResourceRepoWriter( |
213 | BootResourceStore(), None) |
214 | - src, product, version = self.create_simplestream([ |
215 | + src, product, version = self.create_ubuntu_simplestream([ |
216 | BOOT_RESOURCE_FILE_TYPE.ARCHIVE_TAR_XZ, |
217 | ]) |
218 | data = src['products'][product]['versions'][version]['items'][ |
219 | @@ -2215,7 +2250,7 @@ |
220 | boot_resource_repo_writer = BootResourceRepoWriter( |
221 | BootResourceStore(), None) |
222 | unknown_ftype = factory.make_name('ftype') |
223 | - src, product, version = self.create_simplestream([ |
224 | + src, product, version = self.create_ubuntu_simplestream([ |
225 | unknown_ftype, |
226 | ]) |
227 | data = src['products'][product]['versions'][version]['items'][ |
228 | @@ -2228,105 +2263,43 @@ |
229 | def test_insert_validates_bootloader(self): |
230 | boot_resource_repo_writer = BootResourceRepoWriter( |
231 | BootResourceStore(), None) |
232 | - src, product, version = self.create_simplestream([ |
233 | - BOOT_RESOURCE_FILE_TYPE.BOOTLOADER, |
234 | - ]) |
235 | + src, product, version = self.create_bootloader_simplestream() |
236 | data = src['products'][product]['versions'][version]['items'][ |
237 | BOOT_RESOURCE_FILE_TYPE.BOOTLOADER] |
238 | pedigree = (product, version, BOOT_RESOURCE_FILE_TYPE.BOOTLOADER) |
239 | mock_insert = self.patch(boot_resource_repo_writer.store, 'insert') |
240 | - mock_validate_bootloader = self.patch( |
241 | - boot_resource_repo_writer, '_validate_bootloader') |
242 | boot_resource_repo_writer.insert_item(data, src, None, pedigree, None) |
243 | self.assertThat(mock_insert, MockCalledOnce()) |
244 | - self.assertThat(mock_validate_bootloader, MockCalledOnce()) |
245 | - |
246 | - def test_validate_bootloader_ignores_non_bootloaders(self): |
247 | - boot_resource_repo_writer = BootResourceRepoWriter( |
248 | - BootResourceStore(), None) |
249 | - self.assertTrue( |
250 | - boot_resource_repo_writer._validate_bootloader( |
251 | - {}, 'com.ubuntu.maas.daily:v3:boot:16.04:amd64:hwe-16.04')) |
252 | - |
253 | - def test_validate_bootloader_checks_version(self): |
254 | - boot_resource_repo_writer = BootResourceRepoWriter( |
255 | - BootResourceStore(), None) |
256 | - version = random.randint(2, 100) |
257 | - product_name = "com.ubuntu.maas.daily:%d:pxelinux:pxe:i386" % version |
258 | - self.assertFalse( |
259 | - boot_resource_repo_writer._validate_bootloader( |
260 | - {'bootloader-type': factory.make_name('bootloader-type')}, |
261 | - product_name)) |
262 | - |
263 | - def test_validate_bootloader_allows_acceptable_bootloaders(self): |
264 | - acceptable_bootloaders = [ |
265 | - { |
266 | - 'os': 'pxelinux', |
267 | - 'arch': 'i386', |
268 | - 'bootloader-type': 'pxe', |
269 | - }, |
270 | - { |
271 | - 'os': 'grub-efi-signed', |
272 | - 'arch': 'amd64', |
273 | - 'bootloader-type': 'uefi', |
274 | - }, |
275 | - { |
276 | - 'os': 'grub-efi', |
277 | - 'arch': 'arm64', |
278 | - 'bootloader-type': 'uefi', |
279 | - }, |
280 | - { |
281 | - 'os': 'grub-ieee1275', |
282 | - 'arch': 'ppc64el', |
283 | - 'bootloader-type': 'open-firmware', |
284 | - }, |
285 | - ] |
286 | - boot_resource_repo_writer = BootResourceRepoWriter( |
287 | - BootResourceStore(), None) |
288 | - for bootloader in acceptable_bootloaders: |
289 | - product_name = "com.ubuntu.maas.daily:1:%s:%s:%s" % ( |
290 | - bootloader['os'], bootloader['bootloader-type'], |
291 | - bootloader['arch']) |
292 | - self.assertTrue( |
293 | - boot_resource_repo_writer._validate_bootloader( |
294 | - bootloader, product_name), |
295 | - "Failed to validate %s" % product_name) |
296 | - |
297 | - def test_validate_bootloader_denies_unacceptable_bootloader(self): |
298 | - bootloader = { |
299 | - 'os': factory.make_name('os'), |
300 | - 'arch': factory.make_name('arch'), |
301 | - 'bootloader-type': factory.make_name('bootloader_type'), |
302 | - } |
303 | - product_name = "com.ubuntu.maas.daily:1:%s:%s:%s" % ( |
304 | - bootloader['os'], bootloader['bootloader-type'], |
305 | - bootloader['arch']) |
306 | - boot_resource_repo_writer = BootResourceRepoWriter( |
307 | - BootResourceStore(), None) |
308 | - self.assertFalse( |
309 | - boot_resource_repo_writer._validate_bootloader( |
310 | - bootloader, product_name)) |
311 | + |
312 | + def test_insert_validates_rejects_unknown_version(self): |
313 | + boot_resource_repo_writer = BootResourceRepoWriter( |
314 | + BootResourceStore(), None) |
315 | + src, product, version = self.create_bootloader_simplestream( |
316 | + factory.make_name('stream_version')) |
317 | + data = src['products'][product]['versions'][version]['items'][ |
318 | + BOOT_RESOURCE_FILE_TYPE.BOOTLOADER] |
319 | + pedigree = (product, version, BOOT_RESOURCE_FILE_TYPE.BOOTLOADER) |
320 | + mock_insert = self.patch(boot_resource_repo_writer.store, 'insert') |
321 | + boot_resource_repo_writer.insert_item(data, src, None, pedigree, None) |
322 | + self.assertThat(mock_insert, MockNotCalled()) |
323 | |
324 | def test_insert_validates_ubuntu(self): |
325 | boot_resource_repo_writer = BootResourceRepoWriter( |
326 | BootResourceStore(), None) |
327 | - src, product, version = self.create_simplestream([ |
328 | + src, product, version = self.create_ubuntu_simplestream([ |
329 | BOOT_RESOURCE_FILE_TYPE.SQUASHFS_IMAGE, |
330 | ]) |
331 | data = src['products'][product]['versions'][version]['items'][ |
332 | BOOT_RESOURCE_FILE_TYPE.SQUASHFS_IMAGE] |
333 | pedigree = (product, version, BOOT_RESOURCE_FILE_TYPE.SQUASHFS_IMAGE) |
334 | mock_insert = self.patch(boot_resource_repo_writer.store, 'insert') |
335 | - mock_validate_bootloader = self.patch( |
336 | - boot_resource_repo_writer, '_validate_ubuntu') |
337 | boot_resource_repo_writer.insert_item(data, src, None, pedigree, None) |
338 | self.assertThat(mock_insert, MockCalledOnce()) |
339 | - self.assertThat(mock_validate_bootloader, MockCalledOnce()) |
340 | |
341 | def test_validate_ubuntu_rejects_unknown_version(self): |
342 | boot_resource_repo_writer = BootResourceRepoWriter( |
343 | BootResourceStore(), None) |
344 | - src, product, version = self.create_simplestream( |
345 | + src, product, version = self.create_ubuntu_simplestream( |
346 | [BOOT_RESOURCE_FILE_TYPE.SQUASHFS_IMAGE], |
347 | factory.make_name('stream_version')) |
348 | data = src['products'][product]['versions'][version]['items'][ |
349 | |
350 | === modified file 'src/provisioningserver/import_images/download_descriptions.py' |
351 | --- src/provisioningserver/import_images/download_descriptions.py 2017-01-25 16:13:42 +0000 |
352 | +++ src/provisioningserver/import_images/download_descriptions.py 2017-04-26 00:29:21 +0000 |
353 | @@ -10,8 +10,10 @@ |
354 | |
355 | __all__ = [ |
356 | 'download_all_image_descriptions', |
357 | + 'validate_product', |
358 | ] |
359 | |
360 | +import re |
361 | |
362 | from provisioningserver.import_images.boot_image_mapping import ( |
363 | BootImageMapping, |
364 | @@ -31,6 +33,13 @@ |
365 | products_exdata, |
366 | ) |
367 | |
368 | +# Compile a regex to validate Ubuntu product names. This only allows V2 and V3 |
369 | +# Ubuntu images. |
370 | +UBUNTU_REGEX = re.compile('.*:v[23]:.*', re.IGNORECASE) |
371 | +# Compile a regex to validate bootloader product names. This only allows V1 |
372 | +# bootloaders. |
373 | +BOOTLOADER_REGEX = re.compile('.*:1:.*', re.IGNORECASE) |
374 | + |
375 | |
376 | def clean_up_repo_item(item): |
377 | """Return a subset of dict `item` for storing in a boot images dict.""" |
378 | @@ -46,6 +55,67 @@ |
379 | return compact_item |
380 | |
381 | |
382 | +def validate_ubuntu(data, product_name): |
383 | + osystem = data.get('os', '') |
384 | + if 'ubuntu' not in osystem.lower(): |
385 | + # It's not an Ubuntu product, nothing to validate. |
386 | + return True |
387 | + elif UBUNTU_REGEX.search(product_name) is None: |
388 | + # Only insert v2 or v3 Ubuntu products. |
389 | + return False |
390 | + else: |
391 | + return True |
392 | + |
393 | + |
394 | +def validate_bootloader(data, product_name): |
395 | + bootloader_type = data.get('bootloader-type') |
396 | + if bootloader_type is None: |
397 | + # It's not a bootloader, nothing to validate |
398 | + return True |
399 | + if BOOTLOADER_REGEX.search(product_name) is None: |
400 | + # Only insert V1 bootloaders from the stream |
401 | + return False |
402 | + # Validate MAAS supports the specific bootloader_type, os, arch |
403 | + # combination. |
404 | + SUPPORTED_BOOTLOADERS = { |
405 | + 'pxe': [ |
406 | + { |
407 | + 'os': 'pxelinux', |
408 | + 'arch': 'i386', |
409 | + } |
410 | + ], |
411 | + 'uefi': [ |
412 | + { |
413 | + 'os': 'grub-efi-signed', |
414 | + 'arch': 'amd64', |
415 | + }, |
416 | + { |
417 | + 'os': 'grub-efi', |
418 | + 'arch': 'arm64', |
419 | + } |
420 | + ], |
421 | + 'open-firmware': [ |
422 | + { |
423 | + 'os': 'grub-ieee1275', |
424 | + 'arch': 'ppc64el', |
425 | + } |
426 | + ], |
427 | + } |
428 | + for bootloader in SUPPORTED_BOOTLOADERS.get(bootloader_type, []): |
429 | + if ( |
430 | + data.get('os') == bootloader['os'] and |
431 | + data.get('arch') == bootloader['arch']): |
432 | + return True |
433 | + |
434 | + # Bootloader not supported, ignore |
435 | + return False |
436 | + |
437 | + |
438 | +def validate_product(data, product_name): |
439 | + return (validate_ubuntu(data, product_name) and |
440 | + validate_bootloader(data, product_name)) |
441 | + |
442 | + |
443 | class RepoDumper(BasicMirrorWriter): |
444 | """Gather metadata about boot images available in a Simplestreams repo. |
445 | |
446 | @@ -79,6 +149,8 @@ |
447 | def insert_item(self, data, src, target, pedigree, contentsource): |
448 | """Overridable from `BasicMirrorWriter`.""" |
449 | item = products_exdata(src, pedigree) |
450 | + if not validate_product(item, pedigree[0]): |
451 | + return |
452 | os = get_os_from_product(item) |
453 | arch = item['arch'] |
454 | subarches = item.get('subarches', 'generic') |
455 | |
456 | === modified file 'src/provisioningserver/import_images/tests/test_download_descriptions.py' |
457 | --- src/provisioningserver/import_images/tests/test_download_descriptions.py 2017-01-25 16:13:42 +0000 |
458 | +++ src/provisioningserver/import_images/tests/test_download_descriptions.py 2017-04-26 00:29:21 +0000 |
459 | @@ -6,6 +6,7 @@ |
460 | __all__ = [] |
461 | |
462 | import logging |
463 | +import random |
464 | from unittest.mock import ( |
465 | ANY, |
466 | call, |
467 | @@ -27,6 +28,7 @@ |
468 | from provisioningserver.import_images.download_descriptions import ( |
469 | clean_up_repo_item, |
470 | RepoDumper, |
471 | + validate_product, |
472 | ) |
473 | from provisioningserver.import_images.testing.factory import ( |
474 | make_image_spec, |
475 | @@ -34,6 +36,78 @@ |
476 | ) |
477 | |
478 | |
479 | +class TestValidateProduct(MAASTestCase): |
480 | + """Tests for `validate_product`.""" |
481 | + |
482 | + def test__ignores_random(self): |
483 | + self.assertTrue( |
484 | + validate_product({}, factory.make_name('product_name'))) |
485 | + |
486 | + def test__validates_ubuntu(self): |
487 | + self.assertTrue(validate_product( |
488 | + {'os': 'ubuntu'}, |
489 | + 'com.ubuntu.maas.daily:v%d:boot:%s:%s:%s' % ( |
490 | + random.choice([2, 3]), factory.make_name('version'), |
491 | + factory.make_name('arch'), factory.make_name('sub_arch')))) |
492 | + |
493 | + def test__rejects_unknown_ubuntu_version(self): |
494 | + self.assertFalse(validate_product( |
495 | + {'os': 'ubuntu'}, |
496 | + 'com.ubuntu.maas.daily:v%d:boot:%s:%s:%s' % ( |
497 | + random.randint(4, 100), factory.make_name('version'), |
498 | + factory.make_name('arch'), factory.make_name('sub_arch')))) |
499 | + |
500 | + def test__validates_bootloaders(self): |
501 | + acceptable_bootloaders = [ |
502 | + { |
503 | + 'os': 'pxelinux', |
504 | + 'arch': 'i386', |
505 | + 'bootloader-type': 'pxe', |
506 | + }, |
507 | + { |
508 | + 'os': 'grub-efi-signed', |
509 | + 'arch': 'amd64', |
510 | + 'bootloader-type': 'uefi', |
511 | + }, |
512 | + { |
513 | + 'os': 'grub-efi', |
514 | + 'arch': 'arm64', |
515 | + 'bootloader-type': 'uefi', |
516 | + }, |
517 | + { |
518 | + 'os': 'grub-ieee1275', |
519 | + 'arch': 'ppc64el', |
520 | + 'bootloader-type': 'open-firmware', |
521 | + }, |
522 | + ] |
523 | + for bootloader in acceptable_bootloaders: |
524 | + product_name = "com.ubuntu.maas.daily:1:%s:%s:%s" % ( |
525 | + bootloader['os'], bootloader['bootloader-type'], |
526 | + bootloader['arch']) |
527 | + self.assertTrue( |
528 | + validate_product(bootloader, product_name), |
529 | + "Failed to validate %s" % product_name) |
530 | + |
531 | + def test__rejects_unknown_bootloader_version(self): |
532 | + version = random.randint(2, 100) |
533 | + product_name = "com.ubuntu.maas.daily:%d:pxelinux:pxe:i386" % version |
534 | + self.assertFalse( |
535 | + validate_product( |
536 | + {'bootloader-type': factory.make_name('bootloader-type')}, |
537 | + product_name)) |
538 | + |
539 | + def test__rejects_unknown_bootloader(self): |
540 | + bootloader = { |
541 | + 'os': factory.make_name('os'), |
542 | + 'arch': factory.make_name('arch'), |
543 | + 'bootloader-type': factory.make_name('bootloader_type'), |
544 | + } |
545 | + product_name = "com.ubuntu.maas.daily:1:%s:%s:%s" % ( |
546 | + bootloader['os'], bootloader['bootloader-type'], |
547 | + bootloader['arch']) |
548 | + self.assertFalse(validate_product(bootloader, product_name)) |
549 | + |
550 | + |
551 | class TestValuePassesFilterList(MAASTestCase): |
552 | """Tests for `value_passes_filter_list`.""" |
553 | |
554 | @@ -280,7 +354,10 @@ |
555 | download_descriptions, 'products_exdata').return_value = item |
556 | dumper.insert_item( |
557 | sentinel.data, sentinel.src, sentinel.target, |
558 | - sentinel.pedigree, sentinel.contentsource) |
559 | + ( |
560 | + factory.make_name('product_name'), |
561 | + factory.make_name('product_version') |
562 | + ), sentinel.contentsource) |
563 | image_specs = [ |
564 | make_image_spec( |
565 | os=item['os'], release=item['release'], |
566 | @@ -306,7 +383,10 @@ |
567 | for _ in range(2): |
568 | dumper.insert_item( |
569 | sentinel.data, sentinel.src, sentinel.target, |
570 | - sentinel.pedigree, sentinel.contentsource) |
571 | + ( |
572 | + factory.make_name('product_name'), |
573 | + factory.make_name('product_version') |
574 | + ), sentinel.contentsource) |
575 | image_spec = make_image_spec( |
576 | os=item['os'], release=item['release'], |
577 | arch=item['arch'], subarch=compat_subarch, |
578 | @@ -337,8 +417,11 @@ |
579 | 'products_exdata').side_effect = [hwep_item, hwes_item] |
580 | for _ in range(2): |
581 | dumper.insert_item( |
582 | - sentinel.data, sentinel.src, sentinel.target, |
583 | - sentinel.pedigree, sentinel.contentsource) |
584 | + {'os': 'ubuntu'}, sentinel.src, sentinel.target, |
585 | + ( |
586 | + 'com.ubuntu.maas.daily:v3:boot:12.04:amd64:hwe-p', |
587 | + factory.make_name('product_version'), |
588 | + ), sentinel.contentsource) |
589 | image_spec = make_image_spec( |
590 | os=os, release=release, arch=arch, subarch='generic', |
591 | label=label) |
592 | @@ -368,8 +451,11 @@ |
593 | 'products_exdata').side_effect = [hwep_item, hwes_item] |
594 | for _ in range(2): |
595 | dumper.insert_item( |
596 | - sentinel.data, sentinel.src, sentinel.target, |
597 | - sentinel.pedigree, sentinel.contentsource) |
598 | + {'os': 'ubuntu'}, sentinel.src, sentinel.target, |
599 | + ( |
600 | + 'com.ubuntu.maas.daily:v3:boot:12.04:amd64:hwe-p', |
601 | + factory.make_name('product_version'), |
602 | + ), sentinel.contentsource) |
603 | image_spec = make_image_spec( |
604 | os=os, release=release, arch=arch, subarch='generic', |
605 | label=label) |
606 | @@ -378,21 +464,42 @@ |
607 | def test_insert_item_sets_release_to_bootloader_type(self): |
608 | boot_images_dict = BootImageMapping() |
609 | dumper = RepoDumper(boot_images_dict) |
610 | - bootloader_type = factory.make_name('bootloader-type') |
611 | - item, _ = self.make_item(bootloader_type=bootloader_type) |
612 | + item, _ = self.make_item( |
613 | + arch='amd64', bootloader_type='uefi', os='grub-efi-signed') |
614 | self.patch( |
615 | download_descriptions, 'products_exdata').return_value = item |
616 | dumper.insert_item( |
617 | - sentinel.data, sentinel.src, sentinel.target, |
618 | - sentinel.pedigree, sentinel.contentsource) |
619 | + { |
620 | + 'bootloader_type': 'uefi', |
621 | + 'os': 'grub-efi-signed', |
622 | + 'arch': 'amd64', |
623 | + }, sentinel.src, sentinel.target, |
624 | + ( |
625 | + 'com.ubuntu.maas.daily:1:grub-efi-signed:uefi:amd64', |
626 | + factory.make_name('product_version'), |
627 | + ), sentinel.contentsource) |
628 | image_specs = [ |
629 | make_image_spec( |
630 | - os=item['os'], release=bootloader_type, arch=item['arch'], |
631 | + os=item['os'], release='uefi', arch=item['arch'], |
632 | subarch=subarch, kflavor='bootloader', label=item['label']) |
633 | for subarch in item['subarches'].split(',') |
634 | ] |
635 | self.assertItemsEqual(image_specs, list(boot_images_dict.mapping)) |
636 | |
637 | + def test_insert_item_validates(self): |
638 | + boot_images_dict = BootImageMapping() |
639 | + dumper = RepoDumper(boot_images_dict) |
640 | + item, _ = self.make_item(os='ubuntu') |
641 | + self.patch( |
642 | + download_descriptions, 'products_exdata').return_value = item |
643 | + dumper.insert_item( |
644 | + {'os': 'ubuntu'}, sentinel.src, sentinel.target, |
645 | + ( |
646 | + factory.make_name('product_name'), |
647 | + factory.make_name('product_version'), |
648 | + ), sentinel.contentsource) |
649 | + self.assertItemsEqual([], list(boot_images_dict.mapping)) |
650 | + |
651 | def test_sync_does_propagate_ioerror(self): |
652 | io_error = factory.make_exception_type(bases=(IOError,)) |
653 |
Looks good.