From 31495a0626c106c3f2e2e1211c1b6f2dcba57cfc Mon Sep 17 00:00:00 2001 From: Robert Latta <robert.latta@geant.org> Date: Fri, 13 Sep 2024 15:06:08 +0100 Subject: [PATCH] added additional endpoint for Coriant RE. DBOARD3-1006 --- inventory_provider/routes/classifier.py | 46 +++++++++++++++++++++---- test/test_classifier_routes.py | 18 ++++++---- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index 61e6bdac..e4a81488 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -23,10 +23,15 @@ These endpoints are intended for use by Dashboard V3. .. autofunction:: inventory_provider.routes.classifier.get_fiberlink_trap_metadata -/classifier/coriant-info ------------------------- +/classifier/coriant-port-info +----------------------------- + +.. autofunction:: inventory_provider.routes.classifier.get_coriant_port_info + +/classifier/coriant-tp-info +--------------------------- -.. autofunction:: inventory_provider.routes.classifier.get_coriant_info +.. autofunction:: inventory_provider.routes.classifier.get_coriant_tp_info /classifier/mtc-interface-info @@ -985,8 +990,31 @@ def get_tnms_fibre_trap_metadata(enms_pc_name: str) -> Response: @routes.route('/coriant-info/<equipment_name>/<path:entity_string>', methods=['GET']) +@routes.route('/coriant-port-info/<equipment_name>/<path:entity_string>', + methods=['GET']) +@common.require_accepts_json +def get_coriant_port_info(equipment_name: str, entity_string: str) -> Response: + """ + Handler for /classifier/coriant-info that + returns metadata for a coriant path. + + The response will be formatted according to the following schema: + + .. asjson:: + inventory_provider.routes.classifier_schema.CORIANT_INFO_RESPONSE_SCHEMA + + :param equipment_name: grv hostname + :param entity_string: path name + :return: + """ + card_port_regex = r'^(\d+\-\d+)\.(\d+(\.\d+)*)' + return _get_coriant_info(equipment_name, entity_string, card_port_regex) + + +@routes.route('/coriant-tp-info/<equipment_name>/<path:entity_string>', + methods=['GET']) @common.require_accepts_json -def get_coriant_info(equipment_name: str, entity_string: str) -> Response: +def get_coriant_tp_info(equipment_name: str, entity_string: str) -> Response: """ Handler for /classifier/coriant-info that returns metadata for a coriant path. @@ -996,10 +1024,16 @@ def get_coriant_info(equipment_name: str, entity_string: str) -> Response: .. asjson:: inventory_provider.routes.classifier_schema.CORIANT_INFO_RESPONSE_SCHEMA - :param source_equipment: grv hostname + :param equipment_name: grv hostname :param entity_string: path name :return: """ + card_port_regex = r'^(\d+\-\d+)\.(\d+)' + return _get_coriant_info(equipment_name, entity_string, card_port_regex) + + +def _get_coriant_info( + equipment_name: str, entity_string: str, card_port_regex: str) -> Response: r = common.get_current_redis() @@ -1013,7 +1047,7 @@ def get_coriant_info(equipment_name: str, entity_string: str) -> Response: if not result: - m = re.match(r'^(\d+\-\d+)\.((\d+)(\.\d+)*)', ims_interface) + m = re.match(card_port_regex, ims_interface) if not m: logger.error( f'invalid coriant entity string format: {ims_interface}') diff --git a/test/test_classifier_routes.py b/test/test_classifier_routes.py index 93a12882..aee43eac 100644 --- a/test/test_classifier_routes.py +++ b/test/test_classifier_routes.py @@ -121,14 +121,20 @@ def test_peer_not_found(client): assert response_data == {'locations': [], "contacts": []} -@pytest.mark.parametrize('equipment,entity_name,expected_card_id,expected_port', [ - ('grv3.ams.nl.geant.net', '1-3.3.1-Optical-10GbE-TTP', '1/3', '3.1'), - ('bogus-hostname.with&special.char', - '234-2345234.7878i234crazynamewithslash/1-2.3', '234/2345234', '7878') +@pytest.mark.parametrize('equipment,entity_name,expected_card_id,expected_port,endpoint', [ + ('grv3.ams.nl.geant.net', '1-3.3.1-Optical-10GbE-TTP', + '1/3', '3.1', 'coriant-port-info'), + ('grv3.ams.nl.geant.net', '1-3.3.1-Optical-10GbE-TTP', + '1/3', '3.1', 'coriant-info'), + ('grv3.ams.nl.geant.net', '1-1.3.1-100GbE-ODU4-TTP', + '1/1', '3', 'coriant-tp-info'), + ('bogus-hostname.with&special.char', '234-2345234.7878i234crazynamewithslash/1-2.3', + '234/2345234', '7878', 'coriant-port-info') ]) -def test_coriant_info(client, equipment, entity_name, expected_card_id, expected_port): +def test_coriant_info( + client, equipment, entity_name, expected_card_id, expected_port, endpoint): rv = client.get( - f'/classifier/coriant-info/{equipment}/{entity_name}', + f'/classifier/{endpoint}/{equipment}/{entity_name}', headers=DEFAULT_REQUEST_HEADERS) assert rv.status_code == 200 assert rv.is_json -- GitLab