def test_cluster_ready(self, mock_is_sufficient_peers, mock_rabbitmq_is_installed, mock_clustered): # Not sufficient number of peers mock_is_sufficient_peers.return_value = False self.assertFalse(rabbit_utils.cluster_ready()) # This unit not yet clustered mock_is_sufficient_peers.return_value = True self.relation_ids.return_value = ['cluster:0'] self.related_units.return_value = ['test/0', 'test/1'] self.relation_get.return_value = 'teset/0' _config = {'min-cluster-size': 3} self.config.side_effect = lambda key: _config.get(key) mock_clustered.return_value = False self.assertFalse(rabbit_utils.cluster_ready()) # Not all cluster ready mock_is_sufficient_peers.return_value = True self.relation_ids.return_value = ['cluster:0'] self.related_units.return_value = ['test/0', 'test/1'] self.relation_get.return_value = False _config = {'min-cluster-size': 3} self.config.side_effect = lambda key: _config.get(key) mock_clustered.return_value = True self.assertFalse(rabbit_utils.cluster_ready()) # All cluster ready mock_is_sufficient_peers.return_value = True self.relation_ids.return_value = ['cluster:0'] self.related_units.return_value = ['test/0', 'test/1'] self.relation_get.return_value = 'teset/0' _config = {'min-cluster-size': 3} self.config.side_effect = lambda key: _config.get(key) mock_clustered.return_value = True self.assertTrue(rabbit_utils.cluster_ready()) # Not all cluster ready no min-cluster-size mock_is_sufficient_peers.return_value = True self.relation_ids.return_value = ['cluster:0'] self.related_units.return_value = ['test/0', 'test/1'] self.relation_get.return_value = False _config = {'min-cluster-size': None} self.config.side_effect = lambda key: _config.get(key) mock_clustered.return_value = True self.assertFalse(rabbit_utils.cluster_ready()) # All cluster ready no min-cluster-size mock_is_sufficient_peers.return_value = True self.relation_ids.return_value = ['cluster:0'] self.related_units.return_value = ['test/0', 'test/1'] self.relation_get.return_value = 'teset/0' _config = {'min-cluster-size': None} self.config.side_effect = lambda key: _config.get(key) mock_clustered.return_value = True self.assertTrue(rabbit_utils.cluster_ready()) # Assume single unit no-min-cluster-size mock_is_sufficient_peers.return_value = True self.relation_ids.return_value = [] self.related_units.return_value = [] self.relation_get.return_value = None _config = {'min-cluster-size': None} self.config.side_effect = lambda key: _config.get(key) mock_clustered.return_value = True self.assertTrue(rabbit_utils.cluster_ready())