From c24693e32606a42a902f6128a8f145d484d81f9b Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Tue, 4 Oct 2022 11:46:05 -0700 Subject: [PATCH] Combine ensure-pip playbooks into a test role The ensure-pip and ensure-pip-localhost playbooks were identical except for the hosts line. Refactor them into a test role and invoke that role from the test playbooks. Change-Id: I037a5d0cb56f96f6ebbbbffbc49cd68a26c71f24 --- test-playbooks/ensure-pip-localhost.yaml | 72 ------------------- test-playbooks/ensure-pip.yaml | 72 ------------------- .../ensure-pip/ensure-pip-localhost.yaml | 3 + test-playbooks/ensure-pip/ensure-pip.yaml | 3 + .../roles/ensure-pip-test/tasks/main.yaml | 68 ++++++++++++++++++ zuul-tests.d/python-jobs.yaml | 4 +- 6 files changed, 76 insertions(+), 146 deletions(-) delete mode 100644 test-playbooks/ensure-pip-localhost.yaml delete mode 100644 test-playbooks/ensure-pip.yaml create mode 100644 test-playbooks/ensure-pip/ensure-pip-localhost.yaml create mode 100644 test-playbooks/ensure-pip/ensure-pip.yaml create mode 100644 test-playbooks/ensure-pip/roles/ensure-pip-test/tasks/main.yaml diff --git a/test-playbooks/ensure-pip-localhost.yaml b/test-playbooks/ensure-pip-localhost.yaml deleted file mode 100644 index 66e57940d..000000000 --- a/test-playbooks/ensure-pip-localhost.yaml +++ /dev/null @@ -1,72 +0,0 @@ -- hosts: localhost - tasks: - # ensure-pip - - - name: Include ensure-pip - include_role: - name: ensure-pip - - - name: Create temp directory - tempfile: - state: directory - suffix: venv-test - register: _tmp_venv - - - name: Sanity check provided virtualenv command installs - pip: - name: tox - virtualenv_command: '{{ ensure_pip_virtualenv_command }}' - virtualenv: '{{ _tmp_venv.path }}' - - - name: Sanity check installed command runs without error - command: '{{ _tmp_venv.path }}/bin/tox --version' - - - name: Remove tmpdir - file: - path: '{{ _tmp_venv.path }}' - state: absent - - - name: Sanity check pip wheel generation - shell: | - cd {{ ansible_user_dir }}/src/opendev.org/zuul/zuul-jobs/tools/dummy-package - # This should run anywhere without too much logic ... - run_pip=$(command -v pip3 || command -v pip2 || command -v pip) - # Preinstall pbr to work around very old distutils lacking SNI support - $run_pip install pbr - $run_pip wheel --no-deps . - ls dummy_package*.whl || exit 1 - - - name: Test virtualenv - # NOTE(ianw) 2022-02-03 : not supported on 9-stream, see inline comments - # NOTE(frickler) 2022-03-01 : pin pluggy so as to work on Debian Buster - when: not (ansible_facts['distribution'] == 'CentOS' and ansible_facts['distribution_major_version']|int >= 9) - block: - # ensure-virtualenv - - name: Include ensure-virtualenv - include_role: - name: ensure-virtualenv - - - name: Sanity check virtualenv command works - shell: | - tmp_venv=$(mktemp -d -t venv-XXXXXXXXXX) - trap "rm -rf $tmp_venv" EXIT - virtualenv $tmp_venv - $tmp_venv/bin/pip install tox "pluggy<1" - failed_when: false - register: _virtualenv_sanity - - - name: Assert sanity check - fail: - msg: 'The virtualenv command does not appear to work!' - when: - - _virtualenv_sanity.rc != 0 - -# NOTE(ianw) : this does not play nicely with pip-and-virtualenv which -# has already installed from source. We might be able to test this -# once it's gone... - -# - hosts: all -# roles: -# - role: ensure-pip -# vars: -# ensure_pip_from_upstream: True diff --git a/test-playbooks/ensure-pip.yaml b/test-playbooks/ensure-pip.yaml deleted file mode 100644 index 6c24a350a..000000000 --- a/test-playbooks/ensure-pip.yaml +++ /dev/null @@ -1,72 +0,0 @@ -- hosts: all - tasks: - # ensure-pip - - - name: Include ensure-pip - include_role: - name: ensure-pip - - - name: Create temp directory - tempfile: - state: directory - suffix: venv-test - register: _tmp_venv - - - name: Sanity check provided virtualenv command installs - pip: - name: tox - virtualenv_command: '{{ ensure_pip_virtualenv_command }}' - virtualenv: '{{ _tmp_venv.path }}' - - - name: Sanity check installed command runs without error - command: '{{ _tmp_venv.path }}/bin/tox --version' - - - name: Remove tmpdir - file: - path: '{{ _tmp_venv.path }}' - state: absent - - - name: Sanity check pip wheel generation - shell: | - cd {{ ansible_user_dir }}/src/opendev.org/zuul/zuul-jobs/tools/dummy-package - # This should run anywhere without too much logic ... - run_pip=$(command -v pip3 || command -v pip2 || command -v pip) - # Preinstall pbr to work around very old distutils lacking SNI support - $run_pip install pbr - $run_pip wheel --no-deps . - ls dummy_package*.whl || exit 1 - - - name: Test virtualenv - # NOTE(ianw) 2022-02-03 : not supported on 9-stream, see inline comments - # NOTE(frickler) 2022-03-01 : pin pluggy so as to work on Debian Buster - when: not (ansible_facts['distribution'] == 'CentOS' and ansible_facts['distribution_major_version']|int >= 9) - block: - # ensure-virtualenv - - name: Include ensure-virtualenv - include_role: - name: ensure-virtualenv - - - name: Sanity check virtualenv command works - shell: | - tmp_venv=$(mktemp -d -t venv-XXXXXXXXXX) - trap "rm -rf $tmp_venv" EXIT - virtualenv $tmp_venv - $tmp_venv/bin/pip install tox "pluggy<1" - failed_when: false - register: _virtualenv_sanity - - - name: Assert sanity check - fail: - msg: 'The virtualenv command does not appear to work!' - when: - - _virtualenv_sanity.rc != 0 - -# NOTE(ianw) : this does not play nicely with pip-and-virtualenv which -# has already installed from source. We might be able to test this -# once it's gone... - -# - hosts: all -# roles: -# - role: ensure-pip -# vars: -# ensure_pip_from_upstream: True diff --git a/test-playbooks/ensure-pip/ensure-pip-localhost.yaml b/test-playbooks/ensure-pip/ensure-pip-localhost.yaml new file mode 100644 index 000000000..ae3a51307 --- /dev/null +++ b/test-playbooks/ensure-pip/ensure-pip-localhost.yaml @@ -0,0 +1,3 @@ +- hosts: localhost + roles: + - ensure-pip-test diff --git a/test-playbooks/ensure-pip/ensure-pip.yaml b/test-playbooks/ensure-pip/ensure-pip.yaml new file mode 100644 index 000000000..d38a391ea --- /dev/null +++ b/test-playbooks/ensure-pip/ensure-pip.yaml @@ -0,0 +1,3 @@ +- hosts: all + roles: + - ensure-pip-test diff --git a/test-playbooks/ensure-pip/roles/ensure-pip-test/tasks/main.yaml b/test-playbooks/ensure-pip/roles/ensure-pip-test/tasks/main.yaml new file mode 100644 index 000000000..f632b3f40 --- /dev/null +++ b/test-playbooks/ensure-pip/roles/ensure-pip-test/tasks/main.yaml @@ -0,0 +1,68 @@ +- name: Include ensure-pip + include_role: + name: ensure-pip + +- name: Create temp directory + tempfile: + state: directory + suffix: venv-test + register: _tmp_venv + +- name: Sanity check provided virtualenv command installs + pip: + name: tox + virtualenv_command: '{{ ensure_pip_virtualenv_command }}' + virtualenv: '{{ _tmp_venv.path }}' + +- name: Sanity check installed command runs without error + command: '{{ _tmp_venv.path }}/bin/tox --version' + +- name: Remove tmpdir + file: + path: '{{ _tmp_venv.path }}' + state: absent + +- name: Sanity check pip wheel generation + shell: | + cd {{ ansible_user_dir }}/src/opendev.org/zuul/zuul-jobs/tools/dummy-package + # This should run anywhere without too much logic ... + run_pip=$(command -v pip3 || command -v pip2 || command -v pip) + # Preinstall pbr to work around very old distutils lacking SNI support + $run_pip install pbr + $run_pip wheel --no-deps . + ls dummy_package*.whl || exit 1 + +- name: Test virtualenv + # NOTE(ianw) 2022-02-03 : not supported on 9-stream, see inline comments + # NOTE(frickler) 2022-03-01 : pin pluggy so as to work on Debian Buster + when: not (ansible_facts['distribution'] == 'CentOS' and ansible_facts['distribution_major_version']|int >= 9) + block: + # ensure-virtualenv + - name: Include ensure-virtualenv + include_role: + name: ensure-virtualenv + + - name: Sanity check virtualenv command works + shell: | + tmp_venv=$(mktemp -d -t venv-XXXXXXXXXX) + trap "rm -rf $tmp_venv" EXIT + virtualenv $tmp_venv + $tmp_venv/bin/pip install tox "pluggy<1" + failed_when: false + register: _virtualenv_sanity + + - name: Assert sanity check + fail: + msg: 'The virtualenv command does not appear to work!' + when: + - _virtualenv_sanity.rc != 0 + +# NOTE(ianw) : this does not play nicely with pip-and-virtualenv which +# has already installed from source. We might be able to test this +# once it's gone... + +# - hosts: all +# roles: +# - role: ensure-pip +# vars: +# ensure_pip_from_upstream: True diff --git a/zuul-tests.d/python-jobs.yaml b/zuul-tests.d/python-jobs.yaml index d289c40d1..aa156e4a1 100644 --- a/zuul-tests.d/python-jobs.yaml +++ b/zuul-tests.d/python-jobs.yaml @@ -4,7 +4,7 @@ files: - roles/ensure-pip/.* - roles/ensure-virtualenv/.* - run: test-playbooks/ensure-pip.yaml + run: test-playbooks/ensure-pip/ensure-pip.yaml tags: all-platforms - job: @@ -111,7 +111,7 @@ name: zuul-jobs-test-ensure-pip-localhost description: Test the ensure-pip role on the executor parent: zuul-jobs-test-ensure-pip - run: test-playbooks/ensure-pip-localhost.yaml + run: test-playbooks/ensure-pip/ensure-pip-localhost.yaml nodeset: nodes: []