From 142dadbf29702513d232f2049443e61d985b6235 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Mon, 3 Sep 2018 17:46:02 +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: I8b213b0590891b7862aa304f01504295371ea167 Implements: blueprint python-build-install-simplification Signed-off-by: Jesse Pretorius --- defaults/main.yml | 13 +++- handlers/main.yml | 2 + tasks/tacker_install.yml | 141 +++++++-------------------------------- vars/ubuntu-14.04.yml | 27 -------- 4 files changed, 37 insertions(+), 146 deletions(-) delete mode 100644 vars/ubuntu-14.04.yml diff --git a/defaults/main.yml b/defaults/main.yml index bdb3ad2..de37ab1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -36,8 +36,19 @@ tacker_developer_mode: false tacker_developer_constraints: - "git+{{ tacker_git_repo }}@{{ tacker_git_install_branch }}#egg=tacker" +# 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. +tacker_pip_install_args: >- + {{ tacker_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('') }} + # Name of the virtual env to deploy into -tacker_venv_tag: untagged +tacker_venv_tag: "{{ venv_tag | default('untagged') }}" tacker_bin: "/openstack/venvs/tacker-{{ tacker_venv_tag }}/bin" # Set the etc dir path where tacker is installed. diff --git a/handlers/main.yml b/handlers/main.yml index a81d8e4..cb375e4 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -24,6 +24,8 @@ daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}" with_items: "{{ tacker_service_names }}" failed_when: false + listen: + - "venv changed" - name: Restart apache service: diff --git a/tasks/tacker_install.yml b/tasks/tacker_install.yml index aa8e4a6..51fc3f7 100644 --- a/tasks/tacker_install.yml +++ b/tasks/tacker_install.yml @@ -15,17 +15,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Install distro packages - package: - name: "{{ tacker_distro_packages }}" - state: "{{ tacker_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 - +# 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" @@ -36,112 +31,22 @@ when: - tacker_developer_mode | bool -- name: Retrieve checksum for venv download - uri: - url: "{{ tacker_venv_download_url | replace('tgz', 'checksum') }}" - return_content: yes - register: tacker_venv_checksum - when: tacker_venv_download | bool - -- name: Attempt venv download - get_url: - url: "{{ tacker_venv_download_url }}" - dest: "/var/cache/{{ tacker_venv_download_url | basename }}" - checksum: "sha1:{{ tacker_venv_checksum.content | trim }}" - register: tacker_get_venv +- name: Ensure remote wheel building is disabled in developer mode + set_fact: + venv_build_host: "{{ ansible_hostname }}" when: - - tacker_venv_download | bool + - tacker_developer_mode | bool -- name: Remove existing venv - file: - path: "{{ tacker_bin | dirname }}" - state: absent - when: - - tacker_get_venv is changed - -- name: Create tacker venv dir - file: - path: "{{ tacker_bin | dirname }}" - state: directory - register: tacker_venv_dir - when: - - tacker_get_venv is changed - -- name: Unarchive pre-built venv - unarchive: - src: "/var/cache/{{ tacker_venv_download_url | basename }}" - dest: "{{ tacker_bin | dirname }}" - copy: "no" - when: - - tacker_get_venv is changed - notify: - - Restart tacker services - -- name: Install pip packages - pip: - name: "{{ tacker_pip_packages }}" - state: "{{ tacker_pip_package_state }}" - virtualenv: "{{ tacker_bin | dirname }}" - virtualenv_site_packages: "no" - extra_args: >- - {{ tacker_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: - - tacker_get_venv | failed or tacker_get_venv | skipped - notify: - - Restart tacker services - -- name: Remove python from path first (CentOS, openSUSE) - file: - path: "{{ tacker_bin | dirname }}/bin/python2.7" - state: "absent" - when: - - ansible_pkg_mgr in ['yum', 'dnf', 'zypper'] - - tacker_get_venv is changed - -# NOTE(odyssey4me): -# We reinitialize the venv to ensure that the right -# version of python is in the venv, but we do not -# want virtualenv to also replace pip, setuptools -# and wheel so we tell it not to. -# We do not use --always-copy for CentOS/SuSE due -# to https://github.com/pypa/virtualenv/issues/565 -- name: Update virtualenv path - shell: | - find {{ tacker_bin }} -name \*.pyc -delete - sed -si '1s/^.*python.*$/#!{{ tacker_bin | replace ('/','\/') }}\/python/' {{ tacker_bin }}/* - virtualenv {{ tacker_bin | dirname }} \ - {{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }} \ - --no-pip \ - --no-setuptools \ - --no-wheel - tags: - - skip_ansible_lint - when: - - tacker_get_venv is changed - -- name: Install optional pip packages - pip: - name: "{{ tacker_optional_oslomsg_amqp1_pip_packages }}" - state: "{{ tacker_pip_package_state }}" - virtualenv: "{{ tacker_bin | dirname }}" - virtualenv_site_packages: "no" - when: tacker_oslomsg_amqp1_enabled - register: install_optional_packages - until: install_optional_packages is success - retries: 5 - delay: 2 - notify: - - Restart tacker services - -- name: Record the venv tag deployed - ini_file: - dest: "/etc/ansible/facts.d/openstack_ansible.fact" - section: tacker - option: venv_tag - value: "{{ tacker_venv_tag }}" +- name: Install the python venv + include_role: + name: "python_venv_build" + private: yes + vars: + venv_install_destination_path: "{{ tacker_bin | dirname }}" + venv_install_distro_package_list: "{{ tacker_distro_packages }}" + venv_pip_install_args: "{{ tacker_pip_install_args }}" + venv_pip_packages: "{{ (tacker_oslomsg_amqp1_enabled | bool) | ternary(tacker_pip_packages + tacker_optional_oslomsg_amqp1_pip_packages, tacker_pip_packages) }}" + venv_facts_when_changed: + - section: "tacker" + option: "venv_tag" + value: "{{ tacker_venv_tag }}" diff --git a/vars/ubuntu-14.04.yml b/vars/ubuntu-14.04.yml deleted file mode 100644 index 4906bc1..0000000 --- a/vars/ubuntu-14.04.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -# (C)2016 Brocade Communications Systems, Inc. -# 130 Holger Way, San Jose, CA 95134. -# All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -## APT Cache options -cache_timeout: 600 - -tacker_distro_packages: - - rsync - - git - #- remove after testing - - python-pip - #- remove after testing - - python-mysqldb