From b0cdb0de462cea5968214674fef4d113e2ad9f64 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Sat, 10 Oct 2015 21:07:56 -0500 Subject: [PATCH] Implement aodh venv support This commit conditionally allows the os_aodh role to install build and deploy within a venv. This is the new default behavior of the role however the functionality can be disabled. Change-Id: I9f9e09b2a68e843da1d92a782cd29fc563379a6d Implements: blueprint enable-venv-support-within-the-roles Signed-off-by: Kevin Carter --- playbooks/os-aodh-install.yml | 5 ++- playbooks/roles/os_aodh/defaults/main.yml | 17 +++++++++ .../roles/os_aodh/tasks/aodh_install.yml | 37 ++++++++++++++++++- .../roles/os_aodh/tasks/aodh_post_install.yml | 17 ++++++++- .../roles/os_aodh/tasks/aodh_pre_install.yml | 11 ++++++ .../os_aodh/templates/aodh-upstart-init.j2 | 7 +++- 6 files changed, 90 insertions(+), 4 deletions(-) diff --git a/playbooks/os-aodh-install.yml b/playbooks/os-aodh-install.yml index 68f3a277ec..26def617f1 100644 --- a/playbooks/os-aodh-install.yml +++ b/playbooks/os-aodh-install.yml @@ -61,7 +61,10 @@ - aodh-logs - aodh-log-dirs roles: - - { role: "os_aodh", tags: [ "os-aodh" ] } + - role: "os_aodh" + aodh_venv_tag: "{{ openstack_release }}" + tags: + - "os-aodh" - { role: "openstack_openrc", tags: [ "openstack-openrc" ] } - role: "rsyslog_client" rsyslog_client_log_rotate_file: aodh_log_rotate diff --git a/playbooks/roles/os_aodh/defaults/main.yml b/playbooks/roles/os_aodh/defaults/main.yml index 08ba6d681d..d737566f4f 100644 --- a/playbooks/roles/os_aodh/defaults/main.yml +++ b/playbooks/roles/os_aodh/defaults/main.yml @@ -17,6 +17,18 @@ debug: False verbose: False +# Name of the virtual env to deploy into +aodh_venv_tag: untagged +aodh_venv_bin: "/openstack/venvs/aodh-{{ aodh_venv_tag }}/bin" + +# Set this to enable or disable installing in a venv +aodh_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. +aodh_bin: "{{ aodh_venv_bin }}" + ## System info aodh_system_user_name: aodh aodh_system_group_name: aodh @@ -70,6 +82,11 @@ aodh_service_adminurl: "{{ aodh_service_adminuri }}" aodh_apt_packages: - rpcbind +# aodh packages that must be installed before anything else +aodh_requires_pip_packages: + - virtualenv + - python-keystoneclient # Keystoneclient needed to OSA keystone lib + # Common pip packages aodh_pip_packages: - aodh diff --git a/playbooks/roles/os_aodh/tasks/aodh_install.yml b/playbooks/roles/os_aodh/tasks/aodh_install.yml index f4f5e9a01d..d71fd3069c 100644 --- a/playbooks/roles/os_aodh/tasks/aodh_install.yml +++ b/playbooks/roles/os_aodh/tasks/aodh_install.yml @@ -25,10 +25,43 @@ delay: 2 with_items: aodh_apt_packages tags: + - aodh-install - aodh-apt-packages +- name: Install requires pip packages + pip: + name: "{{ item }}" + state: present + extra_args: "{{ pip_install_options|default('') }}" + register: install_packages + until: install_packages|success + retries: 5 + delay: 2 + with_items: + - "{{ aodh_requires_pip_packages }}" + tags: + - aodh-install + - aodh-pip-packages -- name: Install pip packages +- name: Install pip packages (venv) + pip: + name: "{{ item }}" + state: present + virtualenv: "{{ aodh_venv_bin | dirname }}" + virtualenv_site_packages: "no" + extra_args: "{{ pip_install_options|default('') }}" + register: install_packages + until: install_packages|success + retries: 5 + delay: 2 + with_items: + - "{{ aodh_pip_packages }}" + when: aodh_venv_enabled | bool + tags: + - aodh-install + - aodh-pip-packages + +- name: Install pip packages (no venv) pip: name: "{{ item }}" state: present @@ -39,5 +72,7 @@ delay: 2 with_items: - "{{ aodh_pip_packages }}" + when: not aodh_venv_enabled | bool tags: + - aodh-install - aodh-pip-packages diff --git a/playbooks/roles/os_aodh/tasks/aodh_post_install.yml b/playbooks/roles/os_aodh/tasks/aodh_post_install.yml index 9345d573f1..6a735e16eb 100644 --- a/playbooks/roles/os_aodh/tasks/aodh_post_install.yml +++ b/playbooks/roles/os_aodh/tasks/aodh_post_install.yml @@ -13,6 +13,22 @@ # See the License for the specific language governing permissions and # limitations under the License. +- name: Get aodh command path + command: which aodh + register: aodh_command_path + when: + - not aodh_venv_enabled | bool + tags: + - aodh-command-bin + +- name: Set aodh command path + set_fact: + aodh_bin: "{{ aodh_command_path.stdout | dirname }}" + when: + - not aodh_venv_enabled | bool + tags: + - aodh-command-bin + - name: Copy aodh config config_template: src: "{{ item.src }}" @@ -39,4 +55,3 @@ tags: - aodh-config - aodh-post-install - diff --git a/playbooks/roles/os_aodh/tasks/aodh_pre_install.yml b/playbooks/roles/os_aodh/tasks/aodh_pre_install.yml index d31aa1460d..6e4a820dc2 100644 --- a/playbooks/roles/os_aodh/tasks/aodh_pre_install.yml +++ b/playbooks/roles/os_aodh/tasks/aodh_pre_install.yml @@ -48,6 +48,17 @@ tags: - aodh-dirs +- name: Create aodh venv dir + file: + path: "{{ item.path }}" + state: directory + with_items: + - { path: "/openstack/venvs" } + - { path: "{{ aodh_venv_bin }}" } + when: aodh_venv_enabled | bool + tags: + - aodh-dirs + - name: Test for log directory or link shell: | if [ -h "/var/log/aodh" ]; then diff --git a/playbooks/roles/os_aodh/templates/aodh-upstart-init.j2 b/playbooks/roles/os_aodh/templates/aodh-upstart-init.j2 index 9455552fd5..f1b5741cbe 100644 --- a/playbooks/roles/os_aodh/templates/aodh-upstart-init.j2 +++ b/playbooks/roles/os_aodh/templates/aodh-upstart-init.j2 @@ -12,7 +12,7 @@ respawn respawn limit 10 5 # Set the RUNBIN environment variable -env RUNBIN="/usr/local/bin/{{ program_name }}" +env RUNBIN="{{ aodh_bin }}/{{ program_name }}" # Change directory to service users home chdir "{{ service_home }}" @@ -24,6 +24,11 @@ pre-start script mkdir -p "/var/lock/{{ program_name }}" chown {{ system_user }}:{{ system_group }} "/var/lock/{{ program_name }}" + + {% if aodh_venv_enabled | bool -%} + . {{ aodh_bin }}/activate + {%- endif %} + end script # Post stop actions