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

added id to service response, and return ordered

parent 032f60bb
No related branches found
No related tags found
No related merge requests found
......@@ -144,6 +144,7 @@ PEERING_ADDRESS_SERVICES_LIST = {
'definitions': {
'service': {
'properties': {
'id': {'type': 'integer'},
'name': {'type': 'string'},
'type': {'type': 'string'},
'status': {'type': 'string'}
......@@ -445,6 +446,15 @@ def _get_subnet_interfaces(address, r):
def _get_peer_address_services(address: str, r: 'StrictRedis'):
def _formatted_service(s):
return {
'id': s['id'],
'name': s['name'],
'type': s['service_type'],
'status': s['status']
}
for ifc_info in _get_subnet_interfaces(address, r):
ims_source_equipment = get_ims_equipment_name(
ifc_info['router'], r)
......@@ -452,20 +462,15 @@ def _get_peer_address_services(address: str, r: 'StrictRedis'):
service_info = get_interface_services_and_loc(
ims_source_equipment, ims_interface, r)
# make a dict to de-dup the services list
services_dict = {}
for s in service_info.get('services', []):
services_dict[s['id']] = {
'name': s['name'],
'type': s['service_type'],
'status': s['status']
}
services = service_info.get('services', [])
services = map(_formatted_service, services)
services = sorted(services, key=lambda x: x['name'])
yield {
'address': address,
'hostname': ifc_info['router'],
'interface': ifc_info['interface name'],
'services': list(services_dict.values())
'services': list(services)
}
......
......@@ -139,8 +139,28 @@ def test_peerings_group_list(client, uri):
assert response_data # test data is non-empty
# taken from a sample splunk query
@pytest.mark.parametrize('address', [
'62.40.127.141',
'62.40.127.139'
])
def test_lookup_services_for_address(address, mocked_redis):
_redis_instance = _get_redis({
'redis': {
'hostname': None,
'port': None
},
'redis-databases': [9, 7, 5]
})
info = list(_get_peer_address_services(address, r=_redis_instance))
jsonschema.validate(info, PEERING_ADDRESS_SERVICES_LIST)
# sanity check to be sure we have interesting test data
assert all(x['services'] for x in info)
_OUTAGE_PEER_ADDRESSES = [
# taken from a sample splunk query result
'83.97.93.247',
'146.48.78.13',
'185.6.36.40',
......@@ -244,24 +264,6 @@ _OUTAGE_PEER_ADDRESSES = [
]
@pytest.mark.parametrize('address', [
'62.40.127.141',
'62.40.127.139'
])
def test_lookup_peer_services(address, mocked_redis):
_redis_instance = _get_redis({
'redis': {
'hostname': None,
'port': None
},
'redis-databases': [0, 7]
})
info = list(_get_peer_address_services(address, r=_redis_instance))
jsonschema.validate(info, PEERING_ADDRESS_SERVICES_LIST)
assert all(x['services'] for x in info)
def test_peering_services(client):
headers = {'Content-Type': 'application/json'}
headers.update(DEFAULT_REQUEST_HEADERS)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment