From e3d63ab1ef347c0b3c641e5d9d41b25a1e22a6f0 Mon Sep 17 00:00:00 2001 From: Anton Khaldin Date: Wed, 6 Jul 2016 16:21:23 -0700 Subject: [PATCH] Only install to virtual environment Remove all tasks and variables related to toggling between installation of zaqar inside or outside of a Python virtual environment. Installing within a venv is now the only supported deployment. Additionally, a few changes have been made to make the creation of the venv more resistant to interruptions during a run of the role. * unarchiving a pre-built venv will now also occur when the venv directory is created, not only after being downloaded * virtualenv-tools is run against both pre-built and non pre-built venvs to account for interruptions during or prior to unarchiving Change-Id: I4a67a53d3d685c1e2f937114352569c9f45a74a0 Implements: blueprint only-install-venvs --- defaults/main.yml | 10 +--- ...ar-only-install-venv-76801d8a0053772d.yaml | 5 ++ tasks/zaqar_install.yml | 54 +++++-------------- tasks/zaqar_post_install.yml | 15 ------ tasks/zaqar_pre_install.yml | 11 ---- templates/zaqar-upstart-init.j2 | 4 +- templates/zaqar-wsgi.py.j2 | 4 +- 7 files changed, 20 insertions(+), 83 deletions(-) create mode 100644 releasenotes/notes/os_zaqar-only-install-venv-76801d8a0053772d.yaml diff --git a/defaults/main.yml b/defaults/main.yml index 1d4bf51..7403d18 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -18,15 +18,7 @@ debug: False # Name of the virtual env to deploy into zaqar_venv_tag: untagged -zaqar_venv_bin: "/openstack/venvs/zaqar-{{ zaqar_venv_tag }}/bin" - -# Set this to enable or disable installing in a venv -zaqar_venv_enabled: true - -# The bin path defaults to the venv path however if installation in a -# venv is disabled the bin path will be dynamically set based on the -# system path used when the installing. -zaqar_bin: "{{ zaqar_venv_bin }}" +zaqar_bin: "/openstack/venvs/zaqar-{{ zaqar_venv_tag }}/bin" zaqar_venv_download_url: http://127.0.0.1/venvs/untagged/ubuntu/zaqar.tgz zaqar_venv_localpath: /opt/kong/zaqar.tgz diff --git a/releasenotes/notes/os_zaqar-only-install-venv-76801d8a0053772d.yaml b/releasenotes/notes/os_zaqar-only-install-venv-76801d8a0053772d.yaml new file mode 100644 index 0000000..8c0a002 --- /dev/null +++ b/releasenotes/notes/os_zaqar-only-install-venv-76801d8a0053772d.yaml @@ -0,0 +1,5 @@ +--- +upgrade: + - Installation of zaqar and its dependent pip packages will now only + occur within a Python virtual environment. The ``zaqar_venv_enabled``, + ``zaqar_venv_bin`` variables have been removed. diff --git a/tasks/zaqar_install.yml b/tasks/zaqar_install.yml index fa7cb48..6915745 100644 --- a/tasks/zaqar_install.yml +++ b/tasks/zaqar_install.yml @@ -78,7 +78,6 @@ get_md5: False when: - not zaqar_developer_mode | bool - - zaqar_venv_enabled | bool - not zaqar_local_mode | bool register: local_venv_stat tags: @@ -91,7 +90,6 @@ return_content: True when: - not zaqar_developer_mode | bool - - zaqar_venv_enabled | bool - not zaqar_local_mode | bool register: remote_venv_checksum tags: @@ -113,7 +111,6 @@ when: - not zaqar_developer_mode | bool - not zaqar_local_mode | bool - - zaqar_venv_enabled | bool - (local_venv_stat.stat.exists == False or {{ local_venv_stat.stat.checksum is defined and local_venv_stat.stat.checksum != remote_venv_checksum.content | trim }}) tags: @@ -134,17 +131,15 @@ - name: Set zaqar get_venv fact set_fact: zaqar_get_venv: "{{ get_venv }}" - when: zaqar_venv_enabled | bool tags: - zaqar-install - zaqar-pip-packages - name: Remove existing venv file: - path: "{{ zaqar_venv_bin | dirname }}" + path: "{{ zaqar_bin | dirname }}" state: absent when: - - zaqar_venv_enabled | bool - zaqar_get_venv | changed tags: - zaqar-install @@ -152,12 +147,9 @@ - name: Create zaqar venv dir file: - path: "{{ zaqar_venv_bin | dirname }}" + path: "{{ zaqar_bin | dirname }}" state: directory - when: - - not zaqar_developer_mode | bool or zaqar_local_mode | bool - - zaqar_venv_enabled | bool - - zaqar_get_venv | changed + register: zaqar_venv_dir tags: - zaqar-install - zaqar-pip-packages @@ -165,34 +157,22 @@ - name: Unarchive pre-built venv unarchive: src: "/var/cache/{{ zaqar_venv_download_url | basename }}" - dest: "{{ zaqar_venv_bin | dirname }}" + dest: "{{ zaqar_bin | dirname }}" copy: "no" when: - not zaqar_developer_mode | bool or zaqar_local_mode | bool - - zaqar_venv_enabled | bool - - zaqar_get_venv | changed + - zaqar_get_venv | changed or zaqar_venv_dir | changed # notify: # - Restart zaqar api tags: - zaqar-install - zaqar-pip-packages -- name: Update virtualenv path - command: > - virtualenv-tools --update-path=auto {{ zaqar_venv_bin | dirname }} - when: - - not zaqar_developer_mode | bool or zaqar_local_mode | bool - - zaqar_venv_enabled | bool - - zaqar_get_venv | success - tags: - - zaqar-install - - zaqar-pip-packages - - name: Install pip packages (venv) pip: name: "{{ item }}" state: latest - virtualenv: "{{ zaqar_venv_bin | dirname }}" + virtualenv: "{{ zaqar_bin | dirname }}" virtualenv_site_packages: "no" extra_args: "{{ pip_install_options|default('') }}" register: install_packages @@ -201,7 +181,6 @@ delay: 2 with_items: "{{ zaqar_pip_packages }}" when: - - zaqar_venv_enabled | bool - zaqar_get_venv | failed or zaqar_developer_mode | bool or zaqar_local_mode | bool # notify: # - Restart zaqar api @@ -209,22 +188,13 @@ - zaqar-install - zaqar-pip-packages -- name: Install pip packages (no venv) - pip: - name: "{{ item }}" - state: latest - extra_args: "{{ pip_install_options|default('') }}" - register: install_packages - until: install_packages|success - retries: 5 - delay: 2 - with_items: "{{ zaqar_pip_packages }}" +- name: Update virtualenv path + command: > + virtualenv-tools --update-path=auto {{ zaqar_bin | dirname }} when: - - not zaqar_developer_mode | bool - - not zaqar_venv_enabled | bool - - not zaqar_local_mode | bool -# notify: -# - Restart zaqar api + - not zaqar_developer_mode | bool or zaqar_local_mode | bool + - zaqar_get_venv | success tags: - zaqar-install - zaqar-pip-packages + diff --git a/tasks/zaqar_post_install.yml b/tasks/zaqar_post_install.yml index 803ebe9..f9a0480 100644 --- a/tasks/zaqar_post_install.yml +++ b/tasks/zaqar_post_install.yml @@ -36,18 +36,3 @@ - zaqar-config - zaqar-post-install -- name: Get zaqar command path - command: which zaqar - register: zaqar_command_path - when: - - not zaqar_venv_enabled | bool - tags: - - zaqar-command-bin - -- name: Set zaqar command path - set_fact: - zaqar_bin: "{{ zaqar_command_path.stdout | dirname }}" - when: - - not zaqar_venv_enabled | bool - tags: - - zaqar-command-bin diff --git a/tasks/zaqar_pre_install.yml b/tasks/zaqar_pre_install.yml index c797a94..475606e 100644 --- a/tasks/zaqar_pre_install.yml +++ b/tasks/zaqar_pre_install.yml @@ -51,17 +51,6 @@ tags: - zaqar-dirs -- name: Create zaqar venv dir - file: - path: "{{ item.path }}" - state: directory - with_items: - - { path: "/openstack/venvs" } - - { path: "{{ zaqar_venv_bin }}" } - when: zaqar_venv_enabled | bool - tags: - - zaqar-dirs - - name: Test for log directory or link shell: | if [ -h "/var/log/zaqar" ]; then diff --git a/templates/zaqar-upstart-init.j2 b/templates/zaqar-upstart-init.j2 index 55a6e39..3db2f1a 100644 --- a/templates/zaqar-upstart-init.j2 +++ b/templates/zaqar-upstart-init.j2 @@ -25,9 +25,7 @@ pre-start script mkdir -p "/var/lock/{{ zaqar_api_program_name }}" chown {{ zaqar_system_user_name }}:{{ zaqar_system_group_name }} "/var/lock/{{ zaqar_api_program_name }}" - {% if zaqar_venv_enabled | bool -%} - . {{ zaqar_venv_bin }}/activate - {%- endif %} + . {{ zaqar_bin }}/activate end script diff --git a/templates/zaqar-wsgi.py.j2 b/templates/zaqar-wsgi.py.j2 index 08c57a1..c642fd5 100644 --- a/templates/zaqar-wsgi.py.j2 +++ b/templates/zaqar-wsgi.py.j2 @@ -14,10 +14,8 @@ import os -{% if zaqar_venv_enabled | bool %} -activate_this = os.path.expanduser("{{ zaqar_venv_bin }}/activate_this.py") +activate_this = os.path.expanduser("{{ zaqar_bin }}/activate_this.py") execfile(activate_this, dict(__file__=activate_this)) -{% endif %} from keystonemiddleware import auth_token from zaqar.transport.wsgi import app