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

better test and bugfix

parent 5b8ef6cf
No related branches found
No related tags found
No related merge requests found
......@@ -609,7 +609,7 @@ def _build_interface_services(update_callback=lambda s: None):
if not service_type:
continue
rp.set(
f'interface-services:{service_type}:'
f'interface-services:{service_type}'
f':{ifc["router"]}:{ifc["interface"]}',
json.dumps(ifc))
......
......@@ -4,6 +4,7 @@ tests of a few worker utilities
import contextlib
import json
import os
import re
import jsonschema
......@@ -30,36 +31,58 @@ def test_build_interface_services(mocked_worker_module):
:return:
"""
ifc_list_schema = {
# ifc_list_schema = {
# '$schema': 'http://json-schema.org/draft-07/schema#',
#
# 'definitions': {
# 'ifc-info': {
# 'type': 'object',
# 'properties': {
# 'description': {'type': 'string'},
# 'router': {'type': 'string'},
# 'interface': {'type': 'string'}
# },
# 'required': ['router', 'interface', 'description'],
# 'additionalProperties': False
# },
# },
#
# 'type': 'array',
# 'items': { '$ref': '#/definitions/ifc-info' }
# }
ifc_schema = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'ifc-info': {
'type': 'object',
'properties': {
'description': {'type': 'string'},
'router': {'type': 'string'},
'interface': {'type': 'string'}
},
'required': ['router', 'interface', 'description'],
'additionalProperties': False
},
'type': 'object',
'properties': {
'description': {'type': 'string'},
'router': {'type': 'string'},
'interface': {'type': 'string'}
},
'type': 'array',
'items': { '$ref': '#/definitions/ifc-info' }
'required': ['router', 'interface', 'description'],
'additionalProperties': False
}
db = backend_db() # also forces initialization
worker._build_interface_services()
mdvpn = [json.loads(v) for (k, v) in db.items()
if k.startswith('interface-services:mdvpn')]
jsonschema.validate(mdvpn, ifc_list_schema)
assert mdvpn, 'expected at least one interface'
seen_types = set()
for k, v in db.items():
if not k.startswith('interface-services:'):
continue
(_, type, router, ifc_name) = k.split(':')
ifc_info = json.loads(v)
jsonschema.validate(json.loads(v), ifc_schema)
assert ifc_info['router'] == router
assert ifc_info['interface'] == ifc_name
seen_types.add(type)
lhcone = [json.loads(v) for (k, v) in db.items()
if k.startswith('interface-services:mdvpn')]
jsonschema.validate(lhcone, ifc_list_schema)
assert lhcone, 'expected at least one interface'
assert type in ('mdvpn', 'lhcone')
expected_seen_types = set(['mdvpn', 'lhcone'])
assert seen_types == expected_seen_types
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