From e23c01c68bbd3375c919c5b49a56ab9d34e1c03a Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Sat, 24 May 2025 15:18:25 +0200 Subject: [PATCH] template service build --- mapping_provider/backends/services.py | 26 +++++++++++++------------- test/conftest.py | 17 ++++++++++++++--- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/mapping_provider/backends/services.py b/mapping_provider/backends/services.py index 89427a0..aabafda 100644 --- a/mapping_provider/backends/services.py +++ b/mapping_provider/backends/services.py @@ -33,15 +33,6 @@ class Service(BaseModel): endpoints: list[Endpoint] overlays: Overlays - @classmethod - def from_inprov_service(cls, service: dict[str, Any]) -> 'Service': - return cls( - sid = service['sid'], - name = service['name'], - type = service['type'], - endpoints = list(map(Endpoint.from_inprov_endpoint, service['endpoints'])), - overlays = Overlays.from_inprov_overlays(service['overlays']), - ) class ServiceList(BaseModel): services: list[Service] @@ -53,13 +44,22 @@ def _services() -> Generator[Service, None, None]: scid_current = cache.get(inventory.REPORTING_SCID_CURRENT_CACHE_FILENAME) poller_interfaces = cache.get(inventory.INPROV_POLLER_INTERFACES_CACHE_FILENAME) correlator_state = cache.get(correlator.CACHED_CORRELATOR_STATE_FILENAME) - except IOError: + except FileNotFoundError: logger.exception('not enough data available to build the service list') return - # for service in cache.get(INPROV_MAP_SERVICES_CACHE_FILENAME): - # yield Service.from_inprov_service(service) + for service in inprov_map_services: + overlays = Overlays(speed = service['overlays']['speed']) + endpoints = list(map(Endpoint.from_inprov_endpoint, service['endpoints'])) + yield Service( + sid = service['sid'], + name = service['name'], + type = service['type'], + endpoints = endpoints, + overlays = overlays, + ) + def build_service_info_list() -> ServiceList: - return ServiceList(services=[]) + return ServiceList(services=_services()) diff --git a/test/conftest.py b/test/conftest.py index 290a35d..512fb7a 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -7,7 +7,8 @@ import pytest from fastapi.testclient import TestClient from mapping_provider import create_app -from mapping_provider.backends import cache +from mapping_provider.backends import cache, inventory, correlator +from .common import load_test_data @pytest.fixture @@ -44,8 +45,18 @@ def dummy_config_filename(dummy_config): @pytest.fixture def client(dummy_config_filename): os.environ['SETTINGS_FILENAME'] = dummy_config_filename - with patch('sentry_sdk.init') as _mock_sentry_init: - return TestClient(create_app()) + + with tempfile.TemporaryDirectory() as tmp_dir: + cache.init(tmp_dir) # there's no rmq in config, so workers won't start + + 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(correlator.CACHED_CORRELATOR_STATE_FILENAME, load_test_data('correlator-state.json')) + + with patch('sentry_sdk.init') as _mock_sentry_init: + yield TestClient(create_app()) + @pytest.fixture(autouse=True) def run_around_tests(): -- GitLab