From a9c05684e9ec82b07cbc2c06488675447c6e973c Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotjagov Date: Wed, 27 Mar 2019 10:46:04 +0200 Subject: [PATCH] Update role for new source build process The variables masakari_developer_mode and masakari_venv_download no longer carry any meaning. This review changes masakari to do the equivalent of what developer_mode was all the time, meaning that it always builds the venv and never requires the repo server, but it will use a repo server when available. We also change include_tasks to import_tasks and include_role to import_role so that the tags in the python_venv_build role will work. Depends-On: https://review.openstack.org/#/c/647571/ Change-Id: I850ba83a8683be45988f2d9eafcc6a2e8ad4d8b2 --- defaults/main.yml | 21 ++-------- tasks/main.yml | 27 +++++++++--- tasks/masakari_install.yml | 84 -------------------------------------- 3 files changed, 25 insertions(+), 107 deletions(-) delete mode 100644 tasks/masakari_install.yml diff --git a/defaults/main.yml b/defaults/main.yml index bdba387..f1a2bf3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -29,9 +29,10 @@ masakari_pip_package_state: "latest" masakari_git_repo: https://git.openstack.org/openstack/masakari masakari_git_install_branch: master -masakari_developer_mode: false -masakari_developer_constraints: +masakari_upper_constraints_url: "{{ requirements_git_url | default('https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=' ~ requirements_git_install_branch | default('master')) }}" +masakari_git_constraints: - "git+{{ masakari_git_repo }}@{{ masakari_git_install_branch }}#egg=masakari" + - "--constraint {{ masakari_upper_constraints_url }}" ## System info masakari_system_user_name: masakari @@ -48,21 +49,7 @@ masakari_galera_user: masakari masakari_galera_use_ssl: "{{ galera_use_ssl | default(False) }}" masakari_galera_ssl_ca_cert: "{{ galera_ssl_ca_cert | default('/etc/ssl/certs/galera-ca.pem') }}" -# venv_download, even when true, will use the fallback method of building the -# venv from scratch if the venv download fails. -masakari_venv_download: "{{ not masakari_developer_mode | bool }}" -masakari_venv_download_url: http://127.0.0.1/venvs/untagged/ubuntu/masakari.tgz - -# 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. -masakari_pip_install_args: >- - {{ masakari_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('') }} +masakari_pip_install_args: "{{ pip_install_options | default('') }}" # Name of the virtual env to deploy into masakari_venv_tag: "{{ venv_tag | default('untagged') }}" diff --git a/tasks/main.yml b/tasks/main.yml index 41fec10..9e757aa 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -25,20 +25,35 @@ tags: - always -- include_tasks: masakari_pre_install.yml +- import_tasks: masakari_pre_install.yml tags: - masakari-install -- include_tasks: masakari_install.yml +- name: Install the python venv + import_role: + name: "python_venv_build" + vars: + venv_build_constraints: "{{ masakari_git_constraints }}" + venv_build_distro_package_list: "{{ masakari_devel_distro_packages }}" + venv_install_destination_path: "{{ masakari_bin | dirname }}" + venv_install_distro_package_list: >- + {{ ('masakari_monitor' in group_names) | ternary(masakari_monitor_distro_packages, masakari_distro_packages) }} + venv_pip_install_args: "{{ masakari_pip_install_args }}" + venv_pip_packages: "{{ masakari_pip_venv_packages }}" + venv_packages_to_symlink: "{{ ('masakari_monitor' in group_names) | ternary(masakari_monitor_packages_to_symlink, []) }}" + venv_facts_when_changed: + - section: "masakari" + option: "venv_tag" + value: "{{ masakari_venv_tag }}" tags: - masakari-install -- include_tasks: masakari_post_install.yml +- import_tasks: masakari_post_install.yml tags: - masakari-config - name: Run the systemd service role - include_role: + import_role: name: systemd_service private: true vars: @@ -84,12 +99,12 @@ - common-mq - masakari-config -- include_tasks: masakari_db_setup.yml +- import_tasks: masakari_db_setup.yml when: - "masakari_services['masakari-api']['group'] in group_names" - "inventory_hostname == ((groups[masakari_services['masakari-api']['group']] | intersect(ansible_play_hosts)) | list)[0]" -- include_tasks: masakari_service_setup.yml +- import_tasks: masakari_service_setup.yml when: - "masakari_services['masakari-api']['group'] in group_names" - "inventory_hostname == ((groups[masakari_services['masakari-api']['group']] | intersect(ansible_play_hosts)) | list)[0]" diff --git a/tasks/masakari_install.yml b/tasks/masakari_install.yml deleted file mode 100644 index 1b69787..0000000 --- a/tasks/masakari_install.yml +++ /dev/null @@ -1,84 +0,0 @@ ---- -# Copyright (c) 2018 NTT DATA -# -# 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. - -# 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" - content: | - {% for item in masakari_developer_constraints %} - {{ item }} - {% endfor %} - when: masakari_developer_mode | bool - -- name: Ensure remote wheel building is disabled in developer mode - set_fact: - venv_build_host: "{{ ansible_hostname }}" - when: - - masakari_developer_mode | bool - -- name: Install the python venv - include_role: - name: "python_venv_build" - private: yes - vars: - venv_install_destination_path: "{{ masakari_bin | dirname }}" - venv_install_distro_package_list: >- - {{ ('masakari_monitor' in group_names) | ternary(masakari_monitor_distro_packages, masakari_distro_packages) }} - venv_build_distro_package_list: "{{ masakari_devel_distro_packages }}" - venv_pip_install_args: "{{ masakari_pip_install_args }}" - venv_pip_packages: "{{ masakari_pip_venv_packages }}" - venv_facts_when_changed: - - section: "masakari" - option: "venv_tag" - value: "{{ masakari_venv_tag }}" - -- block: - - name: Find the venv's python version - find: - paths: "{{ masakari_bin | dirname }}/lib/" - patterns: "python*" - file_type: directory - recurse: no - register: python_venv_details - - - name: Set python venvs details - set_fact: - venv_python_version: "{{ (python_venv_details.files[0].path | basename) }}" - venv_python_major_version: "{{ (python_venv_details.files[0].path | basename)[:-2] }}" - venv_python_lib_folder: "{{ python_venv_details.files[0].path }}" - - - name: Search for lib files to link - shell: >- - {{ (ansible_pkg_mgr == 'apt') | ternary('dpkg -L ' ~ (masakari_monitor_packages_to_symlink | join(' ')), 'rpm -ql ' ~ (masakari_monitor_packages_to_symlink | join(' ')) ) }} - | egrep '^.*{{ venv_python_major_version }}.*/(site|dist)-packages/.*\.(py|so)' - args: - warn: no - changed_when: false - register: _python_files - - - name: Link the python host package files into venv - file: - src: "{{ item }}" - dest: "{{ venv_python_lib_folder }}/site-packages/{{ item | basename }}" - state: link - force: yes - with_items: "{{ _python_files.stdout_lines }}" - when: "'masakari_monitor' in group_names"