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

added /data/pop route, some name refactoring

parent f018c3eb
Branches
Tags
No related merge requests found
...@@ -212,7 +212,7 @@ def get_circuit_hierarchy(connection): # pragma: no cover ...@@ -212,7 +212,7 @@ def get_circuit_hierarchy(connection): # pragma: no cover
return r return r
def get_pop_info(connection, equipment_name): def lookup_pop_info(connection, equipment_name):
query = """ query = """
SELECT SELECT
e.name AS equipment_name, e.name AS equipment_name,
...@@ -251,8 +251,7 @@ ORDER BY FIELD(e.status, 'Operational', 'Installed') ...@@ -251,8 +251,7 @@ ORDER BY FIELD(e.status, 'Operational', 'Installed')
return list([_row2rsp(r) for r in rows]) return list([_row2rsp(r) for r in rows])
def lookup_coriant_path(connection, equipment_name, card_id, port_number):
def get_coriant_path(connection, equipment_name, card_id, port_number):
base_query = """ base_query = """
SELECT SELECT
......
...@@ -298,7 +298,7 @@ def get_coriant_info(equipment_name, card_id, port_number): ...@@ -298,7 +298,7 @@ def get_coriant_info(equipment_name, card_id, port_number):
config = current_app.config['INVENTORY_PROVIDER_CONFIG'] config = current_app.config['INVENTORY_PROVIDER_CONFIG']
with db.connection(config['ops-db']) as cx: with db.connection(config['ops-db']) as cx:
path = opsdb.get_coriant_path( path = opsdb.lookup_coriant_path(
cx, equipment_name, card_id, port_number) cx, equipment_name, card_id, port_number)
if not path: if not path:
......
...@@ -47,7 +47,7 @@ def equipment_location(equipment_name): ...@@ -47,7 +47,7 @@ def equipment_location(equipment_name):
config = current_app.config['INVENTORY_PROVIDER_CONFIG'] config = current_app.config['INVENTORY_PROVIDER_CONFIG']
with db.connection(config['ops-db']) as cx: with db.connection(config['ops-db']) as cx:
result = opsdb.get_equipment_location_data(cx, equipment_name) result = opsdb.lookup_pop_info(cx, equipment_name)
if not result: if not result:
return Response( return Response(
......
...@@ -59,7 +59,7 @@ def test_snmp_ids(router, client_with_mocked_data): ...@@ -59,7 +59,7 @@ def test_snmp_ids(router, client_with_mocked_data):
} }
rv = client_with_mocked_data.post( rv = client_with_mocked_data.post(
"/data/snmp/" + router, "/testing/snmp/" + router,
headers=DEFAULT_REQUEST_HEADERS) headers=DEFAULT_REQUEST_HEADERS)
response = json.loads(rv.data.decode("utf-8")) response = json.loads(rv.data.decode("utf-8"))
...@@ -111,7 +111,7 @@ def test_router_bgp_routes(router, client_with_mocked_data): ...@@ -111,7 +111,7 @@ def test_router_bgp_routes(router, client_with_mocked_data):
} }
rv = client_with_mocked_data.post( rv = client_with_mocked_data.post(
"/data/bgp/" + router, "/testing/bgp/" + router,
headers=DEFAULT_REQUEST_HEADERS) headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200 assert rv.status_code == 200
......
...@@ -292,7 +292,7 @@ def test_coriant_info(client, mocker): ...@@ -292,7 +292,7 @@ def test_coriant_info(client, mocker):
mocker.patch( mocker.patch(
'inventory_provider.db.db.connection', mocked_connection) 'inventory_provider.db.db.connection', mocked_connection)
mocker.patch( mocker.patch(
'inventory_provider.db.opsdb.get_coriant_path', 'inventory_provider.db.opsdb.lookup_coriant_path',
lambda a, b, c, d: {'C': a, 'E': b, 'CID': c, 'P': d}) lambda a, b, c, d: {'C': a, 'E': b, 'CID': c, 'P': d})
rv = client.get( rv = client.get(
...@@ -319,7 +319,7 @@ def test_coriant_info_not_found(client, mocker): ...@@ -319,7 +319,7 @@ def test_coriant_info_not_found(client, mocker):
mocker.patch( mocker.patch(
'inventory_provider.db.db.connection', mocked_connection) 'inventory_provider.db.db.connection', mocked_connection)
mocker.patch( mocker.patch(
'inventory_provider.db.opsdb.get_coriant_path', 'inventory_provider.db.opsdb.lookup_coriant_path',
lambda a, b, c, d: None) lambda a, b, c, d: None)
rv = client.get( rv = client.get(
......
import contextlib
import json import json
import jsonschema import jsonschema
import pytest
from inventory_provider.db import db
DEFAULT_REQUEST_HEADERS = { DEFAULT_REQUEST_HEADERS = {
"Content-type": "application/json", "Content-type": "application/json",
...@@ -21,3 +25,56 @@ def test_get_routers(client): ...@@ -21,3 +25,56 @@ def test_get_routers(client):
response = json.loads(rv.data.decode("utf-8")) response = json.loads(rv.data.decode("utf-8"))
jsonschema.validate(response, version_schema) jsonschema.validate(response, version_schema)
assert response assert response
def test_pop_info(client, mocker):
"""
just check the correct method is called, but mock out all sql access
"""
expected_pop_info = {
'C': 'bogus connection',
'E': 'bogus equipment name'
}
@contextlib.contextmanager
def mocked_connection(ignored):
yield expected_pop_info['C']
mocker.patch(
'inventory_provider.db.db.connection', mocked_connection)
mocker.patch(
'inventory_provider.db.opsdb.lookup_pop_info',
lambda c, e: {'C': c, 'E': e})
rv = client.get(
'/data/pop/{E}'.format(**expected_pop_info),
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
response = json.loads(rv.data.decode('utf-8'))
assert response == expected_pop_info
def test_pop_not_found(client, mocker):
"""
just check the correct method is called, but mock out all sql access
"""
@contextlib.contextmanager
def mocked_connection(ignored):
yield 'xyz'
mocker.patch(
'inventory_provider.db.db.connection', mocked_connection)
mocker.patch(
'inventory_provider.db.opsdb.lookup_pop_info',
lambda a, b: None)
rv = client.get(
'/data/pop/aabbcc',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 404
...@@ -154,7 +154,7 @@ CORIANT_PATH_METADATA = { ...@@ -154,7 +154,7 @@ CORIANT_PATH_METADATA = {
'mx1.gen.ch.geant.net' 'mx1.gen.ch.geant.net'
]) ])
def test_equipment_location(connection, equipment): def test_equipment_location(connection, equipment):
circuit = opsdb.get_pop_info(connection, equipment) circuit = opsdb.lookup_pop_info(connection, equipment)
jsonschema.validate(circuit, EQUIPMENT_LOCATION_METADATA) jsonschema.validate(circuit, EQUIPMENT_LOCATION_METADATA)
assert len(circuit) == 1 assert len(circuit) == 1
...@@ -166,5 +166,5 @@ def test_equipment_location(connection, equipment): ...@@ -166,5 +166,5 @@ def test_equipment_location(connection, equipment):
('grv3.lon.uk.geant.net', '1-1', '1'), ('grv3.lon.uk.geant.net', '1-1', '1'),
]) ])
def test_coriant_path(connection, equipment, card, port): def test_coriant_path(connection, equipment, card, port):
circuit = opsdb.get_coriant_path(connection, equipment, card, port) circuit = opsdb.lookup_coriant_path(connection, equipment, card, port)
jsonschema.validate(circuit, CORIANT_PATH_METADATA) jsonschema.validate(circuit, CORIANT_PATH_METADATA)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment