diff --git a/hooks/hooks.py b/hooks/hooks.py index 6b613ea3..38de5edf 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -239,10 +239,7 @@ def cluster_joined(rid=None): config('os-{}-network'.format(addr_type)) ) if address: - relation_set( - relation_id=rid, - settings={'{}-address'.format(addr_type): address} - ) + settings['{}-address'.format(addr_type)] = address if config('prefer-ipv6'): private_addr = get_ipv6_addr(exc_list=[config('vip')])[0] diff --git a/unit_tests/test_hooks.py b/unit_tests/test_hooks.py index 4687b040..007cc35d 100644 --- a/unit_tests/test_hooks.py +++ b/unit_tests/test_hooks.py @@ -13,7 +13,7 @@ # limitations under the License. from mock import ( - patch, + patch, call ) from test_utils import ( @@ -218,6 +218,28 @@ class CephRadosGWTests(CharmTestCase): self.assertEquals(ceph_hooks.canonical_url({}, PUBLIC), 'http://[%s]' % ipv6_addr) + @patch.object(ceph_hooks, 'get_address_in_network') + def test_cluster_joined(self, mock_get_addr): + addrs = {'10.0.0.0/24': '10.0.0.1', + '10.0.1.0/24': '10.0.1.1', + '10.0.2.0/24': '10.0.2.1'} + + def fake_get_address_in_network(network): + return addrs.get(network) + + mock_get_addr.side_effect = fake_get_address_in_network + + self.test_config.set('os-public-network', '10.0.0.0/24') + self.test_config.set('os-admin-network', '10.0.1.0/24') + self.test_config.set('os-internal-network', '10.0.2.0/24') + + ceph_hooks.cluster_joined() + self.relation_set.assert_has_calls( + [call(relation_id=None, + **{'admin-address': '10.0.1.1', + 'internal-address': '10.0.2.1', + 'public-address': '10.0.0.1'})]) + def test_cluster_changed(self): _id_joined = self.patch('identity_joined') self.relation_ids.return_value = ['rid']