diff --git a/hooks/rabbit_utils.py b/hooks/rabbit_utils.py index 235e7464..57b3a35c 100644 --- a/hooks/rabbit_utils.py +++ b/hooks/rabbit_utils.py @@ -29,6 +29,7 @@ from charmhelpers.core.hookenv import ( status_set, cached, unit_get, + relation_set, ) from charmhelpers.core.host import ( @@ -368,6 +369,9 @@ def cluster_with(): time.sleep(random.random() * 100) try: join_cluster(node) + # NOTE: toggle the cluster relation to ensure that any peers + # already clustered re-assess status correctly + relation_set(clustered=get_local_nodename()) return True except subprocess.CalledProcessError as e: status_set('blocked', 'Failed to cluster with %s. Exception: %s' diff --git a/hooks/rabbitmq_server_relations.py b/hooks/rabbitmq_server_relations.py index f54fd232..eb64f9f8 100755 --- a/hooks/rabbitmq_server_relations.py +++ b/hooks/rabbitmq_server_relations.py @@ -367,9 +367,6 @@ def cluster_changed(): rabbit.cluster_with() update_nrpe_checks() - # NOTE: toggle the cluster relation to ensure that any peers already - # clustered re-assess status correctly - relation_set(clustered=True) # If cluster has changed peer db may have changed so run amqp_changed # to sync any changes for rid in relation_ids('amqp'): diff --git a/unit_tests/test_rabbit_utils.py b/unit_tests/test_rabbit_utils.py index 06f38922..69999f0a 100644 --- a/unit_tests/test_rabbit_utils.py +++ b/unit_tests/test_rabbit_utils.py @@ -173,6 +173,8 @@ class UtilsTests(unittest.TestCase): self.assertEqual(rabbit_utils.leader_node(), 'rabbit@juju-devel3-machine-15') + @mock.patch('rabbit_utils.relation_set') + @mock.patch('rabbit_utils.get_local_nodename') @mock.patch('rabbit_utils.wait_app') @mock.patch('rabbit_utils.subprocess.check_call') @mock.patch('rabbit_utils.subprocess.check_output') @@ -185,7 +187,8 @@ class UtilsTests(unittest.TestCase): mock_clustered, mock_leader_node, mock_running_nodes, mock_time, mock_check_output, mock_check_call, - mock_wait_app): + mock_wait_app, mock_get_local_nodename, + mock_relation_set): mock_cmp_pkgrevno.return_value = True mock_clustered.return_value = False mock_leader_node.return_value = 'rabbit@juju-devel7-machine-11'