Merge ~ack/maas:deb-to-snap-migration-fix-db-access into maas:master

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: baed0232212a531ca3a6a628eeeba6a48a2f7517
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ack/maas:deb-to-snap-migration-fix-db-access
Merge into: maas:master
Diff against target: 32 lines (+11/-7)
1 file modified
snap/local/tree/bin/maas-deb-migrate (+11/-7)
Reviewer Review Type Date Requested Status
Björn Tillenius Approve
Review via email: mp+402344@code.launchpad.net

Commit message

LP: #1927340 - mas-deb-migrate: fix db patching process

This ensures bootsource entries are corretly updated when the migrating node is
a region controller, and uses Django rather than direct psql access to work
even if the database is not local

To post a comment you must log in.
Revision history for this message
Björn Tillenius (bjornt) wrote :

+1

review: Approve

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 febca85..f646f0f 100755
3--- a/snap/local/tree/bin/maas-deb-migrate
4+++ b/snap/local/tree/bin/maas-deb-migrate
5@@ -65,17 +65,21 @@ cleanup_data() {
6 }
7
8 apply_db_patches() {
9- if maas_snap_mode | grep -q "region"; then
10- snap_run "maas-region migrate"
11+ if ! maas_snap_mode | grep -q "region"; then
12+ return
13 fi
14
15+ snap_run "maas-region migrate"
16 # patch the value of the default cloud images keyring to point to the one
17 # in the snap
18- local keyring="/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg"
19- cat <<EOF | pg_do psql maasdb
20-UPDATE maasserver_bootsource
21-SET keyring_filename = '${MAAS_SNAP}${keyring}'
22-WHERE keyring_filename = '${keyring}'
23+ cat <<EOF | snap_run "maas-region shell"
24+from maasserver.models import BootSource
25+keyring = "/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg"
26+(
27+ BootSource.objects
28+ .filter(keyring_filename=keyring)
29+ .update(keyring_filename=f"/snap/maas/current{keyring}")
30+)
31 EOF
32 }
33

Subscribers

People subscribed via source and target branches