From a0d2b2196aaaec710b6a9d9232ba444223658daf Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Wed, 23 Sep 2020 12:15:46 +0200 Subject: [PATCH] don't return dummy location for unknown routers --- inventory_provider/routes/classifier.py | 29 +++++++------------------ test/test_classifier_routes.py | 10 ++------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index 2d082836..a9e5e211 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -33,35 +33,24 @@ def _remove_duplicates_from_list(all): return list(tmp_dict.values()) -def _location_from_router(router_name): +def _locations_from_router(router_name): r = common.get_current_redis() result = r.get(f'opsdb:location:{router_name}') if not result: logger.error(f'error looking up location for {router_name}') - return { - 'a': _LOCATION( - equipment=router_name, - name='?', - abbreviation='?') - } + return [] result = json.loads(result.decode('utf-8')) if not result: logger.error(f'sanity failure: empty list for location {router_name}') - return None - return { - 'a': _LOCATION( - equipment=router_name, - name='?', - abbreviation='?') - } + return [] - return { + return [{ 'a': _LOCATION( equipment=result[0]['equipment-name'], name=result[0]['pop']['name'], abbreviation=result[0]['pop']['abbreviation']) - } + }] def _location_from_service_dict(s): @@ -217,7 +206,7 @@ def get_juniper_link_info(source_equipment, interface): result['related-services'] = top_level_services if not result['locations']: - result['locations'] = [_location_from_router(source_equipment)] + result['locations'] = _locations_from_router(source_equipment) result['locations'] = _remove_duplicates_from_list(result['locations']) result = json.dumps(result) @@ -351,16 +340,14 @@ def peer_info(address): info = info.decode('utf-8') info = json.loads(info) result['ix-public-peer-info'] = ix_peering_info(info) - router_location = _location_from_router(info['router']) - result['locations'] += [router_location] + result['locations'] += _locations_from_router(info['router']) info = r.get('vpn_rr_peer:%s' % address) if info: info = info.decode('utf-8') info = json.loads(info) result['vpn-rr-peer-info'] = info - router_location = _location_from_router(info['router']) - result['locations'] += [router_location] + result['locations'] += _locations_from_router(info['router']) interfaces = list(find_interfaces_and_services(address)) if interfaces: diff --git a/test/test_classifier_routes.py b/test/test_classifier_routes.py index a2558096..5de175c9 100644 --- a/test/test_classifier_routes.py +++ b/test/test_classifier_routes.py @@ -30,8 +30,7 @@ LOCATIONS_DEFINITIONS = { }, "locations-list": { "type": "array", - "items": {"$ref": "#/definitions/location"}, - "minitems": 1 + "items": {"$ref": "#/definitions/location"} } } @@ -235,12 +234,7 @@ def test_juniper_link_unknown_router(client): 'bundle': [], 'bundle_members': [] }, - 'locations': [{ - 'a': { - 'equipment': 'unknown-router', - 'name': '?', - 'abbreviation': '?'} - }] + 'locations': [] } -- GitLab