From c38bd3cf46b0a42da0bc9c711bf3fc08c6105354 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Tue, 29 Sep 2015 21:15:04 -0500 Subject: [PATCH] Implement heat venv support This commit conditionally allows the os_heat 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: I55c0ad20d67c9d97df9d11d01e4c63fa0a904188 Implements: blueprint enable-venv-support-within-the-roles Signed-off-by: Kevin Carter --- playbooks/os-heat-install.yml | 7 +++- playbooks/roles/os_heat/defaults/main.yml | 22 +++++++++-- .../roles/os_heat/tasks/heat_db_setup.yml | 3 +- .../roles/os_heat/tasks/heat_domain_setup.yml | 9 ++++- .../roles/os_heat/tasks/heat_install.yml | 38 ++++++++++++++++++- .../roles/os_heat/tasks/heat_post_install.yml | 16 ++++++++ .../roles/os_heat/tasks/heat_pre_install.yml | 14 +++++++ playbooks/roles/os_heat/tasks/main.yml | 3 +- .../os_heat/templates/heat-upstart-init.j2 | 7 +++- 9 files changed, 107 insertions(+), 12 deletions(-) diff --git a/playbooks/os-heat-install.yml b/playbooks/os-heat-install.yml index 8952bcfc85..9617145c44 100644 --- a/playbooks/os-heat-install.yml +++ b/playbooks/os-heat-install.yml @@ -70,7 +70,11 @@ tags: - heat-logs roles: - - { role: "os_heat", tags: [ "os-heat" ] } + - role: "os_heat" + heat_venv_tag: "{{ openstack_release }}" + heat_galera_address: "{{ galera_address }}" + tags: + - "os-heat" - role: "rsyslog_client" rsyslog_client_log_rotate_file: heat_log_rotate rsyslog_client_log_dir: "/var/log/heat" @@ -83,7 +87,6 @@ - "system-crontab-coordination" vars: galera_address: "{{ internal_lb_vip_address }}" - heat_galera_address: "{{ internal_lb_vip_address }}" ansible_hostname: "{{ container_name }}" is_metal: "{{ properties.is_metal|default(false) }}" vars_files: diff --git a/playbooks/roles/os_heat/defaults/main.yml b/playbooks/roles/os_heat/defaults/main.yml index 434213c26f..dfdd88428b 100644 --- a/playbooks/roles/os_heat/defaults/main.yml +++ b/playbooks/roles/os_heat/defaults/main.yml @@ -16,15 +16,25 @@ # The variables file used by the playbooks in the Heat-api group. # These don't have to be explicitly imported by vars_files: they are autopopulated. -# Defines that the role will be deployed on a host machine -is_metal: true - # Enable/Disable Ceilometer heat_ceilometer_enabled: False ## Verbosity Options debug: False verbose: True + +# Name of the virtual env to deploy into +heat_venv_tag: untagged +heat_venv_bin: "/openstack/venvs/heat-{{ heat_venv_tag }}/bin" + +# Set this to enable or disable installing in a venv +heat_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. +heat_bin: "{{ heat_venv_bin }}" + heat_fatal_deprecations: False heat_clients_endpoint: internalURL @@ -144,6 +154,12 @@ heat_apt_packages: - rsync - libxslt1.1 +# Heat packages that must be installed before anything else +heat_requires_pip_packages: + - virtualenv + - python-keystoneclient # Keystoneclient needed to OSA keystone lib + +# Common pip packages heat_pip_packages: - keystonemiddleware - MySQL-python diff --git a/playbooks/roles/os_heat/tasks/heat_db_setup.yml b/playbooks/roles/os_heat/tasks/heat_db_setup.yml index ae1b40ebb1..d10fe658e0 100644 --- a/playbooks/roles/os_heat/tasks/heat_db_setup.yml +++ b/playbooks/roles/os_heat/tasks/heat_db_setup.yml @@ -40,9 +40,10 @@ - heat-db-setup - name: Perform a heat DB sync - command: heat-manage db_sync + command: "{{ heat_bin }}/heat-manage db_sync" sudo: yes sudo_user: "{{ heat_system_user_name }}" tags: - heat-db-sync - heat-setup + - heat-command-bin diff --git a/playbooks/roles/os_heat/tasks/heat_domain_setup.yml b/playbooks/roles/os_heat/tasks/heat_domain_setup.yml index 8b780a3bb2..2bff2d57cd 100644 --- a/playbooks/roles/os_heat/tasks/heat_domain_setup.yml +++ b/playbooks/roles/os_heat/tasks/heat_domain_setup.yml @@ -57,7 +57,8 @@ - name: Ensure heat user shell: | . {{ ansible_env.HOME }}/openrc - openstack --os-identity-api-version=3 \ + {{ heat_bin }}/openstack \ + --os-identity-api-version=3 \ --os-auth-url={{ keystone_service_adminurl_v3 }} \ --os-project-name={{ heat_project_name }} \ --os-project-domain-name={{ heat_project_domain_name }} \ @@ -72,13 +73,16 @@ - heat-domain - heat-domain-setup - heat-config + - heat-command-bin + # TODO Change the keystone library to support adding # a role to a user without specifying a project - name: Assign admin role to heat domain admin user shell: | . {{ ansible_env.HOME }}/openrc - openstack --os-identity-api-version=3 \ + {{ heat_bin }}/openstack \ + --os-identity-api-version=3 \ --os-auth-url={{ keystone_service_adminurl_v3 }} \ --os-project-name={{ heat_project_name }} \ --os-project-domain-name={{ heat_project_domain_name }} \ @@ -92,3 +96,4 @@ - heat-domain - heat-domain-setup - heat-config + - heat-command-bin diff --git a/playbooks/roles/os_heat/tasks/heat_install.yml b/playbooks/roles/os_heat/tasks/heat_install.yml index 9302cfc014..4b0157ec7b 100644 --- a/playbooks/roles/os_heat/tasks/heat_install.yml +++ b/playbooks/roles/os_heat/tasks/heat_install.yml @@ -34,9 +34,43 @@ delay: 2 with_items: heat_apt_packages tags: + - heat-install - heat-apt-packages -- name: Install pip 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: + - "{{ heat_requires_pip_packages }}" + tags: + - heat-install + - heat-pip-packages + +- name: Install pip packages (venv) + pip: + name: "{{ item }}" + state: present + virtualenv: "{{ heat_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: + - "{{ heat_pip_packages }}" + when: heat_venv_enabled | bool + tags: + - heat-install + - heat-pip-packages + +- name: Install pip packages (no venv) pip: name: "{{ item }}" state: present @@ -47,5 +81,7 @@ delay: 2 with_items: - "{{ heat_pip_packages }}" + when: not heat_venv_enabled | bool tags: + - heat-install - heat-pip-packages diff --git a/playbooks/roles/os_heat/tasks/heat_post_install.yml b/playbooks/roles/os_heat/tasks/heat_post_install.yml index f6a80a3e6b..be28be9f91 100644 --- a/playbooks/roles/os_heat/tasks/heat_post_install.yml +++ b/playbooks/roles/os_heat/tasks/heat_post_install.yml @@ -51,3 +51,19 @@ - Restart heat services tags: - heat-config + +- name: Get heat command path + command: which heat + register: heat_command_path + when: + - not heat_venv_enabled | bool + tags: + - heat-command-bin + +- name: Set heat command path + set_fact: + heat_bin: "{{ heat_command_path.stdout | dirname }}" + when: + - not heat_venv_enabled | bool + tags: + - heat-command-bin diff --git a/playbooks/roles/os_heat/tasks/heat_pre_install.yml b/playbooks/roles/os_heat/tasks/heat_pre_install.yml index 3740e35fc6..082bb82c8e 100644 --- a/playbooks/roles/os_heat/tasks/heat_pre_install.yml +++ b/playbooks/roles/os_heat/tasks/heat_pre_install.yml @@ -41,6 +41,7 @@ group: "{{ item.group|default(heat_system_group_name) }}" mode: "{{ item.mode|default('0755') }}" with_items: + - { path: "/openstack", mode: "0755", owner: "root", group: "root" } - { path: "/etc/heat" } - { path: "/etc/heat/environment.d" } - { path: "/etc/heat/templates" } @@ -50,6 +51,19 @@ tags: - heat-dirs +- name: Create heat venv dir + file: + path: "{{ item.path }}" + state: directory + owner: "{{ item.owner|default(heat_system_user_name) }}" + group: "{{ item.group|default(heat_system_group_name) }}" + with_items: + - { path: "/openstack/venvs", mode: "0755", owner: "root", group: "root" } + - { path: "{{ heat_venv_bin }}" } + when: heat_venv_enabled | bool + tags: + - heat-dirs + - name: Create heat plugin dirs file: path: "{{ item }}" diff --git a/playbooks/roles/os_heat/tasks/main.yml b/playbooks/roles/os_heat/tasks/main.yml index 4503c5a757..843feeec8e 100644 --- a/playbooks/roles/os_heat/tasks/main.yml +++ b/playbooks/roles/os_heat/tasks/main.yml @@ -15,13 +15,12 @@ - include: heat_pre_install.yml - include: heat_install.yml +- include: heat_post_install.yml - include: heat_domain_setup.yml when: > inventory_hostname == groups['heat_all'][0] -- include: heat_post_install.yml - - include: heat_db_setup.yml when: > inventory_hostname == groups['heat_all'][0] diff --git a/playbooks/roles/os_heat/templates/heat-upstart-init.j2 b/playbooks/roles/os_heat/templates/heat-upstart-init.j2 index 34fd56230d..a37848ebc5 100644 --- a/playbooks/roles/os_heat/templates/heat-upstart-init.j2 +++ b/playbooks/roles/os_heat/templates/heat-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="{{ heat_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 heat_venv_enabled | bool -%} + . {{ heat_venv_bin }}/activate + {%- endif %} + end script # Post stop actions