diff --git a/changelog b/changelog index de0f2f802115f5f2053358bfed2372cc344870c7..dd8c210b48676a8c2be9f422e4fa48634dda56cd 100644 --- a/changelog +++ b/changelog @@ -36,3 +36,4 @@ added top-level services to responses 0.20: included both v4 & v6 addresses in peering info 0.21: added parsing of 'logical-systems' (DBOARD3-150) +0.22: return a skeleton response for unknown interfaces (DBOARD3-169) diff --git a/inventory_provider/db/opsdb.py b/inventory_provider/db/opsdb.py index a8a094c591fe2242b8325b9ee5c230cf7d316cd2..548cadc6e70d6ca8961b85be8f818758f4baf499 100644 --- a/inventory_provider/db/opsdb.py +++ b/inventory_provider/db/opsdb.py @@ -132,7 +132,8 @@ retrieve_services_query = """SELECT * WHERE equipment IS NOT NULL AND equipment != '' - AND circuit_type IN ('path', 'service', 'l2circuit') + AND circuit_type IN ( + 'path', 'service', 'l2circuit', 'link-aggr-group') ORDER BY name, FIELD(status, @@ -165,6 +166,25 @@ def _infinera_field_update(record): record["interface_name"] += "-" + record["port"] record["interface_name"] = record["interface_name"] \ .replace("--", "-").upper() + + # + + equipment_parts = record["other_end_equipment"].rsplit("-", 1) + card_parts = record["other_end_card_id"].split("-", 1) + record["other_end_interface_name"] = "" + record["other_end_equipment"] = equipment_parts[0] + try: + record["other_end_interface_name"] = equipment_parts[1] + "-" + except IndexError: + pass # Nothing to see here + try: + record["other_end_interface_name"] += card_parts[1] + except IndexError: + record["other_end_interface_name"] += card_parts[0] + if record["other_end_port"] is not None and record["other_end_port"] != "": + record["other_end_interface_name"] += "-" + record["other_end_port"] + record["other_end_interface_name"] = record["other_end_interface_name"] \ + .replace("--", "-").upper() return record @@ -176,6 +196,20 @@ def _juniper_field_update(record): record["interface_name"] += separator + str(record["port"]) if record["logical_unit"] is not None and record["logical_unit"] != "": record["interface_name"] += "." + str(record["logical_unit"]) + + if not record["other_end_interface_name"]: + record["other_end_interface_name"] = record["other_end_card_id"] + if record["other_end_port"] is not None \ + and record["other_end_port"] != "": + separator = "" + if "-" in record["other_end_interface_name"]: + separator = "/" + record["other_end_interface_name"] += \ + separator + str(record["other_end_port"]) + if record["other_end_logical_unit"] is not None \ + and record["other_end_logical_unit"] != "": + record["other_end_interface_name"] += \ + "." + str(record["other_end_logical_unit"]) return record diff --git a/inventory_provider/juniper.py b/inventory_provider/juniper.py index 2925b7075cc6055e1c21b81e8429a2fa47030450..d7eca477fb5ecf567c1dc4121e928c9d878ebb1f 100644 --- a/inventory_provider/juniper.py +++ b/inventory_provider/juniper.py @@ -209,6 +209,8 @@ def list_interfaces(netconf_config): """ def _ifc_info(e): + # warning: this structure should match the default + # returned from routes.classifier.juniper_link_info name = e.find('name') assert name is not None, "expected interface 'name' child element" ifc = { diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index c8c36c5e0b17750dad8aaf38bea368b78f9fdefc..c29d2d8ed8c239d92e5e10c9e5de031d18e65dd9 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -107,6 +107,16 @@ def get_juniper_link_info(source_equipment, interface): 'netconf-interfaces:%s:%s' % (source_equipment, interface)) if ifc_info: result['interface'] = json.loads(ifc_info.decode('utf-8')) + else: + # warning: this should match the structure returned by + # juniper:list_interfaces:_ifc_info + result['interface'] = { + 'name': interface, + 'description': '', + 'bundle': [], + 'ipv4': [], + 'ipv6': [] + } def _related_services(): for related in related_interfaces(source_equipment, interface): @@ -123,12 +133,14 @@ def get_juniper_link_info(source_equipment, interface): related_services.extend(top_level_services) result['related-services'] = related_services - if not result: - return Response( - response="no available info for {} {}".format( - source_equipment, interface), - status=404, - mimetype="text/html") + # no longer possible, now that at least 'interface' is + # returned for unknown interfaces + # if not result: + # return Response( + # response="no available info for {} {}".format( + # source_equipment, interface), + # status=404, + # mimetype="text/html") result = json.dumps(result) # cache this data for the next call diff --git a/setup.py b/setup.py index cc5dcd9d6d7b5b2c79f73cda39f1e7b37c843be8..2ef16d74521bd373a69600c23a177cda06855b3e 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name='inventory-provider', - version="0.21", + version="0.22", author='GEANT', author_email='swd@geant.org', description='Dashboard inventory provider', diff --git a/test/test_opsdb.py b/test/test_opsdb.py index 2b0a299b3ebccff745cbe2108745711e01711d13..f86eb67204a9d4e55d1087cf0832b5eb34c0abb7 100644 --- a/test/test_opsdb.py +++ b/test/test_opsdb.py @@ -25,80 +25,124 @@ def test_infinera_field_update(): i = { "equipment": "AMS01-DTNX10-1-1", "card_id": "tim-b-5-7", - "port": "1" + "port": "1", + "other_end_equipment": "LON01-DTNX10-1-1", + "other_end_card_id": "tim-b-5-8", + "other_end_port": "2" } r = inventory_provider.db.opsdb._infinera_field_update(i) assert r["equipment"] == "AMS01-DTNX10-1" assert r["interface_name"] == "1-B-5-7-1" + assert r["other_end_equipment"] == "LON01-DTNX10-1" + assert r["other_end_interface_name"] == "1-B-5-8-2" i = { "equipment": "BUD01_CX_01", "card_id": "tim-1/2", - "port": "1" + "port": "1", + "other_end_equipment": "LON01_CX_01", + "other_end_card_id": "tim-2/3", + "other_end_port": "4" } r = inventory_provider.db.opsdb._infinera_field_update(i) assert r["equipment"] == "BUD01_CX_01" assert r["interface_name"] == "1/2-1" + assert r["other_end_equipment"] == "LON01_CX_01" + assert r["other_end_interface_name"] == "2/3-4" i = { "equipment": "irrelevant", "card_id": "tim_1/2", - "port": "1" + "port": "1", + "other_end_equipment": "irrelevant", + "other_end_card_id": "tim_2/3", + "other_end_port": "4" } r = inventory_provider.db.opsdb._infinera_field_update(i) assert r["interface_name"] == "TIM_1/2-1" + assert r["other_end_interface_name"] == "TIM_2/3-4" def test_juniper_field_update(): i = { "interface_name": "xe-1/2", - "logical_unit": None + "logical_unit": None, + "other_end_interface_name": "xe-3/2", + "other_end_logical_unit": None } r = inventory_provider.db.opsdb._juniper_field_update(i) assert r["interface_name"] == "xe-1/2" + assert r["other_end_interface_name"] == "xe-3/2" i["interface_name"] = "xe-1/2" i["logical_unit"] = 101 + i["other_end_interface_name"] = "xe-3/2" + i["other_end_logical_unit"] = 301 r = inventory_provider.db.opsdb._juniper_field_update(i) assert r["interface_name"] == "xe-1/2.101" + assert r["other_end_interface_name"] == "xe-3/2.301" i["interface_name"] = "xe-1/2" i["logical_unit"] = 0 + i["other_end_interface_name"] = "xe-3/2" + i["other_end_logical_unit"] = 0 r = inventory_provider.db.opsdb._juniper_field_update(i) assert r["interface_name"] == "xe-1/2.0" + assert r["other_end_interface_name"] == "xe-3/2.0" i["interface_name"] = "xe-1/2" i["logical_unit"] = None i["port"] = 0 + i["other_end_interface_name"] = "xe-3/2" + i["other_end_logical_unit"] = None + i["other_end_port"] = 0 r = inventory_provider.db.opsdb._juniper_field_update(i) assert r["interface_name"] == "xe-1/2" + assert r["other_end_interface_name"] == "xe-3/2" i["interface_name"] = None i["card_id"] = "xe-2/0" i["logical_unit"] = None i["port"] = None + i["other_end_interface_name"] = None + i["other_end_card_id"] = "xe-3/0" + i["other_end_logical_unit"] = None + i["other_end_port"] = None r = inventory_provider.db.opsdb._juniper_field_update(i) assert r["interface_name"] == "xe-2/0" + assert r["other_end_interface_name"] == "xe-3/0" i["interface_name"] = None i["port"] = "0" + i["other_end_interface_name"] = None + i["other_end_port"] = "0" r = inventory_provider.db.opsdb._juniper_field_update(i) assert r["interface_name"] == "xe-2/0/0" + assert r["other_end_interface_name"] == "xe-3/0/0" i["interface_name"] = None i["port"] = 0 + i["other_end_interface_name"] = None + i["other_end_port"] = 0 r = inventory_provider.db.opsdb._juniper_field_update(i) assert r["interface_name"] == "xe-2/0/0" + assert r["other_end_interface_name"] == "xe-3/0/0" i["interface_name"] = None i["logical_unit"] = "123" + i["other_end_interface_name"] = None + i["other_end_logical_unit"] = "323" r = inventory_provider.db.opsdb._juniper_field_update(i) assert r["interface_name"] == "xe-2/0/0.123" + assert r["other_end_interface_name"] == "xe-3/0/0.323" i["interface_name"] = None i["logical_unit"] = 123 + i["other_end_interface_name"] = None + i["other_end_logical_unit"] = 323 r = inventory_provider.db.opsdb._juniper_field_update(i) assert r["interface_name"] == "xe-2/0/0.123" + assert r["other_end_interface_name"] == "xe-3/0/0.323" def test_coriant_update_fields():