diff --git a/inventory_provider/db/opsdb.py b/inventory_provider/db/opsdb.py index 4153611308e0291723887fcbdfba3d04d6f14898..3074c856c3ee9ca3e4c54de769c653fe386c0869 100644 --- a/inventory_provider/db/opsdb.py +++ b/inventory_provider/db/opsdb.py @@ -336,7 +336,7 @@ WHERE def _row2rsp(row): print(row) return { - 'equipment-name': row['router_name'], + 'equipment name': row['router_name'], 'type': 'INTERNAL' if row['pop_name'] in INTERNAL_POP_NAMES else 'CORE', 'pop': { 'name': row['pop_name'], diff --git a/test/test_opsdb_queries.py b/test/test_opsdb_queries.py index a268ccb7d370ce0542381f0af8149d558d6d1ab6..dd45730ea25d9c6fd20f1d01221920dbd2efc119 100644 --- a/test/test_opsdb_queries.py +++ b/test/test_opsdb_queries.py @@ -144,6 +144,51 @@ CORIANT_PATH_METADATA = { "additionalProperties": False } +LG_ROUTERS_SCHEMA = { + "$schema": "http://json-schema.org/draft-07/schema#", + + "definitions": { + "pop-info": { + "type": "object", + "properties": { + "name": {"type": "string"}, + "abbreviation": {"type": "string"}, + "country": {"type": "string"}, + "country code": {"type": "string"}, + "city": {"type": "string"}, + "longitude": {"type": "number"}, + "latitude": {"type": "number"} + }, + "required": [ + "name", + "abbreviation", + "country", + "country code", + "city", + "longitude", + "latitude" + ], + "additionalProperties": False + }, + "router": { + "type": "object", + "properties": { + "equipment name": {"type": "string"}, + "type": { + "type": "string", + "enum": ["INTERNAL", "CORE"] + }, + "pop": {"$ref": "#/definitions/pop-info"} + }, + "required": ["equipment name", "type", "pop"], + "additionalProperties": False + } + }, + + "type": "array", + "items": {"$ref": "#/definitions/router"} +} + @pytest.mark.parametrize('equipment', [ 'mx1.cbg.uk.geant.net', @@ -227,3 +272,9 @@ def test_get_all_service_users(connection, cached_test_data): # services.setdefault(user['service_id'], []).append(user['user']) # # print([f'{k}: {v}' for k, v in services.items() if len(v) > 1]) + + +def test_lookup_lg_routers(connection, cached_test_data): + routers = list(opsdb.lookup_lg_routers(connection)) + jsonschema.validate(routers, LG_ROUTERS_SCHEMA) + assert routers # shouldn't be empty