Merge ~ack/maas:1890468-snap-images-keyring-path into maas:master

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: 2f21438e8c65e12156746e248fd55ee0c0f87c14
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ack/maas:1890468-snap-images-keyring-path
Merge into: maas:master
Diff against target: 89 lines (+42/-0)
3 files modified
snap/local/tree/bin/maas-deb-migrate (+9/-0)
src/maasserver/bootsources.py (+9/-0)
src/maasserver/tests/test_bootsources.py (+24/-0)
Reviewer Review Type Date Requested Status
Björn Tillenius Approve
MAAS Lander Approve
Dougal Matthews (community) Approve
Review via email: mp+392133@code.launchpad.net

Commit message

LP: #1890468 - update the default keyrings path in the db for deb-to-snap transitions

To post a comment you must log in.
Revision history for this message
Dougal Matthews (d0ugal) wrote :

lgtm

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b 1890468-snap-images-keyring-path lp:~ack/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 2f21438e8c65e12156746e248fd55ee0c0f87c14

review: Approve
Revision history for this message
Björn Tillenius (bjornt) wrote :

+1

review: Approve

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/snap/local/tree/bin/maas-deb-migrate b/snap/local/tree/bin/maas-deb-migrate
index fea33f4..febca85 100755
--- a/snap/local/tree/bin/maas-deb-migrate
+++ b/snap/local/tree/bin/maas-deb-migrate
@@ -68,6 +68,15 @@ apply_db_patches() {
68 if maas_snap_mode | grep -q "region"; then68 if maas_snap_mode | grep -q "region"; then
69 snap_run "maas-region migrate"69 snap_run "maas-region migrate"
70 fi70 fi
71
72 # patch the value of the default cloud images keyring to point to the one
73 # in the snap
74 local keyring="/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg"
75 cat <<EOF | pg_do psql maasdb
76UPDATE maasserver_bootsource
77SET keyring_filename = '${MAAS_SNAP}${keyring}'
78WHERE keyring_filename = '${keyring}'
79EOF
71}80}
7281
73configure_supervisord() {82configure_supervisord() {
diff --git a/src/maasserver/bootsources.py b/src/maasserver/bootsources.py
index f36e617..9e9d32a 100644
--- a/src/maasserver/bootsources.py
+++ b/src/maasserver/bootsources.py
@@ -79,6 +79,15 @@ def ensure_boot_source_definition():
79 )79 )
80 return True80 return True
81 else:81 else:
82 # XXX ensure the default keyrings path in the database points to the
83 # right file when running in a snap. (see lp:1890468) The
84 # DEFAULT_KEYRINGS_PATH points to the right file whether running from
85 # deb or snap, but the path stored in the DB might be wrong if a
86 # snap-to-deb transition happened with a script without the fix.
87 if os.environ.get("SNAP"):
88 BootSource.objects.filter(url=DEFAULT_IMAGES_URL).update(
89 keyring_filename=DEFAULT_KEYRINGS_PATH
90 )
82 return False91 return False
8392
8493
diff --git a/src/maasserver/tests/test_bootsources.py b/src/maasserver/tests/test_bootsources.py
index 2c4f6ea..01db0c0 100644
--- a/src/maasserver/tests/test_bootsources.py
+++ b/src/maasserver/tests/test_bootsources.py
@@ -11,6 +11,7 @@ import random
11from unittest import skip11from unittest import skip
12from unittest.mock import ANY, MagicMock12from unittest.mock import ANY, MagicMock
1313
14from fixtures import EnvironmentVariableFixture
14from requests.exceptions import ConnectionError15from requests.exceptions import ConnectionError
15from testtools.matchers import HasLength16from testtools.matchers import HasLength
1617
@@ -44,6 +45,7 @@ from maasserver.testing.testcase import (
44)45)
45from maasserver.tests.test_bootresources import SimplestreamsEnvFixture46from maasserver.tests.test_bootresources import SimplestreamsEnvFixture
46from maasserver.utils import get_maas_user_agent47from maasserver.utils import get_maas_user_agent
48from maasserver.utils.orm import reload_object
47from maastesting.djangotestcase import count_queries49from maastesting.djangotestcase import count_queries
48from maastesting.matchers import MockCalledOnceWith50from maastesting.matchers import MockCalledOnceWith
49from provisioningserver.config import DEFAULT_IMAGES_URL51from provisioningserver.config import DEFAULT_IMAGES_URL
@@ -141,6 +143,28 @@ class TestHelpers(MAASServerTestCase):
141 },143 },
142 )144 )
143145
146 def test_ensure_boot_source_definition_updates_default_source_snap(self):
147 BootSource.objects.all().delete()
148 self.assertTrue(ensure_boot_source_definition())
149 source = BootSource.objects.first()
150 self.assertEqual(
151 source.keyring_filename,
152 "/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg",
153 )
154 self.useFixture(
155 EnvironmentVariableFixture("SNAP", "/snap/maas/current")
156 )
157 self.patch(
158 bootsources,
159 "DEFAULT_KEYRINGS_PATH",
160 "/some/other/path/keyring.gpg",
161 )
162 self.assertFalse(ensure_boot_source_definition())
163 source = reload_object(source)
164 self.assertEqual(
165 source.keyring_filename, "/some/other/path/keyring.gpg"
166 )
167
144 def test_ensure_boot_source_definition_creates_with_default_arch(self):168 def test_ensure_boot_source_definition_creates_with_default_arch(self):
145 BootSource.objects.all().delete()169 BootSource.objects.all().delete()
146 mock_get_architecture = self.patch(bootsources, "get_architecture")170 mock_get_architecture = self.patch(bootsources, "get_architecture")

Subscribers

People subscribed via source and target branches