Skip to content
Snippets Groups Projects
Commit 47dff691 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Fix CI/CD pipeline

parent 46fc68a9
No related branches found
No related tags found
2 merge requests!235Release TeraFlowSDN 3.0,!215Resolve "Fix CI/CD pipeline issues"
...@@ -38,45 +38,45 @@ build bgpls_speaker: ...@@ -38,45 +38,45 @@ build bgpls_speaker:
- manifests/${IMAGE_NAME}service.yaml - manifests/${IMAGE_NAME}service.yaml
- .gitlab-ci.yml - .gitlab-ci.yml
# Apply unit test to the component ## Apply unit test to the component
unit_test bgpls_speaker: #unit_test bgpls_speaker:
variables: # variables:
IMAGE_NAME: 'bgpls_speaker' # name of the microservice # IMAGE_NAME: 'bgpls_speaker' # name of the microservice
IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) # IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
stage: unit_test # stage: unit_test
needs: # needs:
- build bgpls_speaker # - build bgpls_speaker
before_script: # before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY # - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create --driver=bridge teraflowbridge; fi # - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create --driver=bridge teraflowbridge; fi
- if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME image is not in the system"; fi # - if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME image is not in the system"; fi
script: # script:
- docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" # - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
- docker run --name $IMAGE_NAME -d -p 20030:20030 -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG # - docker run --name $IMAGE_NAME -d -p 20030:20030 -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG
- sleep 5 # - sleep 5
- docker ps -a # - docker ps -a
- docker logs $IMAGE_NAME # - 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 --junitxml=/opt/results/${IMAGE_NAME}_report.xml"
- docker exec -i $IMAGE_NAME bash -c "coverage report --include='${IMAGE_NAME}/*' --show-missing" # - docker exec -i $IMAGE_NAME bash -c "coverage report --include='${IMAGE_NAME}/*' --show-missing"
coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/' # coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
after_script: # after_script:
- docker rm -f $IMAGE_NAME # - docker rm -f $IMAGE_NAME
- docker network rm teraflowbridge # - docker network rm teraflowbridge
rules: # rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' # - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"' # - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
- changes: # - changes:
- src/common/**/*.py # - src/common/**/*.py
- proto/*.proto # - proto/*.proto
- src/$IMAGE_NAME/**/*.{py,in,yml} # - src/$IMAGE_NAME/**/*.{py,in,yml}
- src/$IMAGE_NAME/Dockerfile # - src/$IMAGE_NAME/Dockerfile
- src/$IMAGE_NAME/tests/*.py # - src/$IMAGE_NAME/tests/*.py
- manifests/${IMAGE_NAME}service.yaml # - manifests/${IMAGE_NAME}service.yaml
- .gitlab-ci.yml # - .gitlab-ci.yml
artifacts: # artifacts:
when: always # when: always
reports: # reports:
junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml # junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml
## Deployment of the service in Kubernetes Cluster ## Deployment of the service in Kubernetes Cluster
#deploy bgpls_speaker: #deploy bgpls_speaker:
......
...@@ -12,15 +12,20 @@ ...@@ -12,15 +12,20 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import os
from common.Constants import ServiceNameEnum from common.Constants import ServiceNameEnum
from common.Settings import get_service_port_grpc from common.Settings import get_service_port_grpc
from common.proto.device_pb2_grpc import add_DeviceServiceServicer_to_server from common.proto.device_pb2_grpc import add_DeviceServiceServicer_to_server
from common.proto.openconfig_device_pb2_grpc import add_OpenConfigServiceServicer_to_server
from common.tools.service.GenericGrpcService import GenericGrpcService from common.tools.service.GenericGrpcService import GenericGrpcService
from .driver_api.DriverInstanceCache import DriverInstanceCache from .driver_api.DriverInstanceCache import DriverInstanceCache
from .DeviceServiceServicerImpl import DeviceServiceServicerImpl from .DeviceServiceServicerImpl import DeviceServiceServicerImpl
from .monitoring.MonitoringLoops import MonitoringLoops from .monitoring.MonitoringLoops import MonitoringLoops
from .OpenConfigServicer import OpenConfigServicer from .OpenConfigServicer import OpenConfigServicer
from common.proto.openconfig_device_pb2_grpc import add_OpenConfigServiceServicer_to_server
TRUE_VALUES = {'T', 'TRUE', 'YES', '1'}
DEVICE_EMULATED_ONLY = os.environ.get('DEVICE_EMULATED_ONLY')
LOAD_ALL_DEVICE_DRIVERS = (DEVICE_EMULATED_ONLY is None) or (DEVICE_EMULATED_ONLY.upper() not in TRUE_VALUES)
# Custom gRPC settings # Custom gRPC settings
# Multiple clients might keep connections alive waiting for RPC methods to be executed. # Multiple clients might keep connections alive waiting for RPC methods to be executed.
...@@ -33,12 +38,14 @@ class DeviceService(GenericGrpcService): ...@@ -33,12 +38,14 @@ class DeviceService(GenericGrpcService):
super().__init__(port, max_workers=GRPC_MAX_WORKERS, cls_name=cls_name) super().__init__(port, max_workers=GRPC_MAX_WORKERS, cls_name=cls_name)
self.monitoring_loops = MonitoringLoops() self.monitoring_loops = MonitoringLoops()
self.device_servicer = DeviceServiceServicerImpl(driver_instance_cache, self.monitoring_loops) self.device_servicer = DeviceServiceServicerImpl(driver_instance_cache, self.monitoring_loops)
self.openconfig_device_servicer=OpenConfigServicer(driver_instance_cache,self.monitoring_loops) if LOAD_ALL_DEVICE_DRIVERS:
self.openconfig_device_servicer = OpenConfigServicer(driver_instance_cache,self.monitoring_loops)
def install_servicers(self): def install_servicers(self):
self.monitoring_loops.start() self.monitoring_loops.start()
add_DeviceServiceServicer_to_server(self.device_servicer, self.server) add_DeviceServiceServicer_to_server(self.device_servicer, self.server)
add_OpenConfigServiceServicer_to_server(self.openconfig_device_servicer,self.server) if LOAD_ALL_DEVICE_DRIVERS:
add_OpenConfigServiceServicer_to_server(self.openconfig_device_servicer,self.server)
def stop(self): def stop(self):
super().stop() super().stop()
......
...@@ -71,6 +71,7 @@ COPY src/device/client/. device/client/ ...@@ -71,6 +71,7 @@ COPY src/device/client/. device/client/
COPY src/forecaster/__init__.py forecaster/__init__.py COPY src/forecaster/__init__.py forecaster/__init__.py
COPY src/forecaster/client/. forecaster/client/ COPY src/forecaster/client/. forecaster/client/
COPY src/forecaster/service/. forecaster/service/ COPY src/forecaster/service/. forecaster/service/
COPY src/forecaster/tests/. forecaster/tests/
COPY src/monitoring/__init__.py monitoring/__init__.py COPY src/monitoring/__init__.py monitoring/__init__.py
COPY src/monitoring/client/. monitoring/client/ COPY src/monitoring/client/. monitoring/client/
COPY src/service/__init__.py service/__init__.py COPY src/service/__init__.py service/__init__.py
......
...@@ -38,46 +38,46 @@ build slice: ...@@ -38,46 +38,46 @@ build slice:
- manifests/${IMAGE_NAME}service.yaml - manifests/${IMAGE_NAME}service.yaml
- .gitlab-ci.yml - .gitlab-ci.yml
# Apply unit test to the component ## Apply unit test to the component
unit_test slice: #unit_test slice:
variables: # variables:
IMAGE_NAME: 'slice' # name of the microservice # IMAGE_NAME: 'slice' # name of the microservice
IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) # IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
stage: unit_test # stage: unit_test
needs: # needs:
- build slice # - build slice
before_script: # before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY # - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi # - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi
- if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME image is not in the system"; fi # - if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME image is not in the system"; fi
script: # script:
- docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" # - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
- docker run --name $IMAGE_NAME -d -p 4040:4040 -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG # - docker run --name $IMAGE_NAME -d -p 4040:4040 -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG
- sleep 5 # - sleep 5
- docker ps -a # - docker ps -a
- docker logs $IMAGE_NAME # - 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 --junitxml=/opt/results/${IMAGE_NAME}_report.xml"
- docker exec -i $IMAGE_NAME bash -c "coverage report --include='${IMAGE_NAME}/*' --show-missing" # - docker exec -i $IMAGE_NAME bash -c "coverage report --include='${IMAGE_NAME}/*' --show-missing"
coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/' # coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
after_script: # after_script:
- docker rm -f $IMAGE_NAME # - docker rm -f $IMAGE_NAME
- docker network rm teraflowbridge # - docker network rm teraflowbridge
rules: # rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' # - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"' # - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
- changes: # - changes:
- src/common/**/*.py # - src/common/**/*.py
- proto/*.proto # - proto/*.proto
- src/$IMAGE_NAME/**/*.{py,in,yml} # - src/$IMAGE_NAME/**/*.{py,in,yml}
- src/$IMAGE_NAME/Dockerfile # - src/$IMAGE_NAME/Dockerfile
- src/$IMAGE_NAME/tests/*.py # - src/$IMAGE_NAME/tests/*.py
- src/$IMAGE_NAME/tests/Dockerfile # - src/$IMAGE_NAME/tests/Dockerfile
- manifests/${IMAGE_NAME}service.yaml # - manifests/${IMAGE_NAME}service.yaml
- .gitlab-ci.yml # - .gitlab-ci.yml
artifacts: # artifacts:
when: always # when: always
reports: # reports:
junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml # junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml
## Deployment of the service in Kubernetes Cluster ## Deployment of the service in Kubernetes Cluster
#deploy slice: #deploy slice:
......
...@@ -29,8 +29,8 @@ MSG_REST_FAILED = '[rest_request] Query({:s}) failed, retry={:d}/{:d}...' ...@@ -29,8 +29,8 @@ MSG_REST_FAILED = '[rest_request] Query({:s}) failed, retry={:d}/{:d}...'
MSG_ERROR_MAX_RETRIES = 'Maximum number of retries achieved: {:d}' MSG_ERROR_MAX_RETRIES = 'Maximum number of retries achieved: {:d}'
METRICSDB_HOSTNAME = os.environ.get('METRICSDB_HOSTNAME') METRICSDB_HOSTNAME = os.environ.get('METRICSDB_HOSTNAME')
METRICSDB_ILP_PORT = int(os.environ.get('METRICSDB_ILP_PORT')) METRICSDB_ILP_PORT = int(os.environ.get('METRICSDB_ILP_PORT', 0))
METRICSDB_REST_PORT = int(os.environ.get('METRICSDB_REST_PORT')) METRICSDB_REST_PORT = int(os.environ.get('METRICSDB_REST_PORT', 0))
METRICSDB_TABLE_SLICE_GROUPS = os.environ.get('METRICSDB_TABLE_SLICE_GROUPS') METRICSDB_TABLE_SLICE_GROUPS = os.environ.get('METRICSDB_TABLE_SLICE_GROUPS')
COLORS = { COLORS = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment