Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_leader requires juju 1.22.0 or better #16

Merged
merged 5 commits into from Aug 10, 2015

Conversation

lazypower
Copy link
Collaborator

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

@@ -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.'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@mbruzek
Copy link
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.

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
@lazypower
Copy link
Collaborator Author

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

@mbruzek
Copy link
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?

@marcoceppi
Copy link

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)

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
whitmo#16 for more information on why
this is probing as it were.
@lazypower
Copy link
Collaborator Author

@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.

return True
else:
return False
except OSError as e:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@marcoceppi
Copy link

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

refactored from a bash based sniff to just consume charm helpers and abort
on NotImplementedError
@marcoceppi
Copy link

LGTM +1

@mbruzek
Copy link
Collaborator

mbruzek commented Aug 10, 2015

+1 LGTM

mbruzek pushed a commit that referenced this pull request Aug 10, 2015
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants