From 27d370ccdc2fa78cfcf4af9bce707fa3dbd84098 Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Sun, 3 Feb 2019 21:12:21 +0100 Subject: [PATCH] use common.get_redis to create connection --- inventory_provider/routes/data.py | 25 +++++-------------------- test/test_external_inventory_routes.py | 2 +- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/inventory_provider/routes/data.py b/inventory_provider/routes/data.py index ec40db53..066e9494 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 ba7d6149..94687251 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) -- GitLab