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):
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:
......
......@@ -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': []
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment