diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 9ed2eb2570682d3c257988a137a21863db0acb83..a97e4a61eaa9c0e7c87db01b83369d15830f0a65 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -609,7 +609,7 @@ def _build_interface_services(update_callback=lambda s: None): if not service_type: continue rp.set( - f'interface-services:{service_type}:' + f'interface-services:{service_type}' f':{ifc["router"]}:{ifc["interface"]}', json.dumps(ifc)) diff --git a/test/test_worker_utils.py b/test/test_worker_utils.py index e86a9af380908caeccc39d3c088c6eddf705cb4f..186f01173f18db0d1f29f4ce0f834e00618ff98e 100644 --- a/test/test_worker_utils.py +++ b/test/test_worker_utils.py @@ -4,6 +4,7 @@ tests of a few worker utilities import contextlib import json import os +import re import jsonschema @@ -30,36 +31,58 @@ def test_build_interface_services(mocked_worker_module): :return: """ - ifc_list_schema = { + # ifc_list_schema = { + # '$schema': 'http://json-schema.org/draft-07/schema#', + # + # 'definitions': { + # 'ifc-info': { + # 'type': 'object', + # 'properties': { + # 'description': {'type': 'string'}, + # 'router': {'type': 'string'}, + # 'interface': {'type': 'string'} + # }, + # 'required': ['router', 'interface', 'description'], + # 'additionalProperties': False + # }, + # }, + # + # 'type': 'array', + # 'items': { '$ref': '#/definitions/ifc-info' } + # } + + ifc_schema = { '$schema': 'http://json-schema.org/draft-07/schema#', - 'definitions': { - 'ifc-info': { - 'type': 'object', - 'properties': { - 'description': {'type': 'string'}, - 'router': {'type': 'string'}, - 'interface': {'type': 'string'} - }, - 'required': ['router', 'interface', 'description'], - 'additionalProperties': False - }, + 'type': 'object', + 'properties': { + 'description': {'type': 'string'}, + 'router': {'type': 'string'}, + 'interface': {'type': 'string'} }, - - 'type': 'array', - 'items': { '$ref': '#/definitions/ifc-info' } + 'required': ['router', 'interface', 'description'], + 'additionalProperties': False } db = backend_db() # also forces initialization worker._build_interface_services() - mdvpn = [json.loads(v) for (k, v) in db.items() - if k.startswith('interface-services:mdvpn')] - jsonschema.validate(mdvpn, ifc_list_schema) - assert mdvpn, 'expected at least one interface' + seen_types = set() + for k, v in db.items(): + if not k.startswith('interface-services:'): + continue + + (_, type, router, ifc_name) = k.split(':') + + ifc_info = json.loads(v) + jsonschema.validate(json.loads(v), ifc_schema) + + assert ifc_info['router'] == router + assert ifc_info['interface'] == ifc_name + + seen_types.add(type) - lhcone = [json.loads(v) for (k, v) in db.items() - if k.startswith('interface-services:mdvpn')] - jsonschema.validate(lhcone, ifc_list_schema) - assert lhcone, 'expected at least one interface' + assert type in ('mdvpn', 'lhcone') + expected_seen_types = set(['mdvpn', 'lhcone']) + assert seen_types == expected_seen_types