Skip to content
Snippets Groups Projects
Commit 44afd145 authored by Erik Reid's avatar Erik Reid
Browse files

pep8

parent 370c720d
No related branches found
No related tags found
No related merge requests found
...@@ -427,8 +427,10 @@ def _find_subnet_keys(addresses): ...@@ -427,8 +427,10 @@ def _find_subnet_keys(addresses):
interface = ipaddress.ip_interface(m.group(1)) interface = ipaddress.ip_interface(m.group(1))
try: try:
matched_address = next(a for a, v in remaining_addresses.items() matched_address = next(
if v == interface.ip) a for a, v
in remaining_addresses.items()
if v == interface.ip)
del remaining_addresses[matched_address] del remaining_addresses[matched_address]
yield k, matched_address yield k, matched_address
except StopIteration: except StopIteration:
...@@ -455,7 +457,7 @@ def _get_subnet_interfaces(address, r): ...@@ -455,7 +457,7 @@ def _get_subnet_interfaces(address, r):
_subnet_lookup_semaphore.acquire() _subnet_lookup_semaphore.acquire()
try: try:
all_subnets = _get_subnets(r) all_subnets = _get_subnets(r)
except: except Exception:
logger.exception('error looking up subnets') logger.exception('error looking up subnets')
all_subnets = {} all_subnets = {}
finally: finally:
...@@ -473,8 +475,18 @@ def _get_subnet_interfaces(address, r): ...@@ -473,8 +475,18 @@ def _get_subnet_interfaces(address, r):
yield from json.loads(value.decode('utf-8')) yield from json.loads(value.decode('utf-8'))
def _get_services_for_address(address: str, r: 'StrictRedis'): def _get_services_for_address(address: str, r):
"""
match this address against all interfaces, then look up
any known services for that port
address is assumed to be in a valid v4/v6 format (it's used to
construct a ipaddress.ip_address object without try/except)
:param address: ip address string
:param r: a Redis instance
:return: yields PEERING_ADDRESS_SERVICES_LIST elements
"""
def _formatted_service(s): def _formatted_service(s):
return { return {
'id': s['id'], 'id': s['id'],
...@@ -532,7 +544,9 @@ def _load_address_services_proc(address_queue, results_queue, config_params): ...@@ -532,7 +544,9 @@ def _load_address_services_proc(address_queue, results_queue, config_params):
except json.JSONDecodeError: except json.JSONDecodeError:
logger.exception(f'error decoding redis entry for {address}') logger.exception(f'error decoding redis entry for {address}')
except: except Exception:
# just log info about this error (for debugging only)
# ... and quit (i.e. let finally cleanup)
logger.exception(f'error looking up service info for {address}') logger.exception(f'error looking up service info for {address}')
finally: finally:
# contract is to return None when finished # contract is to return None when finished
......
...@@ -20,6 +20,8 @@ TEST_DATA_DIRNAME = os.path.realpath(os.path.join( ...@@ -20,6 +20,8 @@ TEST_DATA_DIRNAME = os.path.realpath(os.path.join(
"test", "test",
"data")) "data"))
_bootstrap_semaphore = threading.Semaphore()
@pytest.fixture @pytest.fixture
def data_config_filename(): def data_config_filename():
...@@ -86,17 +88,6 @@ def data_config(data_config_filename): ...@@ -86,17 +88,6 @@ def data_config(data_config_filename):
return config.load(f) return config.load(f)
TEST_DATA_DIRNAME = os.path.realpath(os.path.join(
inventory_provider.__path__[0],
"..",
"test",
"data"))
_bootstrap_semaphore = threading.Semaphore()
class MockedRedis(object): class MockedRedis(object):
db = None db = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment