Commit 2d918155 authored by Carlos Manso's avatar Carlos Manso
Browse files

etsi_bwm fixes and unit tests

parent 1cdafbad
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
#!/bin/bash
# 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.


PROJECTDIR=`pwd`

cd $PROJECTDIR/src
RCFILE=$PROJECTDIR/coverage/.coveragerc

# Run unitary tests and analyze coverage of code at same time 
coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    nbi/tests/test_etsi_bwm.py
+1 −1
Original line number Diff line number Diff line
@@ -494,7 +494,7 @@ class MockServicerImpl_Context(ContextServiceServicer):

    def RemoveService(self, request: ServiceId, context : grpc.ServicerContext) -> Empty:
        LOGGER.debug('[RemoveService] request={:s}'.format(grpc_message_to_json_string(request)))
        context_uuid = str(request.service_id.context_id.context_uuid.uuid)
        context_uuid = str(request.context_id.context_uuid.uuid)
        container_name = 'service[{:s}]'.format(context_uuid)
        service_uuid = request.service_uuid.uuid
        reply = self._del(request, container_name, service_uuid, 'service_id', TOPIC_SERVICE, context)
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ unit_test nbi:
    - sleep 5
    - docker ps -a
    - docker logs $IMAGE_NAME
    - docker exec -i $IMAGE_NAME bash -c "coverage run -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_unitary.py --junitxml=/opt/results/${IMAGE_NAME}_report.xml"
    - docker exec -i $IMAGE_NAME bash -c "coverage run -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_unitary.py $IMAGE_NAME/tests/test_etsi_bwm.py --junitxml=/opt/results/${IMAGE_NAME}_report.xml"
    - docker exec -i $IMAGE_NAME bash -c "coverage report --include='${IMAGE_NAME}/*' --show-missing"
  coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
  after_script:
+14 −9
Original line number Diff line number Diff line
@@ -12,14 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import copy
import copy, json, logging
from common.Constants import DEFAULT_CONTEXT_NAME
from flask_restful import Resource, request
from context.client.ContextClient import ContextClient
from flask_restful import Resource, request
from service.client.ServiceClient import ServiceClient
from .Tools import (
    format_grpc_to_json, grpc_context_id, grpc_service_id, bwInfo_2_service, service_2_bwInfo)

LOGGER = logging.getLogger(__name__)


class _Resource(Resource):
@@ -39,7 +40,6 @@ class BwInfo(_Resource):
        bwinfo = request.get_json()
        service = bwInfo_2_service(self.client, bwinfo)
        stripped_service = copy.deepcopy(service)

        stripped_service.ClearField('service_endpoint_ids')
        stripped_service.ClearField('service_constraints')
        stripped_service.ClearField('service_config')
@@ -57,19 +57,24 @@ class BwInfoId(_Resource):
        return service_2_bwInfo(service)

    def put(self, allocationId: str):
        json_data = request.get_json()
        json_data = json.loads(request.get_json())
        service = bwInfo_2_service(self.client, json_data)
        response = self.service_client.UpdateService(service)
        return format_grpc_to_json(response)
        self.service_client.UpdateService(service)
        service = self.client.GetService(grpc_service_id(DEFAULT_CONTEXT_NAME, json_data['appInsId']))
        response_bwm = service_2_bwInfo(service)

        return response_bwm

    def patch(self, allocationId: str):
        json_data = request.get_json()
        if not 'appInsId' in json_data:
            json_data['appInsId'] = allocationId
        service = bwInfo_2_service(self.client, json_data)
        response = self.service_client.UpdateService(service)
        return format_grpc_to_json(response)
        self.service_client.UpdateService(service)
        service = self.client.GetService(grpc_service_id(DEFAULT_CONTEXT_NAME, json_data['appInsId']))
        response_bwm = service_2_bwInfo(service)

        return response_bwm

    def delete(self, allocationId: str):
        self.service_client.DeleteService(grpc_service_id(DEFAULT_CONTEXT_NAME, allocationId))
        return
+1 −8
Original line number Diff line number Diff line
@@ -27,13 +27,12 @@ LOGGER = logging.getLogger(__name__)
def service_2_bwInfo(service: Service) -> dict:
    response = {}
    # allocationDirection = '??' # String: 00 = Downlink (towards the UE); 01 = Uplink (towards the application/session); 10 = Symmetrical
    response['appInsId'] = service.service_id.context_id.context_uuid.uuid # String: Application instance identifier
    response['appInsId'] = service.service_id.service_uuid.uuid # String: Application instance identifier
    for constraint in service.service_constraints:
        if constraint.WhichOneof('constraint') == 'sla_capacity':
            response['fixedAllocation'] = str(constraint.sla_capacity.capacity_gbps*1000) # String: Size of requested fixed BW allocation in [bps]
            break


    for config_rule in service.service_config.config_rules:
        for key in ['allocationDirection', 'fixedBWPriority', 'requestType', 'sourceIp', 'sourcePort', 'dstPort', 'protocol', 'sessionFilter']:
            if config_rule.custom.resource_key == key:
@@ -42,7 +41,6 @@ def service_2_bwInfo(service: Service) -> dict:
                else:
                    response[key] = json.loads(config_rule.custom.resource_value)

    
    unixtime = time.time()
    response['timeStamp'] = { # Time stamp to indicate when the corresponding information elements are sent
        "seconds": int(unixtime),
@@ -53,7 +51,6 @@ def service_2_bwInfo(service: Service) -> dict:

def bwInfo_2_service(client, bwInfo: dict) -> Service:
    service = Service()

    for key in ['allocationDirection', 'fixedBWPriority', 'requestType', 'timeStamp', 'sessionFilter']:
        if key not in bwInfo:
            continue
@@ -83,10 +80,6 @@ def bwInfo_2_service(client, bwInfo: dict) -> Service:
                            ep_id.device_id.device_uuid.uuid = device.device_id.device_uuid.uuid
                            service.service_endpoint_ids.append(ep_id)

        if len(service.service_endpoint_ids) < 2:
            LOGGER.error('No endpoints matched')
            return None

    service.service_type = ServiceTypeEnum.SERVICETYPE_L3NM

    if 'appInsId' in bwInfo:
Loading