From 44487c344881f98a35c4ca9da79ef51a75c0ef31 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Thu, 12 Sep 2019 12:47:29 +0200 Subject: [PATCH] Configure to build on CircleCI --- .circleci/config.yml | 67 +++++++++++++++++++++++++++++++++++++ CHANGELOG.md | 3 ++ README.md | 2 +- influxdb2_test/base_test.py | 3 +- influxdb2_test/test_gzip.py | 2 +- scripts/ci-test.sh | 21 ++++++++++++ scripts/influxdb-restart.sh | 26 +++++++------- 7 files changed, 109 insertions(+), 15 deletions(-) create mode 100644 .circleci/config.yml create mode 100755 scripts/ci-test.sh diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..8588e905 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,67 @@ +version: 2.1 + +commands: + influxdb-restart: + steps: + - run: + name: "Start InfluxDB service" + command: ./scripts/influxdb-restart.sh + prepare: + description: "Prepare environment to tests" + steps: + - checkout + - influxdb-restart + client-test: + description: "Run tests" + parameters: + python-version: + type: string + default: &default-python-version "3" + steps: + - restore_cache: + name: Restoring Pip Cache + keys: + - &cache-key pip-cache-<< parameters.python-version >>-{{ checksum "requirements.txt" }}-{{ checksum "test-requirements.txt" }} + - pip-cache-<< parameters.python-version >>- + - run: + name: "Running tests" + command: | + docker run -it --rm \ + --volume ${PWD}:/usr/src/project \ + --volume ${PWD}/.cache:/root/.cache/pip/ \ + --workdir /usr/src/project \ + --network influx_network \ + --env INFLUXDB_IP=192.168.0.2 \ + python:<< parameters.python-version >> /bin/bash -c "./scripts/ci-test.sh" + - save_cache: + name: Saving Pip Cache + key: *cache-key + paths: + - ${PWD}/.cache + when: always +jobs: + tests-python-3: + machine: true + steps: + - prepare + - client-test: + python-version: *default-python-version + - store_test_results: + path: test-reports + +workflows: + version: 2 + build: + jobs: + - tests-python-3 + + nightly: + triggers: + - schedule: + cron: "0 0 * * *" + filters: + branches: + only: + - master + jobs: + - tests-python-3 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 100c96fe..279eadb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,3 +10,6 @@ ### Bugs 1. [#3](https://github.com/bonitoo-io/influxdb-client-python/issues/3): The management API correctly supports inheritance defined in Influx API 1. [#7](https://github.com/bonitoo-io/influxdb-client-python/issues/7): Drop NaN and infinity values from fields when writing to InfluxDB + +### CI +1. [#11](https://github.com/bonitoo-io/influxdb-client-python/pull/11): Switch CI to CircleCI diff --git a/README.md b/README.md index 2787f449..8cb3dc04 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # influxdb-client-python -[![Build Status](https://travis-ci.org/bonitoo-io/influxdb-client-python.svg?branch=master)](https://travis-ci.org/bonitoo-io/influxdb-client-python) +[![CircleCI](https://circleci.com/gh/bonitoo-io/influxdb-client-python.svg?style=svg)](https://circleci.com/gh/bonitoo-io/influxdb-client-python) InfluxDB 2.0 python client library. TODO... diff --git a/influxdb2_test/base_test.py b/influxdb2_test/base_test.py index d805e016..81638350 100644 --- a/influxdb2_test/base_test.py +++ b/influxdb2_test/base_test.py @@ -1,4 +1,5 @@ import datetime +import os import re import time import unittest @@ -18,7 +19,7 @@ class BaseTest(unittest.TestCase): def setUp(self) -> None: self.conf = influxdb2.configuration.Configuration() - self.host = "http://localhost:9999/api/v2" + self.host = "http://{0}:9999/api/v2".format(os.getenv("INFLUXDB_IP", "localhost")) self.debug = False self.auth_token = "my-token" self.org = "my-org" diff --git a/influxdb2_test/test_gzip.py b/influxdb2_test/test_gzip.py index ffb06358..45bcd6c6 100644 --- a/influxdb2_test/test_gzip.py +++ b/influxdb2_test/test_gzip.py @@ -129,7 +129,7 @@ def test_gzip_enabled(self): def test_write_query_gzip(self): httpretty.disable() - self.client = InfluxDBClient("http://localhost:9999/api/v2", token="my-token", org="my-org", debug=False, + self.client = InfluxDBClient(self.host, token="my-token", org="my-org", debug=False, enable_gzip=True) self.api_client = self.client.api_client self.buckets_client = self.client.buckets_api() diff --git a/scripts/ci-test.sh b/scripts/ci-test.sh new file mode 100755 index 00000000..76a82a4a --- /dev/null +++ b/scripts/ci-test.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -e + +# +# Install requirements +# +python --version +pip install -r requirements.txt +pip install -r test-requirements.txt + +# +# Prepare for test results +# +mkdir test-reports || true + +# +# Test +# +pytest influxdb2_test --junitxml=test-reports/junit.xml + diff --git a/scripts/influxdb-restart.sh b/scripts/influxdb-restart.sh index 918b29ba..9602f3cb 100755 --- a/scripts/influxdb-restart.sh +++ b/scripts/influxdb-restart.sh @@ -32,6 +32,10 @@ INFLUXDB_V2_IMAGE=${DOCKER_REGISTRY}influx:${INFLUXDB_V2_VERSION} SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )" +docker kill influxdb_v2 || true +docker rm influxdb_v2 || true +docker network rm influx_network || true +docker network create -d bridge influx_network --subnet 192.168.0.0/24 --gateway 192.168.0.1 # # InfluxDB 2.0 @@ -40,12 +44,11 @@ echo echo "Restarting InfluxDB 2.0 [${INFLUXDB_V2_IMAGE}] ... " echo -docker kill my-influxdb2 || true -docker rm my-influxdb2 || true docker pull ${INFLUXDB_V2_IMAGE} || true docker run \ --detach \ - --name my-influxdb2 \ + --name influxdb_v2 \ + --network influx_network \ --publish 9999:9999 \ ${INFLUXDB_V2_IMAGE} @@ -55,12 +58,11 @@ wget -S --spider --tries=20 --retry-connrefused --waitretry=5 http://localhost:9 echo echo "Post onBoarding request, to setup initial user (my-user@my-password), org (my-org) and bucketSetup (my-bucket)" echo - -docker exec -it my-influxdb2 influx setup --username my-user --password my-password \ - --token my-token --org my-org --bucket my-bucket --retention 48 --force - -## show created orgId -ORGID=`docker exec -it my-influxdb2 influx org find | grep my-org | awk '{ print $1 }'` -echo "orgId="${ORGID} - - +curl -i -X POST http://localhost:9999/api/v2/setup -H 'accept: application/json' \ + -d '{ + "username": "my-user", + "password": "my-password", + "org": "my-org", + "bucket": "my-bucket", + "token": "my-token" + }'