diff --git a/.gitignore b/.gitignore index 0ff6c0f6..34420bd7 100644 --- a/.gitignore +++ b/.gitignore @@ -109,6 +109,9 @@ ENV/ #pycharm-ide .idea/ +# osx +.DS_Store + # makefile build/lint artifacts /charts/deckhand/*.tgz /charts/deckhand/*.lock diff --git a/.zuul.yaml b/.zuul.yaml index aa250f2f..d5691ab5 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -16,10 +16,8 @@ - airship-deckhand-linter - airship-deckhand-ubuntu: voting: false - irrelevant-files: - - ^.*\.rst$ - - ^doc/.*$ - - ^releasenotes/.*$ + - airship-deckhand-tox-functional + - airship-deckhand-tox-functional-py35 gate: jobs: - airship-deckhand-linter @@ -29,19 +27,23 @@ # - ^.*\.rst$ # - ^doc/.*$ # - ^releasenotes/.*$ + - airship-deckhand-tox-functional + - airship-deckhand-tox-functional-py35 - job: name: airship-deckhand-linter + description: | + Lints all files by checking them for whitespace. run: tools/gate/playbooks/zuul-linter.yaml nodeset: openstack-helm-single-node - job: - name: airship-deckhand + name: airship-deckhand-base roles: - zuul: openstack/openstack-helm-infra vars: zuul_osh_infra_relative_path: ../openstack-helm-infra/ - timeout: 7200 + timeout: 3600 pre-run: - tools/gate/playbooks/osh-infra-upgrade-host.yaml - tools/gate/playbooks/osh-infra-deploy-docker.yaml @@ -54,5 +56,48 @@ - job: name: airship-deckhand-ubuntu - parent: airship-deckhand + parent: airship-deckhand-base nodeset: openstack-helm-single-node + irrelevant-files: + - ^.*\.rst$ + - ^doc/.*$ + - ^releasenotes/.*$ + +- job: + name: airship-deckhand-tox-functional-base + description: | + Base job for running airship-deckhand functional tests. Runs tests + against Docker image generated from source code. + roles: + - zuul: openstack/openstack-helm-infra + timeout: 3600 + pre-run: + - tools/gate/playbooks/osh-infra-upgrade-host.yaml + - tools/gate/playbooks/osh-infra-deploy-docker.yaml + run: tools/gate/playbooks/run-functional-tests.yaml + required-projects: + - openstack/openstack-helm-infra + irrelevant-files: + - ^.*\.rst$ + - ^doc/.*$ + - ^releasenotes/.*$ + +- job: + name: airship-deckhand-tox-functional + description: | + Run tox-based functional tests for the Airship Deckhand project under + cPython version 2.7. Uses tox with the ``functional`` environment. + parent: airship-deckhand-tox-functional-base + nodeset: openstack-helm-single-node + vars: + tox_envlist: functional + +- job: + name: airship-deckhand-tox-functional-py35 + description: | + Run tox-based functional tests for the Airship Deckhand project under + cPython version 3.5. Uses tox with the ``functional-py35`` environment. + parent: airship-deckhand-tox-functional-base + nodeset: openstack-helm-single-node + vars: + tox_envlist: functional-py35 diff --git a/tools/common-tests.sh b/tools/common-tests.sh index df766078..db0b1794 100644 --- a/tools/common-tests.sh +++ b/tools/common-tests.sh @@ -22,6 +22,7 @@ function deploy_postgre { ####################################### set -xe + # TODO(felipemonteiro): Use OSH PostgreSQL chart. POSTGRES_ID=$( sudo docker run \ --detach \ diff --git a/tools/functional-tests.sh b/tools/functional-tests.sh index 772380c3..2daea3fd 100755 --- a/tools/functional-tests.sh +++ b/tools/functional-tests.sh @@ -33,11 +33,13 @@ function cleanup_deckhand { rm -rf $CONF_DIR - # Kill all processes and child processes (for example, if workers > 1) - # if using uwsgi only. - PGID=$(ps -o comm -o pgid | grep uwsgi | grep -o [0-9]* | head -n 1) - if [ -n "$PGID" ]; then - setsid kill -- -$PGID + if [ -z "$DECKHAND_IMAGE" ]; then + # Kill uwsgi service if it is still running. + PID=$( sudo netstat -tulpn | grep ":9000" | head -n 1 | awk '{print $NF}' ) + if [ -n $PID ]; then + PID=${PID%/*} + sudo kill -9 $PID + fi fi } diff --git a/tools/gate/playbooks/roles b/tools/gate/playbooks/roles new file mode 120000 index 00000000..7b9ade87 --- /dev/null +++ b/tools/gate/playbooks/roles @@ -0,0 +1 @@ +../roles/ \ No newline at end of file diff --git a/tools/gate/playbooks/run-functional-tests.yaml b/tools/gate/playbooks/run-functional-tests.yaml new file mode 100644 index 00000000..b5a6dd4e --- /dev/null +++ b/tools/gate/playbooks/run-functional-tests.yaml @@ -0,0 +1,28 @@ +# 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. + +- hosts: all + gather_facts: False + become: yes + roles: + - build-images + tags: + - build-images + +- hosts: all + gather_facts: False + roles: + - run-tests + tags: + - run-tests diff --git a/tools/gate/roles/build-images/tasks/airship-deckhand.yaml b/tools/gate/roles/build-images/tasks/airship-deckhand.yaml new file mode 100644 index 00000000..bf5623e7 --- /dev/null +++ b/tools/gate/roles/build-images/tasks/airship-deckhand.yaml @@ -0,0 +1,56 @@ +# 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: set zuul_site_mirror_fqdn from env var if not defined + when: zuul_site_mirror_fqdn is not defined + set_fact: + zuul_site_mirror_fqdn: "{{ lookup('env','zuul_site_mirror_fqdn') }}" + +# NOTE(portdirect): Untill https://github.com/ansible/ansible/issues/21433 is +# resolved, we build with a shell script to make use of the host network. +- name: Build Airship-Deckhand Image + block: + # NOTE(portdirect): We do this to ensure we are feeding the docker build + # a clean path to work with. + - name: Airship-Deckhand image build path + shell: cd "{{ work_dir }}"; pwd + register: airship_deckhand_path + vars: + zuul_airship_deckhand_relative_path: ../airship-deckhand + work_dir: "{{ zuul.project.src_dir }}/{{ zuul_airship_deckhand_relative_path | default('') }}" + + - name: Airship-Deckhand image build path + shell: |- + set -ex; + docker build \ + --network host \ + --force-rm \ + --label zuul \ + --file images/deckhand/Dockerfile \ + {% if zuul_site_mirror_fqdn is defined and zuul_site_mirror_fqdn %} + --build-arg UBUNTU_URL="http://{{ zuul_site_mirror_fqdn }}/ubuntu/" \ + --build-arg ALLOW_UNAUTHENTICATED="true" \ + --build-arg PIP_INDEX_URL="http://{{ zuul_site_mirror_fqdn }}/pypi/simple" \ + --build-arg PIP_TRUSTED_HOST="{{ zuul_site_mirror_fqdn }}" \ + {% endif %} + . + args: + chdir: "{{ airship_deckhand_path.stdout }}" + executable: /bin/bash + + - name: Register Deckhand Image ID + shell: |- + set -e; + echo $( docker images --filter label=zuul | awk '{print $3}' | head -2 | tail -1 ) + register: deckhand_image_id diff --git a/tools/gate/roles/build-images/tasks/main.yaml b/tools/gate/roles/build-images/tasks/main.yaml new file mode 100644 index 00000000..8fd8a90f --- /dev/null +++ b/tools/gate/roles/build-images/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: airship-deckhand.yaml diff --git a/tools/gate/roles/run-tests/tasks/main.yaml b/tools/gate/roles/run-tests/tasks/main.yaml new file mode 100644 index 00000000..a1c8c122 --- /dev/null +++ b/tools/gate/roles/run-tests/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: tox-tests.yaml diff --git a/tools/gate/roles/run-tests/tasks/tox-tests.yaml b/tools/gate/roles/run-tests/tasks/tox-tests.yaml new file mode 100644 index 00000000..a81ebb6e --- /dev/null +++ b/tools/gate/roles/run-tests/tasks/tox-tests.yaml @@ -0,0 +1,22 @@ +# 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: Run Tox Tests + shell: | + set -xe; + tox -e {{ tox_envlist }} + args: + chdir: "{{ zuul.project.src_dir }}" + environment: + DECKHAND_IMAGE: "{{ deckhand_image_id.stdout }}" diff --git a/tox.ini b/tox.ini index 28f53eac..b25a6309 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{35,27},py{35,27}-{postgresql},cover,pep8,bandit,docs +envlist = py{35,27},py{35,27}-{postgresql},functional,cover,pep8,bandit,docs [testenv] usedevelop = True @@ -41,7 +41,17 @@ commands = {toxinidir}/tools/run_pifpaf.sh '{posargs}' [testenv:functional] -# Always run functional tests using Python 3. +basepython = python2.7 +setenv = VIRTUAL_ENV={envdir} + OS_TEST_PATH=./deckhand/tests/functional + LANGUAGE=en_US +deps = -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt +commands = + find . -type f -name "*.pyc" -delete + {toxinidir}/tools/functional-tests.sh '{posargs}' + +[testenv:functional-py35] basepython=python3.5 setenv = VIRTUAL_ENV={envdir} OS_TEST_PATH=./deckhand/tests/functional