From ba64ce308332fc990f09f0dbb2f470c305f0520e Mon Sep 17 00:00:00 2001 From: Markos Chandras Date: Thu, 3 May 2018 13:52:33 +0100 Subject: [PATCH] Add support for using distribution packages for OpenStack services Distributions provide packages for the OpenStack services so we add support for using these instead of the pip ones. Change-Id: I026a440b6a0fda43b613e30f359b2a23c3c1151f Depends-On: I5a78e2120e596d36629b4ba978b2b5df76b149b0 Implements: blueprint openstack-distribution-packages --- defaults/main.yml | 13 +- ...istribution-packages-2f041fb59bfbb7ef.yaml | 7 + tasks/glance_install.yml | 132 ++---------------- tasks/glance_install_source.yml | 128 +++++++++++++++++ tasks/main.yml | 15 ++ templates/glance-uwsgi.ini.j2 | 2 + tox.ini | 9 ++ vars/distro_install.yml | 20 +++ vars/redhat-7.yml | 7 + vars/source_install.yml | 20 +++ vars/suse-42.yml | 8 ++ vars/ubuntu-16.04.yml | 8 ++ zuul.d/project.yaml | 3 + 13 files changed, 249 insertions(+), 123 deletions(-) create mode 100644 releasenotes/notes/openstack-distribution-packages-2f041fb59bfbb7ef.yaml create mode 100644 tasks/glance_install_source.yml create mode 100644 vars/distro_install.yml create mode 100644 vars/source_install.yml diff --git a/defaults/main.yml b/defaults/main.yml index b4f2a1cc..da9d23cf 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -16,6 +16,9 @@ ## Verbosity Options debug: False +# Set installation method +glance_install_method: "source" + # Set the package install state for distribution and pip packages # Options are 'present' and 'latest' glance_package_state: "latest" @@ -29,13 +32,13 @@ glance_developer_constraints: # Name of the virtual env to deploy into glance_venv_tag: untagged -glance_bin: "/openstack/venvs/glance-{{ glance_venv_tag }}/bin" +glance_bin: "{{ _glance_bin }}" # Set the etc dir path where glance is installed. # This is used for role access to the db migrations. # Example: # glance_etc_dir: "/usr/local/etc/glance" -glance_etc_dir: "{{ glance_bin | dirname }}/etc/glance" +glance_etc_dir: "{{ _glance_etc }}/glance" # venv_download, even when true, will use the fallback method of building the # venv from scratch if the venv download fails. @@ -255,12 +258,12 @@ glance_services: execstarts: >- {{ glance_enable_v1_api | ternary( glance_bin ~ '/glance-api', - glance_bin ~ '/uwsgi --autoload --ini /etc/uwsgi/glance-api.ini') + _glance_wsgi_bin ~ '/uwsgi --autoload --ini /etc/uwsgi/glance-api.ini') }} execreloads: >- {{ glance_enable_v1_api | ternary( '/bin/kill -HUP $MAINPID', - glance_bin ~ '/uwsgi --reload /var/run/glance-api/glance-api.pid') + _glance_wsgi_bin ~ '/uwsgi --reload /var/run/glance-api/glance-api.pid') }} glance-registry: group: glance_registry @@ -268,7 +271,7 @@ glance_services: condition: "{{ glance_enable_v1_api | bool or glance_enable_v2_registry | bool }}" init_config_overrides: "{{ glance_registry_init_overrides }}" start_order: 2 - execstarts: "{{ glance_bin }}/glance-registry" + execstarts: "{{ _glance_bin }}/glance-registry" # Glance uWSGI settings glance_wsgi_processes_max: 16 diff --git a/releasenotes/notes/openstack-distribution-packages-2f041fb59bfbb7ef.yaml b/releasenotes/notes/openstack-distribution-packages-2f041fb59bfbb7ef.yaml new file mode 100644 index 00000000..8326a91e --- /dev/null +++ b/releasenotes/notes/openstack-distribution-packages-2f041fb59bfbb7ef.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + The role now supports using the distribution packages for the OpenStack + services instead of the pip ones. This feature is disabled by default + and can be enabled by simply setting the ``glance_install_method`` + variable to ``distro``. diff --git a/tasks/glance_install.yml b/tasks/glance_install.yml index 4ac18181..c4bca696 100644 --- a/tasks/glance_install.yml +++ b/tasks/glance_install.yml @@ -85,7 +85,7 @@ - name: Install distro packages package: - name: "{{ glance_distro_packages }}" + name: "{{ glance_package_list }}" state: "{{ glance_package_state }}" update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}" cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}" @@ -94,134 +94,30 @@ retries: 5 delay: 2 -- name: Create developer mode constraint file - copy: - dest: "/opt/developer-pip-constraints.txt" - content: | - {% for item in glance_developer_constraints %} - {{ item }} - {% endfor %} - when: glance_developer_mode | bool - -- name: Install requires pip packages - pip: - name: "{{ glance_requires_pip_packages }}" - state: "{{ glance_pip_package_state }}" - extra_args: >- - {{ glance_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|success - retries: 5 - delay: 2 - -- name: Retrieve checksum for venv download - uri: - url: "{{ glance_venv_download_url | replace('tgz', 'checksum') }}" - return_content: yes - register: glance_venv_checksum - when: glance_venv_download | bool - -- name: Attempt venv download - get_url: - url: "{{ glance_venv_download_url }}" - dest: "/var/cache/{{ glance_venv_download_url | basename }}" - checksum: "sha1:{{ glance_venv_checksum.content | trim }}" - register: glance_get_venv - when: glance_venv_download | bool - -- name: Remove existing venv - file: - path: "{{ glance_bin | dirname }}" - state: absent - when: glance_get_venv | changed - -- name: Create glance venv dir - file: - path: "{{ glance_bin | dirname }}" - state: directory - register: glance_venv_dir - when: glance_get_venv | changed - -- name: Unarchive pre-built venv - unarchive: - src: "/var/cache/{{ glance_venv_download_url | basename }}" - dest: "{{ glance_bin | dirname }}" - copy: "no" - when: glance_get_venv | changed - notify: - - Manage LB - - Restart glance services - -- name: Install pip packages - pip: - name: "{{ glance_pip_packages }}" - state: "{{ glance_pip_package_state }}" - virtualenv: "{{ glance_bin | dirname }}" - virtualenv_site_packages: "no" - extra_args: >- - {{ glance_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|success - retries: 5 - delay: 2 - when: glance_get_venv | failed or glance_get_venv | skipped - notify: - - Manage LB - - Restart glance services - -- name: Remove python from path first (CentOS, openSUSE) - file: - path: "{{ glance_bin | dirname }}/bin/python2.7" - state: "absent" - when: - - ansible_pkg_mgr in ['yum', 'dnf', 'zypper'] - - glance_get_venv | 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 {{ glance_bin }} -name \*.pyc -delete - sed -si '1s/^.*python.*$/#!{{ glance_bin | replace ('/','\/') }}\/python/' {{ glance_bin }}/* - virtualenv {{ glance_bin | dirname }} \ - {{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }} \ - --no-pip \ - --no-setuptools \ - --no-wheel - when: glance_get_venv | changed - tags: - - skip_ansible_lint +- name: Install glance packages from PIP + include_tasks: glance_install_source.yml + when: glance_install_method == 'source' - name: Record the need for a service restart ini_file: dest: "/etc/ansible/facts.d/openstack_ansible.fact" section: glance - option: need_service_restart - value: True - when: (glance_get_venv | changed) or - (glance_venv_dir | changed) or + option: "{{ item.name }}" + value: "{{ item.state }}" + with_items: + - name: "need_service_restart" + state: "True" + - name: "install_method" + state: "{{ glance_install_method }}" + when: (glance_install_method == 'source' and + ((glance_get_venv | changed) or + (glance_venv_dir | changed))) or (install_packages | changed) or (ansible_local is not defined) or ('openstack_ansible' not in ansible_local) or ('glance' not in ansible_local['openstack_ansible']) or ('need_service_restart' not in ansible_local['openstack_ansible']['glance']) -- name: Record the venv tag deployed - ini_file: - dest: "/etc/ansible/facts.d/openstack_ansible.fact" - section: glance - option: venv_tag - value: "{{ glance_venv_tag }}" - - name: Run the systemd service role include_role: name: systemd_service diff --git a/tasks/glance_install_source.yml b/tasks/glance_install_source.yml new file mode 100644 index 00000000..340d7813 --- /dev/null +++ b/tasks/glance_install_source.yml @@ -0,0 +1,128 @@ +--- +# Copyright 2014, Rackspace US, Inc. +# +# 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. + +- name: Create developer mode constraint file + copy: + dest: "/opt/developer-pip-constraints.txt" + content: | + {% for item in glance_developer_constraints %} + {{ item }} + {% endfor %} + when: glance_developer_mode | bool + +- name: Install requires pip packages + pip: + name: "{{ glance_requires_pip_packages }}" + state: "{{ glance_pip_package_state }}" + extra_args: >- + {{ glance_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|success + retries: 5 + delay: 2 + +- name: Retrieve checksum for venv download + uri: + url: "{{ glance_venv_download_url | replace('tgz', 'checksum') }}" + return_content: yes + register: glance_venv_checksum + when: glance_venv_download | bool + +- name: Attempt venv download + get_url: + url: "{{ glance_venv_download_url }}" + dest: "/var/cache/{{ glance_venv_download_url | basename }}" + checksum: "sha1:{{ glance_venv_checksum.content | trim }}" + register: glance_get_venv + when: glance_venv_download | bool + +- name: Remove existing venv + file: + path: "{{ glance_bin | dirname }}" + state: absent + when: glance_get_venv | changed + +- name: Create glance venv dir + file: + path: "{{ glance_bin | dirname }}" + state: directory + register: glance_venv_dir + when: glance_get_venv | changed + +- name: Unarchive pre-built venv + unarchive: + src: "/var/cache/{{ glance_venv_download_url | basename }}" + dest: "{{ glance_bin | dirname }}" + copy: "no" + when: glance_get_venv | changed + notify: + - Manage LB + - Restart glance services + +- name: Install pip packages + pip: + name: "{{ glance_pip_packages }}" + state: "{{ glance_pip_package_state }}" + virtualenv: "{{ glance_bin | dirname }}" + virtualenv_site_packages: "no" + extra_args: >- + {{ glance_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|success + retries: 5 + delay: 2 + when: glance_get_venv | failed or glance_get_venv | skipped + notify: + - Manage LB + - Restart glance services + +- name: Remove python from path first (CentOS, openSUSE) + file: + path: "{{ glance_bin | dirname }}/bin/python2.7" + state: "absent" + when: + - ansible_pkg_mgr in ['yum', 'dnf', 'zypper'] + - glance_get_venv | 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 {{ glance_bin }} -name \*.pyc -delete + sed -si '1s/^.*python.*$/#!{{ glance_bin | replace ('/','\/') }}\/python/' {{ glance_bin }}/* + virtualenv {{ glance_bin | dirname }} \ + {{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }} \ + --no-pip \ + --no-setuptools \ + --no-wheel + when: glance_get_venv | changed + tags: + - skip_ansible_lint + +- name: Record the venv tag deployed + ini_file: + dest: "/etc/ansible/facts.d/openstack_ansible.fact" + section: glance + option: venv_tag + value: "{{ glance_venv_tag }}" diff --git a/tasks/main.yml b/tasks/main.yml index 57326729..79ae3a3f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -25,6 +25,21 @@ tags: - always +- name: Fail if service was deployed using a different installation method + fail: + msg: "Switching installation methods for OpenStack services is not supported" + when: + - ansible_local is defined + - ansible_local.openstack_ansible is defined + - ansible_local.openstack_ansible.glance is defined + - ansible_local.openstack_ansible.glance.install_method is defined + - ansible_local.openstack_ansible.glance.install_method != glance_install_method + +- name: Gather variables for installation method + include_vars: "{{ glance_install_method }}_install.yml" + tags: + - always + - include_tasks: glance_install.yml tags: - glance-install diff --git a/templates/glance-uwsgi.ini.j2 b/templates/glance-uwsgi.ini.j2 index 9957a3b4..11ef7d8a 100644 --- a/templates/glance-uwsgi.ini.j2 +++ b/templates/glance-uwsgi.ini.j2 @@ -2,7 +2,9 @@ uid = {{ glance_system_user_name }} gid = {{ glance_system_group_name }} +{% if glance_install_method == 'source' %} virtualenv = /openstack/venvs/glance-{{ glance_venv_tag }} +{% endif %} wsgi-file = {{ glance_bin }}/{{ item.wsgi_name }} http-socket = {{ item.uwsgi_bind_address }}:{{ item.uwsgi_port }} diff --git a/tox.ini b/tox.ini index 52708b09..85ca18d2 100644 --- a/tox.ini +++ b/tox.ini @@ -100,6 +100,15 @@ deps = commands = bash -c "{toxinidir}/tests/common/test-ansible-functional.sh" +[testenv:distro_install] +deps = + {[testenv:ansible]deps} +setenv = + {[testenv]setenv} + ANSIBLE_PARAMETERS=-e glance_install_method=distro +commands = + bash -c "{toxinidir}/tests/common/test-ansible-functional.sh" + [testenv:upgrade] deps = diff --git a/vars/distro_install.yml b/vars/distro_install.yml new file mode 100644 index 00000000..13a4389b --- /dev/null +++ b/vars/distro_install.yml @@ -0,0 +1,20 @@ +--- +# Copyright 2017, Rackspace US, Inc. +# +# 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. + +glance_package_list: "{{ glance_distro_packages + glance_service_distro_packages }}" + +_glance_bin: "/usr/bin" +_glance_etc: "/etc" +_glance_wsgi_bin: "{{ glance_wsgi_bin }}" diff --git a/vars/redhat-7.yml b/vars/redhat-7.yml index 1fe9e858..4febb90b 100644 --- a/vars/redhat-7.yml +++ b/vars/redhat-7.yml @@ -18,3 +18,10 @@ glance_distro_packages: - libxml2-devel - nfs-utils - rpcbind + +glance_service_distro_packages: + - openstack-glance + - uwsgi + - uwsgi-plugin-python + +glance_wsgi_bin: '/usr/sbin' diff --git a/vars/source_install.yml b/vars/source_install.yml new file mode 100644 index 00000000..d66521ba --- /dev/null +++ b/vars/source_install.yml @@ -0,0 +1,20 @@ +--- +# Copyright 2018, SUSE Linux GmbH. +# +# 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. + +glance_package_list: "{{ glance_distro_packages }}" + +_glance_bin: "/openstack/venvs/glance-{{ glance_venv_tag }}/bin" +_glance_etc: "{{ _glance_bin | dirname + '/etc' }}" +_glance_wsgi_bin: "{{ _glance_bin }}" diff --git a/vars/suse-42.yml b/vars/suse-42.yml index 4e480425..ef254199 100644 --- a/vars/suse-42.yml +++ b/vars/suse-42.yml @@ -19,3 +19,11 @@ glance_distro_packages: - libxml2-devel - nfs-utils - rpcbind + +glance_service_distro_packages: + - openstack-glance + - openstack-glance-api + - uwsgi + - uwsgi-python + +glance_wsgi_bin: '/usr/sbin' diff --git a/vars/ubuntu-16.04.yml b/vars/ubuntu-16.04.yml index e1ea5f18..ebe0206b 100644 --- a/vars/ubuntu-16.04.yml +++ b/vars/ubuntu-16.04.yml @@ -22,3 +22,11 @@ glance_distro_packages: - libxml2-dev - nfs-common - rpcbind + +glance_service_distro_packages: + - glance + - glance-api + - uwsgi + - uwsgi-plugin-python + +glance_wsgi_bin: '/usr/bin' diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml index a943f086..72b97fd1 100644 --- a/zuul.d/project.yaml +++ b/zuul.d/project.yaml @@ -24,6 +24,9 @@ - openstack-ansible-v1_api_enabled - openstack-ansible-v2_registry_enabled - openstack-ansible-glance-ssl-nv + - openstack-ansible-functional-distro_install-ubuntu-xenial + - openstack-ansible-functional-distro_install-centos-7 + - openstack-ansible-functional-distro_install-opensuse-423 experimental: jobs: - openstack-ansible-integrated-deploy-aio