From 07d79cd0a0c67f3e4d18a57d2ed417f49cc8d92e Mon Sep 17 00:00:00 2001 From: Markos Chandras Date: Fri, 18 May 2018 16:50:00 +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: Iab155254fa3600e1b6b3e8992f7c1fdc6f710ed6 Implements: blueprint openstack-distribution-packages --- defaults/main.yml | 7 +- ...istribution-packages-9fa11225b7f06125.yaml | 7 + tasks/designate_install.yml | 129 +++--------------- tasks/designate_install_source.yml | 128 +++++++++++++++++ tasks/main.yml | 15 ++ tests/os_designate-overrides.yml | 1 - tox.ini | 10 ++ vars/distro_install.yml | 19 +++ vars/redhat-7.yml | 11 ++ vars/source_install.yml | 19 +++ vars/suse-42.yml | 28 +++- vars/ubuntu-16.04.yml | 11 ++ zuul.d/project.yaml | 7 + 13 files changed, 275 insertions(+), 117 deletions(-) create mode 100644 releasenotes/notes/openstack-distribution-packages-9fa11225b7f06125.yaml create mode 100644 tasks/designate_install_source.yml create mode 100644 vars/distro_install.yml create mode 100644 vars/source_install.yml mode change 120000 => 100644 vars/suse-42.yml diff --git a/defaults/main.yml b/defaults/main.yml index 84673c5..d9ac3f1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -21,6 +21,9 @@ debug: False designate_package_state: "latest" designate_pip_package_state: "latest" +# Set installation method. +designate_install_method: "source" + ## The git source/branch designate_git_repo: https://git.openstack.org/openstack/designate designate_git_install_branch: master @@ -36,13 +39,13 @@ designate_developer_constraints: # Name of the virtual env to deploy into designate_venv_tag: untagged -designate_bin: "/openstack/venvs/designate-{{ designate_venv_tag }}/bin" +designate_bin: "{{ _designate_bin }}" # Set the etc dir path where designate is installed. # This is used for role access to the db migrations. # Example: # designate_etc_dir: "/usr/local/etc/designate" -designate_etc_dir: "{{ designate_bin | dirname }}/etc/designate" +designate_etc_dir: "{{ _designate_etc }}/designate" # venv_download, even when true, will use the fallback method of building the # venv from scratch if the venv download fails. diff --git a/releasenotes/notes/openstack-distribution-packages-9fa11225b7f06125.yaml b/releasenotes/notes/openstack-distribution-packages-9fa11225b7f06125.yaml new file mode 100644 index 0000000..b2872fd --- /dev/null +++ b/releasenotes/notes/openstack-distribution-packages-9fa11225b7f06125.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 ``designate_install_method`` + variable to ``distro``. diff --git a/tasks/designate_install.yml b/tasks/designate_install.yml index 546b694..cea1446 100644 --- a/tasks/designate_install.yml +++ b/tasks/designate_install.yml @@ -13,9 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. +- name: Record the installation method + ini_file: + dest: "/etc/ansible/facts.d/openstack_ansible.fact" + section: "designate" + option: "install_method" + value: "{{ designate_install_method }}" + +- name: Refresh local facts to ensure the designate section is present + setup: + filter: ansible_local + gather_subset: "!all" + - name: Install designate distro packages package: - name: "{{ designate_distro_packages }}" + name: "{{ designate_package_list }}" state: "{{ designate_package_state }}" update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}" cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}" @@ -24,115 +36,6 @@ retries: 5 delay: 2 -- name: Create developer mode constraint file - copy: - dest: "/opt/developer-pip-constraints.txt" - content: | - {% for item in designate_developer_constraints %} - {{ item }} - {% endfor %} - when: designate_developer_mode | bool - -- name: Install requires pip packages - pip: - name: "{{ designate_requires_pip_packages }}" - state: "{{ designate_pip_package_state }}" - extra_args: >- - {{ designate_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: "{{ designate_venv_download_url | replace('tgz', 'checksum') }}" - return_content: yes - register: designate_venv_checksum - when: designate_venv_download | bool - -- name: Attempt venv download - get_url: - url: "{{ designate_venv_download_url }}" - dest: "/var/cache/{{ designate_venv_download_url | basename }}" - checksum: "sha1:{{ designate_venv_checksum.content | trim }}" - register: designate_get_venv - when: designate_venv_download | bool - -- name: Remove existing venv - file: - path: "{{ designate_bin | dirname }}" - state: absent - when: designate_get_venv | changed - -- name: Create designate venv dir - file: - path: "{{ designate_bin | dirname }}" - state: directory - mode: "0755" - register: designate_venv_dir - when: designate_get_venv | changed - -- name: Unarchive pre-built venv - unarchive: - src: "/var/cache/{{ designate_venv_download_url | basename }}" - dest: "{{ designate_bin | dirname }}" - copy: "no" - when: designate_get_venv | changed - notify: - - Restart designate services - -- name: Install pip packages - pip: - name: "{{ designate_pip_packages }}" - state: "{{ designate_pip_package_state }}" - virtualenv: "{{ designate_bin | dirname }}" - virtualenv_site_packages: "no" - extra_args: >- - {{ designate_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: designate_get_venv | failed or designate_get_venv | skipped - notify: - - Restart designate services - -- name: Remove python from path first (CentOS, openSUSE) - file: - path: "{{ designate_bin | dirname }}/bin/python2.7" - state: "absent" - when: - - ansible_pkg_mgr in ['yum', 'dnf', 'zypper'] - - not designate_developer_mode | bool - - designate_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 {{ designate_bin }} -name \*.pyc -delete - sed -si '1s/^.*python.*$/#!{{ designate_bin | replace ('/','\/') }}\/python/' {{ designate_bin }}/* - virtualenv {{ designate_bin | dirname }} \ - {{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }} \ - --no-pip \ - --no-setuptools \ - --no-wheel - when: designate_get_venv | changed - tags: - - skip_ansible_lint -- name: Record the venv tag deployed - ini_file: - dest: "/etc/ansible/facts.d/openstack_ansible.fact" - section: designate - option: venv_tag - value: "{{ designate_venv_tag }}" +- name: Install designate packages from PIP + include_tasks: designate_install_source.yml + when: designate_install_method == 'source' diff --git a/tasks/designate_install_source.yml b/tasks/designate_install_source.yml new file mode 100644 index 0000000..b4582a2 --- /dev/null +++ b/tasks/designate_install_source.yml @@ -0,0 +1,128 @@ +--- +# 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. + +- name: Create developer mode constraint file + copy: + dest: "/opt/developer-pip-constraints.txt" + content: | + {% for item in designate_developer_constraints %} + {{ item }} + {% endfor %} + when: designate_developer_mode | bool + +- name: Install requires pip packages + pip: + name: "{{ designate_requires_pip_packages }}" + state: "{{ designate_pip_package_state }}" + extra_args: >- + {{ designate_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: "{{ designate_venv_download_url | replace('tgz', 'checksum') }}" + return_content: yes + register: designate_venv_checksum + when: designate_venv_download | bool + +- name: Attempt venv download + get_url: + url: "{{ designate_venv_download_url }}" + dest: "/var/cache/{{ designate_venv_download_url | basename }}" + checksum: "sha1:{{ designate_venv_checksum.content | trim }}" + register: designate_get_venv + when: designate_venv_download | bool + +- name: Remove existing venv + file: + path: "{{ designate_bin | dirname }}" + state: absent + when: designate_get_venv | changed + +- name: Create designate venv dir + file: + path: "{{ designate_bin | dirname }}" + state: directory + mode: "0755" + register: designate_venv_dir + when: designate_get_venv | changed + +- name: Unarchive pre-built venv + unarchive: + src: "/var/cache/{{ designate_venv_download_url | basename }}" + dest: "{{ designate_bin | dirname }}" + copy: "no" + when: designate_get_venv | changed + notify: + - Restart designate services + +- name: Install pip packages + pip: + name: "{{ designate_pip_packages }}" + state: "{{ designate_pip_package_state }}" + virtualenv: "{{ designate_bin | dirname }}" + virtualenv_site_packages: "no" + extra_args: >- + {{ designate_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: designate_get_venv | failed or designate_get_venv | skipped + notify: + - Restart designate services + +- name: Remove python from path first (CentOS, openSUSE) + file: + path: "{{ designate_bin | dirname }}/bin/python2.7" + state: "absent" + when: + - ansible_pkg_mgr in ['yum', 'dnf', 'zypper'] + - not designate_developer_mode | bool + - designate_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 {{ designate_bin }} -name \*.pyc -delete + sed -si '1s/^.*python.*$/#!{{ designate_bin | replace ('/','\/') }}\/python/' {{ designate_bin }}/* + virtualenv {{ designate_bin | dirname }} \ + {{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }} \ + --no-pip \ + --no-setuptools \ + --no-wheel + when: designate_get_venv | changed + tags: + - skip_ansible_lint + +- name: Record the venv tag deployed + ini_file: + dest: "/etc/ansible/facts.d/openstack_ansible.fact" + section: designate + option: venv_tag + value: "{{ designate_venv_tag }}" diff --git a/tasks/main.yml b/tasks/main.yml index cc10746..d6f8fe1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -13,6 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +- 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.designate is defined + - ansible_local.openstack_ansible.designate.install_method is defined + - ansible_local.openstack_ansible.designate.install_method != designate_install_method + - name: Gather variables for each operating system include_vars: "{{ item }}" with_first_found: @@ -24,6 +34,11 @@ tags: - always +- name: Gather variables for installation method + include_vars: "{{ designate_install_method }}_install.yml" + tags: + - always + - include: designate_pre_install.yml tags: - designate-install diff --git a/tests/os_designate-overrides.yml b/tests/os_designate-overrides.yml index e166a9b..83fed90 100644 --- a/tests/os_designate-overrides.yml +++ b/tests/os_designate-overrides.yml @@ -27,7 +27,6 @@ designate_rabbitmq_vhost: /designate designate_rabbitmq_servers: "{{ rabbitmq_servers }}" designate_rabbitmq_use_ssl: "{{ rabbitmq_use_ssl }}" designate_rabbitmq_port: "{{ rabbitmq_port }}" -designate_bin: "/openstack/venvs/designate-{{ designate_venv_tag }}/bin" designate_pools_yaml: - name: "default" description: Default BIND9 Pool diff --git a/tox.ini b/tox.ini index 401d5bb..735e23b 100644 --- a/tox.ini +++ b/tox.ini @@ -101,6 +101,16 @@ commands = bash -c "{toxinidir}/tests/common/test-ansible-functional.sh" +[testenv:distro_install] +deps = + {[testenv:ansible]deps} +setenv = + {[testenv]setenv} + ANSIBLE_PARAMETERS=-e designate_install_method=distro +commands = + bash -c "{toxinidir}/tests/common/test-ansible-functional.sh" + + [testenv:ssl] deps = {[testenv:ansible]deps} diff --git a/vars/distro_install.yml b/vars/distro_install.yml new file mode 100644 index 0000000..577d0ab --- /dev/null +++ b/vars/distro_install.yml @@ -0,0 +1,19 @@ +--- +# 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. +# + +designate_package_list: "{{ designate_distro_packages + designate_service_distro_packages }}" +_designate_bin: "/usr/bin" +_designate_etc: "/etc" diff --git a/vars/redhat-7.yml b/vars/redhat-7.yml index a22827a..dac0bb9 100644 --- a/vars/redhat-7.yml +++ b/vars/redhat-7.yml @@ -16,3 +16,14 @@ # Common yum packages designate_distro_packages: - which + +designate_service_distro_packages: + - openstack-designate-agent + - openstack-designate-api + - openstack-designate-central + - openstack-designate-mdns + - openstack-designate-pool-manager + - openstack-designate-producer + - openstack-designate-sink + - openstack-designate-worker + - openstack-designate-zone-manager diff --git a/vars/source_install.yml b/vars/source_install.yml new file mode 100644 index 0000000..cc3d065 --- /dev/null +++ b/vars/source_install.yml @@ -0,0 +1,19 @@ +--- +# 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. +# + +designate_package_list: "{{ designate_distro_packages }}" +_designate_bin: "/openstack/venvs/designate-{{ designate_venv_tag }}/bin" +_designate_etc: "{{ _designate_bin | dirname + '/etc' }}" diff --git a/vars/suse-42.yml b/vars/suse-42.yml deleted file mode 120000 index 6b25f3f..0000000 --- a/vars/suse-42.yml +++ /dev/null @@ -1 +0,0 @@ -redhat-7.yml \ No newline at end of file diff --git a/vars/suse-42.yml b/vars/suse-42.yml new file mode 100644 index 0000000..a40129d --- /dev/null +++ b/vars/suse-42.yml @@ -0,0 +1,27 @@ +--- +# 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. + +# Common yum packages +designate_distro_packages: + - which + +designate_service_distro_packages: + - openstack-designate + - openstack-designate-agent + - openstack-designate-api + - openstack-designate-central + - openstack-designate-producer + - openstack-designate-sink + - openstack-designate-worker diff --git a/vars/ubuntu-16.04.yml b/vars/ubuntu-16.04.yml index 25afd08..a2a7f2a 100644 --- a/vars/ubuntu-16.04.yml +++ b/vars/ubuntu-16.04.yml @@ -18,3 +18,14 @@ cache_timeout: 600 # Common apt packages designate_distro_packages: [] + +designate_service_distro_packages: + - designate + - designate-agent + - designate-api + - designate-central + - designate-pool-manager + - designate-producer + - designate-sink + - designate-worker + - designate-zone-manager diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml index 4db2433..a9cb756 100644 --- a/zuul.d/project.yaml +++ b/zuul.d/project.yaml @@ -20,6 +20,11 @@ - openstack-ansible-functional-opensuse-423 - openstack-ansible-functional-ubuntu-xenial - openstack-ansible-designate-ssl-nv + - openstack-ansible-functional-distro_install-ubuntu-xenial + # NOTE(hwoarang) Centos7 is having some troubles with repo dependencies + # so disabling until it's investigated. + - openstack-ansible-functional-distro_install-centos-7-nv + - openstack-ansible-functional-distro_install-opensuse-423 experimental: jobs: - openstack-ansible-integrated-deploy-aio @@ -29,3 +34,5 @@ - openstack-ansible-functional-centos-7 - openstack-ansible-functional-opensuse-423 - openstack-ansible-functional-ubuntu-xenial + - openstack-ansible-functional-distro_install-ubuntu-xenial + - openstack-ansible-functional-distro_install-opensuse-423