Commit ecb0e423 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch...

Merge branch 'feat/67-cttc-implement-unitary-tests-in-nbi-for-etsi-mec-bandwidth-management-api-plugin' into 'develop'

Resolve "(CTTC) Implement unitary tests in NBI for ETSI MEC Bandwidth Management API plugin"

Closes #67

See merge request !179
parents 8c02bbd6 c7e957fb
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -22,8 +22,14 @@ RCFILE=$PROJECTDIR/coverage/.coveragerc
# Run unitary tests and analyze coverage of code at same time
# helpful pytest flags: --log-level=INFO -o log_cli=true --verbose --maxfail=1 --durations=0

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    nbi/tests/test_etsi_bwm.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    nbi/tests/test_ietf_l2vpn.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    nbi/tests/test_ietf_l3vpn.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    nbi/tests/test_ietf_network.py
+25 −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
# helpful pytest flags: --log-level=INFO -o log_cli=true --verbose --maxfail=1 --durations=0
coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    nbi/tests/test_etsi_bwm.py
+1 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ unit_test nbi:
    - docker exec -i $IMAGE_NAME bash -c "coverage run --append -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_ietf_l2vpn.py --junitxml=/opt/results/${IMAGE_NAME}_report_ietf_l2vpn.xml"
    - docker exec -i $IMAGE_NAME bash -c "coverage run --append -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_ietf_network.py --junitxml=/opt/results/${IMAGE_NAME}_report_ietf_network.xml"
    - docker exec -i $IMAGE_NAME bash -c "coverage run --append -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_ietf_l3vpn.py --junitxml=/opt/results/${IMAGE_NAME}_report_ietf_l3vpn.xml"
    - docker exec -i $IMAGE_NAME bash -c "coverage run --append -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_etsi_bwm.py --junitxml=/opt/results/${IMAGE_NAME}_report_etsi_bwm.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:
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
# limitations under the License.

deepdiff==6.7.*
deepmerge==1.1.*
Flask==2.1.3
Flask-HTTPAuth==4.5.0
Flask-RESTful==0.3.9
+21 −10
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, deepmerge, 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,30 @@ 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)
        
        service = self.client.GetService(grpc_service_id(DEFAULT_CONTEXT_NAME, json_data['appInsId']))
        current_bwm = service_2_bwInfo(service)
        new_bmw = deepmerge.always_merger.merge(current_bwm, json_data)
        
        service = bwInfo_2_service(self.client, new_bmw)
        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
Loading