Loading scripts/run_tests_locally-nbi-ietf-network.sh 0 → 100755 +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_ietf_network.py src/common/tests/MockServicerImpl_Context.py +28 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ from common.proto.context_pb2 import ( Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList) from common.proto.context_pb2_grpc import ContextServiceServicer from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string from common.tools.object_factory.Device import json_device_id from common.tools.object_factory.Link import json_link_id from .InMemoryObjectDatabase import InMemoryObjectDatabase from .MockMessageBroker import ( TOPIC_CONNECTION, TOPIC_CONTEXT, TOPIC_DEVICE, TOPIC_LINK, TOPIC_SERVICE, TOPIC_SLICE, TOPIC_TOPOLOGY, Loading Loading @@ -146,6 +148,32 @@ class MockServicerImpl_Context(ContextServiceServicer): context_uuid = str(request.topology_id.context_id.context_uuid.uuid) container_name = 'topology[{:s}]'.format(context_uuid) topology_uuid = request.topology_id.topology_uuid.uuid if self.obj_db.has_entry(container_name, topology_uuid): # merge device_ids and link_ids from database and request, and update request db_topology = self.obj_db.get_entry(container_name, topology_uuid, context) device_uuids = set() for device_id in request.device_ids: device_uuids.add(device_id.device_uuid.uuid) for device_id in db_topology.device_ids: device_uuids.add(device_id.device_uuid.uuid) link_uuids = set() for link_id in request.link_ids: link_uuids.add(link_id.link_uuid.uuid) for link_id in db_topology.link_ids: link_uuids.add(link_id.link_uuid.uuid) rw_request = Topology() rw_request.CopyFrom(request) del rw_request.device_ids[:] for device_uuid in sorted(device_uuids): rw_request.device_ids.append(DeviceId(**json_device_id(device_uuid))) del rw_request.link_ids[:] for link_uuid in sorted(link_uuids): rw_request.link_ids.append(LinkId(**json_link_id(link_uuid))) request = rw_request reply,_ = self._set(request, container_name, topology_uuid, 'topology_id', TOPIC_TOPOLOGY) context_ = self.obj_db.get_entry('context', context_uuid, context) Loading src/nbi/.gitlab-ci.yml +1 −1 Original line number Diff line number Diff line Loading @@ -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_ietf_network.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: Loading src/nbi/Dockerfile +8 −3 Original line number Diff line number Diff line Loading @@ -63,9 +63,14 @@ RUN python3 -m pip install -r requirements.txt # Add component files into working directory WORKDIR /var/teraflow COPY src/nbi/. nbi/ COPY src/context/. context/ COPY src/service/. service/ COPY src/slice/. slice/ COPY src/context/__init__.py context/__init__.py COPY src/context/client/. context/client/ COPY src/device/__init__.py device/__init__.py COPY src/device/client/. device/client/ COPY src/service/__init__.py service/__init__.py COPY src/service/client/. service/client/ COPY src/slice/__init__.py slice/__init__.py COPY src/slice/client/. slice/client/ RUN mkdir -p /var/teraflow/tests/tools COPY src/tests/tools/mock_osm/. tests/tools/mock_osm/ Loading src/nbi/requirements.in +4 −1 Original line number Diff line number Diff line Loading @@ -12,9 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. deepdiff==6.7.* Flask==2.1.3 Flask-HTTPAuth==4.5.0 Flask-RESTful==0.3.9 jsonschema==4.4.0 pyang git+https://github.com/robshakir/pyangbind.git requests==2.27.1 werkzeug==2.3.7 Loading
scripts/run_tests_locally-nbi-ietf-network.sh 0 → 100755 +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_ietf_network.py
src/common/tests/MockServicerImpl_Context.py +28 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ from common.proto.context_pb2 import ( Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList) from common.proto.context_pb2_grpc import ContextServiceServicer from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string from common.tools.object_factory.Device import json_device_id from common.tools.object_factory.Link import json_link_id from .InMemoryObjectDatabase import InMemoryObjectDatabase from .MockMessageBroker import ( TOPIC_CONNECTION, TOPIC_CONTEXT, TOPIC_DEVICE, TOPIC_LINK, TOPIC_SERVICE, TOPIC_SLICE, TOPIC_TOPOLOGY, Loading Loading @@ -146,6 +148,32 @@ class MockServicerImpl_Context(ContextServiceServicer): context_uuid = str(request.topology_id.context_id.context_uuid.uuid) container_name = 'topology[{:s}]'.format(context_uuid) topology_uuid = request.topology_id.topology_uuid.uuid if self.obj_db.has_entry(container_name, topology_uuid): # merge device_ids and link_ids from database and request, and update request db_topology = self.obj_db.get_entry(container_name, topology_uuid, context) device_uuids = set() for device_id in request.device_ids: device_uuids.add(device_id.device_uuid.uuid) for device_id in db_topology.device_ids: device_uuids.add(device_id.device_uuid.uuid) link_uuids = set() for link_id in request.link_ids: link_uuids.add(link_id.link_uuid.uuid) for link_id in db_topology.link_ids: link_uuids.add(link_id.link_uuid.uuid) rw_request = Topology() rw_request.CopyFrom(request) del rw_request.device_ids[:] for device_uuid in sorted(device_uuids): rw_request.device_ids.append(DeviceId(**json_device_id(device_uuid))) del rw_request.link_ids[:] for link_uuid in sorted(link_uuids): rw_request.link_ids.append(LinkId(**json_link_id(link_uuid))) request = rw_request reply,_ = self._set(request, container_name, topology_uuid, 'topology_id', TOPIC_TOPOLOGY) context_ = self.obj_db.get_entry('context', context_uuid, context) Loading
src/nbi/.gitlab-ci.yml +1 −1 Original line number Diff line number Diff line Loading @@ -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_ietf_network.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: Loading
src/nbi/Dockerfile +8 −3 Original line number Diff line number Diff line Loading @@ -63,9 +63,14 @@ RUN python3 -m pip install -r requirements.txt # Add component files into working directory WORKDIR /var/teraflow COPY src/nbi/. nbi/ COPY src/context/. context/ COPY src/service/. service/ COPY src/slice/. slice/ COPY src/context/__init__.py context/__init__.py COPY src/context/client/. context/client/ COPY src/device/__init__.py device/__init__.py COPY src/device/client/. device/client/ COPY src/service/__init__.py service/__init__.py COPY src/service/client/. service/client/ COPY src/slice/__init__.py slice/__init__.py COPY src/slice/client/. slice/client/ RUN mkdir -p /var/teraflow/tests/tools COPY src/tests/tools/mock_osm/. tests/tools/mock_osm/ Loading
src/nbi/requirements.in +4 −1 Original line number Diff line number Diff line Loading @@ -12,9 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. deepdiff==6.7.* Flask==2.1.3 Flask-HTTPAuth==4.5.0 Flask-RESTful==0.3.9 jsonschema==4.4.0 pyang git+https://github.com/robshakir/pyangbind.git requests==2.27.1 werkzeug==2.3.7