zuul-jobs/test-playbooks/ensure-pip.yaml
Ian Wienand 6dce7ba605 ensure-pip: export ensure_pip_virtualenv_command
This makes ensure-pip export something that should be sensible for
users of pip: to put in their 'virtualenv_command' for their host.

The theory of operation is fairly simple; see if "python3 -m venv"
looks like it works, and set that as the command if it does.  If not,
set "virtualenv".  For sanity, we check if it works.

We pull in virtualenv in the Python 2 case, but for Python 3 we are
deliberately do not bring it as it is an unnecessary dependency.  If
jobs do require the actual `virtualenv` package, they should provision
it themselves ... except for Xenial, which, as described inline, has
issues.

Follow-on changes will convert existing zuul-jobs roles that install
tools into virtualenvs to use this argument.

Change-Id: Idad14c0e77eed5bf8df2c8f84f52fbdea2236a9f
2020-04-15 15:34:19 -07:00

30 lines
807 B
YAML

- hosts: all
roles:
- ensure-pip
tasks:
- name: Sanity check provided virtualenv command works
shell: |
tmp_venv=$(mktemp -d -t venv-XXXXXXXXXX)
trap "rm -rf $tmp_venv" EXIT
{{ ensure_pip_virtualenv_command }} $tmp_venv
$tmp_venv/bin/pip install tox
failed_when: false
register: _venv_sanity
- name: Assert sanity check
fail:
msg: 'The virtualenv_command: "{{ ensure_pip_virtualenv_command }}" does not appear to work!'
when:
- _venv_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