Skip to content
Snippets Groups Projects
Commit 4e6b64da authored by Erik Reid's avatar Erik Reid
Browse files

pep8

parent 56c91490
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
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
......
import json
import pkg_resources
from flask import Blueprint, jsonify
......
......@@ -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__)
......
......@@ -5,4 +5,3 @@ def get_redis(config):
return redis.StrictRedis(
host=config['redis']['hostname'],
port=config['redis']['port'])
......@@ -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"],
......
......@@ -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()
......
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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment