diff --git a/inventory_provider/juniper.py b/inventory_provider/juniper.py index ebb015ddd70b45c9b58b00368542f19fcca98f71..7645ed5a3df9e9ce7fa5bc1712d656d24a1412dc 100644 --- a/inventory_provider/juniper.py +++ b/inventory_provider/juniper.py @@ -112,6 +112,7 @@ def _rpc(hostname, ssh): def validate_netconf_config(config_doc): juniper_logger = logging.getLogger(JUNIPER_LOGGER_NAME) + def _validate(schema, doc): if schema.validate(doc): return @@ -131,6 +132,7 @@ def validate_netconf_config(config_doc): for u in i.xpath('./unit'): _validate(unit_schema, u) + def load_config(hostname, ssh_params): """ loads netconf data from the router, validates and diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index 4d5f896a8eef2bd0df29761312f701e39206c62f..62124e1643d2e84c922c4a6369f4f3ab9c8fd397 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -1,7 +1,6 @@ import json from flask import Blueprint, Response, current_app, jsonify -import jsonschema from inventory_provider.routes import common @@ -38,8 +37,6 @@ def juniper_addresses(): methods=['GET', 'POST']) @common.require_accepts_json def get_trap_metadata(source_equipment, interface): - # todo - Move this to config - interface_info_key = "interface_services" r = common.get_redis() # todo - Change this to a call to the yet-to-be-created one source of all diff --git a/inventory_provider/routes/default.py b/inventory_provider/routes/default.py index 38bf3ea3b25e9ff2fccf568d512a2d5aad23b823..fd480bac9c3f76db58d4cc5e854bc9459d343c80 100644 --- a/inventory_provider/routes/default.py +++ b/inventory_provider/routes/default.py @@ -1,4 +1,3 @@ -import json import pkg_resources from flask import Blueprint, jsonify diff --git a/inventory_provider/routes/opsdb.py b/inventory_provider/routes/opsdb.py index 8543c25dc17c30c0522a0d7f76e63ac43b252c89..4b7fba38a3ea89d7b03933ded6f5b145dab978c9 100644 --- a/inventory_provider/routes/opsdb.py +++ b/inventory_provider/routes/opsdb.py @@ -2,7 +2,7 @@ import collections import json import re -from flask import Blueprint, Response, jsonify +from flask import Blueprint, jsonify from inventory_provider.routes import common routes = Blueprint("inventory-opsdb-query-routes", __name__) diff --git a/inventory_provider/tasks/common.py b/inventory_provider/tasks/common.py index 6868ffa33e95752119070b0f00eea74be13e04a9..342408350aaa5a0310f2f961648712e6af9fc958 100644 --- a/inventory_provider/tasks/common.py +++ b/inventory_provider/tasks/common.py @@ -5,4 +5,3 @@ def get_redis(config): return redis.StrictRedis( host=config['redis']['hostname'], port=config['redis']['port']) - diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 8b9ebd6dbad7841889d1abed77cad5a09c8fd3f9..54c26e587bb8afae7571dc40986e6241d6690d2e 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -16,10 +16,10 @@ from inventory_provider.db import db, opsdb, alarmsdb from inventory_provider import snmp from inventory_provider import juniper +# TODO: error callback (cf. http://docs.celeryproject.org/en/latest/userguide/calling.html#linking-callbacks-errbacks) # noqa: E501 environment.setup_logging() -# TODO: error callback (cf. http://docs.celeryproject.org/en/latest/userguide/calling.html#linking-callbacks-errbacks) class InventoryTask(Task): @@ -201,12 +201,12 @@ def update_circuit_hierarchy(): @app.task() def update_interface_statuses(): with db.connection(InventoryTask.config["ops-db"]) as cx: - services = opsdb.get_circuits(cx) + services = opsdb.get_circuits(cx) with db.connection(InventoryTask.config["alarms-db"]) as cx: with db.cursor(cx) as csr: for service in services: key = 'alarmsdb:interface_status:%s:%s' \ - % (service['equipment'], service['interface_name']) + % (service['equipment'], service['interface_name']) status = alarmsdb.get_last_known_interface_status( csr, service["equipment"], diff --git a/test/conftest.py b/test/conftest.py index d48a042a1a5ff9a0608dcba7611e67fcc8912bf3..52fa1af377207a4546aa9d853ecb58ef505d239f 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -85,6 +85,7 @@ TEST_DATA_DIRNAME = os.path.realpath(os.path.join( "test", "data")) + class MockedRedis(object): db = None @@ -109,7 +110,7 @@ class MockedRedis(object): def keys(self, glob=None): if not glob: return list([k.encode("utf-8") for k in MockedRedis.db.keys()]) - m = re.match('^([^\*]+)\*$', glob) + m = re.match(r'^([^*]+)\*$', glob) assert m # all expected global are like this return list([ k.encode("utf-8") for k in MockedRedis.db.keys() diff --git a/test/test_external_inventory_routes.py b/test/test_external_inventory_routes.py index 5087bac3724eab3266e20231e018e6a81c4801cd..ba7d61497b3abf6fd644be545bc07578cce92699 100644 --- a/test/test_external_inventory_routes.py +++ b/test/test_external_inventory_routes.py @@ -1,8 +1,3 @@ -import json -import os - -import inventory_provider -from inventory_provider.tasks import worker DEFAULT_REQUEST_HEADERS = { "Content-type": "application/json", @@ -10,36 +5,6 @@ DEFAULT_REQUEST_HEADERS = { } - -# def test_get_one_equipment_location(mocker, client): -# mocked_redis = mocker.patch( -# "inventory_provider.routes.common.get_redis") -# mocked_hget = mocked_redis.return_value.hget -# dummy_data = { -# "absid": 1404, -# "equipment_name": "pp-cz-e13b", -# "pop_name": "Prague", -# "pop_abbreviation": "pra", -# "pop_site_id": "", -# "country": "Czech Republic", -# "longitude": 14.391738888889, -# "latitude": 50.101847222222 -# } -# mocked_hget.return_value = json.dumps(dummy_data) -# -# rv = client.get( -# '/opsdb/equipment-location/dummy-equipment', -# headers=DEFAULT_REQUEST_HEADERS) -# assert rv.status_code == 200 -# assert rv.is_json -# assert dummy_data == json.loads(rv.data.decode("utf-8")) -# -# mocked_hget.assert_called_with( -# worker.equipment_locations_key, -# "dummy-equipment" -# ) - - def test_get_equipment_location(client_with_mocked_data): rv = client_with_mocked_data.get( '/opsdb/equipment-location', @@ -67,7 +32,8 @@ def test_get_interface_info_for_equipment(client_with_mocked_data): # TODO: validate against schema -def test_get_interface_info_for_equipment_and_interface(client_with_mocked_data): +def test_get_interface_info_for_equipment_and_interface( + client_with_mocked_data): rv = client_with_mocked_data.get( '/opsdb/interfaces/mx1.ams.nl.geant.net/ae0.0', headers=DEFAULT_REQUEST_HEADERS)