diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index e9d09c597169a474466495db359fe96c42ec2d43..d5a558e1c1628328611c6853528bab9805625231 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 660d0af868b308dce1c92404a6101c9bf5f69d5c..8b5006bcaa6e162763c22f9739010bb85b886a24 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 692b31cbd66adfb3d340bfaa7a7adcd56be2a6fa..ac902211e9a8196c69671b9a6a1fb6891f576605 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):