Merge ~ltrager/maas:lp1749246_2.3 into maas:2.3

Proposed by Lee Trager
Status: Merged
Approved by: Lee Trager
Approved revision: 8d55114af22e219ebb79ea37abb6b961e66745f0
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ltrager/maas:lp1749246_2.3
Merge into: maas:2.3
Diff against target: 80 lines (+38/-5)
2 files modified
src/provisioningserver/import_images/download_resources.py (+5/-3)
src/provisioningserver/import_images/tests/test_download_resources.py (+33/-2)
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
Review via email: mp+337749@code.launchpad.net

Commit message

Backport of 583a8cc: LP: #1749246 - Only create generic hardlink for ga generic kernels.

To post a comment you must log in.
Revision history for this message
Lee Trager (ltrager) wrote :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/provisioningserver/import_images/download_resources.py b/src/provisioningserver/import_images/download_resources.py
2index 5062b85..f423a76 100644
3--- a/src/provisioningserver/import_images/download_resources.py
4+++ b/src/provisioningserver/import_images/download_resources.py
5@@ -1,4 +1,4 @@
6-# Copyright 2014-2017 Canonical Ltd. This software is licensed under the
7+# Copyright 2014-2018 Canonical Ltd. This software is licensed under the
8 # GNU Affero General Public License version 3 (see the file LICENSE).
9
10 """Simplestreams code to download boot resources."""
11@@ -302,8 +302,10 @@ class RepoWriter(BasicMirrorWriter):
12 if 'subarch' in item:
13 # MAAS uses the 'generic' subarch when it doesn't know which
14 # subarch to use. This happens during enlistment and commissioning.
15- # Allow the 'generic' kflavor to own the 'generic' hardlink.
16- if item.get('kflavor') == 'generic':
17+ # Allow the 'generic' kflavor to own the 'generic' hardlink. The
18+ # generic kernel should always be the ga kernel.
19+ if (item['subarch'].startswith('ga-') and
20+ item.get('kflavor') == 'generic'):
21 subarches = {item['subarch'], 'generic'}
22 else:
23 subarches = {item['subarch']}
24diff --git a/src/provisioningserver/import_images/tests/test_download_resources.py b/src/provisioningserver/import_images/tests/test_download_resources.py
25index f13b392..f1e7759 100644
26--- a/src/provisioningserver/import_images/tests/test_download_resources.py
27+++ b/src/provisioningserver/import_images/tests/test_download_resources.py
28@@ -1,4 +1,4 @@
29-# Copyright 2014-2016 Canonical Ltd. This software is licensed under the
30+# Copyright 2014-2018 Canonical Ltd. This software is licensed under the
31 # GNU Affero General Public License version 3 (see the file LICENSE).
32
33 """Tests for `provisioningserver.import_images.download_resources`."""
34@@ -361,7 +361,7 @@ class TestRepoWriter(MAASTestCase):
35 label=product['label'], subarches={'ga-16.04'},
36 bootloader_type=None))
37
38- def test_inserts_generic_link_for_generic_kflavor(self):
39+ def test_inserts_generic_link_for_generic_ga_kflavor(self):
40 product_mapping = ProductMapping()
41 product = self.make_product(subarch='ga-16.04', kflavor='generic')
42 product_mapping.add(product, 'ga-16.04')
43@@ -391,6 +391,37 @@ class TestRepoWriter(MAASTestCase):
44 label=product['label'], subarches={'ga-16.04', 'generic'},
45 bootloader_type=None))
46
47+ def test_inserts_no_generic_link_for_generic_non_ga_kflavor(self):
48+ # Regression test for LP:1749246
49+ product_mapping = ProductMapping()
50+ product = self.make_product(subarch='hwe-16.04', kflavor='generic')
51+ product_mapping.add(product, 'hwe-16.04')
52+ repo_writer = download_resources.RepoWriter(
53+ None, None, product_mapping)
54+ self.patch(
55+ download_resources, 'products_exdata').return_value = product
56+ # Prevent MAAS from trying to actually write the file.
57+ mock_insert_file = self.patch(download_resources, 'insert_file')
58+ mock_link_resources = self.patch(download_resources, 'link_resources')
59+ # We only need to provide the product as the other fields are only used
60+ # when writing the actual files to disk.
61+ repo_writer.insert_item(product, None, None, None, None)
62+ # None is used for the store and the content source as we're not
63+ # writing anything to disk.
64+ self.assertThat(
65+ mock_insert_file,
66+ MockCalledOnceWith(
67+ None, os.path.basename(product['path']), product['sha256'],
68+ {'sha256': product['sha256']}, product['size'], None))
69+ # links are mocked out by the mock_insert_file above.
70+ self.assertThat(
71+ mock_link_resources,
72+ MockCalledOnceWith(
73+ snapshot_path=None, links=mock.ANY, osystem=product['os'],
74+ arch=product['arch'], release=product['release'],
75+ label=product['label'], subarches={'hwe-16.04'},
76+ bootloader_type=None))
77+
78
79 class TestLinkResources(MAASTestCase):
80 """Tests for `LinkResources`()."""

Subscribers

People subscribed via source and target branches