Skip to content
Snippets Groups Projects
Commit 4cffd4c4 authored by Robert Latta's avatar Robert Latta
Browse files

Merge branch 'develop' of...

Merge branch 'develop' of gitlab.geant.net:live-projects/dashboardv3/inventory-provider into develop
parents c3a71b48 2ed4f945
No related branches found
No related tags found
No related merge requests found
...@@ -109,6 +109,64 @@ UNIT_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?> ...@@ -109,6 +109,64 @@ UNIT_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
</xs:schema> </xs:schema>
""" # noqa: E501 """ # noqa: E501
PEERING_LIST_SCHEMA = {
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"top-level-peering": {
"type": "object",
"properties": {
"group": {"type": "string"},
"description": {"type": "string"},
"address": {"type": "string"},
"remote-asn": {"type": "integer"},
"local-asn": {"type": "integer"}
},
# lots of internal peerings - so maybe no explicit asn's
"required": ["group", "address"],
"additionalProperties": False
},
"instance-peering": {
"type": "object",
"properties": {
"instance": {"type": "string"},
"group": {"type": "string"},
"description": {"type": "string"},
"address": {"type": "string"},
"remote-asn": {"type": "integer"},
"local-asn": {"type": "integer"},
},
# description and-or local-asn is not always present,
# just based on empirical tests - not a problem
"required": ["instance", "group", "address", "remote-asn"],
"additionalProperties": False
},
"logical-system-peering": {
"type": "object",
"properties": {
"logical-system": {"type": "string"},
"group": {"type": "string"},
"description": {"type": "string"},
"address": {"type": "string"},
"remote-asn": {"type": "integer"},
"local-asn": {"type": "integer"}
},
# local/remote-asn and/or description are not always present,
# just based on empirical tests - not a problem
"required": ["logical-system", "group", "address"],
"additionalProperties": False
},
"peering": {
"oneOf": [
{"$ref": "#/definitions/top-level-peering"},
{"$ref": "#/definitions/instance-peering"},
{"$ref": "#/definitions/logical-system-peering"}
]
}
},
"type": "array",
"items": {"$ref": "#/definitions/peering"}
}
class NetconfHandlingError(Exception): class NetconfHandlingError(Exception):
pass pass
...@@ -248,6 +306,13 @@ def all_bgp_peers(netconf_config): ...@@ -248,6 +306,13 @@ def all_bgp_peers(netconf_config):
info['description'] = description.text info['description'] = description.text
return info return info
for group in netconf_config.xpath('//configuration/protocols/bgp/group'):
group_name = group.find('name').text
for neighbor in group.xpath('./neighbor'):
peer = _peering_params(neighbor)
peer['group'] = group_name
yield peer
for instance in netconf_config.xpath( for instance in netconf_config.xpath(
'//configuration/routing-instances/instance'): '//configuration/routing-instances/instance'):
instance_name = instance.find('name').text instance_name = instance.find('name').text
......
import json import json
import pytest import pytest
import jsonschema import jsonschema
from inventory_provider.juniper import PEERING_LIST_SCHEMA
DEFAULT_REQUEST_HEADERS = { DEFAULT_REQUEST_HEADERS = {
"Content-type": "application/json", "Content-type": "application/json",
...@@ -82,55 +83,11 @@ def test_router_bgp_routes(router, client): ...@@ -82,55 +83,11 @@ def test_router_bgp_routes(router, client):
pytest.skip('%s is not expected to have bgp peers' % router) pytest.skip('%s is not expected to have bgp peers' % router)
return return
bgp_list_schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"instance-peering": {
"type": "object",
"properties": {
"instance": {"type": "string"},
"group": {"type": "string"},
"description": {"type": "string"},
"address": {"type": "string"},
"remote-asn": {"type": "integer"},
"local-asn": {"type": "integer"}
},
# description and-or local-asn is not always present,
# just based on empirical tests - not a problem
"required": ["instance", "group", "address", "remote-asn"],
"additionalProperties": False
},
"logical-system-peering": {
"type": "object",
"properties": {
"logical-system": {"type": "string"},
"group": {"type": "string"},
"description": {"type": "string"},
"address": {"type": "string"},
"remote-asn": {"type": "integer"},
"local-asn": {"type": "integer"}
},
# local/remote-asn and/or description are not always present,
# just based on empirical tests - not a problem
"required": ["logical-system", "group", "address"],
"additionalProperties": False
},
"peering": {
"oneOf": [
{"$ref": "#/definitions/instance-peering"},
{"$ref": "#/definitions/logical-system-peering"}
]
}
},
"type": "array",
"items": {"$ref": "#/definitions/peering"}
}
rv = client.post( rv = client.post(
"/testing/bgp/" + router, "/testing/bgp/" + router,
headers=DEFAULT_REQUEST_HEADERS) headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200 assert rv.status_code == 200
response = json.loads(rv.data.decode("utf-8")) response = json.loads(rv.data.decode("utf-8"))
jsonschema.validate(response, bgp_list_schema) jsonschema.validate(response, PEERING_LIST_SCHEMA)
assert response # at least shouldn't be empty assert response # at least shouldn't be empty
...@@ -38,52 +38,8 @@ def test_interface_list(netconf_doc): ...@@ -38,52 +38,8 @@ def test_interface_list(netconf_doc):
def test_bgp_peering_data(netconf_doc): def test_bgp_peering_data(netconf_doc):
schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"instance-peering": {
"type": "object",
"properties": {
"instance": {"type": "string"},
"group": {"type": "string"},
"description": {"type": "string"},
"address": {"type": "string"},
"remote-asn": {"type": "integer"},
"local-asn": {"type": "integer"}
},
# description and-or local-asn is not always present,
# just based on empirical tests - not a problem
"required": ["instance", "group", "address", "remote-asn"],
"additionalProperties": False
},
"logical-system-peering": {
"type": "object",
"properties": {
"logical-system": {"type": "string"},
"group": {"type": "string"},
"description": {"type": "string"},
"address": {"type": "string"},
"remote-asn": {"type": "integer"},
"local-asn": {"type": "integer"}
},
# local/remote-asn and/or description are not always present,
# just based on empirical tests - not a problem
"required": ["logical-system", "group", "address"],
"additionalProperties": False
},
"peering": {
"oneOf": [
{"$ref": "#/definitions/instance-peering"},
{"$ref": "#/definitions/logical-system-peering"}
]
}
},
"type": "array",
"items": {"$ref": "#/definitions/peering"}
}
peerings = list(juniper.all_bgp_peers(netconf_doc)) peerings = list(juniper.all_bgp_peers(netconf_doc))
jsonschema.validate(peerings, schema) jsonschema.validate(peerings, juniper.PEERING_LIST_SCHEMA)
assert peerings # there's always at least one assert peerings # there's always at least one
# confirm the addresses are in canonical (exploded) form # confirm the addresses are in canonical (exploded) form
......
...@@ -88,9 +88,26 @@ def test_build_juniper_peering_db(mocked_worker_module): ...@@ -88,9 +88,26 @@ def test_build_juniper_peering_db(mocked_worker_module):
:param mocked_worker_module: fixture :param mocked_worker_module: fixture
""" """
peering_list_schema = { # same as inventory_provider.juniper.PEERING_LIST_SCHEMA,
# but with "hostname" in every returned record
PEERING_LIST_SCHEMA = {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"definitions": { "definitions": {
"top-level-peering": {
"type": "object",
"properties": {
"group": {"type": "string"},
"description": {"type": "string"},
"address": {"type": "string"},
"remote-asn": {"type": "integer"},
"local-asn": {"type": "integer"},
"hostname": {"type": "string"}
},
# lots of internal peerings - so maybe no explicit asn's
"required": ["group", "address"],
"additionalProperties": False
},
"instance-peering": { "instance-peering": {
"type": "object", "type": "object",
"properties": { "properties": {
...@@ -104,9 +121,7 @@ def test_build_juniper_peering_db(mocked_worker_module): ...@@ -104,9 +121,7 @@ def test_build_juniper_peering_db(mocked_worker_module):
}, },
# description and-or local-asn is not always present, # description and-or local-asn is not always present,
# just based on empirical tests - not a problem # just based on empirical tests - not a problem
"required": ["instance", "group", "required": ["instance", "group", "address", "remote-asn"],
"address", "remote-asn",
"hostname"],
"additionalProperties": False "additionalProperties": False
}, },
"logical-system-peering": { "logical-system-peering": {
...@@ -122,11 +137,12 @@ def test_build_juniper_peering_db(mocked_worker_module): ...@@ -122,11 +137,12 @@ def test_build_juniper_peering_db(mocked_worker_module):
}, },
# local/remote-asn and/or description are not always present, # local/remote-asn and/or description are not always present,
# just based on empirical tests - not a problem # just based on empirical tests - not a problem
"required": ["logical-system", "group", "address", "hostname"], "required": ["logical-system", "group", "address"],
"additionalProperties": False "additionalProperties": False
}, },
"peering": { "peering": {
"oneOf": [ "oneOf": [
{"$ref": "#/definitions/top-level-peering"},
{"$ref": "#/definitions/instance-peering"}, {"$ref": "#/definitions/instance-peering"},
{"$ref": "#/definitions/logical-system-peering"} {"$ref": "#/definitions/logical-system-peering"}
] ]
...@@ -167,7 +183,7 @@ def test_build_juniper_peering_db(mocked_worker_module): ...@@ -167,7 +183,7 @@ def test_build_juniper_peering_db(mocked_worker_module):
assert address == canonical assert address == canonical
continue continue
jsonschema.validate(value, peering_list_schema) jsonschema.validate(value, PEERING_LIST_SCHEMA)
assert found_record assert found_record
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment