From 876651cc1c50a723ae1b16a33de691d2efc41285 Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Mon, 7 Dec 2020 19:13:31 +0100 Subject: [PATCH] update visibility per LGR-73 --- inventory_provider/db/opsdb.py | 20 +++++++++++++------- test/test_opsdb_queries.py | 10 ++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/inventory_provider/db/opsdb.py b/inventory_provider/db/opsdb.py index 07a24e27..579a8c66 100644 --- a/inventory_provider/db/opsdb.py +++ b/inventory_provider/db/opsdb.py @@ -400,27 +400,33 @@ SELECT g.longitude AS pop_longitude, p.country_code AS pop_country_code, g.country AS pop_country, - g.city AS pop_city + e.model AS equipment_model FROM opsdb.equipment e LEFT JOIN opsdb.pop p ON p.absid = e.PTR_pop LEFT JOIN opsdb.geocoding g ON g.absid = p.PTR_geocoding LEFT JOIN opsdb.organisation o ON o.absid = e.PTR_owner WHERE - e.model LIKE 'mx%' + e.manufacturer = 'Juniper' AND e.status = 'Operational' AND o.name = 'DANTE / GEANT' AND NOT (e.name REGEXP 'vpn-proxy|vrr|taas') """ + def _public(row): + if row['pop_name'] in INTERNAL_POP_NAMES: + return False + if row['router_name'].startswith('sw'): + return False + if row['pop_city'].lower() == 'slough' \ + and row['equipment_model'].upper().startswith('MX'): + return False + return True + def _row2rsp(row): - print(row) return { 'equipment name': row['router_name'], - 'type': - 'INTERNAL' - if row['pop_name'] in INTERNAL_POP_NAMES - else 'CORE', + 'type': 'CORE' if _public(row) else 'INTERNAL', 'pop': { 'name': row['pop_name'], 'city': row['pop_city'], diff --git a/test/test_opsdb_queries.py b/test/test_opsdb_queries.py index e3d0bc56..eb347d9f 100644 --- a/test/test_opsdb_queries.py +++ b/test/test_opsdb_queries.py @@ -281,6 +281,16 @@ def test_lookup_lg_routers(connection, cached_test_data): jsonschema.validate(routers, LG_ROUTERS_SCHEMA) assert routers # shouldn't be empty + # LGR-73 + assert any( + r['equipment name'].startswith('sw2.am.office') for r in routers) + assert any( + r['equipment name'].startswith('sw3.am.office') for r in routers) + + switches = filter( + lambda r: r['equipment name'].startswith('sw'), routers) + assert all(s['type'] == 'INTERNAL' for s in switches) + CIRCUIT_INFO_SCHEMA = { "$schema": "http://json-schema.org/draft-07/schema#", -- GitLab