From 2bfb16e44df5f8f899f0df06d203e62027b87948 Mon Sep 17 00:00:00 2001 From: Felipe Monteiro Date: Mon, 8 Jan 2018 18:49:21 +0000 Subject: [PATCH] [Gate fix] Fix pifpaf run postgresql failing. This PS unblocks the gate by replacing pifpaf to run postgresql for unit tests with docker, as a workaround. This is because "pifpaf run postgresql" is failing with pifpaf not being able to find the command "pifpaf run". Steps to reproduce: python3 -m virtualenv -p python3 /tmp/venv source /tmp/venv/bin/activate pip install -U pip wheel devpi-client setuptools pip install pifpaf $pifpaf run postgresql >> pifpaf: 'run' is not a pifpaf command. See 'pifpaf --help'. >> Did you mean one of these? help The unit test script for spinning up the docker postgresql container and then running unit tests is very similar to the pre-existing script for running functional tests located in tools/ directory. Change-Id: Ib0f414ff58007037ac12161876dcd7a10e91f48c --- deckhand/tests/unit/base.py | 2 +- test-requirements.txt | 1 - tools/unit-tests.sh | 39 +++++++++++++++++++++++++++++++++++++ tox.ini | 6 ++---- 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100755 tools/unit-tests.sh diff --git a/deckhand/tests/unit/base.py b/deckhand/tests/unit/base.py index 300c3ce4..5e9e7f9f 100644 --- a/deckhand/tests/unit/base.py +++ b/deckhand/tests/unit/base.py @@ -106,7 +106,7 @@ class DeckhandWithDBTestCase(DeckhandTestCase): def setUp(self): super(DeckhandWithDBTestCase, self).setUp() self.override_config( - 'connection', os.environ.get('PIFPAF_URL', 'sqlite://'), + 'connection', os.environ.get('DATABASE_URL', 'sqlite://'), group='database') db_api.setup_db() self.addCleanup(db_api.drop_db) diff --git a/test-requirements.txt b/test-requirements.txt index adf132c4..29ab492e 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -15,7 +15,6 @@ testrepository>=0.0.18 # Apache-2.0/BSD testtools>=1.4.0 # MIT bandit>=1.1.0 # Apache-2.0 gabbi==1.35.1 -pifpaf==0.10.0 pytest-html==1.16.0 # NOTE(fmontei): The requirement below is only included because readthedocs diff --git a/tools/unit-tests.sh b/tools/unit-tests.sh new file mode 100755 index 00000000..92836f69 --- /dev/null +++ b/tools/unit-tests.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Script for setting up temporary PostgreSQL database for testing unit tests +# against. + +function cleanup { + sudo docker stop $POSTGRES_ID +} + +trap cleanup EXIT + + +POSTGRES_ID=$( + sudo docker run \ + --detach \ + --publish :5432 \ + -e POSTGRES_DB=deckhand \ + -e POSTGRES_USER=$(whoami) \ + -e POSTGRES_PASSWORD=password \ + postgres:9.5 +) + +POSTGRES_IP=$( + sudo docker inspect \ + --format='{{ .NetworkSettings.Networks.bridge.IPAddress }}' \ + $POSTGRES_ID +) + +# Used by unit tests to interact with DB. +export DATABASE_URL=postgresql+psycopg2://$(whoami):password@$POSTGRES_IP:5432/deckhand + +set -e +posargs=$@ +if [ ${#posargs} -ge 1 ]; then + ostestr --concurrency 1 --regex ${posargs} +else + ostestr --concurrency 1 +fi +set +e diff --git a/tox.ini b/tox.ini index 7b64d5e8..ae1c4371 100644 --- a/tox.ini +++ b/tox.ini @@ -24,10 +24,9 @@ commands = ostestr '{posargs}' [testenv:py27-postgresql] -#package required in ubuntu: libpq-dev commands = {[testenv]commands} - pifpaf run postgresql -- '{toxinidir}'/tools/pretty_tox.sh '--concurrency=1 {posargs}' + {toxinidir}/tools/unit-tests.sh '{posargs}' [testenv:py35] commands = @@ -35,10 +34,9 @@ commands = ostestr '{posargs}' [testenv:py35-postgresql] -#package required in ubuntu: libpq-dev commands = {[testenv]commands} - pifpaf run postgresql -- '{toxinidir}'/tools/pretty_tox.sh '--concurrency=1 {posargs}' + {toxinidir}/tools/unit-tests.sh '{posargs}' [testenv:functional] usedevelop = True