diff --git a/inventory_provider/routes/poller.py b/inventory_provider/routes/poller.py index 51bfa7d9ec0ac1507a6b1864b87484e103d8e9be..583f2a044973d7f970196b9de4fe449a08e262f2 100644 --- a/inventory_provider/routes/poller.py +++ b/inventory_provider/routes/poller.py @@ -17,7 +17,7 @@ def after_request(resp): def _load_snmp_indexes(hostname=None): result = dict() - key_pattern = f'snmp-interfaces:{hostname}' \ + key_pattern = f'snmp-interfaces:{hostname}*' \ if hostname else 'snmp-interfaces:*' for doc in common.load_json_docs( @@ -85,7 +85,7 @@ def _load_services(hostname=None): return result def _load_interfaces(hostname): - key_pattern = f'netconf:{hostname}' if hostname else 'netconf:*' + key_pattern = f'netconf:{hostname}*' if hostname else 'netconf:*' for doc in common.load_xml_docs( config_params=current_app.config['INVENTORY_PROVIDER_CONFIG'], key_pattern=key_pattern, diff --git a/test/per_router/test_poller_routes.py b/test/per_router/test_poller_routes.py index fe0a91cb585737d04762f886c1d17cd2066b9218..8d3805533e0a9dc2acf8c351cb50be54b68d0626 100644 --- a/test/per_router/test_poller_routes.py +++ b/test/per_router/test_poller_routes.py @@ -6,61 +6,63 @@ DEFAULT_REQUEST_HEADERS = { "Accept": ["application/json"] } +INTERFACE_LIST_SCHEMA = { + '$schema': 'http://json-schema.org/draft-07/schema#', -def test_router_interfaces(router, client): - interfaces_list_schema = { - "$schema": "http://json-schema.org/draft-07/schema#", - - "definitions": { - "circuit": { - "type": "object", - "properties": { - "name": {"type": "string"}, - "status": {"type": "string"}, - "type": {"type": "string"}, - "id": {"type": "integer"} - }, - "required": ["name", "status", "type", "id"], - "additionalProperties": False - } + 'definitions': { + 'service': { + 'type': 'object', + 'properties': { + 'id': {'type': 'integer'}, + 'name': {'type': 'string'}, + 'type': {'type': 'string'}, + 'status': {'type': 'string'}, + }, + 'required': ['id', 'name', 'type', 'status'], + 'additionalProperties': False }, - - "type": "array", - "items": { - "type": "object", - "properties": { - "circuits": { - "type": "array", - "items": {"$ref": "#/definitions/circuit"} + 'interface': { + 'type': 'object', + 'properties': { + 'router': {'type': 'string'}, + 'name': {'type': 'string'}, + 'description': {'type': 'string'}, + 'snmp-index': { + 'type': 'integer', + 'minimum': 1 }, - "bundle": { - "type": "array", - "items": {"type": "string"} + 'bundle': { + 'type' : 'array', + 'items': {'type': 'string'} }, - "bundle-parents": { - "type": "array", - "items": {"type": "string"} + 'bundle-parents': { + 'type': 'array', + 'items': {'type': 'string'} }, - "description": {"type": "string"}, - "name": {"type": "string"}, - "snmp-index": {"type": "integer"} + 'circuits': { + 'type': 'array', + 'items': {'$ref': '#/definitions/service'} + } }, - "required": [ - "circuits", - "bundle", - "bundle-parents", - "description", - "name", - "snmp-index"], - "additionalProperties": False - } - } + 'required': [ + 'router', 'name', 'description', + 'snmp-index', 'bundle', 'bundle-parents', + 'circuits'], + 'additionalProperties': False + }, + }, + + 'type': 'array', + 'items': {'$ref': '#/definitions/interface'} +} + +def test_router_interfaces(router, client): rv = client.post( "/poller/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) + jsonschema.validate(response, INTERFACE_LIST_SCHEMA) assert response # at least shouldn't be empty diff --git a/test/test_general_poller_routes.py b/test/test_general_poller_routes.py index 166696f01069332bbbeae0552a5dbf7ae25dd311..e14491ab0ed99bc5d917322c1fbbe8156cfee6d2 100644 --- a/test/test_general_poller_routes.py +++ b/test/test_general_poller_routes.py @@ -11,7 +11,7 @@ DEFAULT_REQUEST_HEADERS = { } -INTERFACE_LIST_SCHEMA = { +SCHEMA_INTERFACE_LIST_SCHEMA = { '$schema': 'http://json-schema.org/draft-07/schema#', 'definitions': { @@ -33,6 +33,56 @@ INTERFACE_LIST_SCHEMA = { } +INTERFACE_LIST_SCHEMA = { + '$schema': 'http://json-schema.org/draft-07/schema#', + + 'definitions': { + 'service': { + 'type': 'object', + 'properties': { + 'id': {'type': 'integer'}, + 'name': {'type': 'string'}, + 'type': {'type': 'string'}, + 'status': {'type': 'string'}, + }, + 'required': ['id', 'name', 'type', 'status'], + 'additionalProperties': False + }, + 'interface': { + 'type': 'object', + 'properties': { + 'router': {'type': 'string'}, + 'name': {'type': 'string'}, + 'description': {'type': 'string'}, + 'snmp-index': { + 'type': 'integer', + 'minimum': 1 + }, + 'bundle': { + 'type' : 'array', + 'items': {'type': 'string'} + }, + 'bundle-parents': { + 'type': 'array', + 'items': {'type': 'string'} + }, + 'circuits': { + 'type': 'array', + 'items': {'$ref': '#/definitions/service'} + } + }, + 'required': [ + 'router', 'name', 'description', + 'snmp-index', 'bundle', 'bundle-parents', + 'circuits'], + 'additionalProperties': False + }, + }, + + 'type': 'array', + 'items': {'$ref': '#/definitions/interface'} +} + @pytest.mark.parametrize('category', ['mdvpn', 'lhcone', 'MDVpn', 'LHCONE']) def test_service_category(client, mocked_worker_module, category): worker._build_service_category_interface_list() @@ -42,7 +92,7 @@ def test_service_category(client, mocked_worker_module, category): assert rv.status_code == 200 assert rv.is_json response_data = json.loads(rv.data.decode('utf-8')) - jsonschema.validate(response_data, INTERFACE_LIST_SCHEMA) + jsonschema.validate(response_data, SCHEMA_INTERFACE_LIST_SCHEMA) assert response_data, 'expected a non-empty list' @@ -60,3 +110,7 @@ def test_get_all_interfaces(client): f'/poller/interfaces', 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, INTERFACE_LIST_SCHEMA) + assert response_data, 'expected a non-empty list'