Skip to content
Snippets Groups Projects
Commit 23f081b7 authored by Release Webservice's avatar Release Webservice
Browse files

Finished release 0.55.

parents f42836f6 084af737
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## [0.55] - 2020-12-08
- LGR-73: updated business logic for classifying LG routers public/internal
## [0.54] - 2020-10-07 ## [0.54] - 2020-10-07
- DBOARD3-334: peer-info classifier performance improvement - DBOARD3-334: peer-info classifier performance improvement
......
...@@ -400,27 +400,40 @@ SELECT ...@@ -400,27 +400,40 @@ SELECT
g.longitude AS pop_longitude, g.longitude AS pop_longitude,
p.country_code AS pop_country_code, p.country_code AS pop_country_code,
g.country AS pop_country, g.country AS pop_country,
g.city AS pop_city e.model AS equipment_model
FROM FROM
opsdb.equipment e opsdb.equipment e
LEFT JOIN opsdb.pop p ON p.absid = e.PTR_pop 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.geocoding g ON g.absid = p.PTR_geocoding
LEFT JOIN opsdb.organisation o ON o.absid = e.PTR_owner LEFT JOIN opsdb.organisation o ON o.absid = e.PTR_owner
WHERE WHERE
e.model LIKE 'mx%' e.manufacturer = 'Juniper'
AND e.status = 'Operational' AND e.status = 'Operational'
AND o.name = 'DANTE / GEANT' AND o.name = 'DANTE / GEANT'
AND NOT (e.name REGEXP 'vpn-proxy|vrr|taas') AND NOT (e.name REGEXP 'vpn-proxy|vrr|taas|junosspace')
""" """
def _public(row):
# cf. LGR-73
if row['pop_name'] in INTERNAL_POP_NAMES:
return False
router_name_lower = row['router_name'].lower()
if any(router_name_lower.startswith(prefix)
for prefix in ['srx', 'gts', 'sw', 'qfx']):
return False
if row['pop_city'].lower() == 'slough' \
and not row['equipment_model'].upper().startswith('MX'):
return False
return True
def _row2rsp(row): def _row2rsp(row):
print(row)
return { return {
'equipment name': row['router_name'], 'equipment name': row['router_name'],
'type': 'type': 'CORE' if _public(row) else 'INTERNAL',
'INTERNAL'
if row['pop_name'] in INTERNAL_POP_NAMES
else 'CORE',
'pop': { 'pop': {
'name': row['pop_name'], 'name': row['pop_name'],
'city': row['pop_city'], 'city': row['pop_city'],
......
import json import json
from flask import Blueprint, jsonify, Response from flask import Blueprint, jsonify, Response, current_app
from inventory_provider.routes import common from inventory_provider.routes import common
...@@ -25,29 +25,25 @@ def routers(access): ...@@ -25,29 +25,25 @@ def routers(access):
status=404, status=404,
mimetype='text/html') mimetype='text/html')
redis = common.get_current_redis()
def _visible(router): def _visible(router):
if access == ACCESS_INTERNAL: if access == ACCESS_INTERNAL:
return True return True
return router['type'] == 'CORE' return router['type'] == 'CORE'
def _routers(): def _routers():
i = 0 for doc in common.load_json_docs(
for k in redis.scan_iter('opsdb:lg:*'): config_params=current_app.config['INVENTORY_PROVIDER_CONFIG'],
rtr = redis.get(k.decode('utf-8')).decode('utf-8') key_pattern='opsdb:lg:*'):
rtr = json.loads(rtr) yield doc['value']
i += 1
if _visible(rtr):
yield rtr
redis = common.get_current_redis()
cache_key = f'classifier-cache:lg:{access}' cache_key = f'classifier-cache:lg:{access}'
result = redis.get(cache_key) result = redis.get(cache_key)
if result: if result:
result = json.loads(result.decode('utf-8')) result = json.loads(result.decode('utf-8'))
else: else:
result = list(_routers()) result = list(filter(_visible, _routers()))
# cache this data for the next call # cache this data for the next call
redis.set(cache_key, json.dumps(result).encode('utf-8')) redis.set(cache_key, json.dumps(result).encode('utf-8'))
......
...@@ -2,7 +2,7 @@ from setuptools import setup, find_packages ...@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup( setup(
name='inventory-provider', name='inventory-provider',
version="0.54", version="0.55",
author='GEANT', author='GEANT',
author_email='swd@geant.org', author_email='swd@geant.org',
description='Dashboard inventory provider', description='Dashboard inventory provider',
......
...@@ -281,6 +281,26 @@ def test_lookup_lg_routers(connection, cached_test_data): ...@@ -281,6 +281,26 @@ def test_lookup_lg_routers(connection, cached_test_data):
jsonschema.validate(routers, LG_ROUTERS_SCHEMA) jsonschema.validate(routers, LG_ROUTERS_SCHEMA)
assert routers # shouldn't be empty 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)
assert not any(
r['equipment name'].lower().startswith('junosspace') for r in routers)
internal_prefix_patterns = ['srx', 'gts', 'qfx']
for prefix in internal_prefix_patterns:
filtered = filter(
lambda r: r['equipment name'].lower().startswith(prefix), routers)
assert all(r['type'] == 'INTERNAL' for r in filtered), \
f'not all {prefix}* routers are INTERNAL'
CIRCUIT_INFO_SCHEMA = { CIRCUIT_INFO_SCHEMA = {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
......
...@@ -11,7 +11,7 @@ deps = ...@@ -11,7 +11,7 @@ deps =
commands = commands =
coverage erase coverage erase
coverage run --source inventory_provider -m py.test {posargs} coverage run --source inventory_provider --omit='inventory_provider/routes/ims*,inventory_provider/db/ims*,inventory_provider/tasks/ims*' -m py.test {posargs}
coverage xml coverage xml
coverage html coverage html
coverage report --fail-under 75 coverage report --fail-under 75
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment