Albin Vass 86041d9914 Don't require tox_envlist
Since tox_envlist has a default value it cannot be undefined
so the fail task will never run. Instead handle the case when
tox_envlist is an empty string by getting the default configured
envlist from tox. Also handle the casewhen tox_envlist is 'ALL'.

This also updates tox_install_sibling_packages to correctly
handle multiple testenvs and uses configuration supplied by
'tox --showconfig -e <envlist>' instead of guessing where the
envdir and logdir are located.

We also cannot run tox inside python because it gets complicated
to know which tox_executable we should call during the python test
cases so run these commands in ansible and pass the output to
tox_install_sibling_packages.

Since role params have higher precedence than set_fact we set an
internal _tox_envlist fact that is a comma separated list of testenvs
that should be run.

Change-Id: I9e5a1b041f653cbcff7b8ed62e4a95a0a040fdd7
2020-05-19 14:32:26 +02:00

79 lines
2.6 KiB
YAML

- hosts: all
tasks:
- name: Run bindep
include_role:
name: bindep
- name: Run tox with constraints
include_role:
name: tox
vars:
tox_envlist: docs
tox_constraints_file: '{{ zuul.project.src_dir }}/zuul-tests.d/test-constraints.txt'
- name: Run tox with multiple testenvs
include_role:
name: tox
vars:
tox_envlist: docs,linters
tox_environment:
ANSIBLE_ROLES_PATH: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/roles"
ANSIBLE_LIBRARY: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/tests/fake-ansible"
- name: Create tempfile to verify testenvs ran
tempfile:
register: default_tempfile
- block:
- name: Run tox with empty envlist
include_role:
name: tox
vars:
zuul_work_dir: "{{ zuul.project.src_dir }}/test-playbooks/python/"
tox_extra_args: "{{ default_tempfile.path }}"
tox_install_siblings: false
tox_envlist: ''
tox_environment:
ANSIBLE_ROLES_PATH: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/roles"
ANSIBLE_LIBRARY: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/tests/fake-ansible"
- name: Make sure magic lines are present
lineinfile:
path: "{{ default_tempfile.path }}"
line: linters
check_mode: true
register: default_status
failed_when: default_status is changed
always:
- name: Remove tempfile
file:
state: absent
path: "{{ default_tempfile.path }}"
- block:
- name: Create tempfile to verify testenvs ran
tempfile:
register: ALL_tempfile
- name: Run tox with ALL
include_role:
name: tox
vars:
zuul_work_dir: "{{ zuul.project.src_dir }}/test-playbooks/python/"
tox_install_siblings: false
tox_extra_args: "{{ ALL_tempfile.path }}"
tox_envlist: 'ALL'
tox_environment:
ANSIBLE_ROLES_PATH: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/roles"
ANSIBLE_LIBRARY: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/tests/fake-ansible"
always:
- name: Make sure magic lines are present
loop:
- linters
- non-default
lineinfile:
path: "{{ ALL_tempfile.path }}"
line: "{{ item }}"
check_mode: true
register: ALL_status
failed_when: ALL_status is changed