Skip to content

Commit

Permalink
fix(snap): Install Unit of Measure config file on upgrade (#4125)
Browse files Browse the repository at this point in the history
* fix(snap): Install Unit of Measure config file on upgrade

* refactor: rename snap options for clarity

* fix: Correct legacy snap option name

Signed-off-by: Farshid Tavakolizadeh <farshid.tavakolizadeh@canonical.com>
  • Loading branch information
farshidtz committed Aug 22, 2022
1 parent 96e03a3 commit 0b67b21
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
24 changes: 24 additions & 0 deletions snap/hooks/post-refresh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
#!/bin/bash -e

TAG=$SNAP_INSTANCE_NAME.$(basename "$0")

# read revision/version of the previous installation, set in the pre-refresh hook
pre_rev=$(snapctl get pre-refresh.revision)
pre_ver=$(snapctl get pre-refresh.version)
# read the revision from the legacy lastrev option (EdgeX <2.3)
[ -z "$pre_rev" ] && pre_rev=$(snapctl get lastrev)

logger --tag $TAG "Refreshing from $pre_ver ($pre_rev) to $SNAP_VERSION ($SNAP_REVISION)"

# set up postgres, if we are upgrading it
$SNAP/bin/kong-postgres-setup.sh "post-refresh"

# Install the Unit of Measure config file when upgrading from an old version
# UoM was added in v2.3.0-dev.45 (snap revision 3900):
# https://github.com/edgexfoundry/edgex-go/pull/4119
if (( pre_rev < 3900 )); then
uom="config/core-metadata/res/uom.toml"
logger --tag $TAG "Installing $SNAP/$uom"
if [ -f "$SNAP/$uom" ]; then
# --no-clobber: copy if missing from target
cp --no-clobber "$SNAP/$uom" "$SNAP_DATA/$uom"
else
logger --stderr --tag $TAG "$SNAP/$uom does not exit."
fi
fi
12 changes: 7 additions & 5 deletions snap/hooks/pre-refresh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/bin/bash -e

# save this revision for when we run again in the post-refresh
snapctl set lastrev="$SNAP_REVISION"
# save these for use in the post-refresh hook
snapctl set pre-refresh.revision=$SNAP_REVISION
snapctl set pre-refresh.version=$SNAP_VERSION

# unset legacy EdgeX <2.3 options
snapctl unset lastrev release

snapctl set release="jakarta"

# back up the Kong database, so that if the new snap contains a newer
# postgresql, then the configuration can be imported into the new database
# in the post-refresh hook.
$SNAP/bin/kong-postgres-setup.sh "pre-refresh"
$SNAP/bin/kong-postgres-setup.sh "pre-refresh"

0 comments on commit 0b67b21

Please sign in to comment.