From 8bed9cd4b90b34a255c03cbf1b0470025f6bb4d1 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Tue, 29 Sep 2015 21:01:01 -0500 Subject: [PATCH] Implement glance venv support This commit conditionally allows the os_glance 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: If58b1f2ebe15672602effe5c06c85524385562ba Implements: blueprint enable-venv-support-within-the-roles Signed-off-by: Kevin Carter --- playbooks/os-glance-install.yml | 7 ++- playbooks/roles/os_glance/defaults/main.yml | 25 +++++++-- .../roles/os_glance/tasks/glance_db_setup.yml | 3 +- .../roles/os_glance/tasks/glance_install.yml | 36 ++++++++++++- .../os_glance/tasks/glance_post_install.yml | 54 ++++++++++++------- .../os_glance/tasks/glance_pre_install.yml | 12 +++++ .../templates/glance-upstart-init.j2 | 7 ++- 7 files changed, 115 insertions(+), 29 deletions(-) diff --git a/playbooks/os-glance-install.yml b/playbooks/os-glance-install.yml index b6f5aa5701..a214f55500 100644 --- a/playbooks/os-glance-install.yml +++ b/playbooks/os-glance-install.yml @@ -81,7 +81,11 @@ tags: - glance-logs roles: - - { role: "os_glance", tags: [ "os-glance" ] } + - role: "os_glance" + glance_galera_address: "{{ galera_address }}" + glance_venv_tag: "{{ openstack_release }}" + tags: + - "os-glance" - { role: "openstack_openrc", tags: [ "openstack-openrc" ] } - role: "ceph_client" openstack_service_system_user: "{{ glance_system_user_name }}" @@ -100,6 +104,5 @@ - "system-crontab-coordination" vars: galera_address: "{{ internal_lb_vip_address }}" - glance_galera_address: "{{ internal_lb_vip_address }}" ansible_hostname: "{{ container_name }}" is_metal: "{{ properties.is_metal|default(false) }}" diff --git a/playbooks/roles/os_glance/defaults/main.yml b/playbooks/roles/os_glance/defaults/main.yml index c5b6a22c1c..01e125466c 100644 --- a/playbooks/roles/os_glance/defaults/main.yml +++ b/playbooks/roles/os_glance/defaults/main.yml @@ -13,15 +13,25 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Defines that the role will be deployed on a host machine -is_metal: true +## Verbosity Options +debug: False +verbose: True + +# Name of the virtual env to deploy into +glance_venv_tag: untagged +glance_venv_bin: "/openstack/venvs/glance-{{ glance_venv_tag }}/bin" + +# Set this to enable or disable installing in a venv +glance_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. +glance_bin: "{{ glance_venv_bin }}" # Enable/Disable Ceilometer glance_ceilometer_enabled: False -## Verbosity Options -debug: False -verbose: True glance_profiler_enabled: False glance_fatal_deprecations: False @@ -151,6 +161,11 @@ glance_apt_packages: - git - nfs-common +# Cinder packages that must be installed before anything else +glance_requires_pip_packages: + - virtualenv + - python-keystoneclient # Keystoneclient needed to OSA keystone lib + # Common pip packages glance_pip_packages: - glance diff --git a/playbooks/roles/os_glance/tasks/glance_db_setup.yml b/playbooks/roles/os_glance/tasks/glance_db_setup.yml index bf22377305..925a27ad01 100644 --- a/playbooks/roles/os_glance/tasks/glance_db_setup.yml +++ b/playbooks/roles/os_glance/tasks/glance_db_setup.yml @@ -40,9 +40,10 @@ - glance-db-setup - name: Perform a Glance DB sync - command: glance-manage db_sync + command: "{{ glance_bin }}/glance-manage db_sync" sudo: yes sudo_user: "{{ glance_system_user_name }}" tags: - glance-db-sync - glance-setup + - glance-command-bin diff --git a/playbooks/roles/os_glance/tasks/glance_install.yml b/playbooks/roles/os_glance/tasks/glance_install.yml index f67fb86cfc..010bc42f8d 100644 --- a/playbooks/roles/os_glance/tasks/glance_install.yml +++ b/playbooks/roles/os_glance/tasks/glance_install.yml @@ -37,7 +37,40 @@ - glance-install - glance-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: + - "{{ glance_requires_pip_packages }}" + tags: + - glance-install + - glance-pip-packages + +- name: Install pip packages (venv) + pip: + name: "{{ item }}" + state: present + virtualenv: "{{ glance_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: + - "{{ glance_pip_packages }}" + when: glance_venv_enabled | bool + tags: + - glance-install + - glance-pip-packages + +- name: Install pip packages (no venv) pip: name: "{{ item }}" state: present @@ -48,6 +81,7 @@ delay: 2 with_items: - "{{ glance_pip_packages }}" + when: not glance_venv_enabled | bool tags: - glance-install - glance-pip-packages diff --git a/playbooks/roles/os_glance/tasks/glance_post_install.yml b/playbooks/roles/os_glance/tasks/glance_post_install.yml index cc3e262675..62759658f9 100644 --- a/playbooks/roles/os_glance/tasks/glance_post_install.yml +++ b/playbooks/roles/os_glance/tasks/glance_post_install.yml @@ -13,25 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Create glance cache management cron jobs - cron: - name: "{{ item.name }}" - minute: "{{ 59 |random(start=1) }}" - day: "*" - hour: "{{ item.hour }}" - month: "*" - state: present - job: "{{ item.name }}" - user: glance - with_items: - - name: /usr/local/bin/glance-cache-pruner - hour: "*" - - name: /usr/local/bin/glance-cache-cleaner - hour: "*/5" - when: glance_flavor | search("cache") - tags: - - glance-cron - - name: Drop Glance Config(s) config_template: src: "{{ item.src }}" @@ -112,3 +93,38 @@ tags: - glance-nfs - glance-nfs-local-path + +- name: Get glance command path + command: which glance + register: glance_command_path + when: + - not glance_venv_enabled | bool + tags: + - glance-command-bin + +- name: Set glance command path + set_fact: + glance_bin: "{{ glance_command_path.stdout | dirname }}" + when: + - not glance_venv_enabled | bool + tags: + - glance-command-bin + +- name: Create glance cache management cron jobs + cron: + name: "{{ item.name }}" + minute: "{{ 59 |random(start=1) }}" + day: "*" + hour: "{{ item.hour }}" + month: "*" + state: present + job: "{{ item.name }}" + user: glance + with_items: + - name: "{{ glance_bin }}/glance-cache-pruner" + hour: "*" + - name: "{{ glance_bin }}/glance-cache-cleaner" + hour: "*/5" + when: glance_flavor | search("cache") + tags: + - glance-cron diff --git a/playbooks/roles/os_glance/tasks/glance_pre_install.yml b/playbooks/roles/os_glance/tasks/glance_pre_install.yml index 0f8939f139..4686413613 100644 --- a/playbooks/roles/os_glance/tasks/glance_pre_install.yml +++ b/playbooks/roles/os_glance/tasks/glance_pre_install.yml @@ -41,6 +41,7 @@ group: "{{ item.group|default(glance_system_group_name) }}" mode: "{{ item.mode|default('0755') }}" with_items: + - { path: "/openstack", mode: "0755", owner: "root", group: "root" } - { path: "/etc/glance" } - { path: "/etc/sudoers.d", mode: "0755", owner: "root", group: "root" } - { path: "/var/cache/glance" } @@ -52,6 +53,17 @@ tags: - glance-dirs +- name: Create glance venv dir + file: + path: "{{ item.path }}" + state: directory + with_items: + - { path: "/openstack/venvs" } + - { path: "{{ glance_venv_bin }}" } + when: glance_venv_enabled | bool + tags: + - glance-dirs + - name: Test for log directory or link shell: | if [ -h "/var/log/glance" ]; then diff --git a/playbooks/roles/os_glance/templates/glance-upstart-init.j2 b/playbooks/roles/os_glance/templates/glance-upstart-init.j2 index e477426ca5..870ce3fa48 100644 --- a/playbooks/roles/os_glance/templates/glance-upstart-init.j2 +++ b/playbooks/roles/os_glance/templates/glance-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="{{ glance_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 glance_venv_enabled | bool -%} + . {{ glance_venv_bin }}/activate + {%- endif %} + end script # Post stop actions