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

made locations schema stricter, and added a unit test

parent 59b04681
No related branches found
No related tags found
No related merge requests found
...@@ -39,11 +39,23 @@ def _location_from_router(router_name): ...@@ -39,11 +39,23 @@ def _location_from_router(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 None return None
# 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 None
# return {
# 'a': _LOCATION(
# equipment=router_name,
# name='?',
# abbreviation='?')
# }
return { return {
'a': _LOCATION( 'a': _LOCATION(
......
...@@ -30,7 +30,8 @@ LOCATIONS_DEFINITIONS = { ...@@ -30,7 +30,8 @@ LOCATIONS_DEFINITIONS = {
}, },
"locations-list": { "locations-list": {
"type": "array", "type": "array",
"items": {"$ref": "#/definitions/location"} "items": {"$ref": "#/definitions/location"},
"minitems": 1
} }
} }
...@@ -174,7 +175,7 @@ JUNIPER_LINK_METADATA = { ...@@ -174,7 +175,7 @@ JUNIPER_LINK_METADATA = {
}, },
"locations": {"$ref": "#/definitions/locations-list"} "locations": {"$ref": "#/definitions/locations-list"}
}, },
# "required": ["interface"], "required": ["interface", "locations"],
"additionalProperties": False "additionalProperties": False
} }
...@@ -216,6 +217,33 @@ def test_juniper_link_info_not_found(client): ...@@ -216,6 +217,33 @@ 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': [{
'a': {
'equipment': 'unknown-router',
'name': '?',
'abbreviation': '?'}
}]
}
VPN_RR_PEER_INFO_KEYS = {'vpn-rr-peer-info', 'locations'} VPN_RR_PEER_INFO_KEYS = {'vpn-rr-peer-info', 'locations'}
IX_PUBLIC_PEER_INFO_KEYS = {'ix-public-peer-info', 'interfaces', '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