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

added a schema & testing for get_node_locations

parent 5c2400ac
Branches
Tags
No related merge requests found
......@@ -26,6 +26,40 @@ IMS_OPSDB_STATUS_MAP = {
STATUSES_TO_IGNORE = \
[InventoryStatus.OUT_OF_SERVICE.value]
NODE_LOCATION_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'pop-location': {
'type': 'object',
'properties': {
'name': {'type': 'string'},
'city': {'type': 'string'},
'country': {'type': 'string'},
'abbreviation': {'type': 'string'},
'longitude': {'type': 'number'},
'latitude': {'type': 'number'}
},
'required': [
'name',
'city',
'country',
'abbreviation',
'longitude',
'latitude'],
'additionalProperties': False
}
},
'type': 'object',
'properties': {
'equipment-name': {'type': 'string'},
'status': {'type': 'string'},
'pop': {'$ref': '#/definitions/pop-location'}
},
'required': ['equipment-name', 'status', 'pop'],
'additionalProperties': False
}
def get_non_monitored_circuit_ids(ds: IMS):
# note the id for the relevant field is hard-coded. I didn't want to use
......@@ -300,6 +334,17 @@ def get_circuit_hierarchy(ds: IMS):
def get_node_locations(ds: IMS):
"""
return location info for all Site nodes
yields dictionaries formatted as:
.. as_json::
inventory_provider.db.ims_data.NODE_LOCATION_SCHEMA
:param ds:
:return: yields dicts as above
"""
site_nav_props = [
ims.SITE_PROPERTIES['City'],
ims.SITE_PROPERTIES['SiteAliases'],
......
import json
import os
import jsonschema
import inventory_provider
from inventory_provider.db.ims import InventoryStatus
from inventory_provider.db.ims_data import lookup_lg_routers, \
get_node_locations, IMS_OPSDB_STATUS_MAP, \
get_port_id_services, get_port_details, \
get_circuit_hierarchy
get_circuit_hierarchy, NODE_LOCATION_SCHEMA
def _json_test_data(filename):
abs_filename = os.path.join(
os.path.dirname(__file__),
'data',
filename)
with open(abs_filename) as data:
return json.load(data)
def test_get_circuit_hierarchy(mocker):
ds = inventory_provider.db.ims.IMS(
'http://dummy_base', 'dummy_username', 'dummy_password')
with open('test/data/ims_circuit_hierarchy_data.json') as data:
se_data = json.load(data)
se_data = _json_test_data('ims_circuit_hierarchy_data.json')
mocker.patch.object(
inventory_provider.db.ims.IMS,
'get_filtered_entities',
......@@ -55,8 +66,7 @@ def test_get_circuit_hierarchy(mocker):
def test_get_port_details(mocker):
def _se(entity, y, step_count):
with open(f'test/data/ims_{entity}_details_data.json') as data:
return json.load(data)
return _json_test_data(f'ims_{entity}_details_data.json')
mocker.patch.object(
inventory_provider.db.ims.IMS,
......@@ -105,8 +115,7 @@ def test_get_port_details(mocker):
def test_get_port_id_services(mocker):
with open('test/data/ims_port_id_services_data.json') as data:
d = json.load(data)
d = _json_test_data('ims_port_id_services_data.json')
mocker.patch.object(
inventory_provider.db.ims.IMS,
......@@ -215,8 +224,8 @@ def test_get_port_id_services(mocker):
def test_lookup_lg_routers(mocker):
ims = mocker.patch('inventory_provider.db.ims.IMS')
with open('test/data/ims_lg_data.json') as data:
ims.return_value.get_filtered_entities.return_value = json.load(data)
ims.return_value.get_filtered_entities.return_value \
= _json_test_data('ims_lg_data.json')
ims.return_value.get_entity_by_id.return_value = {
'name': 'pop name',
'longitude': 'long',
......@@ -266,13 +275,16 @@ def test_lookup_lg_routers(mocker):
def test_get_node_location(mocker):
ims = mocker.patch('inventory_provider.db.ims.IMS')
with open('test/data/ims_nodes_data.json') as data:
resp_data = json.load(data)
resp_data = _json_test_data('ims_nodes_data.json')
ims.return_value.get_all_entities.return_value = resp_data
ds = inventory_provider.db.ims.IMS(
'dummy_base', 'dummy_username', 'dummy_password')
res = list(get_node_locations(ds))
for name, node in res:
assert isinstance(name, str)
jsonschema.validate(node, NODE_LOCATION_SCHEMA)
assert len(res) == 36
assert res[0] == ('LON3_CX_01', {
'equipment-name': 'LON3_CX_01',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment