From b5b9aa56f9263557e1cf339cdc471d8bb795b209 Mon Sep 17 00:00:00 2001 From: Javi Moreno Date: Wed, 27 Oct 2021 11:33:30 -0400 Subject: [PATCH] Influxdb added to tests --- src/monitoring/.gitlab-ci.yml | 9 ++++++++- src/monitoring/service/MonitoringServiceServicerImpl.py | 3 ++- src/monitoring/tests/Dockerfile | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/monitoring/.gitlab-ci.yml b/src/monitoring/.gitlab-ci.yml index 1cfbde21f..b1aa8e2ed 100644 --- a/src/monitoring/.gitlab-ci.yml +++ b/src/monitoring/.gitlab-ci.yml @@ -62,6 +62,7 @@ test monitoring run: - docker ps after_script: - docker stop "$IMAGE_NAME" + - docker network rm teraflowbridge 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 == "push" && $CI_COMMIT_BRANCH == "develop"' @@ -82,9 +83,15 @@ test monitoring pytest: stage: unit_test needs: - build monitoring + before_script: + - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi script: + - docker run -p 8086:8086 -e INFLUXDB_DB=$INFLUXDB_DATABASE -e INFLUXDB_ADMIN_USER=$INFLUXDB_USER -e INFLUXDB_ADMIN_PASSWORD=$INFLUXDB_PASSWORD -e INXLUXDB_HTTP_AUTH_ENABLED=True --network=teraflowbridge --name influxdb-tests influxdb:1.8 - docker build -t "$IMAGE_NAME_TEST:$IMAGE_TAG" -f ./src/$IMAGE_NAME/tests/Dockerfile ./src/ - - docker run -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" $IMAGE_NAME_TEST:$IMAGE_TAG + - docker run -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --build-arg user=$INFLUXDB_USER --build-arg pass=$INFLUXDB_PASSWORD --build-arg db=$INFLUXDB_DATABASE --network=teraflowbridge $IMAGE_NAME_TEST:$IMAGE_TAG + after_script: + - docker stop influxdb-tests + - docker network rm teraflowbridge 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 == "push" && $CI_COMMIT_BRANCH == "develop"' diff --git a/src/monitoring/service/MonitoringServiceServicerImpl.py b/src/monitoring/service/MonitoringServiceServicerImpl.py index f1ee6d1cd..0e85d6bb4 100644 --- a/src/monitoring/service/MonitoringServiceServicerImpl.py +++ b/src/monitoring/service/MonitoringServiceServicerImpl.py @@ -23,11 +23,12 @@ INFLUXDB_DB = os.environ.get("INFLUXDB_DATABASE") class MonitoringServiceServicerImpl(monitoring_pb2_grpc.MonitoringServiceServicer): def __init__(self): LOGGER.info('Init monitoringService') + # Init sqlite monitoring db self.sql_db = sqlite_tools.SQLite('monitoring.db') # Create influx_db client - self.influx_db = influx_tools.Influx("localhost","8086",INFLUXDB_USER,INFLUXDB_PASS,INFLUXDB_DB) + self.influx_db = influx_tools.Influx("influxdb-tests","8086",INFLUXDB_USER,INFLUXDB_PASS,INFLUXDB_DB) # CreateKpi (CreateKpiRequest) returns (KpiId) {} def CreateKpi(self, request : monitoring_pb2.CreateKpiRequest, context) -> monitoring_pb2.KpiId : diff --git a/src/monitoring/tests/Dockerfile b/src/monitoring/tests/Dockerfile index 6d57e059e..13524052d 100644 --- a/src/monitoring/tests/Dockerfile +++ b/src/monitoring/tests/Dockerfile @@ -31,6 +31,14 @@ RUN python3 -m pip install -r requirements.txt COPY monitoring/. monitoring COPY common/logger.py common +# define variables for the influxdb +ARG user +ARG pass +ARG db +ENV INFLUXDB_USER=$user +ENV INFLUXDB_PASSWORD=$pass +ENV INFLUXDB_DATABASE=$db + # set listen port ENV PORT=7070 EXPOSE 7070 -- GitLab