Skip to content
Snippets Groups Projects
Commit 006d0006 authored by Sergio Gonzalez Diaz's avatar Sergio Gonzalez Diaz
Browse files

Unit tests mlonitoring influxdb

parent cc93bdae
No related branches found
No related tags found
1 merge request!54Release 2.0.0
...@@ -13,6 +13,7 @@ spec: ...@@ -13,6 +13,7 @@ spec:
app: monitoring app: monitoring
spec: spec:
terminationGracePeriodSeconds: 5 terminationGracePeriodSeconds: 5
restartPolicy: Always
# initContainers: # initContainers:
# - name: influxdb # - name: influxdb
# image: influxdb:1.8 # image: influxdb:1.8
......
...@@ -7,7 +7,7 @@ build monitoring: ...@@ -7,7 +7,7 @@ build monitoring:
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
script: script:
- docker build --build-arg user=$INFLUXDB_USER --build-arg pass=$INFLUXDB_PASSWORD --build-arg db=$INFLUXDB_DATABASE -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile ./src/ - docker build --build-arg hostname=localhost --build-arg user=$INFLUXDB_USER --build-arg pass=$INFLUXDB_PASSWORD --build-arg db=$INFLUXDB_DATABASE -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile ./src/
- docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
- docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
after_script: after_script:
...@@ -85,14 +85,15 @@ test monitoring pytest: ...@@ -85,14 +85,15 @@ test monitoring pytest:
- build monitoring - build monitoring
before_script: before_script:
- 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 influxdb-tests; then docker rm influxdb-tests; fi - if docker container ls | grep influxdb; then docker rm influxdb; fi
script: script:
- docker run -d -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 run --name influxdb -d -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 influxdb:1.8
- docker build -t "$IMAGE_NAME_TEST:$IMAGE_TAG" -f ./src/$IMAGE_NAME/tests/Dockerfile ./src/ - docker build --build-arg hostname=influxdb --build-arg user=$INFLUXDB_USER --build-arg pass=$INFLUXDB_PASSWORD --build-arg db=$INFLUXDB_DATABASE -t "$IMAGE_NAME_TEST:$IMAGE_TAG" -f ./src/$IMAGE_NAME/tests/Dockerfile ./src/
- 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 - docker run --name $IMAGE_NAME_TEST -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $IMAGE_NAME_TEST:$IMAGE_TAG
after_script: after_script:
- docker stop influxdb-tests - docker stop influxdb
- docker rm influxdb-tests - docker rm influxdb
- docker rm $IMAGE_NAME_TEST
- 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)'
......
...@@ -37,6 +37,8 @@ ENV PORT=7070 ...@@ -37,6 +37,8 @@ ENV PORT=7070
ARG user ARG user
ARG pass ARG pass
ARG db ARG db
ARG hostname
ENV INFLUXDB_HOSTNAME=$hostname
ENV INFLUXDB_USER=$user ENV INFLUXDB_USER=$user
ENV INFLUXDB_PASSWORD=$pass ENV INFLUXDB_PASSWORD=$pass
ENV INFLUXDB_DATABASE=$db ENV INFLUXDB_DATABASE=$db
......
...@@ -19,6 +19,7 @@ MONITORING_INCLUDEKPI_COUNTER = Counter('monitoring_includekpi_counter', 'Monito ...@@ -19,6 +19,7 @@ MONITORING_INCLUDEKPI_COUNTER = Counter('monitoring_includekpi_counter', 'Monito
INFLUXDB_USER = os.environ.get("INFLUXDB_USER") INFLUXDB_USER = os.environ.get("INFLUXDB_USER")
INFLUXDB_PASS = os.environ.get("INFLUXDB_PASSWORD") INFLUXDB_PASS = os.environ.get("INFLUXDB_PASSWORD")
INFLUXDB_DB = os.environ.get("INFLUXDB_DATABASE") INFLUXDB_DB = os.environ.get("INFLUXDB_DATABASE")
INFLUXDB_HOST = os.environ.get("INFLUXDB_HOSTNAME")
class MonitoringServiceServicerImpl(monitoring_pb2_grpc.MonitoringServiceServicer): class MonitoringServiceServicerImpl(monitoring_pb2_grpc.MonitoringServiceServicer):
def __init__(self): def __init__(self):
...@@ -28,7 +29,7 @@ class MonitoringServiceServicerImpl(monitoring_pb2_grpc.MonitoringServiceService ...@@ -28,7 +29,7 @@ class MonitoringServiceServicerImpl(monitoring_pb2_grpc.MonitoringServiceService
self.sql_db = sqlite_tools.SQLite('monitoring.db') self.sql_db = sqlite_tools.SQLite('monitoring.db')
# Create influx_db client # Create influx_db client
self.influx_db = influx_tools.Influx("influxdb-tests","8086",INFLUXDB_USER,INFLUXDB_PASS,INFLUXDB_DB) self.influx_db = influx_tools.Influx(INFLUXDB_HOST,"8086",INFLUXDB_USER,INFLUXDB_PASS,INFLUXDB_DB)
# CreateKpi (CreateKpiRequest) returns (KpiId) {} # CreateKpi (CreateKpiRequest) returns (KpiId) {}
def CreateKpi(self, request : monitoring_pb2.CreateKpiRequest, context) -> monitoring_pb2.KpiId : def CreateKpi(self, request : monitoring_pb2.CreateKpiRequest, context) -> monitoring_pb2.KpiId :
......
...@@ -35,6 +35,8 @@ COPY common/logger.py common ...@@ -35,6 +35,8 @@ COPY common/logger.py common
ARG user ARG user
ARG pass ARG pass
ARG db ARG db
ARG hostname
ENV INFLUXDB_HOSTNAME=$hostname
ENV INFLUXDB_USER=$user ENV INFLUXDB_USER=$user
ENV INFLUXDB_PASSWORD=$pass ENV INFLUXDB_PASSWORD=$pass
ENV INFLUXDB_DATABASE=$db ENV INFLUXDB_DATABASE=$db
......
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