Skip to content
Snippets Groups Projects
Commit 776acc25 authored by Erik Reid's avatar Erik Reid
Browse files

load customers for all cached interfaces

parent 728465bc
No related branches found
No related tags found
No related merge requests found
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])
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