diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index 5e6f2c9d906a95975af360e4d0fb155884070ea8..6a604491242dd778ef6a72c456d1654c1cf016ed 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -238,10 +238,11 @@ def peer_info(address): return Response(result, mimetype="application/json") -@routes.route("/infinera-lambda-info/<source_equipment>/<path:interface>", +@routes.route("/infinera-lambda-info/" + "<source_equipment>/<interface>/<circuit_id>", methods=['GET', 'POST']) @common.require_accepts_json -def get_trap_metadata(source_equipment, interface): +def get_trap_metadata(source_equipment, interface, circuit_id): r = common.get_redis() cache_key = 'classifier-cache:infinera:%s:%s' % ( @@ -257,16 +258,12 @@ def get_trap_metadata(source_equipment, interface): 'opsdb:interface_services:%s:%s' % (source_equipment, interface)) if services: result['services'] = json.loads(services.decode('utf=8')) - geant_lambdas = [] - for s in result['services']: - gl = r.get('opsdb:geant_lambdas:%s' % s['name']) - if gl: - t_gl = json.loads(gl.decode('utf=8')) - t_gl['status'] = t_gl['status'].lower() - geant_lambdas.append(t_gl) - - if geant_lambdas: - result['geant-lambdas'] = geant_lambdas + + gl = r.get('opsdb:geant_lambdas:%s' % circuit_id.lower()) + if gl: + t_gl = json.loads(gl.decode('utf=8')) + t_gl['status'] = t_gl['status'].lower() + result['geant-lambda'] = t_gl if not result: return Response( diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 5a7a424c5fcb86431e0cd5fe5970ee4ba04bcd22..7a187b4f61fef3b15f6fb0e7f6163e32443d4c6d 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -210,7 +210,8 @@ def update_geant_lambdas(): r.delete(key) with db.connection(InventoryTask.config["ops-db"]) as cx: for ld in opsdb.get_geant_lambdas(cx): - r.set('opsdb:geant_lambdas:%s' % ld['name'], json.dumps(ld)) + r.set('opsdb:geant_lambdas:%s' % ld['name'].lower(), + json.dumps(ld)) logger.debug('<<< geant_lambdas') diff --git a/test/test_infinera_classifier.py b/test/test_infinera_classifier.py index 0cd26f2cbadbb5fbd3481d447b4be917690eccab..58fc24a5077459f9b2d4d8b17a1ec06ac845be92 100644 --- a/test/test_infinera_classifier.py +++ b/test/test_infinera_classifier.py @@ -61,7 +61,7 @@ INFINERA_LINK_METADATA = { }, "additionalProperties": False }, - "geant-lambdas": { + "geant-lambda": { "type": "object", "properties": { "id": {"type": "integer"}, @@ -81,8 +81,8 @@ INFINERA_LINK_METADATA = { "type": "array", "items": {"$ref": "#/definitions/service-info"} }, - "geant-lambdas": { - "type": "array", + "geant-lambda": { + "type": "object", "items": {"$ref": "#/definitions/geant-lambdas"} }, }, @@ -92,7 +92,8 @@ INFINERA_LINK_METADATA = { def test_trap_metadata(client_with_mocked_data): rv = client_with_mocked_data.get( - '/classifier/infinera-lambda-info/LON01-DTNX10-1/1-B-2-1-3', + '/classifier/infinera-lambda-info/' + 'LON2-DTNX10-1/1-A-2-1-4/gen-lon3_LHC_CERN-JANET_09013', headers=DEFAULT_REQUEST_HEADERS) assert rv.status_code == 200 assert rv.is_json