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

added additional tests for logical-system & group peerings

parent 3771f48d
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,30 @@ ACCESS_SERVICES_LIST_SCHEMA = { ...@@ -38,6 +38,30 @@ ACCESS_SERVICES_LIST_SCHEMA = {
} }
LOGICAL_SYSTEM_PEERING_LIST_SCHEMA = {
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"peering-instance": {
"type": "object",
"properties": {
"address": {"type": "string"},
"description": {"type": "string"},
"logical-system": {"type": "string"},
"group": {"type": "string"},
"hostname": {"type": "string"},
"remote-asn": {"type": "integer"}
},
# only vrr peerings have remote-asn
"required": [
"address", "description", "logical-system", "group", "hostname"],
"additionalProperties": False
}
},
"type": "array",
"items": {"$ref": "#/definitions/peering-instance"}
}
@routes.after_request @routes.after_request
def after_request(resp): def after_request(resp):
return common.after_request(resp) return common.after_request(resp)
...@@ -82,3 +106,45 @@ def access_services(): ...@@ -82,3 +106,45 @@ def access_services():
mimetype="text/html") mimetype="text/html")
return jsonify(result) return jsonify(result)
@routes.route("/logical-system-peerings", methods=['GET', 'POST'])
@routes.route("/logical-system-peerings/<name>", methods=['GET', 'POST'])
@common.require_accepts_json
def access_services():
"""
Handler for `/msr/access-services`.
This method is in development, not yet used.
The response will be formatted according to the following schema:
.. asjson::
inventory_provider.routes.msr.ACCESS_SERVICES_LIST_SCHEMA
:return:
"""
redis = common.get_current_redis()
def _services():
for k in redis.scan_iter('opsdb:access_services:*'):
service = redis.get(k.decode('utf-8')).decode('utf-8')
yield json.loads(service)
cache_key = 'classifier-cache:msr:access-services'
result = redis.get(cache_key)
if result:
result = json.loads(result.decode('utf-8'))
else:
result = list(_services())
# cache this data for the next call
redis.set(cache_key, json.dumps(result).encode('utf-8'))
if not result:
return Response(
response='no access services found',
status=404,
mimetype="text/html")
return jsonify(result)
...@@ -9,6 +9,7 @@ import jsonschema ...@@ -9,6 +9,7 @@ import jsonschema
from inventory_provider.tasks import worker from inventory_provider.tasks import worker
from inventory_provider.tasks import common from inventory_provider.tasks import common
from inventory_provider.routes.msr import LOGICAL_SYSTEM_PEERING_LIST_SCHEMA
def backend_db(): def backend_db():
...@@ -175,6 +176,8 @@ def test_build_juniper_peering_db(mocked_worker_module): ...@@ -175,6 +176,8 @@ def test_build_juniper_peering_db(mocked_worker_module):
worker._build_juniper_peering_db() worker._build_juniper_peering_db()
found_record = False found_record = False
found_logical_system = False
found_group = False
for key, value in db.items(): for key, value in db.items():
if not _x(key): if not _x(key):
...@@ -193,7 +196,20 @@ def test_build_juniper_peering_db(mocked_worker_module): ...@@ -193,7 +196,20 @@ def test_build_juniper_peering_db(mocked_worker_module):
jsonschema.validate(value, PEERING_LIST_SCHEMA) jsonschema.validate(value, PEERING_LIST_SCHEMA)
if 'logical-system:' in key:
jsonschema.validate(value, LOGICAL_SYSTEM_PEERING_LIST_SCHEMA)
m = re.match(r'.*logical-system:(.+)$', key)
assert all(p['logical-system'] == m.group(1) for p in value)
found_logical_system = True
if 'group:' in key:
m = re.match(r'.*group:(.+)$', key)
assert all(p['group'] == m.group(1) for p in value)
found_group = True
assert found_record assert found_record
assert found_logical_system
assert found_group
def test_build_snmp_peering_db(mocked_worker_module): def test_build_snmp_peering_db(mocked_worker_module):
......
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