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', 'ubuntu.com'] ports = [6660, 6661, 6662] self.test_config.set('object-server-port', ports[0]) self.test_config.set('container-server-port', ports[1]) self.test_config.set('account-server-port', ports[2]) RelatedUnits = namedtuple('RelatedUnits', 'rid, unit') 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/4') ] self.ingress_address.side_effect = client_addrs context_call = MagicMock() 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: 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)
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', 'ubuntu.com'] ports = [6660, 6661, 6662] self.test_config.set('object-server-port', ports[0]) self.test_config.set('container-server-port', ports[1]) self.test_config.set('account-server-port', ports[2]) RelatedUnits = namedtuple('RelatedUnits', 'rid, unit') 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/4')] self.ingress_address.side_effect = client_addrs context_call = MagicMock() 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: 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)
def swift_storage_relation_changed(): setup_ufw() rings_url = relation_get('rings_url') swift_hash = relation_get('swift_hash') if '' in [rings_url, swift_hash] or None in [rings_url, swift_hash]: log('swift_storage_relation_changed: Peer not ready?') sys.exit(0) CONFIGS.write('/etc/rsync-juju.d/050-swift-storage.conf') CONFIGS.write('/etc/swift/swift.conf') fetch_swift_rings(rings_url)
def swift_storage_relation_changed(): setup_ufw() rings_url = relation_get('rings_url') swift_hash = relation_get('swift_hash') if '' in [rings_url, swift_hash] or None in [rings_url, swift_hash]: log('swift_storage_relation_changed: Peer not ready?') sys.exit(0) CONFIGS.write('/etc/rsync-juju.d/050-swift-storage.conf') CONFIGS.write('/etc/swift/swift.conf') # NOTE(hopem): retries are handled in the function but it is possible that # we are attempting to get rings from a proxy that is no # longer publiscising them so lets catch the error, log a # message and hope that the good rings_url us waiting to be # consumed. try: fetch_swift_rings(rings_url) except CalledProcessError: log("Failed to sync rings from {} - no longer available from that " "unit?".format(rings_url), level=WARNING)