diff --git a/src/nbi/tests/data/debug_api_dummy.json b/src/nbi/tests/data/debug_api_dummy.json new file mode 100644 index 0000000000000000000000000000000000000000..2e0d755598c8df35c913961eba0dc8d476a81edb --- /dev/null +++ b/src/nbi/tests/data/debug_api_dummy.json @@ -0,0 +1,238 @@ +{ + "dummy_mode": true, + "contexts": [ + { + "context_id": {"context_uuid": {"uuid": "admin"}}, + "name": "admin", + "topology_ids": [ + {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + ], + "service_ids": [ + {"context_id": {"context_uuid": {"uuid": "admin"}}, "service_uuid": {"uuid": "admin"}}, + {"context_id": {"context_uuid": {"uuid": "admin"}}, "service_uuid": {"uuid": "admin"}}, + {"context_id": {"context_uuid": {"uuid": "admin"}}, "service_uuid": {"uuid": "admin"}} + ], + "slice_ids": [ + {"context_id": {"context_uuid": {"uuid": "admin"}}, "slice_uuid": {"uuid": "admin"}} + ] + } + ], + "topologies": [ + { + "device_ids": [ + {"device_uuid": {"uuid": "R1"}}, + {"device_uuid": {"uuid": "R2"}}, + {"device_uuid": {"uuid": "R3"}} + ], + "link_ids": [ + {"link_uuid": {"uuid": "R1/502==R2/501"}}, + {"link_uuid": {"uuid": "R1/503==R3/501"}}, + {"link_uuid": {"uuid": "R2/501==R1/502"}}, + {"link_uuid": {"uuid": "R2/503==R3/502"}}, + {"link_uuid": {"uuid": "R3/501==R1/503"}}, + {"link_uuid": {"uuid": "R3/502==R2/503"}} + ], + "name": "admin", + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + } + ], + "devices": [ + { + "device_id": {"device_uuid": {"uuid": "R1"}}, "name": "R1", "device_type": "emu-packet-router", + "device_drivers": [0], "device_operational_status": 2, + "device_endpoints": [ + {"name": "200", "endpoint_type": "copper", "endpoint_id": { + "device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "200"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }}, + {"name": "502", "endpoint_type": "optical", "endpoint_id": { + "device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "502"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }}, + {"name": "503", "endpoint_type": "optical", "endpoint_id": { + "device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "503"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }} + ], + "device_config": {"config_rules": [ + {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, + {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": 0}}, + {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ + {"uuid": "200", "name": "200", "type": "copper"}, + {"uuid": "502", "name": "502", "type": "optical"}, + {"uuid": "503", "name": "503", "type": "optical"} + ]}}}, + {"action": 1, "custom": {"resource_key": "/endpoints/endpoint[200]", "resource_value": { + "uuid": "200", "name": "200", "type": "copper" + }}}, + {"action": 1, "custom": {"resource_key": "/endpoints/endpoint[502]", "resource_value": { + "uuid": "502", "name": "502", "type": "optical" + }}}, + {"action": 1, "custom": {"resource_key": "/endpoints/endpoint[503]", "resource_value": { + "uuid": "503", "name": "503", "type": "optical" + }}} + ]} + }, + { + "device_id": {"device_uuid": {"uuid": "R2"}}, "name": "R2", "device_type": "emu-packet-router", + "device_drivers": [0], "device_operational_status": 2, + "device_endpoints": [ + {"name": "200", "endpoint_type": "copper", "endpoint_id": { + "device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "200"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }}, + {"name": "501", "endpoint_type": "optical", "endpoint_id": { + "device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "501"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }}, + {"name": "503", "endpoint_type": "optical", "endpoint_id": { + "device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "503"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }} + ], + "device_config": {"config_rules": [ + {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, + {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": 0}}, + {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ + {"uuid": "200", "name": "200", "type": "copper"}, + {"uuid": "501", "name": "501", "type": "optical"}, + {"uuid": "503", "name": "503", "type": "optical"} + ]}}}, + {"action": 1, "custom": {"resource_key": "/endpoints/endpoint[200]", "resource_value": { + "uuid": "200", "name": "200", "type": "copper" + }}}, + {"action": 1, "custom": {"resource_key": "/endpoints/endpoint[501]", "resource_value": { + "uuid": "501", "name": "501", "type": "optical" + }}}, + {"action": 1, "custom": {"resource_key": "/endpoints/endpoint[503]", "resource_value": { + "uuid": "503", "name": "503", "type": "optical" + }}} + ]} + }, + { + "device_id": {"device_uuid": {"uuid": "R3"}}, "name": "R3", "device_type": "emu-packet-router", + "device_drivers": [0], "device_operational_status": 2, + "device_endpoints": [ + {"name": "200", "endpoint_type": "copper", "endpoint_id": { + "device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "200"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }}, + {"name": "502", "endpoint_type": "optical", "endpoint_id": { + "device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "502"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }}, + {"name": "503", "endpoint_type": "optical", "endpoint_id": { + "device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "503"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }} + ], + "device_config": {"config_rules": [ + {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, + {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": 0}}, + {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ + {"uuid": "200", "name": "200", "type": "copper"}, + {"uuid": "502", "name": "502", "type": "optical"}, + {"uuid": "503", "name": "503", "type": "optical"} + ]}}}, + {"action": 1, "custom": {"resource_key": "/endpoints/endpoint[200]", "resource_value": { + "uuid": "200", "name": "200", "type": "copper" + }}}, + {"action": 1, "custom": {"resource_key": "/endpoints/endpoint[502]", "resource_value": { + "uuid": "502", "name": "502", "type": "optical" + }}}, + {"action": 1, "custom": {"resource_key": "/endpoints/endpoint[503]", "resource_value": { + "uuid": "503", "name": "503", "type": "optical" + }}} + ]} + } + ], + "links": [ + { + "link_id": {"link_uuid": {"uuid": "R1/502==R2/501"}}, "name": "R1/502==R2/501", + "attributes": {"total_capacity_gbps": 10.0, "used_capacity_gbps": 0.0}, + "link_endpoint_ids": [ + { + "device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "502"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }, + { + "device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "501"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + } + ] + }, + { + "link_id": {"link_uuid": {"uuid": "R1/503==R3/501"}}, "name": "R1/503==R3/501", + "attributes": {"total_capacity_gbps": 10.0, "used_capacity_gbps": 0.0}, + "link_endpoint_ids": [ + { + "device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "503"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }, + { + "device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "501"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + } + ] + }, + { + "link_id": {"link_uuid": {"uuid": "R2/501==R1/502"}}, "name": "R2/501==R1/502", + "attributes": {"total_capacity_gbps": 10.0, "used_capacity_gbps": 0.0}, + "link_endpoint_ids": [ + { + "device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "501"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }, + { + "device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "502"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + } + ] + }, + { + "link_id": {"link_uuid": {"uuid": "R2/503==R3/502"}}, "name": "R2/503==R3/502", + "attributes": {"total_capacity_gbps": 10.0, "used_capacity_gbps": 0.0}, + "link_endpoint_ids": [ + { + "device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "503"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }, + { + "device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "502"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + } + ] + }, + { + "link_id": {"link_uuid": {"uuid": "R3/501==R1/503"}}, "name": "R3/501==R1/503", + "attributes": {"total_capacity_gbps": 10.0, "used_capacity_gbps": 0.0}, + "link_endpoint_ids": [ + { + "device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "501"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }, + { + "device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "503"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + } + ] + }, + { + "link_id": {"link_uuid": {"uuid": "R3/502==R2/503"}}, "name": "R3/502==R2/503", + "attributes": {"total_capacity_gbps": 10.0, "used_capacity_gbps": 0.0}, + "link_endpoint_ids": [ + { + "device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "502"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + }, + { + "device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "503"}, + "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}} + } + ] + } + ], + "services": [], + "slices": [], + "connections": [] +} diff --git a/src/nbi/tests/test_debug_api.py b/src/nbi/tests/test_debug_api.py index ed788f469bc0a6ea79ac4448673cf505e39d05d7..1618b32420e97fbfb18981c21345d5fee4c7e076 100644 --- a/src/nbi/tests/test_debug_api.py +++ b/src/nbi/tests/test_debug_api.py @@ -12,211 +12,202 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging, os, pytest, time, urllib -import pprint -from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME, ServiceNameEnum -from common.proto.context_pb2 import Connection, Context, Device, Link, Service, Slice, Topology -from common.proto.policy_pb2 import PolicyRuleIdList, PolicyRuleId, PolicyRuleList, PolicyRule -from common.Settings import ( - ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC, ENVVAR_SUFIX_SERVICE_PORT_HTTP, get_env_var_name, - get_service_port_grpc, get_service_port_http +import logging, urllib +from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME +from common.proto.context_pb2 import ContextId +from common.tools.descriptor.Loader import ( + DescriptorLoader, check_descriptor_load_results, validate_empty_scenario ) +from common.tools.object_factory.Context import json_context_id from common.type_checkers.Assertions import ( validate_connection, validate_connection_ids, validate_connections, validate_context, validate_context_ids, validate_contexts, validate_device, validate_device_ids, validate_devices, validate_link, validate_link_ids, validate_links, validate_service, validate_service_ids, validate_services, validate_topologies, validate_topology, validate_topology_ids) -from nbi.tests.PrepareTestScenario import do_rest_get_request, context_client, nbi_service_rest -from ..service.rest_server.RestServer import RestServer -from .MockService_Dependencies import MockService_Dependencies -from context.tests.Objects import ( - CONNECTION_R1_R3, CONTEXT, DEVICE_R1, DEVICE_R2, DEVICE_R3, LINK_R1_R2, LINK_R1_R3, LINK_R2_R3, SERVICE_R1_R2, SERVICE_R1_R3, - SERVICE_R2_R3, SLICE_R1_R3, TOPOLOGY +from context.client.ContextClient import ContextClient +from nbi.service.rest_server.RestServer import RestServer +from .PrepareTestScenario import ( # pylint: disable=unused-import + # be careful, order of symbols is important here! + do_rest_delete_request, do_rest_get_request, do_rest_post_request, + mock_service, nbi_service_rest, osm_wim, context_client ) -from ..service.rest_server.nbi_plugins.debug_api import URL_PREFIX -# from context.client.ContextClient import ContextClient -# from ..service.rest_server.nbi_plugins.debug_api import RESOURCES - -# connection_r1_r3_uuid = '' -# policyrule_uuid = '' -# slice_r1_r3_uuid = '' -# service_r1_r2_uuid = '' -# service_r1_r3_uuid = '' -# link_r1_r2_uuid = '' -# device_r1_uuid = '' - -def pytest_namespace(): - return { - 'connection_r1_r3_uuid' : '', - 'policyrule_uuid' : '', - 'slice_r1_r3_uuid' : '', - 'service_r1_r2_uuid' : '', - 'service_r1_r3_uuid' : '', - 'link_r1_r2_uuid' : '', - 'device_r1_uuid' : '', - } - -@pytest.fixture(scope='session') -def mock_service(): - _service = MockService_Dependencies(MOCKSERVICE_PORT) - _service.configure_env_vars() - _service.start() - yield _service - _service.stop() - - LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) -LOCAL_HOST = '127.0.0.1' -GRPC_PORT = 10000 + int(get_service_port_grpc(ServiceNameEnum.CONTEXT)) # avoid privileged ports -HTTP_PORT = 10000 + int(get_service_port_http(ServiceNameEnum.CONTEXT)) # avoid privileged ports - -MOCKSERVICE_PORT = 10000 -DEVICE_SERVICE_PORT = MOCKSERVICE_PORT + get_service_port_grpc(ServiceNameEnum.DEVICE) # avoid privileged ports - -os.environ[get_env_var_name(ServiceNameEnum.CONTEXT, ENVVAR_SUFIX_SERVICE_HOST )] = str(LOCAL_HOST) -os.environ[get_env_var_name(ServiceNameEnum.CONTEXT, ENVVAR_SUFIX_SERVICE_PORT_GRPC)] = str(GRPC_PORT) -os.environ[get_env_var_name(ServiceNameEnum.CONTEXT, ENVVAR_SUFIX_SERVICE_PORT_HTTP)] = str(HTTP_PORT) - -def test_populate_database(context_client): - set_context_response = context_client.SetContext(Context(**CONTEXT)) - pytest.connection_r1_r3_uuid = set_context_response.context_uuid.uuid - context_client.SetTopology(Topology(**TOPOLOGY)) - set_device_r1_response = context_client.SetDevice(Device(**DEVICE_R1)) - pytest.device_r1_uuid = set_device_r1_response.device_uuid.uuid - context_client.SetDevice(Device(**DEVICE_R2)) - context_client.SetDevice(Device(**DEVICE_R3)) - set_link_r1_r2_response = context_client.SetLink(Link(**LINK_R1_R2)) - pytest.link_r1_r2_uuid = set_link_r1_r2_response.link_uuid.uuid - context_client.SetLink(Link(**LINK_R1_R3)) - context_client.SetLink(Link(**LINK_R2_R3)) - set_service_r1_r2_response = context_client.SetService(Service(**SERVICE_R1_R2)) - pytest.service_r1_r2_uuid = set_service_r1_r2_response.service_uuid.uuid - set_service_r1_r3_response = context_client.SetService(Service(**SERVICE_R1_R3)) - pytest.service_r1_r3_uuid = set_service_r1_r3_response.service_uuid.uuid - context_client.SetService(Service(**SERVICE_R2_R3)) - set_slice_response = context_client.SetSlice(Slice(**SLICE_R1_R3)) - pytest.slice_r1_r3_uuid = set_slice_response.slice_uuid.uuid - context_client.SetConnection(Connection(**CONNECTION_R1_R3)) - -def test_rest_get_context_ids(nbi_service_rest: RestServer): # pylint: disable=redefined-outer-name - reply = do_rest_get_request(URL_PREFIX + '/context_ids') +DESCRIPTOR_FILE = 'nbi/tests/data/debug_api_dummy.json' + +JSON_ADMIN_CONTEXT_ID = json_context_id(DEFAULT_CONTEXT_NAME) +ADMIN_CONTEXT_ID = ContextId(**JSON_ADMIN_CONTEXT_ID) + + +# ----- Prepare Environment -------------------------------------------------------------------------------------------- + +def test_prepare_environment(context_client : ContextClient) -> None: # pylint: disable=redefined-outer-name + validate_empty_scenario(context_client) + descriptor_loader = DescriptorLoader(descriptors_file=DESCRIPTOR_FILE, context_client=context_client) + results = descriptor_loader.process() + check_descriptor_load_results(results, descriptor_loader) + descriptor_loader.validate() + + # Verify the scenario has no services/slices + response = context_client.GetContext(ADMIN_CONTEXT_ID) + assert len(response.topology_ids) == 1 + assert len(response.service_ids ) == 0 + assert len(response.slice_ids ) == 0 + + +# ----- Context -------------------------------------------------------------------------------------------------------- + +def test_rest_get_context_ids(nbi_service_rest: RestServer): # pylint: disable=redefined-outer-name, unused-argument + reply = do_rest_get_request('/debug-api/context_ids') validate_context_ids(reply) -def test_rest_get_contexts(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name - reply = do_rest_get_request(URL_PREFIX + '/contexts') - # LOGGER.warning(reply['contexts'][0]['service_ids'][0]) - # LOGGER.warning(reply['contexts'][0]['service_ids'][0].keys()) - pprint.pprint(reply) +def test_rest_get_contexts(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + reply = do_rest_get_request('/debug-api/contexts') validate_contexts(reply) -# def test_rest_get_context(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) -# reply = do_rest_get_request(URL_PREFIX + '/context/{:s}'.format(context_uuid)) -# validate_context(reply) - -# def test_rest_get_topology_ids(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) -# reply = do_rest_get_request(URL_PREFIX + '/context/{:s}/topology_ids'.format(context_uuid)) -# validate_topology_ids(reply) - -# def test_rest_get_topologies(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) -# reply = do_rest_get_request(URL_PREFIX + '/context/{:s}/topologies'.format(context_uuid)) -# validate_topologies(reply) - -# def test_rest_get_topology(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) -# topology_uuid = urllib.parse.quote(DEFAULT_TOPOLOGY_NAME) -# reply = do_rest_get_request(URL_PREFIX + '/context/{:s}/topology/{:s}'.format(context_uuid, topology_uuid)) -# validate_topology(reply, num_devices=3, num_links=3) - -# def test_rest_get_service_ids(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) -# reply = do_rest_get_request(URL_PREFIX + '/context/{:s}/service_ids'.format(context_uuid)) -# validate_service_ids(reply) - -# def test_rest_get_services(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) -# reply = do_rest_get_request(URL_PREFIX + '/context/{:s}/services'.format(context_uuid)) -# validate_services(reply) - -# def test_rest_get_service(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) -# service_uuid = urllib.parse.quote(service_r1_r2_uuid, safe='') -# reply = do_rest_get_request(URL_PREFIX + '/context/{:s}/service/{:s}'.format(context_uuid, service_uuid)) -# validate_service(reply) - -# def test_rest_get_slice_ids(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) -# reply = do_rest_get_request(URL_PREFIX + '/context/{:s}/slice_ids'.format(context_uuid)) -# #validate_slice_ids(reply) - -# def test_rest_get_slices(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) -# reply = do_rest_get_request(URL_PREFIX + '/context/{:s}/slices'.format(context_uuid)) -# #validate_slices(reply) - -# def test_rest_get_slice(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) -# slice_uuid = urllib.parse.quote(slice_r1_r3_uuid, safe='') -# reply = do_rest_get_request(URL_PREFIX + '/context/{:s}/slice/{:s}'.format(context_uuid, slice_uuid)) -# #validate_slice(reply) - -# def test_rest_get_device_ids(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# reply = do_rest_get_request(URL_PREFIX + '/device_ids') -# validate_device_ids(reply) - -# def test_rest_get_devices(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# reply = do_rest_get_request(URL_PREFIX + '/devices') -# validate_devices(reply) - -# def test_rest_get_device(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# device_uuid = urllib.parse.quote(device_r1_uuid, safe='') -# reply = do_rest_get_request(URL_PREFIX + '/device/{:s}'.format(device_uuid)) -# validate_device(reply) - -# def test_rest_get_link_ids(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# reply = do_rest_get_request(URL_PREFIX + '/link_ids') -# validate_link_ids(reply) - -# def test_rest_get_links(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# reply = do_rest_get_request(URL_PREFIX + '/links') -# validate_links(reply) - -# def test_rest_get_link(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# link_uuid = urllib.parse.quote(link_r1_r2_uuid, safe='') -# reply = do_rest_get_request(URL_PREFIX + '/link/{:s}'.format(link_uuid)) -# validate_link(reply) - -# def test_rest_get_connection_ids(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) -# service_uuid = urllib.parse.quote(service_r1_r3_uuid, safe='') -# reply = do_rest_get_request(URL_PREFIX + '/context/{:s}/service/{:s}/connection_ids'.format(context_uuid, service_uuid)) -# validate_connection_ids(reply) - -# def test_rest_get_connections(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) -# service_uuid = urllib.parse.quote(service_r1_r3_uuid, safe='') -# reply = do_rest_get_request(URL_PREFIX + '/context/{:s}/service/{:s}/connections'.format(context_uuid, service_uuid)) -# validate_connections(reply) - -# def test_rest_get_connection(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# connection_uuid = urllib.parse.quote(connection_r1_r3_uuid, safe='') -# reply = do_rest_get_request(URL_PREFIX + '/connection/{:s}'.format(connection_uuid)) -# validate_connection(reply) - -# def test_rest_get_policyrule_ids(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# reply = do_rest_get_request(URL_PREFIX + '/policyrule_ids') -# #validate_policyrule_ids(reply) - -# def test_rest_get_policyrules(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# reply = do_rest_get_request(URL_PREFIX + '/policyrules') -# #validate_policyrules(reply) - -# def test_rest_get_policyrule(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name -# policyrule_uuid_quoted = urllib.parse.quote(policyrule_uuid, safe='') -# reply = do_rest_get_request(URL_PREFIX + '/policyrule/{:s}'.format(policyrule_uuid_quoted)) -# #validate_policyrule(reply) +def test_rest_get_context(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) + reply = do_rest_get_request('/debug-api/context/{:s}'.format(context_uuid)) + validate_context(reply) + + +# ----- Topology ------------------------------------------------------------------------------------------------------- + +def test_rest_get_topology_ids(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) + reply = do_rest_get_request('/debug-api/context/{:s}/topology_ids'.format(context_uuid)) + validate_topology_ids(reply) + +def test_rest_get_topologies(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) + reply = do_rest_get_request('/debug-api/context/{:s}/topologies'.format(context_uuid)) + validate_topologies(reply) + +def test_rest_get_topology(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) + topology_uuid = urllib.parse.quote(DEFAULT_TOPOLOGY_NAME) + reply = do_rest_get_request('/debug-api/context/{:s}/topology/{:s}'.format(context_uuid, topology_uuid)) + validate_topology(reply, num_devices=3, num_links=3) + + +# ----- Device --------------------------------------------------------------------------------------------------------- + +def test_rest_get_device_ids(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + reply = do_rest_get_request('/debug-api/device_ids') + validate_device_ids(reply) + +def test_rest_get_devices(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + reply = do_rest_get_request('/debug-api/devices') + validate_devices(reply) + +def test_rest_get_device(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + device_uuid = urllib.parse.quote('R1', safe='') + reply = do_rest_get_request('/debug-api/device/{:s}'.format(device_uuid)) + validate_device(reply) + + +# ----- Link ----------------------------------------------------------------------------------------------------------- + +def test_rest_get_link_ids(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + reply = do_rest_get_request('/debug-api/link_ids') + validate_link_ids(reply) + +def test_rest_get_links(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + reply = do_rest_get_request('/debug-api/links') + validate_links(reply) + +def test_rest_get_link(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + link_uuid = urllib.parse.quote('R1/502==R2/501', safe='') + reply = do_rest_get_request('/debug-api/link/{:s}'.format(link_uuid)) + validate_link(reply) + + +# ----- Service -------------------------------------------------------------------------------------------------------- + +def test_rest_get_service_ids(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) + reply = do_rest_get_request('/debug-api/context/{:s}/service_ids'.format(context_uuid)) + validate_service_ids(reply) + +def test_rest_get_services(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) + reply = do_rest_get_request('/debug-api/context/{:s}/services'.format(context_uuid)) + validate_services(reply) + +def test_rest_get_service(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) + service_uuid = urllib.parse.quote('SVC:R1/200==R2/200', safe='') + reply = do_rest_get_request('/debug-api/context/{:s}/service/{:s}'.format(context_uuid, service_uuid)) + validate_service(reply) + + +# ----- Slice ---------------------------------------------------------------------------------------------------------- + +def test_rest_get_slice_ids(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) + reply = do_rest_get_request('/debug-api/context/{:s}/slice_ids'.format(context_uuid)) + validate_slice_ids(reply) + +def test_rest_get_slices(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) + reply = do_rest_get_request('/debug-api/context/{:s}/slices'.format(context_uuid)) + validate_slices(reply) + +def test_rest_get_slice(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) + slice_uuid = urllib.parse.quote('SLC:R1-R2-R3', safe='') + reply = do_rest_get_request('/debug-api/context/{:s}/slice/{:s}'.format(context_uuid, slice_uuid)) + validate_slice(reply) + + +# ----- Connection ----------------------------------------------------------------------------------------------------- + +def test_rest_get_connection_ids(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) + service_uuid = urllib.parse.quote('SVC:R1/200==R2/200', safe='') + reply = do_rest_get_request('/debug-api/context/{:s}/service/{:s}/connection_ids'.format(context_uuid, service_uuid)) + validate_connection_ids(reply) + +def test_rest_get_connections(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME) + service_uuid = urllib.parse.quote('SVC:R1/200==R2/200', safe='') + reply = do_rest_get_request('/debug-api/context/{:s}/service/{:s}/connections'.format(context_uuid, service_uuid)) + validate_connections(reply) + +def test_rest_get_connection(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument + connection_uuid = urllib.parse.quote('CON:R1/200==R2/200:1', safe='') + reply = do_rest_get_request('/debug-api/connection/{:s}'.format(connection_uuid)) + validate_connection(reply) + +# ----- Policy --------------------------------------------------------------------------------------------------------- + +#def test_rest_get_policyrule_ids(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument +# reply = do_rest_get_request('/debug-api/policyrule_ids') +# validate_policyrule_ids(reply) + +#def test_rest_get_policyrules(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument +# reply = do_rest_get_request('/debug-api/policyrules') +# validate_policyrules(reply) + +#def test_rest_get_policyrule(nbi_service_rest : RestServer): # pylint: disable=redefined-outer-name, unused-argument +# policyrule_uuid_quoted = urllib.parse.quote(policyrule_uuid, safe='') +# reply = do_rest_get_request('/debug-api/policyrule/{:s}'.format(policyrule_uuid_quoted)) +# validate_policyrule(reply) + + +# ----- Cleanup Environment -------------------------------------------------------------------------------------------- + +def test_cleanup_environment(context_client : ContextClient) -> None: # pylint: disable=redefined-outer-name + # Verify the scenario has no services/slices + response = context_client.GetContext(ADMIN_CONTEXT_ID) + assert len(response.topology_ids) == 1 + assert len(response.service_ids ) == 0 + assert len(response.slice_ids ) == 0 + + # Load descriptors and validate the base scenario + descriptor_loader = DescriptorLoader(descriptors_file=DESCRIPTOR_FILE, context_client=context_client) + descriptor_loader.validate() + descriptor_loader.unload() + validate_empty_scenario(context_client)