diff --git a/inventory_provider/routes/msr.py b/inventory_provider/routes/msr.py index 942f400f92d2f4b0b83db3f01ac4207f0f2c8f66..fa89e62f12d1ad9567872a0e13db196ba21f7610 100644 --- a/inventory_provider/routes/msr.py +++ b/inventory_provider/routes/msr.py @@ -427,8 +427,10 @@ def _find_subnet_keys(addresses): interface = ipaddress.ip_interface(m.group(1)) try: - matched_address = next(a for a, v in remaining_addresses.items() - if v == interface.ip) + matched_address = next( + a for a, v + in remaining_addresses.items() + if v == interface.ip) del remaining_addresses[matched_address] yield k, matched_address except StopIteration: @@ -455,7 +457,7 @@ def _get_subnet_interfaces(address, r): _subnet_lookup_semaphore.acquire() try: all_subnets = _get_subnets(r) - except: + except Exception: logger.exception('error looking up subnets') all_subnets = {} finally: @@ -473,8 +475,18 @@ def _get_subnet_interfaces(address, r): 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): return { 'id': s['id'], @@ -532,7 +544,9 @@ def _load_address_services_proc(address_queue, results_queue, config_params): except json.JSONDecodeError: 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}') finally: # contract is to return None when finished diff --git a/test/conftest.py b/test/conftest.py index ae7c9c25ede771a380cb627eca7185bc84f016b2..bdfe95676907fa170cde88260eadc5385ffdb9a4 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -20,6 +20,8 @@ TEST_DATA_DIRNAME = os.path.realpath(os.path.join( "test", "data")) +_bootstrap_semaphore = threading.Semaphore() + @pytest.fixture def data_config_filename(): @@ -86,17 +88,6 @@ def data_config(data_config_filename): 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): db = None