Prevent errors when private-address=None

Whenever a peer returns None as its IP, it results in
misconfiguration in corosync.conf, which results in
a series of cascading hook errors that are difficult to
sort out.

More specifically, this usually happens when network-get
does not work for the current binding. The main problem
is that when changing bindings, a hook fires before the
network-get data is updated. This hook fails and prevents
the network-get from being re-read.

This patch changes the code behavior to ignore None IP
entries, therefore gracefully exiting and deferring further
configuration due to insufficient number of peers when that
happens, so that a later hook can successfully read the IP
from the relation and set the IPs correctly in corosync.

Closes-bug: #1961448
Change-Id: I5ed140a17e184fcf6954d0f66e25f74564bd281c
(cherry picked from commit d54de3d346)
This commit is contained in:
Rodrigo Barbieri 2022-04-06 18:42:13 -03:00 committed by Felipe Reyes
parent 567e54d87c
commit 07b7e5e367
2 changed files with 5 additions and 3 deletions

View File

@ -451,6 +451,7 @@ def get_ipv6_addr():
def get_ha_nodes():
ha_units = peer_ips(peer_relation='hanode')
ha_units = {k: v for k, v in ha_units.items() if v is not None}
ha_nodes = {}
for unit in ha_units:
corosync_id = get_corosync_id(unit)
@ -497,6 +498,7 @@ def get_node_flags(flag):
rid=relid,
unit=unit))
hosts = [x for x in hosts if x is not None]
hosts.sort()
return hosts

View File

@ -119,7 +119,7 @@ class UtilsTestCase(unittest.TestCase):
@mock.patch.object(utils.utils, 'is_ipv6', lambda *args: None)
@mock.patch.object(utils, 'get_corosync_id', lambda u: "%s-cid" % (u))
@mock.patch.object(utils, 'peer_ips', lambda *args, **kwargs:
{'hanode/1': '10.0.0.2'})
{'hanode/1': '10.0.0.2', 'hanode/2': None})
@mock.patch.object(utils, 'unit_get')
@mock.patch.object(utils, 'config')
def test_get_ha_nodes(self, mock_config, mock_unit_get, mock_get_host_ip,
@ -955,7 +955,7 @@ class UtilsTestCase(unittest.TestCase):
'private-address': '10.0.0.10'},
'unit2': {
'random_flag': True,
'private-address': '10.0.0.34'},
'private-address': None},
'unit3': {
'random_flag': True,
'private-address': '10.0.0.16'}}
@ -969,7 +969,7 @@ class UtilsTestCase(unittest.TestCase):
mock.call('private-address', rid='relid1', unit='unit3')]
self.assertSequenceEqual(
utils.get_node_flags('random_flag'),
['10.0.0.10', '10.0.0.16', '10.0.0.34', '10.0.0.41'])
['10.0.0.10', '10.0.0.16', '10.0.0.41'])
relation_get.assert_has_calls(rget_calls)
@mock.patch.object(utils, 'get_node_flags')