Merge "Resolve hostnames if needed to allow access in ufw"

This commit is contained in:
Zuul 2018-03-19 10:17:26 +00:00 committed by Gerrit Code Review
commit 0f6a9032a2
2 changed files with 9 additions and 4 deletions

View File

@ -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

View File

@ -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)