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

Finished feature DBOARD-328-handle-unknown-router.

parents 59b04681 a0d2b219
No related branches found
No related tags found
No related merge requests found
......@@ -33,24 +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 None
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 []
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):
......@@ -206,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)
......@@ -340,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:
......
......@@ -174,7 +174,7 @@ JUNIPER_LINK_METADATA = {
},
"locations": {"$ref": "#/definitions/locations-list"}
},
# "required": ["interface"],
"required": ["interface", "locations"],
"additionalProperties": False
}
......@@ -216,6 +216,28 @@ def test_juniper_link_info_not_found(client):
}
def test_juniper_link_unknown_router(client):
rv = client.get(
'/classifier/juniper-link-info/'
'unknown-router/unknown-interface-name',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
response_data = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(response_data, JUNIPER_LINK_METADATA)
assert response_data == {
'interface': {
'name': 'unknown-interface-name',
'description': '',
'ipv4': [],
'ipv6': [],
'bundle': [],
'bundle_members': []
},
'locations': []
}
VPN_RR_PEER_INFO_KEYS = {'vpn-rr-peer-info', 'locations'}
IX_PUBLIC_PEER_INFO_KEYS = {'ix-public-peer-info', 'interfaces', '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