Skip to content
Snippets Groups Projects
test_ietf_l2vpn.py 3.65 KiB
Newer Older
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
import logging
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
from common.Constants import DEFAULT_CONTEXT_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 context.client.ContextClient import ContextClient
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
from tests.tools.mock_osm.MockOSM import MockOSM
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
from .Constants import SERVICE_CONNECTION_POINTS_1, SERVICE_CONNECTION_POINTS_2, SERVICE_TYPE
from .PrepareTestScenario import ( # pylint: disable=unused-import
    # be careful, order of symbols is important here!
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
    mock_service, nbi_service_rest, osm_wim, context_client
)

LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
DESCRIPTOR_FILE = 'nbi/tests/data/topology-7router-emu-dummy.json'
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
JSON_ADMIN_CONTEXT_ID = json_context_id(DEFAULT_CONTEXT_NAME)
ADMIN_CONTEXT_ID = ContextId(**JSON_ADMIN_CONTEXT_ID)

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
def test_ietf_l2vpn_prepare_environment(context_client : ContextClient) -> None: # pylint: disable=redefined-outer-name
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
    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

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
def test_ietf_l2vpn_create_service(osm_wim : MockOSM): # pylint: disable=redefined-outer-name
    osm_wim.create_connectivity_service(SERVICE_TYPE, SERVICE_CONNECTION_POINTS_1)
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
def test_ietf_l2vpn_get_service_status(osm_wim : MockOSM): # pylint: disable=redefined-outer-name
    service_uuid = list(osm_wim.conn_info.keys())[0] # this test adds a single service
    osm_wim.get_connectivity_service_status(service_uuid)
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
def test_ietf_l2vpn_edit_service(osm_wim : MockOSM): # pylint: disable=redefined-outer-name
    service_uuid = list(osm_wim.conn_info.keys())[0] # this test adds a single service
    osm_wim.edit_connectivity_service(service_uuid, SERVICE_CONNECTION_POINTS_2)
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
def test_ietf_l2vpn_delete_service(osm_wim : MockOSM): # pylint: disable=redefined-outer-name
    service_uuid = list(osm_wim.conn_info.keys())[0] # this test adds a single service
    osm_wim.delete_connectivity_service(service_uuid)
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
def test_ietf_l2vpn_cleanup_environment(context_client : ContextClient) -> None: # pylint: disable=redefined-outer-name
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
    # 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)