diff --git a/config.yaml b/config.yaml index 1e55896c..130e4fcf 100644 --- a/config.yaml +++ b/config.yaml @@ -67,3 +67,10 @@ options: The name that will be used to create the Ceph's RBD image with. If the image name exists in Ceph, it will be re-used and the data will be overwritten. + max-cluster-tries: + type: int + default: 3 + description: | + Number of tries to cluster with other units before giving up. + If errors clustering happening in more than these units, charm will + end with an error diff --git a/hooks/rabbit_utils.py b/hooks/rabbit_utils.py index 723a093d..cf3ad479 100644 --- a/hooks/rabbit_utils.py +++ b/hooks/rabbit_utils.py @@ -14,6 +14,7 @@ import _pythonpath _ = _pythonpath from charmhelpers.contrib.openstack.utils import get_hostname +from charmhelpers.core.hookenv import config PACKAGES = ['pwgen', 'rabbitmq-server', 'python-amqplib', 'unison'] @@ -108,8 +109,13 @@ def cluster_with(): current_host = subprocess.check_output(['hostname']).strip() # check if node is already clustered + total_nodes = 1 pattern = '{running_nodes,[]}' - if re.search(pattern, out): + m = re.search("\{running_nodes,\[(.*)\]\}", out.strip()) + if m is not None: + total_nodes = len(m.group(1).split(',')) + + if total_nodes>1: # check all peers and try to cluster with them available_nodes = [] first_hostname = utils.relation_get('host') @@ -125,6 +131,8 @@ def cluster_with(): available_nodes.append(node) # iterate over all the nodes, join to the first available + max_tries = config('max-cluster-tries') + num_tries = 0 for node in available_nodes: utils.juju_log('INFO', 'Clustering with remote rabbit host (%s).' % node) @@ -145,10 +153,12 @@ def cluster_with(): return except: # continue to the next node - pass + num_tries+=1 # error, no nodes available for clustering utils.juju_log('ERROR', 'No nodes available for clustering, retrying') + if num_tries>max_tries: + sys.exit(1) else: utils.juju_log('INFO', 'Node is already clustered, skipping') diff --git a/revision b/revision index 9b252fd0..dee79f10 100644 --- a/revision +++ b/revision @@ -1 +1 @@ -113 +114