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

test coriant response against schema

parent b8455ebf
No related branches found
No related tags found
No related merge requests found
......@@ -254,14 +254,23 @@ SELECT
vcc.circuit_type,
vcc.service_type,
vcc.peering_type,
vcc.status,
eq_a.name as equipment_name_a,
eq_b.name as equipment_name_b,
eqc_a.card_id as card_id_a,
eqc_a.card_id as card_id_b,
pop_a.name as pop_name_a,
pop_b.name as pop_name_b,
vcc.port_a as port_a,
vcc.port_b as port_b
pop_a.abbreviation as pop_abbreviation_a,
pop_b.abbreviation as pop_abbreviation_b,
pop_a.absid as pop_absid_a,
pop_b.absid as pop_absid_b,
pop_a.city as pop_city_a,
pop_b.city as pop_city_b,
pop_a.country as pop_country_a,
pop_b.country as pop_country_b,
vcc.port_a,
vcc.port_b
FROM vcircuitconns vcc
LEFT JOIN equipment eq_a ON eq_a.absid = vcc.PTR_equip_a
......@@ -279,22 +288,35 @@ SELECT
'circuit_type': row['circuit_type'],
'service_type': row['service_type'],
'peering_type': row['peering_type'],
'status': row['status'],
'a': {
'name': row['equipment_name_a'],
'card id': row['card_id_a'],
'port number': row['port_a'],
'pop': row['pop_name_a']
'pop': {
'absid': row['pop_absid_a'],
'name': row['pop_name_a'],
'city': row['pop_city_a'],
'country': row['pop_country_a'],
'abbreviation': row['pop_abbreviation_a']
}
},
'b': {
'name': row['equipment_name_b'],
'card id': row['card_id_b'],
'port number': row['port_b'],
'pop': row['pop_name_b']
'pop': {
'absid': row['pop_absid_b'],
'name': row['pop_name_b'],
'city': row['pop_city_b'],
'country': row['pop_country_b'],
'abbreviation': row['pop_abbreviation_b']
}
}
}
circuit_query = base_query + """
WHERE vcc.status = 'Operational'
WHERE vcc.status <> 'Terminated'
AND (
(eq_a.name = %(equipment_name)s
AND eqc_a.card_id = %(card_id)s
......
......@@ -294,7 +294,9 @@ def get_coriant_info(equipment_name, card_id, port_number):
if result:
result = result.decode('utf-8')
else:
config = current_app.config['INVENTORY_PROVIDER_CONFIG']
with db.connection(config['ops-db']) as cx:
path = opsdb.get_coriant_path(
cx, equipment_name, card_id, port_number)
......@@ -307,6 +309,7 @@ def get_coriant_info(equipment_name, card_id, port_number):
mimetype="text/html")
result = json.dumps({'path': path})
# cache this data for the next call
r.set(cache_key, result.encode('utf-8'))
......
import os
import pytest
import jsonschema
from inventory_provider.db import db
from inventory_provider.db import opsdb
......@@ -35,6 +37,60 @@ def connection(db_params):
yield c
CORIANT_PATH_METADATA = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"definitions": {
"pop-info": {
"type": "object",
"properties": {
"absid": {"type": "integer"},
"name": {"type": "string"},
"abbreviation": {"type": "string"},
"country": {"type": "string"},
"city": {"type": "string"}
},
"required": ["absid", "name", "abbreviation", "country", "city"],
"additionalProperties": False
},
"endpoint": {
"type": "object",
"properties": {
"name": {"type": "string"},
"card id": {"type": "string"},
"port number": {"type": "string"},
"pop": {"$ref": "#/definitions/pop-info"}
},
"required": ["name", "port number", "pop"],
"additionalProperties": False
}
},
"type": "object",
"properties": {
'absid': {"type": "integer"},
'category': {"type": "string"},
'circuit_type': {"type": "string"},
'service_type': {"type": "string"},
'peering_type': {"type": "string"},
'status': {"type": "string"},
'a': {"$ref": "#/definitions/endpoint"},
'b': {"$ref": "#/definitions/endpoint"}
},
"required": [
"absid",
"category",
"circuit_type",
"service_type",
"peering_type",
"status",
"a",
"b"],
"additionalProperties": False
}
@pytest.mark.parametrize('equipment,card,port', [
('grv3.lon.uk.geant.net', '1-1', '3'),
('grv3.lon.uk.geant.net', '1-1', '5'),
......@@ -43,6 +99,4 @@ def connection(db_params):
])
def test_query(connection, equipment, card, port):
circuit = opsdb.get_coriant_path(connection, equipment, card, port)
from pprint import pprint
pprint(circuit)
jsonschema.validate(circuit, CORIANT_PATH_METADATA)
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