Ensure that python3 really is installed on upgrade charm

During a switch from py2 to py3, need to ensure that the required
python3 versions of the required libraries are installed.

Change-Id: I0dbfab4819b873e0476879e42fbad1d40cdf699d
This commit is contained in:
Alex Kavanagh 2020-11-24 12:05:14 +00:00 committed by Alex Kavanagh
parent 3a473381e5
commit 742f7f812d
2 changed files with 24 additions and 1 deletions

View File

@ -1 +0,0 @@
rabbitmq_server_relations.py

23
hooks/upgrade-charm Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash -e
# Wrapper to ensure that the required py3 versions are installed if upgrading
# from a py2 charm to a py3 based charm.
declare -a DEPS=('apt' 'netaddr' 'netifaces' 'pip' 'yaml' 'dnspython' 'requests')
check_and_install() {
pkg="${1}-${2}"
if ! dpkg -s ${pkg} 2>&1 > /dev/null; then
apt-get -y install ${pkg}
fi
}
PYTHON="python3"
for dep in ${DEPS[@]}; do
check_and_install ${PYTHON} ${dep}
done
# python3-croniter not available on trusty
[ "$( lsb_release -sc )" != "trusty" ] && check_and_install ${PYTHON} croniter
exec ./hooks/upgrade-charm.real

1
hooks/upgrade-charm.real Symbolic link
View File

@ -0,0 +1 @@
rabbitmq_server_relations.py