diff --git a/.zuul.yaml b/.zuul.d/zuul.yaml similarity index 85% rename from .zuul.yaml rename to .zuul.d/zuul.yaml index 477f0f72..6a09037d 100644 --- a/.zuul.yaml +++ b/.zuul.d/zuul.yaml @@ -13,16 +13,16 @@ tox_envlist: linters - job: - name: ara-1.0-integration-base + name: ara-integration-base parent: base vars: integration_ansible_name: "{{ ansible_user_dir }}/src/github.com/ansible/ansible" integration_ansible_version: null - run: playbooks/integration-tests.yaml - post-run: tests/integration-post.yaml + run: playbooks/ara_tests.yaml + post-run: tests/ara_tests_post.yaml - job: - name: ara-1.0-integration-fedora-devel + name: ara-integration-fedora-devel parent: ara-integration-base nodeset: fedora-latest required-projects: @@ -30,16 +30,16 @@ override-checkout: devel - job: - name: ara-1.0-integration-fedora-2.7 - parent: ara-1.0-integration-base + name: ara-integration-fedora-2.7 + parent: ara-integration-base nodeset: fedora-latest required-projects: - name: github.com/ansible/ansible override-checkout: stable-2.7 - job: - name: ara-1.0-integration-ubuntu-2.6 - parent: ara-1.0-integration-base + name: ara-integration-ubuntu-2.6 + parent: ara-integration-base nodeset: ubuntu-bionic required-projects: - name: github.com/ansible/ansible @@ -114,10 +114,10 @@ - docs-on-readthedocs check: jobs: - - ara-1.0-integration-fedora-2.7 - - ara-1.0-integration-fedora-devel: + - ara-integration-fedora-2.7 + - ara-integration-fedora-devel: voting: false - - ara-1.0-integration-ubuntu-2.6 + - ara-integration-ubuntu-2.6 - ara-1.0-role-integration-ubuntu - ara-1.0-role-integration-fedora - ara-web-role-integration-ubuntu @@ -126,8 +126,8 @@ - ara-tox-py3 gate: jobs: - - ara-1.0-integration-fedora-2.7 - - ara-1.0-integration-ubuntu-2.6 + - ara-integration-fedora-2.7 + - ara-integration-ubuntu-2.6 - ara-1.0-role-integration-ubuntu - ara-1.0-role-integration-fedora - ara-web-role-integration-ubuntu diff --git a/README.rst b/README.rst index 59391dfd..acbd51f5 100644 --- a/README.rst +++ b/README.rst @@ -16,21 +16,24 @@ The project provides several distinct components in order to make this happen: Quickstart ========== -Here's how you can get started from scratch with default settings:: +Here's how you can get started from scratch with default settings: - # Create a virtual environment - python3 -m venv ~/.ara/venv +.. code-block:: bash + + # Create a virtual environment and activate it so we don't conflict + # with system or distribution packages + python3 -m venv ~/.ara/virtualenv + source ~/.ara/virtualenv/bin/activate # Install Ansible and the required ARA projects - ~/.ara/venv/bin/pip install ansible - ~/.ara/venv/bin/pip install git+https://github.com/openstack/ara@feature/1.0 + pip install ansible git+https://github.com/openstack/ara@feature/1.0 # Tell Ansible to use the ARA callback plugin # "python -m ara.plugins" provides the path to the ARA plugins directory - export ANSIBLE_CALLBACK_PLUGINS="$(~/.ara/venv/bin/python -m ara.plugins)/callback" + export ANSIBLE_CALLBACK_PLUGINS="$(python -m ara.plugins)/callback" # Run your playbook as your normally would - ~/.ara/venv/bin/ansible-playbook playbook.yml + ansible-playbook playbook.yml The data will be saved in real time throughout the execution of the Ansible playbook. @@ -72,12 +75,12 @@ In addition, you can also find ARA on Twitter: `@ARecordsAnsible http://127.0.0.1:8000/api/v1/ tox -e runserver - # Run actual tests or get coverage - tox -e linters - tox -e py3 - tox -e cover - # Build docs tox -e docs diff --git a/doc/source/ansible-role-ara-tests.rst b/doc/source/ansible-role-ara-tests.rst new file mode 100644 index 00000000..15a9dd07 --- /dev/null +++ b/doc/source/ansible-role-ara-tests.rst @@ -0,0 +1,4 @@ +.. _ansible-role-ara-tests: + +.. include:: ../../roles/ara_tests/README.rst + :end-before: include_delimiter_end diff --git a/doc/source/index.rst b/doc/source/index.rst index e4883c73..ee766488 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -20,3 +20,4 @@ Table of Contents ansible-role-ara-api ansible-role-ara-web + ansible-role-ara-tests diff --git a/playbooks/ara_tests.yaml b/playbooks/ara_tests.yaml new file mode 100644 index 00000000..4567f647 --- /dev/null +++ b/playbooks/ara_tests.yaml @@ -0,0 +1,5 @@ +- name: Run ARA smoke tests + hosts: all + gather_facts: yes + roles: + - ara_tests diff --git a/playbooks/integration-tests.yaml b/playbooks/integration-tests.yaml deleted file mode 100644 index a5335f08..00000000 --- a/playbooks/integration-tests.yaml +++ /dev/null @@ -1,7 +0,0 @@ -- name: Run ARA integration tests - hosts: all - gather_facts: yes - tasks: - - name: Include the integration-tests role - include_role: - name: integration-tests diff --git a/roles/ara_tests/README.rst b/roles/ara_tests/README.rst new file mode 100644 index 00000000..c16200b8 --- /dev/null +++ b/roles/ara_tests/README.rst @@ -0,0 +1,53 @@ +ansible-role-ara-tests +====================== + +An Ansible role that installs ARA and Ansible to run quick and inexpensive +tests that do not require superuser privileges. + +Role Variables +-------------- + +See `defaults/main.yaml `_. + +.. literalinclude:: ../../roles/ara_tests/defaults/main.yaml + :language: yaml+jinja + :start-after: www.gnu.org + +TL;DR +----- + +.. code-block:: yaml+jinja + + - name: Test ARA with the latest version of Ansible + hosts: all + gather_facts: yes + roles: + - ara_tests + +What the role ends up doing by default: + +- Creates a directory to contain the files for the duration of the tests +- Installs ARA from source and the latest version of Ansible in a virtualenv +- Runs test playbooks designed to exercise different features of ARA + +.. _include_delimiter_end: + +Copyright +--------- + +.. code-block:: text + + Copyright (c) 2019 Red Hat, Inc. + + ARA Records Ansible is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ARA Records Ansible is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARA Records Ansible. If not, see . diff --git a/roles/integration-tests/defaults/main.yaml b/roles/ara_tests/defaults/main.yaml similarity index 65% rename from roles/integration-tests/defaults/main.yaml rename to roles/ara_tests/defaults/main.yaml index 61cafe7a..6f4da635 100644 --- a/roles/integration-tests/defaults/main.yaml +++ b/roles/ara_tests/defaults/main.yaml @@ -1,37 +1,37 @@ --- -# Copyright (c) 2018 Red Hat, Inc. +# Copyright (c) 2019 Red Hat, Inc. # # This file is part of ARA Records Ansible. # -# ARA is free software: you can redistribute it and/or modify +# ARA Records Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # -# ARA is distributed in the hope that it will be useful, +# ARA Records Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with ARA. If not, see . +# along with ARA Records Ansible. If not, see . # Root directory where integration tests will prepare and store data -integration_root: "/tmp/ara-integration-tests" +ara_tests_root: "/tmp/ara-integration-tests" # Directory where the virtualenv will be created -integration_virtualenv: "{{ integration_root }}/venv" +ara_tests_virtualenv: "{{ ara_tests_root }}/virtualenv" # Directory where ARA_BASE_DIR will be set -integration_data: "{{ integration_root }}/data" +ara_tests_data: "{{ ara_tests_root }}/.ara" # Whether the root directory should be cleaned up between runs -integration_cleanup: true +ara_tests_cleanup: true # Name of the Ansible package # This can be "ansible" which will use pip or it could be something like # /home/user/git/ansible as well as git+https://github.com/ansible/ansible -integration_ansible_name: ansible +ara_tests_ansible_name: ansible # Version of Ansible from pypi to install -integration_ansible_version: latest +ara_tests_ansible_version: latest diff --git a/roles/ara_tests/meta/main.yaml b/roles/ara_tests/meta/main.yaml new file mode 100644 index 00000000..374f2c9a --- /dev/null +++ b/roles/ara_tests/meta/main.yaml @@ -0,0 +1,35 @@ +--- +# Copyright (c) 2019 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA Records Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA Records Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA Records Ansible. If not, see . + +galaxy_info: + author: David Moreau-Simard + description: Self-contained role to test ARA with Ansible + license: GPLv3 + min_ansible_version: 2.7 + platforms: + - name: Fedora + versions: + - 29 + - name: Ubuntu + versions: + - bionic + galaxy_tags: + - ansible + - ara + +dependencies: [] diff --git a/roles/integration-tests/tasks/main.yaml b/roles/ara_tests/tasks/main.yaml similarity index 58% rename from roles/integration-tests/tasks/main.yaml rename to roles/ara_tests/tasks/main.yaml index b87f04d9..056a6ec4 100644 --- a/roles/integration-tests/tasks/main.yaml +++ b/roles/ara_tests/tasks/main.yaml @@ -18,35 +18,24 @@ - name: Clean up integration test root file: - path: "{{ integration_root }}" + path: "{{ ara_tests_root }}" state: absent - when: integration_cleanup | bool + when: ara_tests_cleanup | bool - name: Create integration test root file: - path: "{{ integration_root }}" + path: "{{ ara_tests_root }}" state: directory -# Zuul already prepares the src repository on the remote node -- name: Symlink Zuul repositories to integration test root - file: - src: "{{ ansible_user_dir }}/src/git.openstack.org/openstack/ara" - dest: "{{ integration_root }}/ara" - state: link +- name: Set location of the git repository with Zuul + set_fact: + _ara_tests_repository: "{{ ansible_user_dir }}/src/git.openstack.org/openstack/ara" when: zuul is defined -- when: zuul is not defined - block: - # The expectation is that the integration tests are run from a checked out - # git repository. Use this repository for the tests so we are able to test - # local modifications. Synchronize is used in place of symlink so we are - # able to run integration tests on a remote machine if necessary. - # git rev-parse --show-toplevel returns the root git directory - - name: Synchronize ara-infra to integration root - synchronize: - src: "{{ lookup('pipe', 'git rev-parse --show-toplevel') }}" - dest: "{{ integration_root }}/" - delete: yes +- name: Set location of the git repository without Zuul + set_fact: + _ara_tests_repository: "{{ lookup('pipe', 'git rev-parse --show-toplevel') }}" + when: zuul is not defined # If a version is not explicitly set we want to make sure to # completely omit the version argument to pip, as it will be coming @@ -55,31 +44,31 @@ # any version number, but also set the package state to "latest". - name: Set Ansible version for installation set_fact: - _install_ansible_version: "{{ integration_ansible_version }}" - when: integration_ansible_version not in ("", "latest") + _install_ansible_version: "{{ ara_tests_ansible_version }}" + when: ara_tests_ansible_version not in ("", "latest") - name: Set Ansible package state for installation set_fact: _install_ansible_state: latest - when: integration_ansible_version == "latest" + when: ara_tests_ansible_version == "latest" - name: Initialize virtual environment with Ansible pip: - name: "{{ integration_ansible_name }}" + name: "{{ ara_tests_ansible_name }}" version: "{{ _install_ansible_version | default(omit, True) }}" state: "{{ _install_ansible_state | default(omit, True) }}" - virtualenv: "{{ integration_virtualenv }}" + virtualenv: "{{ ara_tests_virtualenv }}" virtualenv_python: python3 - name: Install ARA from source in virtual environment pip: - name: "{{ integration_root }}/ara" + name: "{{ _ara_tests_repository }}" state: present - virtualenv: "{{ integration_virtualenv }}" + virtualenv: "{{ ara_tests_virtualenv }}" virtualenv_python: python3 - name: Get ARA plugins directory - command: "{{ integration_root }}/venv/bin/python -m ara.plugins" + command: "{{ ara_tests_virtualenv }}/bin/python -m ara.plugins" register: ara_plugins # These aren't in the same task (i.e, with loop) so we can tell individual test @@ -90,31 +79,31 @@ ANSIBLE_ACTION_PLUGINS: "{{ ara_plugins.stdout }}/action" ARA_DEBUG: true ARA_LOG_LEVEL: DEBUG - ARA_BASE_DIR: "{{ integration_data }}" + ARA_BASE_DIR: "{{ ara_tests_data }}" ARA_SECRET_KEY: testing vars: - ansible_playbook: "{{ integration_virtualenv }}/bin/ansible-playbook -vvv" - test_root: "{{ integration_root }}/ara/tests/integration" + _ansible_playbook: "{{ ara_tests_virtualenv }}/bin/ansible-playbook -vvv" + _test_root: "{{ _ara_tests_repository }}/tests/integration" block: # smoke.yaml tests setting ara_playbook_name in one of three plays - name: Run smoke.yaml integration test - command: "{{ ansible_playbook }} {{ test_root }}/smoke.yaml" + command: "{{ _ansible_playbook }} {{ _test_root }}/smoke.yaml" - name: Run hosts.yaml integration test - command: "{{ ansible_playbook }} {{ test_root }}/hosts.yaml" + command: "{{ _ansible_playbook }} {{ _test_root }}/hosts.yaml" - name: Run import.yaml integration test - command: "{{ ansible_playbook }} {{ test_root }}/import.yaml" + command: "{{ _ansible_playbook }} {{ _test_root }}/import.yaml" # Tests setting ara_playbook_name as an extra var - name: Run failed.yaml integration test command: > - {{ ansible_playbook }} {{ test_root }}/failed.yaml -e ara_playbook_name="Failed playbook" + {{ _ansible_playbook }} {{ _test_root }}/failed.yaml -e ara_playbook_name="Failed playbook" ignore_errors: yes - name: Run incomplete.yaml integration test shell: | - {{ ansible_playbook }} {{ test_root }}/incomplete.yaml & + {{ _ansible_playbook }} {{ _test_root }}/incomplete.yaml & sleep 5 kill $! args: diff --git a/roles/integration-tests/README.rst b/roles/integration-tests/README.rst deleted file mode 100644 index 83d35e95..00000000 --- a/roles/integration-tests/README.rst +++ /dev/null @@ -1,47 +0,0 @@ -integration-tests -================= - -Installs a specified version of ARA and Ansible into a virtual environment -and runs integration tests that do not require superuser privileges. - -Requirements -============ - -Since the role is designed to run without superuser privileges, the following -things should be installed in order to let the role use them: - -- git -- python3 -- pip -- virtualenv - -Variables -========= - -From ``defaults/main.yaml``: - -Root directory where integration tests will prepare and store data:: - - integration_root: "/tmp/ara-integration-tests" - -Directory where the virtualenv will be created:: - - integration_virtualenv: "{{ integration_root }}/venv" - -Directory where ARA_BASE_DIR will be set:: - - integration_data: "{{ integration_root }}/data" - -Whether the root directory should be cleaned up between runs:: - - integration_cleanup: true - -Name of the Ansible package. This can be ``ansible`` which will use pip or it -could be something like ``/home/user/git/ansible`` as well as -``git+https://github.com/ansible/ansible``:: - - integration_ansible_name: ansible - -Version of Ansible from pypi to install:: - - integration_ansible_version: latest diff --git a/tests/integration-post.yaml b/tests/ara_tests_post.yaml similarity index 95% rename from tests/integration-post.yaml rename to tests/ara_tests_post.yaml index 528daca8..9bdf3777 100644 --- a/tests/integration-post.yaml +++ b/tests/ara_tests_post.yaml @@ -27,7 +27,7 @@ recurse: yes - name: Recover integration test data - command: cp -rp /tmp/ara-integration-tests/data {{ ansible_user_dir }}/workspace/logs/data + command: cp -rp /tmp/ara-integration-tests/.ara {{ ansible_user_dir }}/workspace/logs/data - name: Upload log artifacts synchronize: diff --git a/tox.ini b/tox.ini index f470fe8a..d4fac6c9 100644 --- a/tox.ini +++ b/tox.ini @@ -36,6 +36,10 @@ setenv = ARA_LOG_LEVEL=DEBUG ARA_BASE_DIR={toxinidir}/.tox/runserver/tmp/ara +[testenv:ansible-integration] +deps = ansible +commands = ansible-playbook -i "localhost," --connection=local {toxinidir}/playbooks/ara_tests.yaml {posargs} + [testenv:cover] commands = coverage erase