diff --git a/hooks/utils.py b/hooks/utils.py index 32c16f5..2e92d6d 100644 --- a/hooks/utils.py +++ b/hooks/utils.py @@ -471,7 +471,15 @@ def get_ha_nodes(): if config('prefer-ipv6'): addr = get_ipv6_addr() else: - addr = get_host_ip(unit_get('private-address')) + rids = relation_ids('hanode') + if len(rids) > 0: + addr = relation_get('ingress-address', + rid=rids[0], + unit=local_unit()) + + addr = get_host_ip(addr) + else: + addr = get_host_ip(unit_get('private-address')) ha_nodes[corosync_id] = addr diff --git a/unit_tests/test_hacluster_utils.py b/unit_tests/test_hacluster_utils.py index 8d109d6..55cfab1 100644 --- a/unit_tests/test_hacluster_utils.py +++ b/unit_tests/test_hacluster_utils.py @@ -129,17 +129,14 @@ class UtilsTestCase(unittest.TestCase): @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/2': None}) - @mock.patch.object(utils, 'unit_get') + @mock.patch.object(utils, 'relation_ids', lambda *args: [1]) + @mock.patch.object(utils, 'relation_get', + lambda *args, **kwargs: '10.0.0.1') @mock.patch.object(utils, 'config') - def test_get_ha_nodes(self, mock_config, mock_unit_get, mock_get_host_ip, + def test_get_ha_nodes(self, mock_config, mock_get_host_ip, mock_get_ipv6_addr): mock_get_host_ip.side_effect = lambda host: host - def unit_get(key): - return {'private-address': '10.0.0.1'}.get(key) - - mock_unit_get.side_effect = unit_get - def config(key): return {'prefer-ipv6': False}.get(key)