From 776acc2551d8f24bcdddb3ac1a4a6c922aca0390 Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Thu, 12 Dec 2019 15:12:59 +0100 Subject: [PATCH] load customers for all cached interfaces --- test/test_opsdb_queries.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/test/test_opsdb_queries.py b/test/test_opsdb_queries.py index 7ef564c2..1282def5 100644 --- a/test/test_opsdb_queries.py +++ b/test/test_opsdb_queries.py @@ -1,7 +1,8 @@ +import json import os -import pytest import jsonschema +import pytest from inventory_provider.db import db from inventory_provider.db import opsdb @@ -191,3 +192,35 @@ def test_get_service_users(connection): users = list(users) jsonschema.validate(users, schema) assert users + + + +def test_get_all_service_users(connection, cached_test_data): + + def _all_interfaces(): + for k in cached_test_data.keys(): + if not k.startswith('netconf-interfaces:'): + continue + (_, hostname, ifc_name) = k.split(':') + yield {'hostname': hostname, 'interface': ifc_name} + + def _all_service_ids(interfaces): + for ifc in interfaces: + key = ('opsdb:interface_services' + f':{ifc["hostname"]}:{ifc["interface"]}') + if key not in cached_test_data: + print(f'warning: {key} not found in cached test data') + continue + for service in json.loads(cached_test_data[key]): + info = {'service_id': service['id']} + info.update(ifc) + yield info + + ids = {s['service_id'] for s in _all_service_ids(_all_interfaces())} + assert len(ids) > 0 + # + # services = {} + # for user in opsdb.get_service_users(connection, list(ids)): + # services.setdefault(user['service_id'], []).append(user['user']) + # + # print([f'{k}: {v}' for k, v in services.items() if len(v) > 1]) -- GitLab