Skip to content

Commit

Permalink
is_leader requires juju 1.22.0 or better
Browse files Browse the repository at this point in the history
The ETCD charm fails with a non committal error message when probing for
is_leader on juju versions <= 1.21, 1.18 is still the default shipping
in universe, and will cause some headaches if users of older juju
versions attempt to use this charm as its leveraging the leader election
components.

There is probably a charm helper for consuming these methods that has a
sane fallback strategy, but for now this will satisfy the requirement of
blocking installation on anything < 1.22.0

Introduces a new dependency 'semver' to perform the version calculation
  • Loading branch information
Charles Butler committed Aug 10, 2015
1 parent 489ddb7 commit 016c4c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions hooks/hooks.py
Expand Up @@ -8,6 +8,7 @@
from path import path
import string
import random
import semver
import shlex
from subprocess import check_output, check_call
import sys
Expand All @@ -24,6 +25,10 @@

@hooks.hook('config-changed')
def config_changed():
if not version_check:
hookenv.log('CRITICAL', 'This charm requires juju 1.22.0 or greater.'
' Panic and exit!')
sys.exit(1)
if not db.get('installed') or hookenv.config().changed('source-sum'):
install_etcd()
if leader_status:
Expand Down Expand Up @@ -152,6 +157,10 @@ def install_etcd():
hookenv.open_port(4001)
db.set('installed', True)

def version_check():
version = check_output(["juju", "--version"])
return semver.match(version, ">=1.22.0")

if __name__ == '__main__':
with hook_data():
hooks.execute(sys.argv)
2 changes: 1 addition & 1 deletion hooks/install
Expand Up @@ -5,7 +5,7 @@ set -ex
# corrected and easy_install is no longer required to make pip function.
# apt-get install -y python-pip
easy_install -U pip
pip install charmhelpers path.py requests
pip install charmhelpers path.py requests semver

echo "Creating etcd data path on $JUJU_UNIT_NAME"
mkdir -p /opt/etcd/var

0 comments on commit 016c4c5

Please sign in to comment.