Merge lp:~blake-rouse/maas/import-with-gpg-home 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: 2829
Proposed branch: lp:~blake-rouse/maas/import-with-gpg-home
Merge into: lp:~maas-committers/maas/trunk
Prerequisite: lp:~blake-rouse/maas/fix-keydata-base64
Diff against target: 156 lines (+60/-14)
4 files modified
src/maasserver/bootresources.py (+20/-14)
src/maasserver/start_up.py (+6/-0)
src/maasserver/tests/test_bootresources.py (+24/-0)
src/maasserver/tests/test_start_up.py (+10/-0)
To merge this branch: bzr merge lp:~blake-rouse/maas/import-with-gpg-home
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+232279@code.launchpad.net

Commit message

On the region import boot resource with gpg home directory set to the maas users. This was done on the cluster side, but was not on the region side, causing verification of simplestreams data to fail.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

test__import_resources_has_env_GNUPGHOME_set has this assertion:

        self.assertTrue(
            bootresources.MAAS_USER_GPGHOME,
            fake_download.env['GNUPGHOME'])

I think that assertTrue should have been assertEqual here.

One big question I'm left with is: who owns that home directory when you create it? It's still the maas user, right? It's important to get that right, but not the sort of thing you can really test.

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

Yes it is owned by maas:maas. It uses the same code, that is used by pserv.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/bootresources.py'
2--- src/maasserver/bootresources.py 2014-08-26 17:32:40 +0000
3+++ src/maasserver/bootresources.py 2014-08-27 12:28:22 +0000
4@@ -48,6 +48,7 @@
5 from maasserver.utils import absolute_reverse
6 from maasserver.utils.async import transactional
7 from maasserver.utils.orm import get_one
8+from provisioningserver.auth import MAAS_USER_GPGHOME
9 from provisioningserver.import_images.download_descriptions import (
10 download_all_image_descriptions,
11 )
12@@ -58,6 +59,7 @@
13 from provisioningserver.import_images.keyrings import write_all_keyrings
14 from provisioningserver.import_images.product_mapping import map_products
15 from provisioningserver.logger import get_maas_logger
16+from provisioningserver.utils.env import environment_variables
17 from provisioningserver.utils.twisted import synchronous
18 from simplestreams import util as sutil
19 from simplestreams.mirrors import (
20@@ -851,20 +853,24 @@
21 return
22
23 try:
24- maaslog.info("Started importing of boot resources.")
25- sources = [source.to_dict() for source in BootSource.objects.all()]
26- sources = write_all_keyrings(sources)
27-
28- image_descriptions = download_all_image_descriptions(sources)
29- if image_descriptions.is_empty():
30- maaslog.warn(
31- "Unable to import boot resources, no image "
32- "descriptions avaliable.")
33- return
34- product_mapping = map_products(image_descriptions)
35-
36- download_all_boot_resources(sources, product_mapping)
37- maaslog.info("Finished importing of boot resources.")
38+ variables = {
39+ 'GNUPGHOME': MAAS_USER_GPGHOME,
40+ }
41+ with environment_variables(variables):
42+ maaslog.info("Started importing of boot resources.")
43+ sources = [source.to_dict() for source in BootSource.objects.all()]
44+ sources = write_all_keyrings(sources)
45+
46+ image_descriptions = download_all_image_descriptions(sources)
47+ if image_descriptions.is_empty():
48+ maaslog.warn(
49+ "Unable to import boot resources, no image "
50+ "descriptions avaliable.")
51+ return
52+ product_mapping = map_products(image_descriptions)
53+
54+ download_all_boot_resources(sources, product_mapping)
55+ maaslog.info("Finished importing of boot resources.")
56 finally:
57 kill_event.set()
58 lock_thread.join()
59
60=== modified file 'src/maasserver/start_up.py'
61--- src/maasserver/start_up.py 2014-08-15 09:44:42 +0000
62+++ src/maasserver/start_up.py 2014-08-27 12:28:22 +0000
63@@ -38,6 +38,7 @@
64 BootImage,
65 NodeGroup,
66 )
67+from provisioningserver.upgrade_cluster import create_gnupg_home
68
69
70 def start_up():
71@@ -88,6 +89,11 @@
72 # This must be serialized or we may initialize the master more than once.
73 NodeGroup.objects.ensure_master()
74
75+ # Make sure that maas user's GNUPG home directory exists. This is needed
76+ # for importing of boot resources, that now occurs on the region as well
77+ # as the clusters.
78+ create_gnupg_home()
79+
80 # If no boot-source definitions yet, create the default definition.
81 ensure_boot_source_definition()
82
83
84=== modified file 'src/maasserver/tests/test_bootresources.py'
85--- src/maasserver/tests/test_bootresources.py 2014-08-25 14:19:51 +0000
86+++ src/maasserver/tests/test_bootresources.py 2014-08-27 12:28:22 +0000
87@@ -16,6 +16,7 @@
88
89 import httplib
90 import json
91+from os import environ
92 from random import randint
93 from StringIO import StringIO
94
95@@ -1010,3 +1011,26 @@
96 self.assertThat(
97 fake_download_all_boot_resources,
98 MockCalledOnceWith(sentinel.sources, sentinel.mapping))
99+
100+ def test__import_resources_has_env_GNUPGHOME_set(self):
101+ fake_image_descriptions = self.patch(
102+ bootresources, 'download_all_image_descriptions')
103+ descriptions = Mock()
104+ descriptions.is_empty.return_value = False
105+ fake_image_descriptions.return_value = descriptions
106+ self.patch(bootresources, 'map_products')
107+
108+ class CaptureEnv:
109+ """Fake function; records a copy of the environment."""
110+
111+ def __call__(self, *args, **kwargs):
112+ self.args = args
113+ self.env = environ.copy()
114+
115+ fake_download = self.patch(
116+ bootresources, 'download_all_boot_resources', CaptureEnv())
117+
118+ bootresources._import_resources(force=True)
119+ self.assertEqual(
120+ bootresources.MAAS_USER_GPGHOME,
121+ fake_download.env['GNUPGHOME'])
122
123=== modified file 'src/maasserver/tests/test_start_up.py'
124--- src/maasserver/tests/test_start_up.py 2014-08-15 03:33:51 +0000
125+++ src/maasserver/tests/test_start_up.py 2014-08-27 12:28:22 +0000
126@@ -66,6 +66,7 @@
127 def setUp(self):
128 super(TestStartUp, self).setUp()
129 self.useFixture(RegionEventLoopFixture())
130+ self.patch(start_up, 'create_gnupg_home')
131
132 def tearDown(self):
133 super(TestStartUp, self).tearDown()
134@@ -93,6 +94,11 @@
135 ('celery', FixtureResource(CeleryFixture())),
136 )
137
138+ def setUp(self):
139+ super(TestInnerStartUp, self).setUp()
140+ self.mock_create_gnupg_home = self.patch(
141+ start_up, 'create_gnupg_home')
142+
143 def test__calls_write_full_dns_config(self):
144 recorder = FakeMethod()
145 self.patch(start_up, 'write_full_dns_config', recorder)
146@@ -107,6 +113,10 @@
147 self.assertThat(clusters, HasLength(1))
148 self.assertItemsEqual([NodeGroup.objects.ensure_master()], clusters)
149
150+ def test__calls_create_gnupg_home(self):
151+ start_up.inner_start_up()
152+ self.assertThat(self.mock_create_gnupg_home, MockCalledOnceWith())
153+
154 def test__initialises_boot_source_config(self):
155 self.assertItemsEqual([], BootSource.objects.all())
156 start_up.inner_start_up()