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

use netconf data for bgp route

parent 101c0336
No related branches found
No related tags found
No related merge requests found
......@@ -141,23 +141,22 @@ def bgp_configs(hostname):
r = redis.StrictRedis(
host=redis_config["hostname"],
port=redis_config["port"])
bgp_data_string = r.hget(hostname, 'bgp')
if not bgp_data_string:
netconf_string = r.hget(hostname, 'netconf')
if not netconf_string:
return Response(
response="no available bgp info for '%s'" % hostname,
response="no available info for '%s'" % hostname,
status=404,
mimetype="text/html")
routes = list(netconf.list_bgp_routes(
etree.XML(netconf_string.decode('utf-8'))))
if not routes:
return Response(
response="no interfaces found for '%s'" % hostname,
status=404,
mimetype="text/html")
def _interfaces(s):
for ifc in json.loads(s):
yield {
"description": ifc["description"][0]["data"],
"as": {
"peer": ifc["peer-as"][0]["data"],
"local": ifc["local-as"][0]["as-number"][0]["data"]
}
}
interfaces = list(_interfaces(bgp_data_string.decode('utf-8')))
return Response(
json.dumps(interfaces),
json.dumps(routes),
mimetype="application/json")
......@@ -85,27 +85,6 @@ def client_with_mocked_data(mocker, client):
return client
# def _routers(client):
# routers_list_schema = {
# "$schema": "http://json-schema.org/draft-07/schema#",
# "type": "array",
# "items": {"type": "string"}
# }
#
# rv = client.post(
# "data/routers",
# headers=DEFAULT_REQUEST_HEADERS)
# assert rv.status_code == 200
#
# response = json.loads(rv.data.decode("utf-8"))
# jsonschema.validate(response, routers_list_schema)
# return response
#
#
# def test_routers_list(client_with_mocked_data):
# assert _routers(client_with_mocked_data)
def test_router_interfaces(router, client_with_mocked_data):
interfaces_list_schema = {
......@@ -156,62 +135,58 @@ def test_snmp_ids(router, client_with_mocked_data):
assert response # at least shouldn't be empty
# def test_router_bgp_route(client_with_mocked_data):
#
# bgp_list_schema = {
# "$schema": "http://json-schema.org/draft-07/schema#",
# "type": "array",
# "items": {
# "type": "object",
# "properties": {
# "description": {"type": "string"},
# "as": {
# "type": "object",
# "properties": {
# "peer": {
# "type": "string",
# "pattern": r'^\d+$'
# },
# "local": {
# "type": "string",
# "pattern": r'^\d+$'
# },
# },
# "required": ["peer", "local"],
# "additionalProperties": False
# },
# },
# "required": ["description", "as"],
# "additionalProperties": False
# }
# }
#
# routers_with_bpg_configs = [
# "mx1.mil2.it.geant.net",
# "mx1.vie.at.geant.net",
# "mx1.fra.de.geant.net",
# "mx1.ams.nl.geant.net",
# "mx1.pra.cz.geant.net",
# "mx1.dub.ie.geant.net",
# "mx1.mad.es.geant.net",
# "mx1.gen.ch.geant.net",
# "mx1.mar.fr.geant.net",
# "mx1.lon.uk.geant.net"
# ]
#
# for router in _routers(client_with_mocked_data):
#
# if router not in routers_with_bpg_configs:
# continue
#
# rv = client_with_mocked_data.post(
# "/data/bgp/" + router,
# headers=DEFAULT_REQUEST_HEADERS)
#
# response = json.loads(rv.data.decode("utf-8"))
# jsonschema.validate(response, bgp_list_schema)
# assert response # at least shouldn't be empty
#
def test_router_bgp_routes(router, client_with_mocked_data):
ROUTERS_WITH_BGP_CONFIG = [
"mx1.bud.hu.geant.net",
"mx1.pra.cz.geant.net",
"mx1.lon.uk.geant.net",
"mx1.vie.at.geant.net",
"mx1.ams.nl.geant.net",
"mx1.fra.de.geant.net",
"mx1.gen.ch.geant.net",
"mx1.mil2.it.geant.net",
"mx1.mad.es.geant.net",
"mx1.dub.ie.geant.net",
"mx1.mar.fr.geant.net"
]
if router not in ROUTERS_WITH_BGP_CONFIG:
pytest.skip('%s is not expected to have bgp peers' % router)
return
bgp_list_schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"description": {"type": "string"},
"as": {
"type": "object",
"properties": {
"peer": {"type": "integer"},
"local": {"type": "integer"}
},
"required": ["peer", "local"],
"additionalProperties": False
},
},
"required": ["description", "as", "name"],
"additionalProperties": False
}
}
rv = client_with_mocked_data.post(
"/data/bgp/" + router,
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
response = json.loads(rv.data.decode("utf-8"))
jsonschema.validate(response, bgp_list_schema)
assert response # at least shouldn't be empty
#
# def test_router_debug_data_route(client_with_mocked_data):
# debug_data_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