[gnuoy,trivial] Pre-release charmhelper sync to pickup leadership election peer migration fix

This commit is contained in:
Liam Young 2015-08-03 14:59:29 +01:00
parent 2e6970ca0e
commit 4f84dd2776
2 changed files with 21 additions and 5 deletions

View File

@ -59,7 +59,7 @@ def some_hook():
""" """
def leader_get(attribute=None): def leader_get(attribute=None, rid=None):
"""Wrapper to ensure that settings are migrated from the peer relation. """Wrapper to ensure that settings are migrated from the peer relation.
This is to support upgrading an environment that does not support This is to support upgrading an environment that does not support
@ -94,7 +94,8 @@ def leader_get(attribute=None):
# If attribute not present in leader db, check if this unit has set # If attribute not present in leader db, check if this unit has set
# the attribute in the peer relation # the attribute in the peer relation
if not leader_settings: if not leader_settings:
peer_setting = relation_get(attribute=attribute, unit=local_unit()) peer_setting = _relation_get(attribute=attribute, unit=local_unit(),
rid=rid)
if peer_setting: if peer_setting:
leader_set(settings={attribute: peer_setting}) leader_set(settings={attribute: peer_setting})
leader_settings = peer_setting leader_settings = peer_setting
@ -103,7 +104,7 @@ def leader_get(attribute=None):
settings_migrated = True settings_migrated = True
migrated.add(attribute) migrated.add(attribute)
else: else:
r_settings = relation_get(unit=local_unit()) r_settings = _relation_get(unit=local_unit(), rid=rid)
if r_settings: if r_settings:
for key in set(r_settings.keys()).difference(migrated): for key in set(r_settings.keys()).difference(migrated):
# Leader setting wins # Leader setting wins
@ -151,7 +152,7 @@ def relation_get(attribute=None, unit=None, rid=None):
""" """
try: try:
if rid in relation_ids('cluster'): if rid in relation_ids('cluster'):
return leader_get(attribute) return leader_get(attribute, rid)
else: else:
raise NotImplementedError raise NotImplementedError
except NotImplementedError: except NotImplementedError:

View File

@ -34,7 +34,22 @@ import errno
import tempfile import tempfile
from subprocess import CalledProcessError from subprocess import CalledProcessError
from charmhelpers.cli import cmdline try:
from charmhelpers.cli import cmdline
except ImportError as e:
# due to the anti-pattern of partially synching charmhelpers directly
# into charms, it's possible that charmhelpers.cli is not available;
# if that's the case, they don't really care about using the cli anyway,
# so mock it out
if str(e) == 'No module named cli':
class cmdline(object):
@classmethod
def subcommand(cls, *args, **kwargs):
def _wrap(func):
return func
return _wrap
else:
raise
import six import six
if not six.PY3: if not six.PY3: