From d7cba9d7d5c6c2ef638b0d61bf11a54a20f78061 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 29 Nov 2017 11:59:58 -0600 Subject: [PATCH] Combine tox-siblings and tox roles There is a bunch of duplicate logic between tox and tox-siblings, the tox-siblings logic is already protected with a flag - and having them be split already led to not doing the right thing with constraints files in siblings when we did it right in tox itself. Combine them into one role. This means the siblings code will run as part of run instead of as part of pre- but that's how things have worked for years anyway until siblings was introduced - and is also the behavior is the siblings flag is false -so it's more consistent overall. Leave a no-op tox-siblings role so that we can gracefully remove the use of tox-siblings from castellan, python-openstacksdk, shade and tacker. Change-Id: Id61ae52d48b28cfc2221cb556a1c1f7c6dfd60dd --- playbooks/tox/pre.yaml | 2 - roles/tox-siblings/README.rst | 29 -------------- roles/tox-siblings/defaults/main.yaml | 6 --- roles/tox-siblings/tasks/main.yaml | 6 +-- roles/tox-siblings/tasks/siblings.yaml | 38 ------------------- roles/tox/README.rst | 6 +++ roles/tox/defaults/main.yaml | 1 + .../library/tox_install_sibling_packages.py | 0 roles/tox/tasks/main.yaml | 13 ++++++- roles/tox/tasks/siblings.yaml | 13 +++++++ 10 files changed, 34 insertions(+), 80 deletions(-) delete mode 100644 roles/tox-siblings/README.rst delete mode 100644 roles/tox-siblings/defaults/main.yaml delete mode 100644 roles/tox-siblings/tasks/siblings.yaml rename roles/{tox-siblings => tox}/library/tox_install_sibling_packages.py (100%) create mode 100644 roles/tox/tasks/siblings.yaml diff --git a/playbooks/tox/pre.yaml b/playbooks/tox/pre.yaml index fde7f6155..69e7def02 100644 --- a/playbooks/tox/pre.yaml +++ b/playbooks/tox/pre.yaml @@ -1,5 +1,3 @@ - hosts: all roles: - ensure-tox - - role: tox-siblings - when: tox_install_siblings diff --git a/roles/tox-siblings/README.rst b/roles/tox-siblings/README.rst deleted file mode 100644 index e7277a5c0..000000000 --- a/roles/tox-siblings/README.rst +++ /dev/null @@ -1,29 +0,0 @@ -Installs python packages from other Zuul repos into a tox environment. - -**Role Variables** - -.. zuul:rolevar:: zuul_workdir - :default: {{ zuul.project.src_dir }} - - Directory to run tox in. - -.. zuul:rolevar:: tox_envlist - :default: venv - - Which tox environment to run. Defaults to 'venv'. - -.. zuul:rolevar:: tox_executable - :default: tox - - Location of the tox executable. Defaults to 'tox'. - -.. zuul:rolevar:: tox_constraints_file - - Path to a pip constraints file. Will be provided to pip via '-c' - argument for any sibling package installations. - -.. zuul:rolevar:: tox_install_siblings - :default: true - - Flag controlling whether to attempt to install python packages from any - other source code repos zuul has checked out. Defaults to True. diff --git a/roles/tox-siblings/defaults/main.yaml b/roles/tox-siblings/defaults/main.yaml deleted file mode 100644 index dded4aec3..000000000 --- a/roles/tox-siblings/defaults/main.yaml +++ /dev/null @@ -1,6 +0,0 @@ ---- -tox_envlist: venv -tox_executable: tox -tox_install_siblings: true - -zuul_work_dir: "{{ zuul.project.src_dir }}" diff --git a/roles/tox-siblings/tasks/main.yaml b/roles/tox-siblings/tasks/main.yaml index fe7b1757a..d9091c52b 100644 --- a/roles/tox-siblings/tasks/main.yaml +++ b/roles/tox-siblings/tasks/main.yaml @@ -1,3 +1,3 @@ -- name: Install tox siblings - include: siblings.yaml - when: tox_install_siblings +- name: Emit warning message + debug: + msg: tox-siblings is no longer needed and should be removed diff --git a/roles/tox-siblings/tasks/siblings.yaml b/roles/tox-siblings/tasks/siblings.yaml deleted file mode 100644 index 0aa391a87..000000000 --- a/roles/tox-siblings/tasks/siblings.yaml +++ /dev/null @@ -1,38 +0,0 @@ -- name: Require tox_envlist variable - fail: - msg: tox_envlist is required for this role - when: tox_envlist is not defined - -- name: Check to see if the constraints file exists - stat: - path: "{{ tox_constraints_file }}" - get_checksum: false - get_mime: false - get_md5: false - register: stat_results - when: tox_constraints_file is defined - -- name: Fail if constraints file is missing - when: tox_constraints_file is defined and not stat_results.stat.exists - fail: - msg: tox_constraints_file is defined but was not found - -- name: Record file location - set_fact: - tox_constraints_env: - UPPER_CONSTRAINTS_FILE: "{{ tox_constraints_file }}" - when: tox_constraints_file is defined - -- name: Run tox without tests - command: "{{ tox_executable }} --notest -e{{ tox_envlist }}" - args: - chdir: "{{ zuul_work_dir }}" - environment: "{{ tox_environment|combine(tox_constraints_env|default({})) }}" - -# TODO(mordred) handle tox_envlist being a list -- name: Install any sibling python packages - tox_install_sibling_packages: - tox_envlist: "{{ tox_envlist }}" - tox_constraints_file: "{{ tox_constraints_file | default(omit) }}" - project_dir: "{{ zuul_work_dir }}" - projects: "{{ zuul.projects | selectattr('required') | list }}" diff --git a/roles/tox/README.rst b/roles/tox/README.rst index cf1921e80..40932402b 100644 --- a/roles/tox/README.rst +++ b/roles/tox/README.rst @@ -26,6 +26,12 @@ Runs tox for a project Path to a pip constraints file. Will be provided to tox via UPPER_CONSTRAINTS_FILE environment variable if it exists. +.. zuul:rolevar:: tox_install_siblings + :default: true + + Flag controlling whether to attempt to install python packages from any + other source code repos zuul has checked out. Defaults to True. + .. zuul:rolevar:: zuul_work_dir :default: {{ zuul.project.src_dir }} diff --git a/roles/tox/defaults/main.yaml b/roles/tox/defaults/main.yaml index f4b08abd2..1178db533 100644 --- a/roles/tox/defaults/main.yaml +++ b/roles/tox/defaults/main.yaml @@ -3,5 +3,6 @@ tox_environment: {} tox_envlist: venv tox_executable: tox tox_extra_args: -vv +tox_install_siblings: true zuul_work_dir: "{{ zuul.project.src_dir }}" diff --git a/roles/tox-siblings/library/tox_install_sibling_packages.py b/roles/tox/library/tox_install_sibling_packages.py similarity index 100% rename from roles/tox-siblings/library/tox_install_sibling_packages.py rename to roles/tox/library/tox_install_sibling_packages.py diff --git a/roles/tox/tasks/main.yaml b/roles/tox/tasks/main.yaml index fe899037b..b1f464fb8 100644 --- a/roles/tox/tasks/main.yaml +++ b/roles/tox/tasks/main.yaml @@ -5,18 +5,27 @@ - name: Check to see if the constraints file exists stat: - path: "{{ tox_constraints_file|default('missing') }}" + path: "{{ tox_constraints_file }}" get_checksum: false get_mime: false get_md5: false register: stat_results when: tox_constraints_file is defined +- name: Fail if constraints file is missing + when: tox_constraints_file is defined and not stat_results.stat.exists + fail: + msg: tox_constraints_file is defined but was not found + - name: Record file location set_fact: tox_constraints_env: UPPER_CONSTRAINTS_FILE: "{{ tox_constraints_file }}" - when: not stat_results|skipped and stat_results.stat.exists + when: tox_constraints_file is defined + +- name: Install tox siblings + include: siblings.yaml + when: tox_install_siblings - name: Emit tox command debug: diff --git a/roles/tox/tasks/siblings.yaml b/roles/tox/tasks/siblings.yaml new file mode 100644 index 000000000..84c43cd73 --- /dev/null +++ b/roles/tox/tasks/siblings.yaml @@ -0,0 +1,13 @@ +- name: Run tox without tests + command: "{{ tox_executable }} --notest -e{{ tox_envlist }}" + args: + chdir: "{{ zuul_work_dir }}" + environment: "{{ tox_environment|combine(tox_constraints_env|default({})) }}" + +# TODO(mordred) handle tox_envlist being a list +- name: Install any sibling python packages + tox_install_sibling_packages: + tox_envlist: "{{ tox_envlist }}" + tox_constraints_file: "{{ tox_constraints_file | default(omit) }}" + project_dir: "{{ zuul_work_dir }}" + projects: "{{ zuul.projects | selectattr('required') | list }}"