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

Finished feature bgp-peer-classifier-route.

parents a43af72b 3d05d984
No related branches found
No related tags found
No related merge requests found
......@@ -355,7 +355,7 @@ Any non-empty responses are JSON formatted messages.
alarms database
* /classifier/*`type`*/*`source-equipment`*/*`source-interface`*
* /classifier/trap-metadata/*`source-equipment`*/*`source-interface`*
The source-equipment is the equipment that causes the trap, not the NMS that
sends it.
......@@ -369,6 +369,71 @@ Any non-empty responses are JSON formatted messages.
}
```
* /classifier/peer-info/*`address`*
The `address` parameter should be the ip address of
a remote peer. If this address is found in the system
then information about the interface is returned, otherwise
404 is returned.
The resp onse will be formatted according to the following syntax:
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"definitions": {
"ip-address": {
"type": "string",
"oneOf": [
{"pattern": r'^(\d+\.){3}\d+$'},
{"pattern": r'^([a-f\d]{4}:){7}[a-f\d]{4}$'}
]
},
"vpn-rr-peer": {
"type": "object",
"properties": {
"name": {"$ref": "#/definitions/ip-address"},
"description": {"type": "string"},
"peer-as": {"type": "integer"},
"router": {"type": "string"}
},
"required": ["name", "description"],
"additionalProperties": False
},
"ix-public-peer": {
"type": "object",
"properties": {
"name": {"$ref": "#/definitions/ip-address"},
"description": {"type": "string"},
"router": {"type": "string"},
"as": {
"type": "object",
"properties": {
"local": {"type": "integer"},
"peer": {"type": "integer"},
},
"required": ["local", "peer"],
"additionalProperties": False
}
},
"required": ["name", "description", "as"],
"additionalProperties": False
}
},
"type": "object",
"properties": {
"ix-public-peer-info": {"$ref": "#/definitions/ix-public-peer"},
"vpn-rr-peer-info": {"$ref": "#/definitions/vpn-rr-peer"}
},
"additionalProperties": False
}
```
* /poller/interfaces/*`hostname`*
The response will be the list of active interfaces on the
......@@ -724,7 +789,7 @@ was started with the `ENABLE_TESTING_ROUTES` flag.
* `vpn_rr_peers/<address>`
* key examples
* `ix_public_peer:193.203.0.203`
* `vpn_rr_peers:193.203.0.203`
* valid values:
```json
{
......
import json
from flask import Blueprint, Response
from flask import Blueprint, Response, jsonify
from inventory_provider.routes import common
......@@ -43,3 +43,30 @@ def get_trap_metadata(source_equipment, interface):
r.set(cache_key, result.encode('utf-8'))
return Response(result, mimetype="application/json")
@routes.route("/peer-info/<address>", methods=['GET', 'POST'])
@common.require_accepts_json
def peer_info(address):
r = common.get_redis()
result = {}
info = r.get('ix_public_peer:%s' % address)
if info:
info = info.decode('utf-8')
result['ix-public-peer-info'] = json.loads(info)
info = r.get('vpn_rr_peer:%s' % address)
if info:
info = info.decode('utf-8')
result['vpn-rr-peer-info'] = json.loads(info)
if not result:
return Response(
response='no peering info found for %s' % address,
status=404,
mimetype="text/html")
return jsonify(result)
import json
import jsonschema
import pytest
DEFAULT_REQUEST_HEADERS = {
"Content-type": "application/json",
......@@ -19,3 +20,86 @@ def test_trap_metadata(client_with_mocked_data):
assert rv.is_json
response_data = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(response_data, response_schema)
@pytest.mark.parametrize("peer_address,peer_type", [
('109.105.110.54', 'vpn-rr-peer-info'),
('2001:07f8:001c:024a:0000:0000:316e:0001', 'ix-public-peer-info'),
('2001:07f8:000b:0100:01d1:a5d1:0310:0029', 'ix-public-peer-info'),
('195.66.224.238', 'ix-public-peer-info'),
]
)
def test_peer_info(client_with_mocked_data, peer_address, peer_type):
response_schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"definitions": {
"ip-address": {
"type": "string",
"oneOf": [
{"pattern": r'^(\d+\.){3}\d+$'},
{"pattern": r'^([a-f\d]{4}:){7}[a-f\d]{4}$'}
]
},
"vpn-rr-peer": {
"type": "object",
"properties": {
"name": {"$ref": "#/definitions/ip-address"},
"description": {"type": "string"},
"peer-as": {"type": "integer"},
"router": {"type": "string"}
},
"required": ["name", "description"],
"additionalProperties": False
},
"ix-public-peer": {
"type": "object",
"properties": {
"name": {"$ref": "#/definitions/ip-address"},
"description": {"type": "string"},
"router": {"type": "string"},
"as": {
"type": "object",
"properties": {
"local": {"type": "integer"},
"peer": {"type": "integer"},
},
"required": ["local", "peer"],
"additionalProperties": False
}
},
"required": ["name", "description", "as"],
"additionalProperties": False
}
},
"type": "object",
"properties": {
"ix-public-peer-info": {"$ref": "#/definitions/ix-public-peer"},
"vpn-rr-peer-info": {"$ref": "#/definitions/vpn-rr-peer"}
},
"additionalProperties": False
}
rv = client_with_mocked_data.get(
'/classifier/peer-info/%s' % peer_address,
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
response_data = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(response_data, response_schema)
assert len(response_data) == 1, \
"peer should be only vpn-rr or ix-public, not both"
assert peer_type in response_data
def test_peer_not_found(client_with_mocked_data):
rv = client_with_mocked_data.get(
'/classifier/peer-info/1.2.3.4.5',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 404
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment