diff --git a/.gitignore b/.gitignore index 25d8aec..3af73ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ bin .coverage .testrepository +.stestr .tox tags *.sw[nop] diff --git a/hooks/swift_hooks.py b/hooks/swift_hooks.py index d81e319..5568ca9 100755 --- a/hooks/swift_hooks.py +++ b/hooks/swift_hooks.py @@ -228,7 +228,7 @@ def keystone_changed(): @hooks.hook('swift-storage-relation-joined') -def storage_joined(): +def storage_joined(rid=None): if not is_elected_leader(SWIFT_HA_RES): log("New storage relation joined - stopping proxy until ring builder " "synced", level=INFO) @@ -241,6 +241,13 @@ def storage_joined(): mark_www_rings_deleted() try_initialize_swauth() + # NOTE(jamespage): Ensure private-address is set to any network-space + # binding provided by the charm user. + relation_set( + relation_id=rid, + relation_settings={'private-address': get_relation_ip('swift-storage')} + ) + def get_host_ip(rid=None, unit=None): addr = relation_get('private-address', rid=rid, unit=unit) diff --git a/unit_tests/test_swift_hooks.py b/unit_tests/test_swift_hooks.py index a6738a0..760757f 100644 --- a/unit_tests/test_swift_hooks.py +++ b/unit_tests/test_swift_hooks.py @@ -233,7 +233,7 @@ class SwiftHooksTestCase(unittest.TestCase): @patch.object(swift_hooks, 'update_dns_ha_resource_params') @patch.object(swift_hooks, 'get_hacluster_config') @patch.object(swift_hooks, 'config') - def test_ha_jrelation_oined_dns_ha(self, test_config, get_hacluster_config, + def test_ha_relation_joined_dns_ha(self, test_config, get_hacluster_config, update_dns_ha_resource_params, relation_set): def _fake_update(resources, resource_params, relation_id=None): @@ -271,3 +271,24 @@ class SwiftHooksTestCase(unittest.TestCase): swift_hooks.ha_relation_joined() self.assertTrue(update_dns_ha_resource_params.called) relation_set.assert_called_with(**args) + + @patch.object(swift_hooks, 'is_elected_leader') + @patch.object(swift_hooks, 'get_relation_ip') + @patch.object(swift_hooks, 'try_initialize_swauth') + @patch.object(swift_hooks, 'mark_www_rings_deleted') + @patch.object(swift_hooks, 'service_stop') + @patch.object(swift_hooks, 'relation_set') + def test_swift_storage_joined(self, relation_set, service_stop, + mark_www_rings_deleted, + try_initialize_swauth, + get_relation_ip, + is_elected_leader): + is_elected_leader.return_value = False + get_relation_ip.return_value = '10.10.20.243' + swift_hooks.storage_joined(rid='swift-storage:23') + get_relation_ip.assert_called_with('swift-storage') + relation_set.assert_called_with( + relation_id='swift-storage:23', + relation_settings={'private-address': '10.10.20.243'} + ) + try_initialize_swauth.assert_called_once()