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

Finished feature NGM-19-new-inprov-all-ims-pops.

parents 81ee733b 4e9a1cab
Branches
Tags
No related merge requests found
......@@ -11,69 +11,64 @@ from mapping_provider.backends import services
router = APIRouter()
class Site(BaseModel):
latitude: float
longitude: float
class Pop(BaseModel):
latitude: float | None
longitude: float | None
name: str
abbreviation: str
city: str
country: str
@classmethod
def from_inprov_site(cls, site: dict[str, Any]) -> 'Site':
return cls(
latitude=site['latitude'],
longitude=site['longitude'],
name=site['name']
)
class SiteList(BaseModel):
sites: list[Site]
class PopList(BaseModel):
pops: list[Pop]
class Router(BaseModel):
fqdn: str
site: str
@classmethod
def from_inprov_router(cls, router: dict[str, Any]) -> 'Router':
return cls(
fqdn = router['fqdn'],
site = router['site']
)
class Equipment(BaseModel):
name: str
pop: str
status: str
class RouterList(BaseModel):
routers: list[Router]
class EquipmentList(BaseModel):
equipment: list[Equipment]
INPROV_SITE_LIST_SCHEMA = {
INPROV_POP_LIST_SCHEMA = {
'$schema': 'https://json-schema.org/draft/2020-12/schema',
'definitions': {
'site': {
'pop': {
'type': 'object',
'properties': {
'name': {'type': 'string'},
'latitude': {'type': 'number'},
'longitude': {'type': 'number'},
'abbreviation': {'type': 'string'},
'city': {'type': 'string'},
'country': {'type': 'string'},
'latitude': {'type': ['number', 'null']},
'longitude': {'type': ['number', 'null']},
},
'required': ['name', 'latitude', 'longitude'],
'required': ['name', 'abbreviation', 'city', 'country', 'latitude', 'longitude'],
'additionalProperties': True,
},
},
'type': 'array',
'items': {'$ref': '#/definitions/site'}
'items': {'$ref': '#/definitions/pop'}
}
INPROV_ROUTER_LIST_SCHEMA = {
INPROV_EQUIPMENT_LIST_SCHEMA = {
'$schema': 'https://json-schema.org/draft/2020-12/schema',
'definitions': {
'router': {
'type': 'object',
'properties': {
'fqdn': {'type': 'string'},
'site': {'type': 'string'},
'name': {'type': 'string'},
'pop': {'type': 'string'},
'status': {'type': 'string'},
},
'required': ['fqdn', 'site'],
'required': ['name', 'pop', 'status'],
},
},
......@@ -81,81 +76,94 @@ INPROV_ROUTER_LIST_SCHEMA = {
'items': {'$ref': '#/definitions/router'}
}
INPROV_SERVICE_LIST_SCHEMA = {
'$schema': 'https://json-schema.org/draft/2020-12/schema',
'definitions': {
'endpoint': {
'type': 'object',
'properties': {
'hostname': {'type': 'string'},
'interface': {'type': 'string'},
},
},
'service': {
'type': 'object',
'properties': {
'sid': {'type': 'string'},
'name': {'type': 'string'},
'type': {'type': 'string'},
'endpoints': {
'type': 'array',
'items': {'$ref': '#/definitions/endpoint'},
'minItems': 1,
},
'overlays': {
'type': 'object', 'properties': {
'speed': {'type': 'number'},
},
'required': ['speed'],
},
},
'required': ['sid', 'name', 'type', 'endpoints', 'overlays'],
},
},
'type': 'array',
'items': {'$ref': '#/definitions/service'}
}
# INPROV_SERVICE_LIST_SCHEMA = {
# '$schema': 'https://json-schema.org/draft/2020-12/schema',
# 'definitions': {
# 'endpoint': {
# 'type': 'object',
# 'properties': {
# 'hostname': {'type': 'string'},
# 'interface': {'type': 'string'},
# },
# },
# 'service': {
# 'type': 'object',
# 'properties': {
# 'sid': {'type': 'string'},
# 'name': {'type': 'string'},
# 'type': {'type': 'string'},
# 'endpoints': {
# 'type': 'array',
# 'items': {'$ref': '#/definitions/endpoint'},
# 'minItems': 1,
# },
# 'overlays': {
# 'type': 'object', 'properties': {
# 'speed': {'type': 'number'},
# },
# 'required': ['speed'],
# },
# },
# 'required': ['sid', 'name', 'type', 'endpoints', 'overlays'],
# },
# },
# 'type': 'array',
# 'items': {'$ref': '#/definitions/service'}
# }
INPROV_API_URL_TODO = 'https://test-inprov01.geant.org'
@router.get("/sites")
def get_sites() -> SiteList:
@router.get("/pops")
def get_pops() -> PopList:
"""
handler for /sites
handler for /pops
"""
# TODO: catch/handle the usual exceptions
app_params = config.load()
rv = requests.get(
f'{app_params.inventory}/map/sites',
f'{app_params.inventory}/map/pops',
headers={'Accept': 'application/json'})
rv.raise_for_status()
site_list_json = rv.json()
jsonschema.validate(site_list_json, INPROV_SITE_LIST_SCHEMA)
rsp_sites = map(Site.from_inprov_site, site_list_json)
return SiteList(sites=list(rsp_sites))
pop_list_obj = rv.json()
jsonschema.validate(pop_list_obj, INPROV_POP_LIST_SCHEMA)
def _make_pop(pop_dict: dict[str, Any]) -> Pop:
return Pop(
latitude=pop_dict['latitude'],
longitude=pop_dict['longitude'],
name=pop_dict['name'],
abbreviation=pop_dict['abbreviation'],
city=pop_dict['city'],
country=pop_dict['country'],
)
return PopList(pops=list(map(_make_pop, pop_list_obj)))
@router.get("/routers")
def get_routers() -> RouterList:
@router.get("/equipment")
def get_equipment() -> EquipmentList:
"""
handler for /sites
handler for /equipment
"""
# TODO: catch/handle the usual exceptions
app_params = config.load()
rv = requests.get(
f'{app_params.inventory}/map/routers',
f'{app_params.inventory}/map/equipment',
headers={'Accept': 'application/json'})
rv.raise_for_status()
router_list_json = rv.json()
jsonschema.validate(router_list_json, INPROV_ROUTER_LIST_SCHEMA)
rsp_routers = map(Router.from_inprov_router, router_list_json)
return RouterList(routers=list(rsp_routers))
equipment_list_obj = rv.json()
jsonschema.validate(equipment_list_obj, INPROV_EQUIPMENT_LIST_SCHEMA)
def _make_equipment(equipment_dict: dict[str, Any]) -> Equipment:
return Equipment(
name=equipment_dict['name'],
pop=equipment_dict['pop'],
status=equipment_dict['status'],
)
return EquipmentList(equipment=list(map(_make_equipment, equipment_list_obj)))
@router.get("/trunks")
......
......@@ -4,21 +4,109 @@ import time
from threading import Event
from typing import Any
import jsonschema
import requests
from . import cache
logger = logging.getLogger(__name__)
INPROV_POLLER_INTERFACES_CACHE_FILENAME = 'inprov-poller-interfaces.json'
# INPROV_POLLER_INTERFACES_CACHE_FILENAME = 'inprov-poller-interfaces.json'
REPORTING_SCID_CURRENT_CACHE_FILENAME = 'reporting-scid-current.json'
INPROV_MAP_SERVICES_CACHE_FILENAME = 'inprov-map-services.json'
# INPROV_MAP_SERVICES_CACHE_FILENAME = 'inprov-map-services.json'
INPROV_EQUIPMENT_CACHE_FILENAME = 'inprov-equipment.json'
REPORTING_SCID_CURRENT_CACHE_SCHEMA = {
'$schema': 'https://json-schema.org/draft/2020-12/schema',
'definitions': {
'interface': {
'type': 'object',
'properties': {
'hostname': {'type': 'string'},
'interface': {'type': 'string'},
# 'addresses': {
# 'type': 'array',
# 'items': {'type': 'string'}
# }
},
'required': ['hostname', 'interface']
},
'lambda_interface': {
'type': 'object',
'properties': {
'equipment': {'type': 'string'},
'port': {'type': 'string'},
},
'required': ['equipment', 'port']
},
'service': {
'type': 'object',
'properties': {
'scid': {'type': 'string'},
'sid': {'type': 'string'},
'name': {'type': 'string'},
'speed': {'type': 'integer'},
'status': {'type': 'string'},
# 'monitored': {'type': 'boolean'},
'service_type': {'type': ['string', 'null']},
# 'imsid': {'type': 'integer'},
# 'customers': {
# 'type': 'array',
# 'items': {'type': 'string'}
# },
'endpoints': {
'type': 'array',
'items': {
'anyOf': [
{'$ref': '#/definitions/interface'},
{'$ref': '#/definitions/lambda_interface'},
]
}
}
},
'required': ['scid', 'sid', 'name', 'speed', 'status', 'service_type', 'endpoints'],
# 'required': ['scid', 'sid', 'name',
# 'speed', 'status', 'monitored',
# 'service_type', 'imsid', 'customers', 'endpoints'],
# 'additionalProperties': False
},
},
'type': 'array',
'items': {'$ref': '#/definitions/service'}
}
INPROV_EQUIPMENT_LIST_SCHEMA = {
'$schema': 'https://json-schema.org/draft/2020-12/schema',
'definitions': {
'equipment': {
'type': 'object',
'properties': {
'name': {'type': 'string'},
'pop': {'type': 'string'},
'status': {'type': 'string'},
},
'required': ['name', 'pop', 'status'],
# 'additionalProperties': False
},
},
'type': 'array',
'items': {'$ref': '#/definitions/equipment'}
}
def _load_and_cache_json(
key: str,
url: str,
cache_filename: str) -> dict[str, Any]:
cache_filename: str,
schema: dict[str, Any] | None = None) -> dict[str, Any]:
"""
Load the JSON from the URL, return and cache it.
......@@ -32,6 +120,9 @@ def _load_and_cache_json(
rv.raise_for_status()
rsp_object = rv.json()
if schema:
jsonschema.validate(instance=rsp_object, schema=schema)
cache.set(cache_filename, rsp_object)
return {
'key': key,
......@@ -50,21 +141,23 @@ def _load_all_inventory(inventory_base_uri: str, reporting_base_uri: str) -> dic
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
futures = [
executor.submit(
_load_and_cache_json,
key='poller-interfaces',
url=f'{inventory_base_uri}/poller/interfaces',
cache_filename=INPROV_POLLER_INTERFACES_CACHE_FILENAME),
# executor.submit(
# _load_and_cache_json,
# key='poller-interfaces',
# url=f'{inventory_base_uri}/poller/interfaces',
# cache_filename=INPROV_POLLER_INTERFACES_CACHE_FILENAME),
executor.submit(
_load_and_cache_json,
key='map-services',
url=f'{inventory_base_uri}/map/services',
cache_filename=INPROV_MAP_SERVICES_CACHE_FILENAME),
url=f'{inventory_base_uri}/map/equipment',
cache_filename=INPROV_EQUIPMENT_CACHE_FILENAME,
schema=INPROV_EQUIPMENT_LIST_SCHEMA),
executor.submit(
_load_and_cache_json,
key='scid-current',
url=f'{reporting_base_uri}/scid/current',
cache_filename=REPORTING_SCID_CURRENT_CACHE_FILENAME),
cache_filename=REPORTING_SCID_CURRENT_CACHE_FILENAME,
schema=REPORTING_SCID_CURRENT_CACHE_SCHEMA),
]
responses = {}
for _f in concurrent.futures.as_completed(futures):
......
import functools
import logging
import re
from collections.abc import Generator
from typing import Any
from pydantic import BaseModel
......@@ -8,11 +11,6 @@ from . import brian, cache, correlator, inventory
logger = logging.getLogger(__name__)
class Endpoint(BaseModel):
equipment: str
interface: str
class BitRates(BaseModel):
ingress: float | None
egress: float | None
......@@ -31,7 +29,7 @@ class Service(BaseModel):
scid: str
name: str
type: str
endpoints: list[Endpoint]
pops: list[str]
overlays: Overlays
......@@ -39,6 +37,33 @@ class ServiceList(BaseModel):
services: list[Service]
def endpoint_to_pop(endpoint: dict[str, Any], inprov_equipment_dict: dict[str, dict[str, Any]]) -> str:
def _hostname_to_equipment(_hn: str) -> str:
m = re.match(r'^(.+)\.geant\.net$', _hn)
if not m:
logger.error(f'unexpected hostname pattern: {_hn}')
return '?'
return m.group(1).upper()
if 'hostname' in endpoint:
eq_name = _hostname_to_equipment(endpoint['hostname'])
elif 'equipment' in endpoint:
eq_name = endpoint['equipment']
else:
# should already be validated
raise AssertionError(f'no equipment or hostname in endpoint: {endpoint}')
if eq_name not in inprov_equipment_dict:
# TODO: is this really possible if all data is read from IMS at the same time?
logger.error(f'unknown endpoint equipment: {eq_name}')
return '?'
pop_name = inprov_equipment_dict[eq_name]['pop']
assert isinstance(pop_name, str) # mypy noise
return pop_name
def _services(service_type: str | None = None) -> Generator[Service]:
"""
load the cached backend data and yield map service records
......@@ -52,6 +77,7 @@ def _services(service_type: str | None = None) -> Generator[Service]:
# poller_interfaces = cache.get(inventory.INPROV_POLLER_INTERFACES_CACHE_FILENAME)
correlator_state = cache.get(correlator.CACHED_CORRELATOR_STATE_FILENAME)
brian_rates = cache.get(brian.CACHED_BRIAN_SCID_RATES_FILENAME)
equipment_list = cache.get(inventory.INPROV_EQUIPMENT_CACHE_FILENAME)
except FileNotFoundError:
logger.exception('not enough data available to build the service list')
return
......@@ -68,6 +94,9 @@ def _services(service_type: str | None = None) -> Generator[Service]:
down_service_sids = set(_get_down_correlator_services())
brian_scid_rates = {r['scid']: r['values'] for r in brian_rates}
equipment_dict = {_x['name']: _x for _x in equipment_list}
_endpoint_to_pop = functools.partial(endpoint_to_pop, inprov_equipment_dict=equipment_dict)
for _s in scid_current:
if _s['status'] != 'operational':
......@@ -76,6 +105,8 @@ def _services(service_type: str | None = None) -> Generator[Service]:
if service_type and _s['service_type'] != service_type:
continue
pops = sorted(set(map(_endpoint_to_pop, _s['endpoints'])))
rates = brian_scid_rates.get(_s['scid'], {})
overlays = Overlays(
speed = _s['speed'],
......@@ -94,18 +125,12 @@ def _services(service_type: str | None = None) -> Generator[Service]:
),
)
endpoints = []
for _e in _s['endpoints']:
equipment = _e['hostname'] if 'hostname' in _e else _e['equipment']
interface = _e['interface'] if 'interface' in _e else _e['port']
endpoints.append(Endpoint(equipment=equipment, interface=interface))
yield Service(
sid = _s['sid'],
scid = _s['scid'],
name = _s['name'],
type = _s['service_type'],
endpoints = endpoints,
pops = pops,
overlays = overlays,
)
......
......@@ -58,9 +58,10 @@ def client(dummy_config_filename):
# there's no rmq in the test config data, so cache won't be initialized
cache.init(tmp_dir)
cache.set(inventory.INPROV_MAP_SERVICES_CACHE_FILENAME, load_test_data('inprov-services.json'))
# cache.set(inventory.INPROV_MAP_SERVICES_CACHE_FILENAME, load_test_data('inprov-services.json'))
cache.set(inventory.REPORTING_SCID_CURRENT_CACHE_FILENAME, load_test_data('scid-current.json'))
cache.set(inventory.INPROV_POLLER_INTERFACES_CACHE_FILENAME, load_test_data('poller-interfaces.json'))
cache.set(inventory.INPROV_EQUIPMENT_CACHE_FILENAME, load_test_data('inprov-equipment.json'))
# cache.set(inventory.INPROV_POLLER_INTERFACES_CACHE_FILENAME, load_test_data('poller-interfaces.json'))
cache.set(correlator.CACHED_CORRELATOR_STATE_FILENAME, load_test_data('correlator-state.json'))
cache.set(brian.CACHED_BRIAN_SCID_RATES_FILENAME, load_test_data('brian-scid-rates.json'))
......
This diff is collapsed.
This diff is collapsed.
[
{
"fqdn": "qfx.par.fr.geant.net",
"site": "PAR"
},
{
"fqdn": "mx2.lis.pt.geant.net",
"site": "LIS"
},
{
"fqdn": "mx1.vie.at.geant.net",
"site": "VIE"
},
{
"fqdn": "qfx.fra.de.geant.net",
"site": "FRA"
},
{
"fqdn": "qfx.lon2.uk.geant.net",
"site": "LON2"
},
{
"fqdn": "mx1.poz.pl.geant.net",
"site": "POZ"
},
{
"fqdn": "rt1.bil.es.geant.net",
"site": "BIL"
},
{
"fqdn": "rt1.chi.md.geant.net",
"site": "CHI"
},
{
"fqdn": "rt0.ath2.gr.geant.net",
"site": "ATH2"
},
{
"fqdn": "rt1.ams.nl.geant.net",
"site": "AMS"
},
{
"fqdn": "rt1.buc.ro.geant.net",
"site": "BUC"
},
{
"fqdn": "rt1.bra.sk.geant.net",
"site": "BRA"
},
{
"fqdn": "rt0.lon.uk.geant.net",
"site": "LON"
},
{
"fqdn": "mx2.zag.hr.geant.net",
"site": "ZAG"
},
{
"fqdn": "srx1.am.office.geant.net",
"site": "AMO"
},
{
"fqdn": "mx1.bud.hu.geant.net",
"site": "BUD"
},
{
"fqdn": "mx1.buc.ro.geant.net",
"site": "BUC"
},
{
"fqdn": "rt0.mil2.it.geant.net",
"site": "MIL2"
},
{
"fqdn": "rt0.mar.fr.geant.net",
"site": "MAR"
},
{
"fqdn": "mx1.lon2.uk.geant.net",
"site": "LON2"
},
{
"fqdn": "mx1.gen.ch.geant.net",
"site": "GEN"
},
{
"fqdn": "mx1.mad.es.geant.net",
"site": "MAD"
},
{
"fqdn": "mx1.par.fr.geant.net",
"site": "PAR"
},
{
"fqdn": "mx1.lon.uk.geant.net",
"site": "LON"
},
{
"fqdn": "srx1.ch.office.geant.net",
"site": "CCH"
},
{
"fqdn": "srx2.am.office.geant.net",
"site": "AMO"
},
{
"fqdn": "srx2.ch.office.geant.net",
"site": "CCH"
},
{
"fqdn": "rt1.kie.ua.geant.net",
"site": "KIE"
},
{
"fqdn": "rt1.fra.de.geant.net",
"site": "FRA"
},
{
"fqdn": "rt1.mar.fr.geant.net",
"site": "MAR"
},
{
"fqdn": "rt1.mil2.it.geant.net",
"site": "MIL2"
},
{
"fqdn": "rt1.por.pt.geant.net",
"site": "POR"
},
{
"fqdn": "rt1.pra.cz.geant.net",
"site": "PRA"
},
{
"fqdn": "rt0.poz.pl.geant.net",
"site": "POZ"
},
{
"fqdn": "rt2.ams.nl.geant.net",
"site": "AMS"
},
{
"fqdn": "rt0.gen.ch.geant.net",
"site": "GEN"
},
{
"fqdn": "rt2.kie.ua.geant.net",
"site": "KIE"
},
{
"fqdn": "rt2.chi.md.geant.net",
"site": "CHI"
},
{
"fqdn": "rt0.zag.hr.geant.net",
"site": "ZAG"
},
{
"fqdn": "rt2.bra.sk.geant.net",
"site": "BRA"
},
{
"fqdn": "rt0.rig.lv.geant.net",
"site": "RIG"
},
{
"fqdn": "rt0.mad.es.geant.net",
"site": "MAD"
},
{
"fqdn": "rt0.kau.lt.geant.net",
"site": "KAU"
},
{
"fqdn": "rt0.the.gr.geant.net",
"site": "THE"
},
{
"fqdn": "rt0.buc.ro.geant.net",
"site": "BUC"
},
{
"fqdn": "rt0.tar.ee.geant.net",
"site": "TAR"
},
{
"fqdn": "rt0.par.fr.geant.net",
"site": "PAR"
},
{
"fqdn": "rt0.bud.hu.geant.net",
"site": "BUD"
},
{
"fqdn": "rt0.bra.sk.geant.net",
"site": "BRA"
},
{
"fqdn": "rt0.pra.cz.geant.net",
"site": "PRA"
},
{
"fqdn": "rt0.lon2.uk.geant.net",
"site": "LON2"
},
{
"fqdn": "rt0.por.pt.geant.net",
"site": "POR"
},
{
"fqdn": "rt0.vie.at.geant.net",
"site": "VIE"
},
{
"fqdn": "rt0.cor.ie.geant.net",
"site": "COR"
},
{
"fqdn": "rt0.dub.ie.geant.net",
"site": "DUB"
},
{
"fqdn": "rt0.bru.be.geant.net",
"site": "BRU"
},
{
"fqdn": "rt0.fra.de.geant.net",
"site": "FRA"
},
{
"fqdn": "rt0.ams.nl.geant.net",
"site": "AMS"
},
{
"fqdn": "rt0.lju.si.geant.net",
"site": "LJU"
},
{
"fqdn": "rt0.sof.bg.geant.net",
"site": "SOF"
},
{
"fqdn": "rt0.ham.de.geant.net",
"site": "HAM"
}
]
This diff is collapsed.
[
{
"city": "AMSTERDAM",
"country": "NETHERLANDS",
"latitude": 52.34638889,
"longitude": 4.93861111,
"name": "AMS"
},
{
"city": "BILBAO",
"country": "SPAIN",
"latitude": 43.3250881,
"longitude": -2.9804526,
"name": "BIL"
},
{
"city": "ATTIKI",
"country": "GREECE",
"latitude": 37.98,
"longitude": 23.73,
"name": "ATH2"
},
{
"city": "CAMBRIDGE",
"country": "UNITED KINGDOM",
"latitude": 52.19152778,
"longitude": 0.13383333,
"name": "CCH"
},
{
"city": "ATHENS",
"country": "GREECE",
"latitude": 37.97308611,
"longitude": 23.74555556,
"name": "ATH"
},
{
"city": "BRATISLAVA",
"country": "SLOVAKIA",
"latitude": 48.116833,
"longitude": 17.094389,
"name": "BRA"
},
{
"city": "BRUSSELS",
"country": "BELGIUM",
"latitude": 50.85694444,
"longitude": 4.41138889,
"name": "BRU"
},
{
"city": "BUCHAREST",
"country": "ROMANIA",
"latitude": 44.44474167,
"longitude": 26.09642222,
"name": "BUC"
},
{
"city": "DUBLIN",
"country": "IRELAND",
"latitude": 53.29198056,
"longitude": -6.41473333,
"name": "DUB"
},
{
"city": "CORK",
"country": "IRELAND",
"latitude": 51.90362538,
"longitude": -8.512314371,
"name": "COR"
},
{
"city": "BUDAPEST",
"country": "HUNGARY",
"latitude": 47.51777778,
"longitude": 19.05527778,
"name": "BUD"
},
{
"city": "CHISINAU",
"country": "MOLDOVA, REPUBLIC OF",
"latitude": 47.03072498,
"longitude": 28.82379273,
"name": "CHI"
},
{
"city": "KAUNAS",
"country": "LITHUANIA",
"latitude": 54.94067222,
"longitude": 24.01801389,
"name": "KAU"
},
{
"city": "KIEV",
"country": "UKRAINE",
"latitude": 50.44909773,
"longitude": 30.46527006,
"name": "KIE"
},
{
"city": "GENEVA",
"country": "SWITZERLAND",
"latitude": 46.2355997,
"longitude": 6.0553345,
"name": "GEN"
},
{
"city": "HAMBURG",
"country": "GERMANY",
"latitude": 53.55090278,
"longitude": 10.04648611,
"name": "HAM"
},
{
"city": "AMSTERDAM - Office",
"country": "NETHERLANDS",
"latitude": 52.31330556,
"longitude": 4.94911111,
"name": "AMO"
},
{
"city": "FRANKFURT",
"country": "GERMANY",
"latitude": 50.12029444,
"longitude": 8.73584444,
"name": "FRA"
},
{
"city": "LONDON",
"country": "UNITED KINGDOM",
"latitude": 51.4981657,
"longitude": -0.0152639,
"name": "LON"
},
{
"city": "ALCOBENDAS",
"country": "SPAIN",
"latitude": 40.53647778,
"longitude": -3.64880278,
"name": "MAD"
},
{
"city": "LISBON",
"country": "PORTUGAL",
"latitude": 38.759325,
"longitude": -9.142339,
"name": "LIS"
},
{
"city": "MARSEILLE",
"country": "FRANCE",
"latitude": 43.338019,
"longitude": 5.347666,
"name": "MAR"
},
{
"city": "LJUBLJANA",
"country": "SLOVENIA",
"latitude": 46.050171,
"longitude": 14.46033,
"name": "LJU"
},
{
"city": "SLOUGH",
"country": "UNITED KINGDOM",
"latitude": 51.5231433,
"longitude": -0.6224058,
"name": "LON2"
},
{
"city": "AUBERVILLIERS",
"country": "FRANCE",
"latitude": 48.90444444,
"longitude": 2.37111111,
"name": "PAR"
},
{
"city": "MILAN",
"country": "ITALY",
"latitude": 45.47527778,
"longitude": 9.10305556,
"name": "MIL2"
},
{
"city": "RIGA",
"country": "LATVIA",
"latitude": 56.94834444,
"longitude": 24.118,
"name": "RIG"
},
{
"city": "PORTO",
"country": "PORTUGAL",
"latitude": 41.177904,
"longitude": -8.594972,
"name": "POR"
},
{
"city": "PRAGUE",
"country": "CZECH REPUBLIC",
"latitude": 50.10166667,
"longitude": 14.39166667,
"name": "PRA"
},
{
"city": "POZNAN",
"country": "POLAND",
"latitude": 52.411775,
"longitude": 16.91756111,
"name": "POZ"
},
{
"city": "SOFIA",
"country": "BULGARIA",
"latitude": 42.67575833,
"longitude": 23.37098611,
"name": "SOF"
},
{
"city": "ZAGREB",
"country": "CROATIA",
"latitude": 45.79194444,
"longitude": 15.96944444,
"name": "ZAG"
},
{
"city": "TARTU",
"country": "ESTONIA",
"latitude": 58.383146,
"longitude": 26.71986,
"name": "TAR"
},
{
"city": "VIENNA",
"country": "AUSTRIA",
"latitude": 48.26888889,
"longitude": 16.41019444,
"name": "VIE"
},
{
"city": "BELGRADE",
"country": "SERBIA",
"latitude": 44.81141383,
"longitude": 20.39871378,
"name": "BEL"
},
{
"city": "THESSALONIKI",
"country": "GREECE",
"latitude": 40.662632,
"longitude": 22.860255,
"name": "THE"
},
{
"city": "GENEVA",
"country": "FR",
"latitude": 46.255952,
"longitude": 6.055262,
"name": "GEN2"
}
]
......@@ -16,11 +16,11 @@ def test_inventory_service_download():
inventory_base_uri = 'https://dummy-hostname.dummy.domain'
reporting_base_uri = 'https://another-dummy-hostname.dummy.domain'
responses.add(
method=responses.GET,
url=f'{inventory_base_uri}/poller/interfaces',
json=load_test_data('poller-interfaces.json')
)
# responses.add(
# method=responses.GET,
# url=f'{inventory_base_uri}/poller/interfaces',
# json=load_test_data('poller-interfaces.json')
# )
responses.add(
method=responses.GET,
url=f'{reporting_base_uri}/scid/current',
......@@ -28,24 +28,24 @@ def test_inventory_service_download():
)
responses.add(
method=responses.GET,
url=f'{inventory_base_uri}/map/services',
json=load_test_data('inprov-services.json')
url=f'{inventory_base_uri}/map/equipment',
json=load_test_data('inprov-equipment.json')
)
with tempfile.TemporaryDirectory() as tmp_dir:
cache.init(tmp_dir)
inventory._load_all_inventory(
inventory_base_uri='https://dummy-hostname.dummy.domain',
reporting_base_uri='https://another-dummy-hostname.dummy.domain')
inventory_base_uri=inventory_base_uri,
reporting_base_uri=reporting_base_uri)
# assert os.path.exists(os.path.join(tmp_dir, services.POLLER_INTERFACES_CACHE_FILENAME))
cached_data = cache.get(inventory.INPROV_POLLER_INTERFACES_CACHE_FILENAME)
assert cached_data == load_test_data('poller-interfaces.json')
# cached_data = cache.get(inventory.INPROV_POLLER_INTERFACES_CACHE_FILENAME)
# assert cached_data == load_test_data('poller-interfaces.json')
cached_data = cache.get(inventory.INPROV_MAP_SERVICES_CACHE_FILENAME)
assert cached_data == load_test_data('inprov-services.json')
cached_data = cache.get(inventory.INPROV_EQUIPMENT_CACHE_FILENAME)
assert cached_data == load_test_data('inprov-equipment.json')
cached_data = cache.get(inventory.REPORTING_SCID_CURRENT_CACHE_FILENAME)
assert cached_data == load_test_data('scid-current.json')
......@@ -2,40 +2,41 @@ import re
import responses
from mapping_provider.api.map import RouterList, SiteList
from mapping_provider.api.map import EquipmentList, PopList
from mapping_provider.backends.services import ServiceList
from .common import load_test_data
@responses.activate
def test_get_sites(client):
def test_get_pops(client):
responses.add(
method=responses.GET,
url=re.compile(r'.*/map/sites$'),
json=load_test_data('inprov-sites.json')
url=re.compile(r'.*/map/pops$'),
json=load_test_data('inprov-pops.json')
)
rv = client.get("/map/sites")
rv = client.get("/map/pops")
assert rv.status_code == 200
site_list = SiteList.model_validate(rv.json())
assert site_list.sites, 'test data should not be empty'
pop_list = PopList.model_validate(rv.json())
assert pop_list.pops, 'test data should not be empty'
@responses.activate
def test_get_routers(client):
def test_get_equipment(client):
responses.add(
method=responses.GET,
url=re.compile(r'.*/map/routers$'),
json=load_test_data('inprov-routers.json')
url=re.compile(r'.*/map/equipment$'),
json=load_test_data('inprov-equipment.json')
)
rv = client.get("/map/routers")
rv = client.get("/map/equipment")
assert rv.status_code == 200
router_list = RouterList.model_validate(rv.json())
assert router_list.routers, 'test data should not be empty'
equipment_list = EquipmentList.model_validate(rv.json())
assert equipment_list.equipment, 'test data should not be empty'
@responses.activate
def test_get_trunks(client):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment