From 41910f2ab79a8453f1b1ca983fc21c8c78658175 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Sat, 1 Sep 2018 18:08:07 +0100 Subject: [PATCH] Use a common python build/install role In order to radically simplify how we prepare the service venvs, we use a common role to do the wheel builds and the venv preparation. This makes the process far simpler to understand, because the role does its own building and installing. It also reduces the code maintenance burden, because instead of duplicating the build processes in the repo_build role and the service role - we only have it all done in a single place. We also change the role venv tag var to use the integrated build's common venv tag so that we can remove the role's venv tag in group_vars in the integrated build. This reduces memory consumption and also reduces the duplication. This is by no means the final stop in the simplification process, but it is a step forward. The will be work to follow which: 1. Replaces 'developer mode' with an equivalent mechanism that uses the common role and is simpler to understand. We will also simplify the provisioning of pip install arguments when doing this. Depends-On: https://review.openstack.org/598957 Change-Id: Ia84e9f0a7b7627182e4b10aa3fc4f0d708edfee8 Implements: blueprint python-build-install-simplification Signed-off-by: Jesse Pretorius --- defaults/main.yml | 13 ++- handlers/main.yml | 5 +- tasks/blazar_install.yml | 121 +++++--------------------- vars/{ubuntu-16.04.yml => ubuntu.yml} | 3 +- 4 files changed, 41 insertions(+), 101 deletions(-) rename vars/{ubuntu-16.04.yml => ubuntu.yml} (93%) diff --git a/defaults/main.yml b/defaults/main.yml index 6d92a46..ea785c9 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -28,7 +28,18 @@ blazar_developer_mode: false blazar_requirements_git_repo: https://git.openstack.org/openstack/requirements blazar_requirements_git_install_branch: master -blazar_venv_tag: untagged +# TODO(odyssey4me): +# This can be simplified once all the roles are using +# python_venv_build. We can then switch to using a +# set of constraints in pip.conf inside the venv, +# perhaps prepared by giving a giving a list of +# constraints to the role. +blazar_pip_install_args: >- + {{ blazar_developer_mode | ternary(pip_install_developer_constraints | default('--constraint /opt/developer-pip-constraints.txt'), '') }} + {{ (pip_install_upper_constraints is defined) | ternary('--constraint ' + pip_install_upper_constraints | default(''), '') }} + {{ pip_install_options | default('') }} + +blazar_venv_tag: "{{ venv_tag | default('untagged') }}" blazar_bin: "/openstack/venvs/blazar-{{ blazar_venv_tag }}/bin" blazar_venv_download_url: http://127.0.0.1/venvs/untagged/ubuntu/blazar.tgz diff --git a/handlers/main.yml b/handlers/main.yml index 8e91c53..a0f1540 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -19,4 +19,7 @@ name: "{{ item.service_name }}" state: restarted with_items: "{{ filtered_blazar_services }}" - failed_when: false + retries: 5 + delay: 2 + listen: + - "venv changed" diff --git a/tasks/blazar_install.yml b/tasks/blazar_install.yml index 743c6f5..7621650 100644 --- a/tasks/blazar_install.yml +++ b/tasks/blazar_install.yml @@ -14,29 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Install distro packages - package: - name: "{{ blazar_distro_packages }}" - state: "{{ blazar_package_state }}" - update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}" - cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}" - register: install_packages - until: install_packages is success - retries: 5 - delay: 2 - -- name: Install distro packages - package: - name: "{{ almanach_developer_mode_distro_packages }}" - state: "{{ blazar_package_state }}" - update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}" - cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}" - when: blazar_developer_mode | bool - register: install_packages - until: install_packages is success - retries: 5 - delay: 2 - +# TODO(odyssey4me): +# This can be simplified once all the roles are using +# python_venv_build. We can then switch to using a +# set of constraints in pip.conf inside the venv, +# perhaps prepared by giving a giving a list of +# constraints to the role. - name: Create developer mode constraint file copy: dest: "/opt/developer-pip-constraints.txt" @@ -46,79 +29,23 @@ {% endfor %} when: blazar_developer_mode | bool -- name: Retrieve checksum for venv download - uri: - url: "{{ blazar_venv_download_url | replace('tgz', 'checksum') }}" - return_content: yes - register: blazar_venv_checksum - when: blazar_venv_download | bool - -- name: Attempt venv download - get_url: - url: "{{ blazar_venv_download_url }}" - dest: "/var/cache/{{ blazar_venv_download_url | basename }}" - checksum: "sha1:{{ blazar_venv_checksum.content | trim }}" - register: blazar_get_venv - when: blazar_venv_download | bool - -- name: Remove existing venv - file: - path: "{{ blazar_bin | dirname }}" - state: absent - when: blazar_get_venv is changed - -- name: Create blazar venv dir - file: - path: "{{ blazar_bin | dirname }}" - state: directory - register: blazar_venv_dir - when: blazar_get_venv is changed - -- name: Unarchive pre-built venv - unarchive: - src: "/var/cache/{{ blazar_venv_download_url | basename }}" - dest: "{{ blazar_bin | dirname }}" - copy: "no" - when: blazar_get_venv is changed - notify: - - Restart blazar services - -- name: Install pip packages - pip: - name: "{{ blazar_pip_packages | join(' ') }}" - state: "{{ blazar_pip_package_state }}" - virtualenv: "{{ blazar_bin | dirname }}" - virtualenv_site_packages: "no" - extra_args: >- - {{ blazar_developer_mode | ternary(pip_install_developer_constraints | default('--constraint /opt/developer-pip-constraints.txt'), '') }} - {{ (pip_install_upper_constraints is defined) | ternary('--constraint ' + pip_install_upper_constraints | default(''),'') }} - {{ pip_install_options | default('') }} - register: install_packages - until: install_packages is success - retries: 5 - delay: 2 - when: blazar_get_venv is failed or blazar_get_venv is skipped - notify: - - Restart blazar services - -- name: Remove python from path first (CentOS, openSUSE) - file: - path: "{{ blazar_bin | dirname }}/bin/python2.7" - state: "absent" +- name: Ensure remote wheel building is disabled in developer mode + set_fact: + venv_build_host: "{{ ansible_hostname }}" when: - - ansible_pkg_mgr in ['yum', 'dnf', 'zypper'] - - blazar_get_venv is changed + - blazar_developer_mode | bool -- name: Update virtualenv path - shell: | - find {{ blazar_bin }} -name \*.pyc -delete - sed -si '1s/^.*python.*$/#!{{ blazar_bin | replace ('/','\/') }}\/python/' {{ blazar_bin }}/* - virtualenv {{ blazar_bin | dirname }} - when: blazar_get_venv is changed - -- name: Record the venv tag deployed - ini_file: - dest: "/etc/ansible/facts.d/openstack_ansible.fact" - section: blazar - option: venv_tag - value: "{{ blazar_venv_tag }}" +- name: Install the python venv + include_role: + name: "python_venv_build" + private: yes + vars: + venv_build_distro_package_list: "{{ blazar_devel_distro_packages }}" + venv_install_destination_path: "{{ blazar_bin | dirname }}" + venv_install_distro_package_list: "{{ blazar_distro_packages }}" + venv_pip_install_args: "{{ blazar_pip_install_args }}" + venv_pip_packages: "{{ blazar_pip_packages }}" + venv_facts_when_changed: + - section: "blazar" + option: "venv_tag" + value: "{{ blazar_venv_tag }}" diff --git a/vars/ubuntu-16.04.yml b/vars/ubuntu.yml similarity index 93% rename from vars/ubuntu-16.04.yml rename to vars/ubuntu.yml index 8db0881..5ae19c5 100644 --- a/vars/ubuntu-16.04.yml +++ b/vars/ubuntu.yml @@ -23,14 +23,13 @@ blazar_distro_packages: - libxslt1-dev - libzip-dev - build-essential - - build-essential - libssl-dev - libffi-dev - python-setuptools - python-mysqldb - python-systemd -almanach_developer_mode_distro_packages: +blazar_devel_distro_packages: - build-essential - libsystemd-dev - pkg-config