clustering: guard on hostname presentation
Deployment environments may have random features with regards to forward/reverse hostname lookups; the charm does endeavour to write reliable hostname/ip maps into /etc/hosts however not all functions that assess the ready-ness of the cluster to form look at whether this has been presented. Update the is_sufficient_peers check to validate with this key and use during changes on the cluster relation to avoid cluster host discovery for unresolvable hostnames as a side effect of peers within the cluster discovering each other outside of the charm code. Change-Id: I27d6356dba4340388211c6dfed383417c35542e0 Closes-Bug: 1812568
This commit is contained in:
parent
da9cfd7ef4
commit
a388bf52c8
|
@ -974,7 +974,7 @@ def is_sufficient_peers():
|
|||
"""Sufficient number of expected peers to build a complete cluster
|
||||
|
||||
If min-cluster-size has been provided, check that we have sufficient
|
||||
number of peers as expected for a complete cluster.
|
||||
number of peers who have presented a hostname for a complete cluster.
|
||||
|
||||
If not defined assume a single unit.
|
||||
|
||||
|
@ -988,7 +988,10 @@ def is_sufficient_peers():
|
|||
# Include this unit
|
||||
units = 1
|
||||
for rid in relation_ids('cluster'):
|
||||
units += len(related_units(rid))
|
||||
for unit in related_units(rid):
|
||||
if relation_get(attribute='hostname',
|
||||
rid=rid, unit=unit):
|
||||
units += 1
|
||||
|
||||
if units < min_size:
|
||||
log("Insufficient number of peer units to form cluster "
|
||||
|
|
|
@ -435,8 +435,9 @@ def cluster_changed(relation_id=None, remote_unit=None):
|
|||
'rabbitmq cluster config.', level=INFO)
|
||||
return
|
||||
|
||||
# NOTE(freyes): all the nodes need to marked as 'clustered' (LP: #1691510)
|
||||
rabbit.cluster_with()
|
||||
if rabbit.is_sufficient_peers():
|
||||
# NOTE(freyes): all the nodes need to marked as 'clustered' (LP: #1691510)
|
||||
rabbit.cluster_with()
|
||||
|
||||
if not is_leader() and is_relation_made('nrpe-external-master'):
|
||||
update_nrpe_checks()
|
||||
|
|
|
@ -471,6 +471,7 @@ class UtilsTests(CharmTestCase):
|
|||
@mock.patch.object(rabbit_utils, 'config')
|
||||
def test_is_sufficient_peers(self, mock_config, mock_relation_ids,
|
||||
mock_related_units, mock_is_leader):
|
||||
self.relation_get.return_value = None
|
||||
# With leadership Election
|
||||
mock_is_leader.return_value = False
|
||||
_config = {'min-cluster-size': None}
|
||||
|
@ -484,6 +485,7 @@ class UtilsTests(CharmTestCase):
|
|||
mock_config.side_effect = lambda key: _config.get(key)
|
||||
self.assertFalse(rabbit_utils.is_sufficient_peers())
|
||||
|
||||
self.relation_get.side_effect = ['testhost0', 'testhost1']
|
||||
mock_is_leader.return_value = False
|
||||
mock_related_units.return_value = ['test/0', 'test/1']
|
||||
_config = {'min-cluster-size': 3}
|
||||
|
|
Loading…
Reference in New Issue