diff --git a/.zuul.yaml b/.zuul.yaml index 0c302d32..0b12c55c 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -17,6 +17,7 @@ - airship-deckhand-ubuntu: voting: false - airship-deckhand-functional-docker-py35 + - airship-deckhand-functional-uwsgi-py35 gate: jobs: - airship-deckhand-linter @@ -27,6 +28,7 @@ # - ^doc/.*$ # - ^releasenotes/.*$ - airship-deckhand-functional-docker-py35 + - airship-deckhand-functional-uwsgi-py35 - job: name: airship-deckhand-linter @@ -80,6 +82,17 @@ - ^doc/.*$ - ^releasenotes/.*$ +- job: + name: airship-deckhand-functional-uwsgi-py35 + description: | + Run tox-based functional tests for the Airship Deckhand project using a + minimalistic deployment consisting of uwsgi for Deckhand API and pifpaf + for ephemeral PostgreSQL DB, under cPython version 3.5. + run: tools/gate/playbooks/run-functional-tests-uwsgi.yaml + nodeset: openstack-helm-single-node + vars: + tox_envlist: functional-dev + - job: name: airship-deckhand-functional-docker-py35 description: | diff --git a/test-requirements.txt b/test-requirements.txt index f3a37438..7506ce60 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -15,5 +15,4 @@ testrepository>=0.0.20 # Apache-2.0/BSD testtools>=2.3.0 # MIT bandit>=1.4.0 # Apache-2.0 gabbi==1.35.1 -pytest-html==1.16.1 -pifpaf==2.0.5 +pifpaf>=0.10.0 # Apache-2.0 diff --git a/tools/common-tests.sh b/tools/common-tests.sh index 36babd4b..539d9a22 100644 --- a/tools/common-tests.sh +++ b/tools/common-tests.sh @@ -9,47 +9,13 @@ function log_section { } -function deploy_postgre { - ####################################### - # Deploy an ephemeral PostgreSQL DB. - # Globals: - # POSTGRES_ID - # POSTGRES_IP - # Arguments: - # None - # Returns: - # None - ####################################### - set -xe - - # TODO(felipemonteiro): Use OSH PostgreSQL chart. - POSTGRES_ID=$( - sudo docker run \ - --detach \ - --publish :5432 \ - -e POSTGRES_DB=deckhand \ - -e POSTGRES_USER=deckhand \ - -e POSTGRES_PASSWORD=password \ - postgres:9.5 - ) - - POSTGRES_IP=$( - sudo docker inspect \ - --format='{{ .NetworkSettings.Networks.bridge.IPAddress }}' \ - $POSTGRES_ID - ) - - echo $POSTGRES_IP -} - - function gen_config { ####################################### # Generate sample configuration file # Globals: # CONF_DIR # DECKHAND_TEST_URL - # DATABASE_URL + # AIRSHIP_DECKHAND_DATABASE_URL # DECKHAND_CONFIG_DIR # Arguments: # disable_keystone: true or false @@ -57,7 +23,7 @@ function gen_config { # Returns: # None ####################################### - set -xe + set -xe; log_section "Creating config directory and test deckhand.conf" @@ -66,14 +32,13 @@ function gen_config { local disable_keystone=$1 export DECKHAND_TEST_URL=$2 - export DATABASE_URL=postgresql+psycopg2://deckhand:password@$POSTGRES_IP:5432/deckhand # Used by Deckhand's initialization script to search for config files. export DECKHAND_CONFIG_DIR=$CONF_DIR local conf_file=${CONF_DIR}/deckhand.conf cp etc/deckhand/logging.conf.sample $CONF_DIR/logging.conf - envsubst '${DATABASE_URL}' < deckhand/tests/deckhand.conf.test > $conf_file + envsubst '${AIRSHIP_DECKHAND_DATABASE_URL}' < deckhand/tests/deckhand.conf.test > $conf_file # Only set up logging if running Deckhand via uwsgi. The container already has # values for logging. @@ -104,7 +69,7 @@ function gen_paste { # Returns: # None ####################################### - set -xe + set -xe; local disable_keystone=$1 diff --git a/tools/functional-tests.sh b/tools/functional-tests.sh index 01d25c98..10af5983 100755 --- a/tools/functional-tests.sh +++ b/tools/functional-tests.sh @@ -2,6 +2,8 @@ # Script intended for running Deckhand functional tests via gabbi for # developers. Dependencies include gabbi, pifpaf and uwsgi. +# +# Usage: pifpaf run postgresql -- tools/functional-tests.sh set -xe @@ -26,41 +28,38 @@ function cleanup_deckhand { trap cleanup_deckhand EXIT -function deploy_postgresql { - eval `pifpaf run postgresql` - export POSTGRES_IP=${PIFPAF_POSTGRESQL_URL} -} - - function deploy_deckhand { - source ${CURRENT_DIR}/common-tests.sh gen_config true "127.0.0.1:9000" gen_paste true log_section "Running Deckhand via uwsgi." - alembic upgrade head - source $ROOTDIR/../entrypoint.sh server & + source ${CURRENT_DIR}/entrypoint.sh alembic upgrade head & + # Give time for migrations to complete. + sleep 5 + source ${CURRENT_DIR}/entrypoint.sh server & # Give the server a chance to come up. Better to poll a health check. sleep 5 } +export AIRSHIP_DECKHAND_DATABASE_URL=${PIFPAF_POSTGRESQL_URL} + # Deploy Deckhand and PostgreSQL and run tests. -deploy_postgresql +source ${CURRENT_DIR}/tools/common-tests.sh deploy_deckhand -log_section Running tests +log_section "Running tests." -export DECKHAND_TEST_DIR=${CURRENT_DIR}/../deckhand/tests/functional/gabbits +export DECKHAND_TEST_DIR=${CURRENT_DIR}/deckhand/tests/functional/gabbits set +e posargs=$@ if [ ${#posargs} -ge 1 ]; then - py.test -k $1 -svx ${CURRENT_DIR}/../deckhand/tests/common/test_gabbi.py + py.test -k $1 -svx ${CURRENT_DIR}/deckhand/tests/common/test_gabbi.py else - py.test -svx ${CURRENT_DIR}/../deckhand/tests/common/test_gabbi.py + py.test -svx ${CURRENT_DIR}/deckhand/tests/common/test_gabbi.py fi TEST_STATUS=$? set -e diff --git a/tools/gate/playbooks/run-functional-tests-uwsgi.yaml b/tools/gate/playbooks/run-functional-tests-uwsgi.yaml index 7e79b2ff..536cf645 100644 --- a/tools/gate/playbooks/run-functional-tests-uwsgi.yaml +++ b/tools/gate/playbooks/run-functional-tests-uwsgi.yaml @@ -15,6 +15,8 @@ - hosts: all gather_facts: False roles: + - install-postgresql - run-tests tags: + - install-postgresql - run-tests diff --git a/tools/gate/roles/install-postgresql/tasks/install-postgresql.yaml b/tools/gate/roles/install-postgresql/tasks/install-postgresql.yaml new file mode 100644 index 00000000..1e9b5679 --- /dev/null +++ b/tools/gate/roles/install-postgresql/tasks/install-postgresql.yaml @@ -0,0 +1,23 @@ +# Copyright 2018 AT&T Intellectual Property. All other rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Install PostgreSQL + shell: |- + set -xe; + if [ -z $(which pg_config) ]; then + apt-get update -y + apt-get install postgresql postgresql-contrib -y + apt-get install libpq-dev -y + fi + become: yes diff --git a/tools/gate/roles/install-postgresql/tasks/main.yaml b/tools/gate/roles/install-postgresql/tasks/main.yaml new file mode 100644 index 00000000..4fb50ef8 --- /dev/null +++ b/tools/gate/roles/install-postgresql/tasks/main.yaml @@ -0,0 +1,15 @@ +# Copyright 2018 AT&T Intellectual Property. All other rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- include: install-postgresql.yaml diff --git a/tools/integration-tests.sh b/tools/integration-tests.sh index 1fe30f1c..eccf7b9d 100755 --- a/tools/integration-tests.sh +++ b/tools/integration-tests.sh @@ -206,7 +206,7 @@ source ${CURRENT_DIR}/tools/common-tests.sh deploy_osh_keystone_barbican # Deploy PostgreSQL and Deckhand. -deploy_postgre +deploy_postgresql deploy_deckhand run_tests "$@" diff --git a/tox.ini b/tox.ini index 42bb92c9..2b695e20 100644 --- a/tox.ini +++ b/tox.ini @@ -54,12 +54,13 @@ commands = basepython=python3.5 # Minimalistic functional test job for running Deckhand functional tests # via uwsgi. Uses pifpaf for DB instantiation. Useful for developers. +# Requires PostgreSQL be installed on host. setenv = VIRTUAL_ENV={envdir} deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt commands = find . -type f -name "*.pyc" -delete - {toxinidir}/tools/functional-tests.sh '{posargs}' + pifpaf run postgresql -- {toxinidir}/tools/functional-tests.sh "{posargs}" [testenv:cover] setenv = {[testenv]setenv}