From 7b4cff8a449202bfe432aa9839aaddad1ee76404 Mon Sep 17 00:00:00 2001 From: Samuel Roberts <sam.roberts@geant.org> Date: Tue, 12 Jul 2022 14:20:15 +0100 Subject: [PATCH] refactor nren-asn-map --- inventory_provider/config.py | 13 +++++++++---- inventory_provider/routes/msr.py | 4 ++-- test/conftest.py | 19 ++++++++++++++----- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/inventory_provider/config.py b/inventory_provider/config.py index 23384f92..f6762d7d 100644 --- a/inventory_provider/config.py +++ b/inventory_provider/config.py @@ -184,11 +184,16 @@ CONFIG_SCHEMA = { 'items': {'$ref': '#/definitions/gws-direct-nren-isp'} }, 'nren-asn-map': { - 'type': 'object', - 'patternProperties': { - r'^\d+$': {'type': 'string'} + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'nren': {'type': 'string'}, + 'asn': {'type': 'integer'} + }, + 'required': ['nren', 'asn'], + 'additionalProperties': False }, - 'additionalProperties': False } }, diff --git a/inventory_provider/routes/msr.py b/inventory_provider/routes/msr.py index 6e251e56..db0ad757 100644 --- a/inventory_provider/routes/msr.py +++ b/inventory_provider/routes/msr.py @@ -1057,9 +1057,9 @@ def mdvpn(): config = current_app.config['INVENTORY_PROVIDER_CONFIG'] nren_asn_map = config['nren-asn-map'] nren_details = [ - _peerings_for_nren(int(asn), + _peerings_for_nren(pair['asn'], bgplu_index, vpnrr_index) - for asn in nren_asn_map] + for pair in nren_asn_map] response = json.dumps(nren_details) return Response(response, mimetype='application/json') diff --git a/test/conftest.py b/test/conftest.py index b54d49f5..af538eb3 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -66,11 +66,20 @@ def data_config_filename(): } ], 'gws-direct': {}, - 'nren-asn-map': { - "1930": "FOO", - "680": "BAR", - "2200": "BAT" - } + 'nren-asn-map': [ + { + "nren": "FOO", + "asn": 1930 + }, + { + "nren": "BAR", + "asn": 680 + }, + { + "nren": "BAT", + "asn": 2200 + } + ] } with open(os.path.join(TEST_DATA_DIRNAME, 'gws-direct.json')) as gws: -- GitLab