Skip to content
Snippets Groups Projects
Commit 01d40f1e authored by Robert Latta's avatar Robert Latta
Browse files

added interfaces endpoint and test

parent 68603522
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,13 @@ NODES_LIST_SCHEMA = {
"additionalProperties": False
}
INTERFACES_LIST_SCHEMA = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"items": {"type": "string"},
"additionalProperties": False
}
@routes.route('/sites')
def get_sites():
......@@ -80,3 +87,21 @@ def get_nodes(site):
r.set(cache_key, result)
result = result.decode('utf-8')
return Response(result, mimetype='application/json')
@routes.route('/interfaces/<node>')
def get_interfaces(node):
cache_key = f'classifier-cache:mic:interfaces:{node}'
r = common.get_current_redis()
result = _ignore_cache_or_retrieve(request, cache_key, r)
if not result:
def _get_intefaces():
key_pattern = f"ims:interface_services:{node}:*"
for k in r.scan_iter(key_pattern, count=1000):
yield ":".join(k.decode('utf-8').split(':')[3:])
interfaces_ = sorted(_get_intefaces())
if interfaces_:
result = json.dumps(interfaces_)
r.set(cache_key, result.encode('utf-8'))
return Response(result, mimetype='application/json')
......@@ -2,7 +2,8 @@ import json
import jsonschema
from inventory_provider.routes.mic import SITES_LIST_SCHEMA, NODES_LIST_SCHEMA
from inventory_provider.routes.mic import SITES_LIST_SCHEMA, \
NODES_LIST_SCHEMA, INTERFACES_LIST_SCHEMA
DEFAULT_REQUEST_HEADERS = {
"Content-type": "application/json",
......@@ -28,3 +29,13 @@ def test_get_nodes(client, mocked_redis):
assert rv.is_json
response_data = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(response_data, NODES_LIST_SCHEMA)
def test_get_interfaces(client, mocked_redis):
rv = client.get(
'/mic/interfaces/MX1.LON.UK',
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, INTERFACES_LIST_SCHEMA)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment