
This adds a secret for authenticating with the live demo instance, and a job which runs basic integration tests. The results of these tests are sent to the live demo instance. The job is set to run in the "post" Zuul pipeline so the secret cannot be exposed by speculatively testing a job change. Change-Id: I8a7926ed547b1acb4b7021ca7c63abb9d68c0ac9
179 lines
7.1 KiB
YAML
179 lines
7.1 KiB
YAML
---
|
|
# 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
|
|
# 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,
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
- name: Basic ARA tests without Ansible roles
|
|
hosts: all
|
|
vars:
|
|
ara_api_root_dir: "{{ ansible_user_dir }}/.ara-tests"
|
|
ara_api_venv_path: "{{ ara_api_root_dir }}/virtualenv"
|
|
ara_api_secret_key: testing
|
|
ara_api_debug: true
|
|
ara_api_log_level: DEBUG
|
|
tasks:
|
|
# The name can be "ansible" when installing from pip or the path to an
|
|
# Ansible git repository on-disk.
|
|
# We're handling it here to allow various levels of variable precedence.
|
|
- name: Set default Ansible name if unset
|
|
set_fact:
|
|
ara_tests_ansible_name: ansible
|
|
when: ara_tests_ansible_name is not defined or ara_tests_ansible_name is none
|
|
|
|
- name: Set default Ansible version is unset
|
|
set_fact:
|
|
ara_tests_ansible_version: latest
|
|
when: ara_tests_ansible_version is not defined or ara_tests_ansible_version is none
|
|
|
|
# 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
|
|
# from the long-form ara_tests_ansible_name variable. Additionally, if
|
|
# the version is the special value "latest", then we also want to omit
|
|
# any version number, but also set the package state to "latest".
|
|
- name: Set Ansible version for installation
|
|
set_fact:
|
|
_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: ara_tests_ansible_version == "latest"
|
|
|
|
- name: Set source to checked out repository if it isn't specified
|
|
set_fact:
|
|
ara_api_source: "{{ lookup('pipe', 'git rev-parse --show-toplevel') }}"
|
|
when: ara_api_source is not defined or ara_api_source is none
|
|
|
|
- name: Ensure root directory exists
|
|
file:
|
|
path: "{{ ara_api_root_dir }}"
|
|
state: directory
|
|
|
|
- name: Ensure python3-venv is installed for Ubuntu
|
|
become: yes
|
|
package:
|
|
name: python3-venv
|
|
state: present
|
|
when: ansible_distribution == "Ubuntu"
|
|
|
|
- name: Initialize virtual environment with Ansible
|
|
pip:
|
|
name: "{{ ara_tests_ansible_name }}"
|
|
version: "{{ _install_ansible_version | default(omit, True) }}"
|
|
state: "{{ _install_ansible_state | default(omit, True) }}"
|
|
virtualenv: "{{ ara_api_venv_path }}"
|
|
virtualenv_command: /usr/bin/python3 -m venv
|
|
|
|
- name: Install ARA from source in virtual environment
|
|
pip:
|
|
name: "{{ ara_api_source }}[server]"
|
|
state: present
|
|
virtualenv: "{{ ara_api_venv_path }}"
|
|
virtualenv_command: /usr/bin/python3 -m venv
|
|
|
|
- name: Get ARA plugins directory
|
|
command: "{{ ara_api_venv_path }}/bin/python -m ara.setup.plugins"
|
|
register: ara_setup_plugins
|
|
|
|
- name: Set default labels with Zuul
|
|
set_fact:
|
|
_default_labels:
|
|
- "nodepool.provider:{{ nodepool.provider }}"
|
|
- "zuul.change:{{ zuul.change }}"
|
|
- "zuul.executor:{{ zuul.executor.hostname }}"
|
|
- "zuul.pipeline:{{ zuul.pipeline }}"
|
|
- "zuul.project:{{ zuul.project.canonical_name }}"
|
|
when: zuul is defined
|
|
|
|
- name: Template an ansible.cfg file
|
|
copy:
|
|
content: |
|
|
[defaults]
|
|
action_plugins = {{ ara_setup_plugins.stdout }}/action
|
|
callback_plugins = {{ ara_setup_plugins.stdout }}/callback
|
|
lookup_plugins = {{ ara_setup_plugins.stdout }}/lookup
|
|
|
|
[ara]
|
|
api_client = {{ ara_api_client | default('offline') }}
|
|
api_server = {{ ara_api_server | default('http://127.0.0.1') }}
|
|
default_labels = "{{ _default_labels | join(',') | default('default-label') }}"
|
|
dest: "{{ ara_api_root_dir }}/ansible.cfg"
|
|
|
|
# We need to do this because we can't omit a dictionary key if it's not set
|
|
# https://github.com/ansible/ansible/issues/14130
|
|
- name: Set environment variables without authentication
|
|
set_fact:
|
|
_env:
|
|
ANSIBLE_CONFIG: "{{ ara_api_root_dir }}/ansible.cfg"
|
|
ARA_DEBUG: "{{ ara_api_debug }}"
|
|
ARA_LOG_LEVEL: "{{ ara_api_log_level }}"
|
|
ARA_BASE_DIR: "{{ ara_api_root_dir }}/server"
|
|
ARA_SECRET_KEY: "{{ ara_api_secret_key }}"
|
|
PATH: "{{ ara_api_venv_path }}/bin:/bin:/usr/bin:/usr/local/bin"
|
|
when: ara_api_credentials is not defined
|
|
|
|
- name: Set environment variables with authentication
|
|
set_fact:
|
|
_env:
|
|
ANSIBLE_CONFIG: "{{ ara_api_root_dir }}/ansible.cfg"
|
|
ARA_DEBUG: "{{ ara_api_debug }}"
|
|
ARA_LOG_LEVEL: "{{ ara_api_log_level }}"
|
|
ARA_BASE_DIR: "{{ ara_api_root_dir }}/server"
|
|
ARA_SECRET_KEY: "{{ ara_api_secret_key }}"
|
|
ARA_API_USERNAME: "{{ ara_api_credentials.username | default(None) }}"
|
|
ARA_API_PASSWORD: "{{ ara_api_credentials.password | default(None) }}"
|
|
PATH: "{{ ara_api_venv_path }}/bin:/bin:/usr/bin:/usr/local/bin"
|
|
when: ara_api_credentials is defined
|
|
|
|
# These aren't in the same task (i.e, with loop) so we can tell individual test
|
|
# runs apart easily rather than keeping all the output bundled in a single task.
|
|
# TODO: Add validation for the tests
|
|
- environment: "{{ _env }}"
|
|
vars:
|
|
_test_root: "{{ ara_api_source }}/tests/integration"
|
|
block:
|
|
# smoke.yaml tests setting ara_playbook_name in one of three plays
|
|
- name: Run smoke.yaml integration test
|
|
command: "ansible-playbook -vvv {{ _test_root }}/smoke.yaml"
|
|
|
|
- name: Run lookup integration tests
|
|
command: "ansible-playbook -vvv {{ _test_root }}/lookups.yaml"
|
|
|
|
- name: Run hosts.yaml integration test
|
|
command: "ansible-playbook -vvv {{ _test_root }}/hosts.yaml"
|
|
|
|
- name: Run import.yaml integration test
|
|
command: "ansible-playbook -vvv {{ _test_root }}/import.yaml"
|
|
|
|
# Tests setting ara_playbook_name as an extra var
|
|
- name: Run failed.yaml integration test
|
|
command: >
|
|
ansible-playbook -vvv {{ _test_root }}/failed.yaml -e ara_playbook_name="Failed playbook"
|
|
ignore_errors: yes
|
|
|
|
- name: Run incomplete.yaml integration test
|
|
shell: |
|
|
ansible-playbook -vvv {{ _test_root }}/incomplete.yaml &
|
|
sleep 5
|
|
kill $!
|
|
args:
|
|
executable: /bin/bash
|
|
ignore_errors: yes
|
|
|
|
- name: Generate static report
|
|
command: ara-manage generate {{ ara_api_root_dir }}/static
|