import json import pytest import jsonschema DEFAULT_REQUEST_HEADERS = { "Content-type": "application/json", "Accept": ["application/json"] } def test_router_interfaces(router, client): interfaces_list_schema = { "$schema": "http://json-schema.org/draft-07/schema#", "type": "array", "items": { "type": "object", "properties": { "name": {"type": "string"}, "description": {"type": "string"}, "router": {"type": "string"}, "bundle": { "type": "array", "items": {"type": "string"} }, "ipv4": { "type": "array", "items": {"type": "string"} }, "ipv6": { "type": "array", "items": {"type": "string"} } }, "required": ["name", "description", "ipv4", "router", "ipv6"], "additionalProperties": False } } rv = client.post( "/data/interfaces/" + router, headers=DEFAULT_REQUEST_HEADERS) assert rv.status_code == 200 response = json.loads(rv.data.decode("utf-8")) jsonschema.validate(response, interfaces_list_schema) assert response # at least shouldn't be empty def test_snmp_ids(router, client): snmp_id_list_schema = { "$schema": "http://json-schema.org/draft-07/schema#", "type": "array", "items": { "type": "object", "properties": { "index": {"type": "integer"}, "name": {"type": "string"}, "community": {"type": "string"} }, "required": ["index", "name"], "additionalProperties": False } } rv = client.post( "/testing/snmp/" + router, headers=DEFAULT_REQUEST_HEADERS) response = json.loads(rv.data.decode("utf-8")) jsonschema.validate(response, snmp_id_list_schema) assert response # at least shouldn't be empty def test_router_bgp_routes(router, client): 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.post( "/testing/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