From 4821b780edf33dc5cc6241257244c4faa3698e10 Mon Sep 17 00:00:00 2001 From: Robert Latta <robert.latta@geant.org> Date: Fri, 12 Feb 2021 13:43:49 +0000 Subject: [PATCH] added all circuits to cache --- inventory_provider/db/ims_data.py | 39 +++++++------------------------ test/test_ims_data.py | 18 ++++---------- 2 files changed, 13 insertions(+), 44 deletions(-) diff --git a/inventory_provider/db/ims_data.py b/inventory_provider/db/ims_data.py index 77614dc3..c0fcc045 100644 --- a/inventory_provider/db/ims_data.py +++ b/inventory_provider/db/ims_data.py @@ -73,19 +73,6 @@ def get_fibre_info(ds: IMS): def get_port_id_services(ds: IMS): - # this is the only place that speeds are used, - # products are used else where to define services, so a relevant list of - # products has been moved to the ims module as IMS_SERVICE_NAMES - # The products here are all the products we need to be able to build map - # ports to services - products = copy(IMS_SERVICE_NAMES) - products.add('ETHERNET') - speeds = { - 'L3VPN', - 'LAG', - 'FIBRE_ROUTE', - # 'BGP', - } circuit_nav_props = [ ims.CIRCUIT_PROPERTIES['Customer'], ims.CIRCUIT_PROPERTIES['Speed'], @@ -95,26 +82,16 @@ def get_port_id_services(ds: IMS): ] def _get_circuits(): - for st in products: - for c in ds.get_filtered_entities( - 'Circuit', - f'product.name == "{st}"', - circuit_nav_props, - step_count=2000): - if c['product']['name'] in IMS_SERVICE_NAMES: - c['circuit_type'] = 'service' - else: - c['circuit_type'] = 'circuit' - yield c - for spd in speeds: - for c in ds.get_filtered_entities( - 'Circuit', - f'speed.name == "{spd}"', - circuit_nav_props, - step_count=2000): + for c in ds.get_all_entities( + 'Circuit', + circuit_nav_props, + step_count=2000): + if c['product']['name'] in IMS_SERVICE_NAMES: + c['circuit_type'] = 'service' + else: c['circuit_type'] = 'circuit' - yield c + yield c circuits = _get_circuits() diff --git a/test/test_ims_data.py b/test/test_ims_data.py index 29e67e0c..a774ad38 100644 --- a/test/test_ims_data.py +++ b/test/test_ims_data.py @@ -101,21 +101,13 @@ def test_get_port_details(mocker): def test_get_port_id_services(mocker): - called = False - - def _se(a, b, c, step_count): - nonlocal called - if called: - return {} - else: - called = True - with open('test/data/ims_port_id_services_data.json') as data: - return json.load(data) + with open('test/data/ims_port_id_services_data.json') as data: + d = json.load(data) mocker.patch.object( inventory_provider.db.ims.IMS, - 'get_filtered_entities', - side_effect=_se + 'get_all_entities', + side_effect=[d] ) ds = inventory_provider.db.ims.IMS( @@ -125,7 +117,7 @@ def test_get_port_id_services(mocker): # this is the number of different product types that are considered service # and speed types that that cover circuit types that have relevant circuits # and ethernet product type as other relevant circuits also need tracking - assert ds.get_filtered_entities.call_count == 20 + assert ds.get_all_entities.call_count == 1 predicted = [ { 'id': 663060, -- GitLab