diff --git a/inventory_provider/routes/data.py b/inventory_provider/routes/data.py index ec40db5300aa6c8c75848c971a8822aeeba1ee6e..066e9494c84a10a66cc0e7a3770aad2ed789cc9e 100644 --- a/inventory_provider/routes/data.py +++ b/inventory_provider/routes/data.py @@ -1,9 +1,8 @@ import json import re -from flask import Blueprint, jsonify, Response, current_app +from flask import Blueprint, jsonify, Response from lxml import etree -import redis from inventory_provider import juniper from inventory_provider.routes import common @@ -14,10 +13,7 @@ routes = Blueprint("inventory-data-query-routes", __name__) @routes.route("/routers", methods=['GET', 'POST']) @common.require_accepts_json def routers(): - redis_config = current_app.config["INVENTORY_PROVIDER_CONFIG"]["redis"] - r = redis.StrictRedis( - host=redis_config["hostname"], - port=redis_config["port"]) + r = common.get_redis() result = [] for k in r.keys('netconf:*'): m = re.match('^netconf:(.+)$', k.decode('utf-8')) @@ -29,11 +25,7 @@ def routers(): @routes.route("/interfaces/<hostname>", methods=['GET', 'POST']) @common.require_accepts_json def router_interfaces(hostname): - redis_config = current_app.config["INVENTORY_PROVIDER_CONFIG"]["redis"] - r = redis.StrictRedis( - host=redis_config["hostname"], - port=redis_config["port"]) - + r = common.get_redis() netconf_string = r.get('netconf:' + hostname) if not netconf_string: return Response( @@ -55,10 +47,7 @@ def router_interfaces(hostname): @routes.route("/snmp/<hostname>", methods=['GET', 'POST']) @common.require_accepts_json def snmp_ids(hostname): - redis_config = current_app.config["INVENTORY_PROVIDER_CONFIG"]["redis"] - r = redis.StrictRedis( - host=redis_config["hostname"], - port=redis_config["port"]) + r = common.get_redis() ifc_data_string = r.get('snmp-interfaces:' + hostname) if not ifc_data_string: return Response( @@ -83,11 +72,7 @@ def snmp_ids(hostname): @routes.route("/bgp/<hostname>", methods=['GET', 'POST']) @common.require_accepts_json def bgp_configs(hostname): - redis_config = current_app.config["INVENTORY_PROVIDER_CONFIG"]["redis"] - r = redis.StrictRedis( - host=redis_config["hostname"], - port=redis_config["port"]) - + r = common.get_redis() netconf_string = r.get('netconf:' + hostname) if not netconf_string: return Response( diff --git a/test/test_external_inventory_routes.py b/test/test_external_inventory_routes.py index ba7d61497b3abf6fd644be545bc07578cce92699..94687251b8fc35075d8a8763a47d9cd69bc4dc87 100644 --- a/test/test_external_inventory_routes.py +++ b/test/test_external_inventory_routes.py @@ -33,7 +33,7 @@ def test_get_interface_info_for_equipment(client_with_mocked_data): def test_get_interface_info_for_equipment_and_interface( - client_with_mocked_data): + client_with_mocked_data): rv = client_with_mocked_data.get( '/opsdb/interfaces/mx1.ams.nl.geant.net/ae0.0', headers=DEFAULT_REQUEST_HEADERS)