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

parse bgp info from netconf data

parent fe29ccd3
No related branches found
No related tags found
No related merge requests found
......@@ -157,3 +157,24 @@ def list_interfaces(netconf_config):
unit_info['name'] = "%s.%s" % (info['name'], unit_info['name'])
yield unit_info
def list_bgp_routes(netconf_config):
for r in netconf_config.xpath(
'//configuration/routing-instances/'
'instance[name/text()="IAS"]/protocols/bgp/'
'group[starts-with(name/text(), "GEANT-IX")]/'
'neighbor'):
name = r.find('name')
description = r.find('description')
local_as = r.find('local-as')
if local_as:
local_as = local_as.find('as-number')
peer_as = r.find('peer-as')
yield {
'name': name.text,
'description': description.text,
'as': {
'local': int(local_as.text),
'peer': int(peer_as.text)
}
}
......@@ -35,7 +35,28 @@ def netconf_doc(mocker, router, data_config):
return netconf.load_config(router, data_config['ssh'])
def test_query_doc_and_validate(netconf_doc):
# def test_interface_list(netconf_doc):
#
# schema = {
# "$schema": "http://json-schema.org/draft-07/schema#",
# "type": "array",
# "items": {
# "type": "object",
# "properties": {
# "name": {"type": "string"},
# "description": {"type": "string"}
# },
# "required": ["name", "description"],
# "additionalProperties": False
# }
# }
#
# interfaces = list(netconf.list_interfaces(netconf_doc))
# jsonschema.validate(interfaces, schema)
# assert interfaces # at least shouldn't be empty
def test_bgp_list(netconf_doc):
schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
......@@ -44,16 +65,22 @@ def test_query_doc_and_validate(netconf_doc):
"type": "object",
"properties": {
"name": {"type": "string"},
"description": {"type": "string"}
"description": {"type": "string"},
"as": {
"type": "object",
"properties": {
"local": {"type": "integer"},
"peer": {"type": "integer"},
},
"required": ["local", "peer"],
"additionalProperties": False
}
},
"required": ["name", "description"],
"required": ["name", "description", "as"],
"additionalProperties": False
}
}
interfaces = list(netconf.list_interfaces(netconf_doc))
jsonschema.validate(interfaces, schema)
assert interfaces # at least shouldn't be empty
routes = list(netconf.list_bgp_routes(netconf_doc))
jsonschema.validate(routes, schema)
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