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

don't return dummy location for unknown routers

parent 4d51292f
No related branches found
No related tags found
No related merge requests found
...@@ -33,35 +33,24 @@ def _remove_duplicates_from_list(all): ...@@ -33,35 +33,24 @@ def _remove_duplicates_from_list(all):
return list(tmp_dict.values()) return list(tmp_dict.values())
def _location_from_router(router_name): def _locations_from_router(router_name):
r = common.get_current_redis() r = common.get_current_redis()
result = r.get(f'opsdb:location:{router_name}') result = r.get(f'opsdb:location:{router_name}')
if not result: if not result:
logger.error(f'error looking up location for {router_name}') logger.error(f'error looking up location for {router_name}')
return { return []
'a': _LOCATION(
equipment=router_name,
name='?',
abbreviation='?')
}
result = json.loads(result.decode('utf-8')) result = json.loads(result.decode('utf-8'))
if not result: if not result:
logger.error(f'sanity failure: empty list for location {router_name}') logger.error(f'sanity failure: empty list for location {router_name}')
return None return []
return {
'a': _LOCATION(
equipment=router_name,
name='?',
abbreviation='?')
}
return { return [{
'a': _LOCATION( 'a': _LOCATION(
equipment=result[0]['equipment-name'], equipment=result[0]['equipment-name'],
name=result[0]['pop']['name'], name=result[0]['pop']['name'],
abbreviation=result[0]['pop']['abbreviation']) abbreviation=result[0]['pop']['abbreviation'])
} }]
def _location_from_service_dict(s): def _location_from_service_dict(s):
...@@ -217,7 +206,7 @@ def get_juniper_link_info(source_equipment, interface): ...@@ -217,7 +206,7 @@ def get_juniper_link_info(source_equipment, interface):
result['related-services'] = top_level_services result['related-services'] = top_level_services
if not result['locations']: 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['locations'] = _remove_duplicates_from_list(result['locations'])
result = json.dumps(result) result = json.dumps(result)
...@@ -351,16 +340,14 @@ def peer_info(address): ...@@ -351,16 +340,14 @@ def peer_info(address):
info = info.decode('utf-8') info = info.decode('utf-8')
info = json.loads(info) info = json.loads(info)
result['ix-public-peer-info'] = ix_peering_info(info) result['ix-public-peer-info'] = ix_peering_info(info)
router_location = _location_from_router(info['router']) result['locations'] += _locations_from_router(info['router'])
result['locations'] += [router_location]
info = r.get('vpn_rr_peer:%s' % address) info = r.get('vpn_rr_peer:%s' % address)
if info: if info:
info = info.decode('utf-8') info = info.decode('utf-8')
info = json.loads(info) info = json.loads(info)
result['vpn-rr-peer-info'] = info result['vpn-rr-peer-info'] = info
router_location = _location_from_router(info['router']) result['locations'] += _locations_from_router(info['router'])
result['locations'] += [router_location]
interfaces = list(find_interfaces_and_services(address)) interfaces = list(find_interfaces_and_services(address))
if interfaces: if interfaces:
......
...@@ -30,8 +30,7 @@ LOCATIONS_DEFINITIONS = { ...@@ -30,8 +30,7 @@ LOCATIONS_DEFINITIONS = {
}, },
"locations-list": { "locations-list": {
"type": "array", "type": "array",
"items": {"$ref": "#/definitions/location"}, "items": {"$ref": "#/definitions/location"}
"minitems": 1
} }
} }
...@@ -235,12 +234,7 @@ def test_juniper_link_unknown_router(client): ...@@ -235,12 +234,7 @@ def test_juniper_link_unknown_router(client):
'bundle': [], 'bundle': [],
'bundle_members': [] 'bundle_members': []
}, },
'locations': [{ 'locations': []
'a': {
'equipment': 'unknown-router',
'name': '?',
'abbreviation': '?'}
}]
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment