diff --git a/lib/swift_storage_utils.py b/lib/swift_storage_utils.py index dfdabf5..afd0ca3 100644 --- a/lib/swift_storage_utils.py +++ b/lib/swift_storage_utils.py @@ -55,6 +55,7 @@ from charmhelpers.core.hookenv import ( ) from charmhelpers.contrib.network import ufw +from charmhelpers.contrib.network.ip import get_host_ip from charmhelpers.contrib.storage.linux.utils import ( is_block_device, @@ -620,7 +621,7 @@ def setup_ufw(): allowed_hosts = RsyncContext()().get('allowed_hosts', '').split(' ') # Storage clients (swift-proxy) - allowed_hosts += [ingress_address(rid=u.rid, unit=u.unit) + allowed_hosts += [get_host_ip(ingress_address(rid=u.rid, unit=u.unit)) for u in iter_units_for_relation_name('swift-storage')] # Grant access for peers and clients diff --git a/unit_tests/test_swift_storage_utils.py b/unit_tests/test_swift_storage_utils.py index ef07351..efa02c7 100644 --- a/unit_tests/test_swift_storage_utils.py +++ b/unit_tests/test_swift_storage_utils.py @@ -479,7 +479,7 @@ class SwiftStorageUtilsTests(CharmTestCase): def test_setup_ufw(self, mock_grant_access, mock_rsync): peer_addr_1 = '10.1.1.1' peer_addr_2 = '10.1.1.2' - client_addrs = ['10.3.3.1', '10.3.3.2','10.3.3.3'] + client_addrs = ['10.3.3.1', '10.3.3.2','10.3.3.3', 'ubuntu.com'] ports = [6660, 6661, 6662] self.test_config.set('object-server-port', ports[0]) self.test_config.set('container-server-port', ports[1]) @@ -488,7 +488,8 @@ class SwiftStorageUtilsTests(CharmTestCase): self.iter_units_for_relation_name.return_value = [ RelatedUnits(rid='rid:1', unit='unit/1'), RelatedUnits(rid='rid:1', unit='unit/2'), - RelatedUnits(rid='rid:1', unit='unit/3')] + RelatedUnits(rid='rid:1', unit='unit/3'), + RelatedUnits(rid='rid:1', unit='unit/4')] self.ingress_address.side_effect = client_addrs context_call = MagicMock() context_call.return_value = {'allowed_hosts': '{} {}' @@ -498,5 +499,8 @@ class SwiftStorageUtilsTests(CharmTestCase): calls = [] for addr in [peer_addr_1, peer_addr_2] + client_addrs: for port in ports: - calls.append(call(addr, port)) + if addr == 'ubuntu.com': + calls.append(call('91.189.94.40', port)) + else: + calls.append(call(addr, port)) mock_grant_access.assert_has_calls(calls)