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
1diff --git a/snap/local/tree/bin/maas-deb-migrate b/snap/local/tree/bin/maas-deb-migrate
2index fea33f4..febca85 100755
3--- a/snap/local/tree/bin/maas-deb-migrate
4+++ b/snap/local/tree/bin/maas-deb-migrate
5@@ -68,6 +68,15 @@ apply_db_patches() {
6 if maas_snap_mode | grep -q "region"; then
7 snap_run "maas-region migrate"
8 fi
9+
10+ # patch the value of the default cloud images keyring to point to the one
11+ # in the snap
12+ local keyring="/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg"
13+ cat <<EOF | pg_do psql maasdb
14+UPDATE maasserver_bootsource
15+SET keyring_filename = '${MAAS_SNAP}${keyring}'
16+WHERE keyring_filename = '${keyring}'
17+EOF
18 }
19
20 configure_supervisord() {
21diff --git a/src/maasserver/bootsources.py b/src/maasserver/bootsources.py
22index f36e617..9e9d32a 100644
23--- a/src/maasserver/bootsources.py
24+++ b/src/maasserver/bootsources.py
25@@ -79,6 +79,15 @@ def ensure_boot_source_definition():
26 )
27 return True
28 else:
29+ # XXX ensure the default keyrings path in the database points to the
30+ # right file when running in a snap. (see lp:1890468) The
31+ # DEFAULT_KEYRINGS_PATH points to the right file whether running from
32+ # deb or snap, but the path stored in the DB might be wrong if a
33+ # snap-to-deb transition happened with a script without the fix.
34+ if os.environ.get("SNAP"):
35+ BootSource.objects.filter(url=DEFAULT_IMAGES_URL).update(
36+ keyring_filename=DEFAULT_KEYRINGS_PATH
37+ )
38 return False
39
40
41diff --git a/src/maasserver/tests/test_bootsources.py b/src/maasserver/tests/test_bootsources.py
42index 2c4f6ea..01db0c0 100644
43--- a/src/maasserver/tests/test_bootsources.py
44+++ b/src/maasserver/tests/test_bootsources.py
45@@ -11,6 +11,7 @@ import random
46 from unittest import skip
47 from unittest.mock import ANY, MagicMock
48
49+from fixtures import EnvironmentVariableFixture
50 from requests.exceptions import ConnectionError
51 from testtools.matchers import HasLength
52
53@@ -44,6 +45,7 @@ from maasserver.testing.testcase import (
54 )
55 from maasserver.tests.test_bootresources import SimplestreamsEnvFixture
56 from maasserver.utils import get_maas_user_agent
57+from maasserver.utils.orm import reload_object
58 from maastesting.djangotestcase import count_queries
59 from maastesting.matchers import MockCalledOnceWith
60 from provisioningserver.config import DEFAULT_IMAGES_URL
61@@ -141,6 +143,28 @@ class TestHelpers(MAASServerTestCase):
62 },
63 )
64
65+ def test_ensure_boot_source_definition_updates_default_source_snap(self):
66+ BootSource.objects.all().delete()
67+ self.assertTrue(ensure_boot_source_definition())
68+ source = BootSource.objects.first()
69+ self.assertEqual(
70+ source.keyring_filename,
71+ "/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg",
72+ )
73+ self.useFixture(
74+ EnvironmentVariableFixture("SNAP", "/snap/maas/current")
75+ )
76+ self.patch(
77+ bootsources,
78+ "DEFAULT_KEYRINGS_PATH",
79+ "/some/other/path/keyring.gpg",
80+ )
81+ self.assertFalse(ensure_boot_source_definition())
82+ source = reload_object(source)
83+ self.assertEqual(
84+ source.keyring_filename, "/some/other/path/keyring.gpg"
85+ )
86+
87 def test_ensure_boot_source_definition_creates_with_default_arch(self):
88 BootSource.objects.all().delete()
89 mock_get_architecture = self.patch(bootsources, "get_architecture")

Subscribers

People subscribed via source and target branches