From 7aaaf5577e21b79b84c32d0e8789be55e3be25f6 Mon Sep 17 00:00:00 2001 From: Robert Latta <robert.latta@geant.org> Date: Tue, 4 May 2021 15:14:56 +0000 Subject: [PATCH] added MTC endpoint implementation --- inventory_provider/routes/classifier.py | 72 +++++++------------ .../routes/classifier_schema.py | 2 +- test/test_classifier_routes.py | 6 +- 3 files changed, 29 insertions(+), 51 deletions(-) diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index e9d09c59..d5a558e1 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -578,53 +578,31 @@ def get_mtc_interface_info(node, interface): :param element: :return: element info """ - dummy_response = { - "contacts": [ - "NOC-RENATER@NOC.RENATER.FR", - "NOC@GEANT.ORG", - "NOC@RESTENA.LU", - "OC@GEANT.ORG", - "SUPPORT@OC.GEANT.NET" - ], - "locations": [ - { - "a": { - "abbreviation": "LON", - "equipment": node, - "name": "LONDON" - } - } - ], - "related-services": [ - { - "circuit_type": "service", - "name": "RENATER_AP2_CLS", - "project": "RENATER", - "status": "operational" - } - ], - "services": [ - { - "card_id": "", - "circuit_type": "circuit", - "equipment": node, - "id": 669120, - "logical_unit": "", - "name": "AMS-LON_EEX_ESNET_1424", - "other_end_equipment": "", - "other_end_pop_abbreviation": "", - "other_end_pop_name": "", - "other_end_port": "", - "pop_abbreviation": "LON", - "pop_name": "LONDON", - "port": interface, - "project": "RENATER", - "service_type": "ETHERNET", - "status": "operational" - } - ] - } - return Response(json.dumps(dummy_response), mimetype='application/json') + + r = common.get_current_redis() + interface = interface.rsplit('-', 1)[0] + + # ims_source_equipment = get_ims_equipment_name(equipment_name, r) + # ims_interface = get_ims_interface(entity_string) + + cache_key = f'classifier-cache:mtc:{node}:{interface}' + + result = _ignore_cache_or_retrieve(request, cache_key, r) + + if not result: + result = get_interface_services_and_loc(node, interface, r) + + if not result['locations'] and 'services' not in result: + result = {} + + if not result: + return Response( + response="no available info for " + f"{node} {interface}", + status=404, + mimetype="text/html") + + return Response(json.dumps(result), mimetype="application/json") @routes.route("/infinera-lambda-info/" diff --git a/inventory_provider/routes/classifier_schema.py b/inventory_provider/routes/classifier_schema.py index 660d0af8..8b5006bc 100644 --- a/inventory_provider/routes/classifier_schema.py +++ b/inventory_provider/routes/classifier_schema.py @@ -449,7 +449,7 @@ _infinera_lambda_response_schema_definitions = { }, "circuit_type": { "type": "string", - "enum": ["path", "service", "l2circuit"] + "enum": ["path", "service", "l2circuit", "circuit"] }, "service_type": {"type": "string"}, "project": {"type": "string"}, diff --git a/test/test_classifier_routes.py b/test/test_classifier_routes.py index 692b31cb..ac902211 100644 --- a/test/test_classifier_routes.py +++ b/test/test_classifier_routes.py @@ -5,7 +5,7 @@ import pytest from inventory_provider.routes.classifier_schema \ import JUNIPER_LINK_RESPONSE_SCHEMA, PEER_INFO_RESPONSE_SCHEMA, \ INFINERA_LAMBDA_INFO_RESPONSE_SCHEMA, CORIANT_INFO_RESPONSE_SCHEMA, \ - INFINERA_FIBERLINK_INFO_RESPONSE_SCHEMA + INFINERA_FIBERLINK_INFO_RESPONSE_SCHEMA, MTC_INTERFACE_INFO_RESPONSE_SCHEMA DEFAULT_REQUEST_HEADERS = { "Content-type": "application/json", @@ -147,14 +147,14 @@ def test_coriant_info_not_found(client): def test_mtc_info(client): rv = client.get( - '/classifier/mtc-interface-info/abc/def', + '/classifier/mtc-interface-info/MAD01-MTC6-1/1-A-1-S1-1', headers=DEFAULT_REQUEST_HEADERS) assert rv.status_code == 200 assert rv.is_json response_data = json.loads(rv.data.decode('utf-8')) assert response_data # schema seems wrong ... - # jsonschema.validate(response_data, MTC_INTERFACE_INFO_RESPONSE_SCHEMA) + jsonschema.validate(response_data, MTC_INTERFACE_INFO_RESPONSE_SCHEMA) def test_infinera_unparseable_fiberlink(client): -- GitLab