is_leader requires juju 1.22.0 or better #16

Merged
merged 5 commits into from Aug 10, 2015

Conversation

Projects
None yet
3 participants
Collaborator

chuckbutler commented Aug 10, 2015

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

hooks/hooks.py
@@ -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.'
@mbruzek

mbruzek Aug 10, 2015

Collaborator

I believe you are calling log() incorrectly here. The message is first and the level is the second argument.

charmhelpers.core.hookenv.log(message, level=None)
    Write a message to the juju log

http://pythonhosted.org/charmhelpers/api/charmhelpers.core.hookenv.html#charmhelpers.core.hookenv.log

Collaborator

mbruzek commented Aug 10, 2015

Hey Chuck,

Thanks for the quick turn around on this issue! I agree that this is the right way to handle this issue, if the charm makes use of a feature that is in a different version of Juju then we should exit.

is_leader requires juju 1.22.0 or better
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
Collaborator

chuckbutler commented Aug 10, 2015

@mbruzek thanks for the review, i've updated the hookenv.log statement

Collaborator

mbruzek commented Aug 10, 2015

Hey Chuck,
I tried to figure out when the is_leader feature landed, and as Marco pointed out it is not recommended to filter on versions rather check for that feature instead.

Could we re-factor this to call "is_leader" and if the command does not exist by exception or return code then just error out with the same message? This would prevent having to import a new package.

They do something similar here:
http://bazaar.launchpad.net/~charm-helpers/charm-helpers/devel/view/head:/charmhelpers/core/hookenv.py#L741

What do you think about that?

I'm a +1 to testing for features instead of trying to make assumptions. You can easily modify the version method to just execute is_leader and capture OSError output. There could be situations where in later versions of juju is_leader is depreciated or removed. There is also the possibility that the juju version format changes (as it has several times already)

Refactor the implementation away from semver check
This favors a `which is_leader` command to probe if the command is
available. It still panic's and bails on the installation if is_leader
is not available (the current defacto method to determine if leader
election is available on a unit - see
#16 for more information on why
this is probing as it were.
Collaborator

chuckbutler commented Aug 10, 2015

@mbruzek @marcoceppi I refactored this to favor a which is_leader sniff to determine if is_leader is available. It's still a predicate check, and encapsulated with the same OSERROR diaper during execution.

LMK if there is more that needs to be done here.

hooks/hooks.py
+ return True
+ else:
+ return False
+ except OSError as e:
@marcoceppi

marcoceppi Aug 10, 2015

I'd remove the entire try block here, since OSError will simply raise just like any other exception. There really isn't any exception handling here. You can also simplify the if block with

return ret == 0

Finally, it appears that charmhelpers has some way of translating whether or not is-leader is available. Doing this

from charmhelpers.core.hookenv import is_leader

try:
    is_leader()
except NotImplementedError:
    print("panic message")

would achieve the same goal.

I had some more pedantic comments, but this is better IMO as is

Refactored is_leader
refactored from a bash based sniff to just consume charm helpers and abort
on NotImplementedError

LGTM +1

Collaborator

mbruzek commented Aug 10, 2015

+1 LGTM

mbruzek added a commit that referenced this pull request Aug 10, 2015

Merge pull request #16 from chuckbutler/minimum-juju-version
is_leader requires juju 1.22.0 or better

@mbruzek mbruzek merged commit 7eb5166 into whitmo:master Aug 10, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment