Ensure that get_host_ip() is mocked out in test
The test test_setup_ufw() didn't mock out get_host_ip() which meant that the test leaked and used an actual IP hostname lookup. This failed when ubuntu.com's IP address changed. This patch mocks it out properly. Change-Id: Ida7aaa7d085cc0316aa496d0a0e24333c5828cee Closes-Bug: #1832829
This commit is contained in:
parent
173f1a99db
commit
c9b558b0ff
|
@ -616,9 +616,10 @@ class SwiftStorageUtilsTests(CharmTestCase):
|
|||
swift_utils.revoke_access(addr, port)
|
||||
self.ufw.revoke_access.assert_called_with(addr, port=port, proto='tcp')
|
||||
|
||||
@patch.object(swift_utils, 'get_host_ip')
|
||||
@patch.object(swift_utils, 'RsyncContext')
|
||||
@patch.object(swift_utils, 'grant_access')
|
||||
def test_setup_ufw(self, mock_grant_access, mock_rsync):
|
||||
def test_setup_ufw(self, mock_grant_access, mock_rsync, mock_get_host_ip):
|
||||
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', 'ubuntu.com']
|
||||
|
@ -637,7 +638,6 @@ class SwiftStorageUtilsTests(CharmTestCase):
|
|||
context_call.return_value = {'allowed_hosts': '{} {}'
|
||||
''.format(peer_addr_1, peer_addr_2)}
|
||||
mock_rsync.return_value = context_call
|
||||
swift_utils.setup_ufw()
|
||||
calls = []
|
||||
for addr in [peer_addr_1, peer_addr_2] + client_addrs:
|
||||
for port in ports:
|
||||
|
@ -645,4 +645,14 @@ class SwiftStorageUtilsTests(CharmTestCase):
|
|||
calls.append(call('91.189.94.40', port))
|
||||
else:
|
||||
calls.append(call(addr, port))
|
||||
|
||||
def _get_host_ip(ip):
|
||||
if ip == 'ubuntu.com':
|
||||
return '91.189.94.40'
|
||||
else:
|
||||
return ip
|
||||
|
||||
mock_get_host_ip.side_effect = _get_host_ip
|
||||
|
||||
swift_utils.setup_ufw()
|
||||
mock_grant_access.assert_has_calls(calls)
|
||||
|
|
Loading…
Reference in New Issue