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

updated cached brian rates format

parent 70d43b96
Branches
Tags
No related merge requests found
...@@ -18,7 +18,7 @@ logger = logging.getLogger(__name__) ...@@ -18,7 +18,7 @@ logger = logging.getLogger(__name__)
BRIAN_SCID_RATES_FILENAME = 'brian-scid-rates.json' CACHED_BRIAN_SCID_RATES_FILENAME = 'brian-scid-rates.json'
CACHED_SCID_RATES_SCHEMA = { CACHED_SCID_RATES_SCHEMA = {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
...@@ -162,7 +162,7 @@ def load_scid_rates(influx_params: config.InfluxConnectionParams) -> list[dict[s ...@@ -162,7 +162,7 @@ def load_scid_rates(influx_params: config.InfluxConnectionParams) -> list[dict[s
'values': values 'values': values
}) })
cache.set(BRIAN_SCID_RATES_FILENAME, rates) cache.set(CACHED_BRIAN_SCID_RATES_FILENAME, rates)
return rates # <-- caller can also retrieve this from the cache return rates # <-- caller can also retrieve this from the cache
... ...
......
...@@ -51,7 +51,7 @@ def _services(service_type: str | None = None) -> Generator[Service]: ...@@ -51,7 +51,7 @@ def _services(service_type: str | None = None) -> Generator[Service]:
scid_current = cache.get(inventory.REPORTING_SCID_CURRENT_CACHE_FILENAME) scid_current = cache.get(inventory.REPORTING_SCID_CURRENT_CACHE_FILENAME)
# poller_interfaces = cache.get(inventory.INPROV_POLLER_INTERFACES_CACHE_FILENAME) # poller_interfaces = cache.get(inventory.INPROV_POLLER_INTERFACES_CACHE_FILENAME)
correlator_state = cache.get(correlator.CACHED_CORRELATOR_STATE_FILENAME) correlator_state = cache.get(correlator.CACHED_CORRELATOR_STATE_FILENAME)
brian_rates = cache.get(brian.BRIAN_SCID_RATES_FILENAME) brian_rates = cache.get(brian.CACHED_BRIAN_SCID_RATES_FILENAME)
except FileNotFoundError: except FileNotFoundError:
logger.exception('not enough data available to build the service list') logger.exception('not enough data available to build the service list')
return return
...@@ -66,6 +66,7 @@ def _services(service_type: str | None = None) -> Generator[Service]: ...@@ -66,6 +66,7 @@ def _services(service_type: str | None = None) -> Generator[Service]:
down_service_sids = set(_get_down_correlator_services()) down_service_sids = set(_get_down_correlator_services())
brian_scid_rates = {r['scid']: r['values'] for r in brian_rates}
for _s in scid_current: for _s in scid_current:
...@@ -75,7 +76,7 @@ def _services(service_type: str | None = None) -> Generator[Service]: ...@@ -75,7 +76,7 @@ def _services(service_type: str | None = None) -> Generator[Service]:
if service_type and _s['service_type'] != service_type: if service_type and _s['service_type'] != service_type:
continue continue
rates = brian_rates.get(_s['scid'], {}) rates = brian_scid_rates.get(_s['scid'], {})
overlays = Overlays( overlays = Overlays(
speed = _s['speed'], speed = _s['speed'],
up = _s['sid'] not in down_service_sids, up = _s['sid'] not in down_service_sids,
... ...
......
...@@ -7,7 +7,7 @@ import pytest ...@@ -7,7 +7,7 @@ import pytest
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from mapping_provider import create_app from mapping_provider import create_app
from mapping_provider.backends import cache, correlator, inventory from mapping_provider.backends import brian, cache, correlator, inventory
from .common import load_test_data from .common import load_test_data
...@@ -62,6 +62,7 @@ def client(dummy_config_filename): ...@@ -62,6 +62,7 @@ def client(dummy_config_filename):
cache.set(inventory.REPORTING_SCID_CURRENT_CACHE_FILENAME, load_test_data('scid-current.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_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(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'))
with patch('sentry_sdk.init') as _mock_sentry_init: with patch('sentry_sdk.init') as _mock_sentry_init:
yield TestClient(create_app()) yield TestClient(create_app())
... ...
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
...@@ -19,8 +19,8 @@ def test_get_sites(client): ...@@ -19,8 +19,8 @@ def test_get_sites(client):
rv = client.get("/map/sites") rv = client.get("/map/sites")
assert rv.status_code == 200 assert rv.status_code == 200
assert rv.json() site_list = SiteList.model_validate(rv.json())
SiteList.model_validate(rv.json()) assert site_list.sites, 'test data should not be empty'
@responses.activate @responses.activate
...@@ -34,8 +34,8 @@ def test_get_routers(client): ...@@ -34,8 +34,8 @@ def test_get_routers(client):
rv = client.get("/map/routers") rv = client.get("/map/routers")
assert rv.status_code == 200 assert rv.status_code == 200
assert rv.json() router_list = RouterList.model_validate(rv.json())
RouterList.model_validate(rv.json()) assert router_list.routers, 'test data should not be empty'
@responses.activate @responses.activate
def test_get_trunks(client): def test_get_trunks(client):
...@@ -48,5 +48,5 @@ def test_get_trunks(client): ...@@ -48,5 +48,5 @@ def test_get_trunks(client):
rv = client.get("/map/trunks") rv = client.get("/map/trunks")
assert rv.status_code == 200 assert rv.status_code == 200
assert rv.json() service_list = ServiceList.model_validate(rv.json())
ServiceList.model_validate(rv.json()) assert service_list.services, 'test data should not be empty'
...@@ -21,7 +21,7 @@ def test_utilization(): ...@@ -21,7 +21,7 @@ def test_utilization():
mocked_influx.return_value = mocked_client_instance mocked_influx.return_value = mocked_client_instance
mocked_query = MagicMock() mocked_query = MagicMock()
mocked_query.return_value.raw = load_test_data('brian-scid-rates.json') mocked_query.return_value.raw = load_test_data('influx-scid-rates-query-result.json')
mocked_client_instance.query = mocked_query mocked_client_instance.query = mocked_query
...@@ -32,6 +32,6 @@ def test_utilization(): ...@@ -32,6 +32,6 @@ def test_utilization():
database='bogus database name', database='bogus database name',
measurement='bogus measurement')) measurement='bogus measurement'))
cached_scid_rates = cache.get(brian.BRIAN_SCID_RATES_FILENAME) cached_scid_rates = cache.get(brian.CACHED_BRIAN_SCID_RATES_FILENAME)
assert cached_scid_rates, "test data is not empty" assert cached_scid_rates, "test data is not empty"
jsonschema.validate(cached_scid_rates, brian.CACHED_SCID_RATES_SCHEMA) jsonschema.validate(cached_scid_rates, brian.CACHED_SCID_RATES_SCHEMA)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment