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

moved opsdb routes to testing/

parent d58c6b53
No related branches found
No related tags found
No related merge requests found
import json
from flask import Blueprint, Response, current_app, jsonify
from flask import Blueprint, Response
from inventory_provider.routes import common
......
......@@ -18,71 +18,3 @@ interface_status_key = "interface_statuses"
# return {k.decode('utf8'): json.loads(v) for k, v in d.items()}
#
#
@routes.route("/interfaces")
def get_all_interface_details():
r = common.get_redis()
result = collections.defaultdict(list)
for k in r.keys('opsdb:interface_services:*'):
m = re.match(
r'^opsdb:interface_services:([^:]+):(.*)$',
k.decode('utf-8'))
assert m
result[m.group(1)].append(m.group(2))
return jsonify(result)
@routes.route("/interfaces/<equipment_name>")
def get_interface_details_for_equipment(equipment_name):
r = common.get_redis()
result = []
for k in r.keys('opsdb:interface_services:%s:*' % equipment_name):
m = re.match(
r'^opsdb:interface_services:%s:(.*)$' % equipment_name,
k.decode('utf-8'))
assert m
result.append(m.group(1))
return jsonify(result)
@routes.route("/interfaces/<equipment_name>/<path:interface>")
def get_interface_details(equipment_name, interface):
r = common.get_redis()
key = 'opsdb:interface_services:%s:%s' % (equipment_name, interface)
# TODO: handle None (return 404)
return jsonify(json.loads(r.get(key).decode('utf-8')))
@routes.route("/equipment-location")
def get_all_equipment_locations():
r = common.get_redis()
result = {}
for k in r.keys('opsdb:location:*'):
k = k.decode('utf-8')
m = re.match(r'^opsdb:location:(.*)$', k)
assert m
result[m.group(1)] = json.loads(r.get(k).decode('utf-8'))
return jsonify(result)
@routes.route("/equipment-location/<path:equipment_name>")
def get_equipment_location(equipment_name):
r = common.get_redis()
result = r.get('opsdb:location:' + equipment_name)
# TODO: handle None (return 404)
return jsonify(json.loads(result.decode('utf-8')))
@routes.route("/circuit-hierarchy/children/<int:parent_id>")
def get_children(parent_id):
r = common.get_redis()
result = r.get('opsdb:services:children:%d' % parent_id)
# TODO: handle None (return 404)
return jsonify(json.loads(result.decode('utf-8')))
@routes.route("/circuit-hierarchy/parents/<int:child_id>")
def get_parents(child_id):
r = common.get_redis()
result = r.get('opsdb:services:parents:%d' % child_id)
# TODO: handle None (return 404)
return jsonify(json.loads(result.decode('utf-8')))
import collections
import json
import re
from flask import Blueprint, Response, current_app, jsonify
from inventory_provider.routes import common
......@@ -6,13 +8,13 @@ from inventory_provider.routes import common
routes = Blueprint("inventory-data-testing-support-routes", __name__)
@routes.route("/flushdb", methods=['GET', 'POST'])
@routes.route("flushdb", methods=['GET', 'POST'])
def flushdb():
common.get_redis().flushdb()
return Response('OK')
@routes.route("/infinera-dna-addresses", methods=['GET', 'POST'])
@routes.route("infinera-dna-addresses", methods=['GET', 'POST'])
@common.require_accepts_json
def infinera_addresses():
infinera_config = current_app.config[
......@@ -20,7 +22,7 @@ def infinera_addresses():
return jsonify([dna['address'] for dna in infinera_config])
@routes.route("/coriant-tnms-addresses", methods=['GET', 'POST'])
@routes.route("coriant-tnms-addresses", methods=['GET', 'POST'])
@common.require_accepts_json
def coriant_addresses():
coriant_config = current_app.config[
......@@ -28,7 +30,7 @@ def coriant_addresses():
return jsonify([tnms['address'] for tnms in coriant_config])
@routes.route("/juniper-server-addresses", methods=['GET', 'POST'])
@routes.route("juniper-server-addresses", methods=['GET', 'POST'])
@common.require_accepts_json
def juniper_addresses():
# TODO: this route (and corant, infinera routes) can be removed
......@@ -40,3 +42,73 @@ def juniper_addresses():
info = json.loads(info.decode('utf-8'))
routers.append(info['address'])
return jsonify(routers)
@routes.route("opsdb/interfaces")
def get_all_interface_details():
r = common.get_redis()
result = collections.defaultdict(list)
for k in r.keys('opsdb:interface_services:*'):
m = re.match(
r'^opsdb:interface_services:([^:]+):(.*)$',
k.decode('utf-8'))
assert m
result[m.group(1)].append(m.group(2))
return jsonify(result)
@routes.route("opsdb/interfaces/<equipment_name>")
def get_interface_details_for_equipment(equipment_name):
r = common.get_redis()
result = []
for k in r.keys('opsdb:interface_services:%s:*' % equipment_name):
m = re.match(
r'^opsdb:interface_services:%s:(.*)$' % equipment_name,
k.decode('utf-8'))
assert m
result.append(m.group(1))
return jsonify(result)
@routes.route("opsdb/interfaces/<equipment_name>/<path:interface>")
def get_interface_details(equipment_name, interface):
r = common.get_redis()
key = 'opsdb:interface_services:%s:%s' % (equipment_name, interface)
# TODO: handle None (return 404)
return jsonify(json.loads(r.get(key).decode('utf-8')))
@routes.route("opsdb/equipment-location")
def get_all_equipment_locations():
r = common.get_redis()
result = {}
for k in r.keys('opsdb:location:*'):
k = k.decode('utf-8')
m = re.match(r'^opsdb:location:(.*)$', k)
assert m
result[m.group(1)] = json.loads(r.get(k).decode('utf-8'))
return jsonify(result)
@routes.route("opsdb/equipment-location/<path:equipment_name>")
def get_equipment_location(equipment_name):
r = common.get_redis()
result = r.get('opsdb:location:' + equipment_name)
# TODO: handle None (return 404)
return jsonify(json.loads(result.decode('utf-8')))
@routes.route("opsdb/circuit-hierarchy/children/<int:parent_id>")
def get_children(parent_id):
r = common.get_redis()
result = r.get('opsdb:services:children:%d' % parent_id)
# TODO: handle None (return 404)
return jsonify(json.loads(result.decode('utf-8')))
@routes.route("opsdb/circuit-hierarchy/parents/<int:child_id>")
def get_parents(child_id):
r = common.get_redis()
result = r.get('opsdb:services:parents:%d' % child_id)
# TODO: handle None (return 404)
return jsonify(json.loads(result.decode('utf-8')))
......@@ -4,57 +4,3 @@ DEFAULT_REQUEST_HEADERS = {
"Accept": ["application/json"]
}
def test_get_equipment_location(client_with_mocked_data):
rv = client_with_mocked_data.get(
'/opsdb/equipment-location',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
# TODO: validate against schema
def test_get_interface_info(client_with_mocked_data):
rv = client_with_mocked_data.get(
'/opsdb/interfaces',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
# TODO: validate against schema
def test_get_interface_info_for_equipment(client_with_mocked_data):
rv = client_with_mocked_data.get(
'/opsdb/interfaces/mx1.ams.nl.geant.net',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
# TODO: validate against schema
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)
assert rv.status_code == 200
assert rv.is_json
# TODO: validate against schema
def test_get_children(client_with_mocked_data):
rv = client_with_mocked_data.get(
'/opsdb/circuit-hierarchy/children/12363',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
# TODO: validate against schema
def test_get_parents(client_with_mocked_data):
rv = client_with_mocked_data.get(
'/opsdb/circuit-hierarchy/parents/11725',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
# TODO: validate against schema
......@@ -38,7 +38,7 @@ def test_coriant_addresses(client):
ROUTER_LIST_SCHEMA)
def test_juniper_addresses(mocker, client):
def test_juniper_addresses(client):
rv = client.post(
"/testing/juniper-server-addresses",
headers=DEFAULT_REQUEST_HEADERS)
......@@ -46,3 +46,59 @@ def test_juniper_addresses(mocker, client):
response_data = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(response_data, ROUTER_LIST_SCHEMA)
assert len(response_data) > 0 # test data is not empty
def test_get_equipment_location(client_with_mocked_data):
rv = client_with_mocked_data.get(
'/testing/opsdb/equipment-location',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
# TODO: validate against schema
def test_get_interface_info(client_with_mocked_data):
rv = client_with_mocked_data.get(
'/testing/opsdb/interfaces',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
# TODO: validate against schema
def test_get_interface_info_for_equipment(client_with_mocked_data):
rv = client_with_mocked_data.get(
'/testing/opsdb/interfaces/mx1.ams.nl.geant.net',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
# TODO: validate against schema
def test_get_interface_info_for_equipment_and_interface(
client_with_mocked_data):
rv = client_with_mocked_data.get(
'/testing/opsdb/interfaces/mx1.ams.nl.geant.net/ae0.0',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
# TODO: validate against schema
def test_get_children(client_with_mocked_data):
rv = client_with_mocked_data.get(
'/testing/opsdb/circuit-hierarchy/children/12363',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
# TODO: validate against schema
def test_get_parents(client_with_mocked_data):
rv = client_with_mocked_data.get(
'/testing/opsdb/circuit-hierarchy/parents/11725',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
# TODO: validate against schema
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment