Delete constraints and requirements files on build fail

If the installation of Python packages fails for any reason, the
constraint and requirements file is already written and therefore
unless you delete the virtualenv, it would not rebuild things
again.

This patch will handle failure and delete those files, then provide
a warning for the user upon failing to inspect the needed file.

Closes-Bug: #1824189

Change-Id: I67db44ce10250908f23c26c90d271a780a875eb6
(cherry picked from commit b2abfe4bad)
This commit is contained in:
Mohammed Naser 2019-04-10 12:18:45 -04:00
parent 8e90807224
commit ed1e941038
1 changed files with 29 additions and 17 deletions

View File

@ -110,23 +110,35 @@
- venv changed
- name: Install python packages into the venv
pip:
name: "{{ (venv_default_pip_packages | union(venv_pip_packages)) | sort }}"
state: "{{ venv_pip_package_state }}"
virtualenv: "{{ venv_install_destination_path }}"
extra_args: >-
--constraint {{ venv_install_destination_path }}/constraints.txt
--pre
--log /var/log/python_venv_build.log
{{ venv_default_pip_install_args }}
{{ venv_pip_install_args }}
when: (_requirement_file is changed) or (_constraint_file is changed)
register: _install_venv_pip_packages
until: _install_venv_pip_packages is success
retries: 5
delay: 2
notify:
- venv changed
block:
- pip:
name: "{{ (venv_default_pip_packages | union(venv_pip_packages)) | sort }}"
state: "{{ venv_pip_package_state }}"
virtualenv: "{{ venv_install_destination_path }}"
extra_args: >-
--constraint {{ venv_install_destination_path }}/constraints.txt
--pre
--log /var/log/python_venv_build.log
{{ venv_default_pip_install_args }}
{{ venv_pip_install_args }}
when: (_requirement_file is changed) or (_constraint_file is changed)
register: _install_venv_pip_packages
until: _install_venv_pip_packages is success
retries: 5
delay: 2
notify:
- venv changed
rescue:
- file:
path: "{{ item }}"
state: absent
with_items:
- "{{ venv_install_destination_path }}/constraints.txt"
- "{{ venv_install_destination_path }}/requirements.txt"
- fail:
msg: >
The python packages have failed to install, please check the log file
located at /var/log/python_venv_build.log for more information.
- name: Add symlinks from distribution python packages
when: