diff --git a/inventory_provider/routes/classifier_schema.py b/inventory_provider/routes/classifier_schema.py index 8b5006bcaa6e162763c22f9739010bb85b886a24..e81703ce08529a80027d07065614d0da64e65a44 100644 --- a/inventory_provider/routes/classifier_schema.py +++ b/inventory_provider/routes/classifier_schema.py @@ -49,6 +49,7 @@ _common_schema_definitions = { "type": "string", "enum": ["circuit", "service"] }, + "service_type": {"type": "string"}, "project": {"type": "string"} }, "additionalProperties": False @@ -247,9 +248,11 @@ _juniper_link_response_schema_definitions = { "type": "string", "enum": ["path", "service", "l2circuit"] }, + "service_type": {"type": "string"}, "project": {"type": "string"} }, - "required": ["name", "status", "circuit_type", "project"], + "required": [ + "name", "status", "circuit_type", "service_type", "project"], "additionalProperties": False } } @@ -499,9 +502,11 @@ _infinera_lambda_response_schema_definitions = { "type": "string", "enum": ["path", "service", "l2circuit"] }, + "service_type": {"type": "string"}, "project": {"type": "string"} }, - "required": ["name", "status", "circuit_type", "project"], + "required": [ + "name", "status", "circuit_type", "sservice_type", "project"], "additionalProperties": False }, "geant-lambda": { diff --git a/inventory_provider/routes/testing.py b/inventory_provider/routes/testing.py index 4cd035f5271048446cb2f2b8084689fbcc4e7eef..f81982283885785da1dfaad497ba8e8ed1899f1c 100644 --- a/inventory_provider/routes/testing.py +++ b/inventory_provider/routes/testing.py @@ -17,6 +17,7 @@ routes = Blueprint("inventory-data-testing-support-routes", __name__) logger = logging.getLogger(__name__) + @routes.route("flushdb", methods=['GET', 'POST']) def flushdb(): common.get_current_redis().flushdb() diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 09f71f72d553f1d68b9cbfe9d130a019ba9453dc..170c0a283b08433a2ec6e7a264b5f729e74cd006 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -683,6 +683,7 @@ def update_circuit_hierarchy_and_port_id_services(self, use_current=False): 'name': c['name'], 'status': c['status'], 'circuit_type': 'service', + 'service_type': c['product'], 'project': c['project'], 'contacts': sorted(list(c['contacts'])) } diff --git a/test/data/router-info.json b/test/data/router-info.json index 87d749d32930dd71e60cc2075f06f02ad72cd1eb..14e59ab1c12192c95f1949146c5e44857b6fedb3 100644 Binary files a/test/data/router-info.json and b/test/data/router-info.json differ diff --git a/test/test_testing_routes.py b/test/test_testing_routes.py index d58d4cfc432abfc1f082ec1a87584fa8d0bea302..0e500b9a1e6625a649b775be1586e5908d2516ec 100644 --- a/test/test_testing_routes.py +++ b/test/test_testing_routes.py @@ -1,6 +1,8 @@ import json import jsonschema +import inventory_provider + DEFAULT_REQUEST_HEADERS = { "Content-type": "application/json", "Accept": ["application/json"] @@ -28,65 +30,53 @@ def test_juniper_addresses(client): assert len(response_data) > 0 # test data is not empty -# def test_get_equipment_location_all(client): -# rv = client.get( -# '/testing/opsdb/equipment-location', -# headers=DEFAULT_REQUEST_HEADERS) -# assert rv.status_code == 200 -# assert rv.is_json -# # TODO: validate against schema -# -# -# def test_get_interface_info(client): -# rv = client.get( -# '/testing/opsdb/interfaces', -# headers=DEFAULT_REQUEST_HEADERS) -# assert rv.status_code == 200 -# assert rv.is_json -# # TODO: validate against schema -# -# -# def test_get_interface_info_for_equipment(client): -# rv = client.get( -# '/testing/opsdb/interfaces/mx1.ams.nl.geant.net', -# headers=DEFAULT_REQUEST_HEADERS) -# assert rv.status_code == 200 -# assert rv.is_json -# # TODO: validate against schema -# -# -# def test_get_interface_info_for_equipment_and_interface( -# client): -# rv = client.get( -# '/testing/opsdb/interfaces/mx1.ams.nl.geant.net/ae3.0', -# headers=DEFAULT_REQUEST_HEADERS) -# assert rv.status_code == 200 -# assert rv.is_json -# # TODO: validate against schema -# -# -# def test_get_children(client): -# rv = client.get( -# '/testing/opsdb/circuit-hierarchy/children/12363', -# headers=DEFAULT_REQUEST_HEADERS) -# assert rv.status_code == 200 -# assert rv.is_json -# # TODO: validate against schema -# -# -# def test_get_parents(client): -# rv = client.get( -# '/testing/opsdb/circuit-hierarchy/parents/47141', -# headers=DEFAULT_REQUEST_HEADERS) -# assert rv.status_code == 200 -# assert rv.is_json -# # TODO: validate against schema -# -# -# def test_get_equipment_location(client): -# rv = client.get( -# '/testing/opsdb/equipment-location/mx1.ams.nl.geant.net', -# headers=DEFAULT_REQUEST_HEADERS) -# assert rv.status_code == 200 -# assert rv.is_json -# # TODO: validate against schema +def test_circuit_tree(client, mocker): + raw = [ + { + 'id': 1, + 'name': 'root circuit', + 'product': 'product A', + 'speed': 'Speed A', + 'status': ' Operational', + 'sub-circuits': [2, 3] + }, + { + 'id': 2, + 'name': 'circuit 2', + 'product': 'product A', + 'speed': 'Speed A', + 'status': ' Operational' + }, + { + 'id': 3, + 'name': 'circuit 3', + 'product': 'product A', + 'speed': 'Speed A', + 'status': ' Operational' + }] + data = {} + for v in raw: + data[f'ims:circuit_hierarchy:{v["id"]}'] = \ + json.dumps([v]).encode('utf-8') + + expected = """<pre>1 -- root circuit -- prod: product A -- spd: Speed A -- status: Operational +├── 2 -- circuit 2 -- prod: product A -- spd: Speed A -- status: Operational +└── 3 -- circuit 3 -- prod: product A -- spd: Speed A -- status: Operational +</pre>""" # noqa + + class MockedR: + def get(self, key): + return data.get(key, None) + + mr = mocker.patch.object( + inventory_provider.tasks.common, + "get_current_redis" + ) + mr.return_value = MockedR() + + rv = client.post( + "/testing/circuit-tree/1", + headers=DEFAULT_REQUEST_HEADERS) + assert rv.status_code == 200 + response_data = rv.data.decode('utf-8') + assert response_data == expected