Implement swift venv support

This commit conditionally allows the os_swift role to
install build and deploy within a venv. This is the new
default behavior of the role however the functionality
can be disabled.

In this PR, like all of the other venv related PRs, the 
`is_metal` flag was removed from the role however unlike 
some of the other PRs this removal required moving some 
of the `is_metal` logic out of the role and into the 
play. This was done for consistency as well as making 
the role more standalone. The only thing that the role 
should care about, in terms of installation, is whether 
or not to install in a venv.

Change-Id: I6f5b883a853611659567bd12e8bcf572189854b7
Implements: blueprint enable-venv-support-within-the-roles
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
Kevin Carter 2015-10-03 01:33:27 -05:00
parent 611958e01e
commit b08b2ea889
19 changed files with 257 additions and 46 deletions

View File

@ -68,8 +68,73 @@
when: is_metal | bool
tags:
- swift-logs
- name: Set swift storage bridge (is_metal)
set_fact:
storage_bridge: "{{ 'ansible_' + swift.storage_network | replace('-', '_') }}"
when:
- swift.storage_network is defined
- is_metal | bool
- name: Set swift storage address (is_metal)
set_fact:
storage_address: "{{ hostvars[inventory_hostname][storage_bridge]['ipv4']['address'] }}"
when:
- swift.storage_network is defined
- is_metal | bool
- name: Set swift storage address (is_metal no storage network)
set_fact:
storage_address: "{{ ansible_ssh_host }}"
when:
- swift.storage_network is undefined
- is_metal | bool
- name: Set swift storage address (container)
set_fact:
storage_address: "{{ hostvars[inventory_hostname]['container_networks']['storage_address']['address'] }}"
when:
- hostvars[inventory_hostname]['container_networks']['storage_address']['address'] is defined
- not is_metal | bool
- name: Set swift storage address (container no storage network)
set_fact:
storage_address: "{{ ansible_ssh_host }}"
when:
- hostvars[inventory_hostname]['container_networks']['storage_address']['address'] is undefined
- not is_metal | bool
- name: Set swift replication bridge (is_metal)
set_fact:
replication_bridge: "{{ 'ansible_' + swift.replication_network | replace('-', '_') }}"
when:
- swift.replication_network is defined
- is_metal | bool
- name: Set swift replication address (is_metal)
set_fact:
replication_address: "{{ hostvars[inventory_hostname][replication_bridge]['ipv4']['address'] }}"
when:
- swift.replication_network is defined
- is_metal | bool
- name: Set swift replication address (is_metal no replication network)
set_fact:
replication_address: "{{ storage_address }}"
when:
- swift.replication_network is undefined
- is_metal | bool
- name: Set swift replication address (container)
set_fact:
replication_address: "{{ hostvars[inventory_hostname]['container_networks']['replication_address']['address'] }}"
when:
- hostvars[inventory_hostname]['container_networks']['replication_address']['address'] is defined
- not is_metal | bool
- name: Set swift replication address (container no replication network)
set_fact:
replication_address: "{{ storage_address }}"
when:
- hostvars[inventory_hostname]['container_networks']['replication_address']['address'] is undefined
- not is_metal | bool
roles:
- { role: "os_swift", tags: [ "os-swift" ] }
- role: "os_swift"
swift_venv_tag: "{{ openstack_release }}"
swift_storage_address: "{{ storage_address }}"
swift_replication_address: "{{ replication_address }}"
tags:
- "os-swift"
- role: "rsyslog_client"
rsyslog_client_log_rotate_file: swift_log_rotate
rsyslog_client_log_dir: "/var/log/swift"

View File

@ -20,7 +20,10 @@
max_fail_percentage: 20
user: root
roles:
- { role: "os_swift_sync", tags: [ "os-swift-sync" ] }
- role: "os_swift_sync"
swift_venv_tag: "{{ openstack_release }}"
tags:
- "os-swift-sync"
vars:
ansible_hostname: "{{ container_name }}"
ansible_ssh_host: "{{ container_address }}"

View File

@ -13,9 +13,6 @@
# 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
# Enable/Disable Ceilometer
swift_ceilometer_enabled: False
@ -23,6 +20,22 @@ swift_ceilometer_enabled: False
debug: False
verbose: True
# Name of the virtual env to deploy into
swift_venv_tag: untagged
swift_venv_bin: "/openstack/venvs/swift-{{ swift_venv_tag }}/bin"
# Set this to enable or disable installing in a venv
swift_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.
swift_bin: "{{ swift_venv_bin }}"
# Set the full path to the swift recon cron
recon_cron_path: "{{ swift_bin }}/swift-recon-cron"
## Swift User / Group
swift_system_user_name: swift
swift_system_group_name: swift
@ -138,6 +151,34 @@ swift_proxy_server_program_config_options: /etc/swift/proxy-server/proxy-server.
# of available VCPUS to compute the number of api workers to use.
# swift_proxy_server_workers: 16
# This is the storage addressed used to define the network for swift replication
swift_storage_address: 127.0.0.1
swift_replication_address: 127.0.0.1
# Basic swift configuration for the cluster
swift: {}
# Example basic swift configuration for the cluster
# swift:
# part_power: 8
# storage_network: 'br-storage'
# replication_network: 'br-storage'
# drives:
# - name: swift1.img
# - name: swift2.img
# - name: swift3.img
# mount_point: /srv
# storage_policies:
# - policy:
# name: default
# index: 0
# default: True
# swift packages that must be installed before anything else
swift_requires_pip_packages:
- virtualenv
- python-keystoneclient # Keystoneclient needed to OSA keystone lib
swift_pip_packages:
- ceilometermiddleware
- dnspython

View File

@ -37,7 +37,40 @@
- swift-install
- swift-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:
- "{{ swift_requires_pip_packages }}"
tags:
- swift-install
- swift-pip-packages
- name: Install pip packages (venv)
pip:
name: "{{ item }}"
state: present
virtualenv: "{{ swift_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:
- "{{ swift_pip_packages }}"
when: swift_venv_enabled | bool
tags:
- swift-install
- swift-pip-packages
- name: Install pip packages (no venv)
pip:
name: "{{ item }}"
state: present
@ -48,6 +81,7 @@
delay: 2
with_items:
- "{{ swift_pip_packages }}"
when: not swift_venv_enabled | bool
tags:
- swift-install
- swift-pip-packages

View File

@ -56,3 +56,19 @@
tags:
- swift-config
- swift-post-install
- name: Get swift command path
command: which swift
register: swift_command_path
when:
- not swift_venv_enabled | bool
tags:
- swift-command-bin
- name: Set swift command path
set_fact:
swift_bin: "{{ swift_command_path.stdout | dirname }}"
when:
- not swift_venv_enabled | bool
tags:
- swift-command-bin

View File

@ -55,7 +55,9 @@
state: directory
owner: "{{ item.owner|default(swift_system_user_name) }}"
group: "{{ item.group|default(swift_system_group_name) }}"
mode: "{{ item.mode|default('0755') }}"
with_items:
- { path: "/openstack", owner: "root", group: "root" }
- { path: "/etc/sudoers.d", mode: "0750", owner: "root", group: "root" }
- { path: "/etc/swift" }
- { path: "/etc/swift/account-server" }
@ -71,6 +73,17 @@
tags:
- swift-dirs
- name: Create swift venv dir
file:
path: "{{ item.path }}"
state: directory
with_items:
- { path: "/openstack/venvs" }
- { path: "{{ swift_venv_bin }}" }
when: swift_venv_enabled | bool
tags:
- swift-dirs
- name: Test for log directory or link
shell: |
if [ -h "/var/log/swift" ]; then

View File

@ -47,17 +47,12 @@
regexp: "^RSYNC_ENABLE*"
notify: ["Ensure rsync service stopped", "Ensure rsync service running"]
# We need the location of swift-recon-cron
- name: "Get location of swift-recon-cron"
shell: which swift-recon-cron
register: recon_cron_path
- name: "Setup swift-recon-cron cron job"
cron:
name: "swift-recon-cron run"
minute: "*/5"
user: "swift"
job: "{{ recon_cron_path.stdout }} /etc/swift/object-server/object-server.conf"
job: "{{ recon_cron_path }} /etc/swift/object-server/object-server.conf"
cron_file: "swift_recon_cron"
- name: "Set ownership on mounted drives"

View File

@ -3,13 +3,8 @@
{% set _api_threads = ansible_processor_vcpus|default(2) // 2 %}
{% set api_threads = _api_threads if _api_threads > 0 else 1 %}
{% if is_metal == true or is_metal == "True" and swift.storage_network is defined %}
{% set storage_bridge = 'ansible_' + swift.storage_network|replace('-', '_') %}
{% set swift_storage_address = hostvars[inventory_hostname][storage_bridge]['ipv4']['address'] %}
{% endif %}
[DEFAULT]
bind_ip = {{ swift_storage_address | default(ansible_ssh_host) }}
bind_ip = {{ swift_storage_address }}
bind_port = {{ swift_account_port }}
workers = {{ swift_account_server_workers | default(api_threads) }}

View File

@ -3,13 +3,8 @@
{% set _api_threads = ansible_processor_vcpus|default(2) // 2 %}
{% set api_threads = _api_threads if _api_threads > 0 else 1 %}
{% if is_metal == true or is_metal == "True" and swift.storage_network is defined %}
{% set storage_bridge = 'ansible_' + swift.storage_network|replace('-', '_') %}
{% set swift_storage_address = hostvars[inventory_hostname][storage_bridge]['ipv4']['address'] %}
{% endif %}
[DEFAULT]
bind_ip = {{ swift_storage_address | default(ansible_ssh_host) }}
bind_ip = {{ swift_storage_address }}
bind_port = {{ swift_container_port }}
workers = {{ swift_container_server_workers | default(api_threads) }}

View File

@ -3,13 +3,8 @@
{% set _api_threads = ansible_processor_vcpus|default(2) // 2 %}
{% set api_threads = _api_threads if _api_threads > 0 else 1 %}
{% if is_metal == true or is_metal == "True" and swift.storage_network is defined %}
{% set storage_bridge = 'ansible_' + swift.storage_network|replace('-', '_') %}
{% set swift_storage_address = hostvars[inventory_hostname][storage_bridge]['ipv4']['address'] %}
{% endif %}
[DEFAULT]
bind_ip = {{ swift_storage_address | default(ansible_ssh_host) }}
bind_ip = {{ swift_storage_address }}
bind_port = {{ swift_object_port }}
workers = {{ swift_object_server_workers | default(api_threads) }}

View File

@ -1,19 +1,10 @@
# {{ ansible_managed }}
{% if is_metal == true or is_metal == "True" and swift.replication_network is defined %}
{% set repl_bridge = 'ansible_' + swift.replication_network|replace('-', '_') %}
{% set bind_ip = hostvars[inventory_hostname][repl_bridge]['ipv4']['address'] %}
{% elif is_metal == true or is_metal == "True" and swift.storage_network is defined %}
{% set storage_bridge = 'ansible_' + swift.storage_network|replace('-', '_') %}
{% set bind_ip = hostvars[inventory_hostname][storage_bridge]['ipv4']['address'] %}
{% endif %}
uid = {{ swift_system_user_name }}
gid = {{ swift_system_group_name }}
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
address = {{ bind_ip | default(ansible_ssh_host) }}
address = {{ swift_replication_address }}
[account]
max connections = 2

View File

@ -14,7 +14,7 @@ respawn
respawn limit 10 5
# Set the RUNBIN environment variable
env RUNBIN="/usr/local/bin/{{ program_binary | default(program_name) }}"
env RUNBIN="{{ swift_bin }}/{{ program_binary | default(program_name) }}"
# Change directory to service users home
chdir "{{ service_home }}"
@ -26,6 +26,11 @@ pre-start script
mkdir -p "/var/lock/{{ program_binary | default(program_name) }}"
chown {{ system_user }}:{{ system_group }} "/var/lock/{{ program_binary | default(program_name) }}"
{% if swift_venv_enabled | bool -%}
. {{ swift_venv_bin }}/activate
{%- endif %}
end script
# Post stop actions

View File

@ -13,6 +13,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Name of the virtual env to deploy into
swift_venv_tag: untagged
swift_venv_bin: "/openstack/venvs/swift-{{ swift_venv_tag }}/bin"
# Set this to enable or disable installing in a venv
swift_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.
swift_bin: "{{ swift_venv_bin }}"
# Set the managed regions as a list of swift regions to manage
# Use for global clusters, default when not set is all regions.
# swift_managed_regions:

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
- include: swift_command_check.yml
- include: swift_key_setup.yml
tags:
- swift-key

View File

@ -0,0 +1,30 @@
---
# Copyright 2015, Rackspace US, Inc.
#
# 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: Get swift command path
command: which swift
register: swift_command_path
when:
- not swift_venv_enabled | bool
tags:
- swift-command-bin
- name: Set swift command path
set_fact:
swift_bin: "{{ swift_command_path.stdout | dirname }}"
when:
- not swift_venv_enabled | bool
tags:
- swift-command-bin

View File

@ -14,8 +14,8 @@
# limitations under the License.
- name: "Copy the swift_rings.py file"
copy:
src: swift_rings.py
template:
src: swift_rings.py.j2
dest: "/etc/swift/scripts/swift_rings.py"
owner: "{{ swift_system_user_name }}"
group: "{{ swift_system_group_name }}"

View File

@ -33,8 +33,8 @@
- swift-ring-check
- name: "Copy the swift_rings_check.py file"
copy:
src: swift_rings_check.py
template:
src: swift_rings_check.py.j2
dest: "/etc/swift/scripts/swift_rings_check.py"
owner: "{{ swift_system_user_name }}"
group: "{{ swift_system_group_name }}"

View File

@ -16,6 +16,16 @@
from __future__ import print_function
from optparse import OptionParser
from os.path import exists
import os
{% if swift_venv_enabled | bool %}
activate_this = os.path.expanduser("{{ swift_venv_bin }}/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
{% endif %}
from swift.cli.ringbuilder import main as rb_main
import json

View File

@ -17,6 +17,15 @@ from __future__ import print_function
from optparse import OptionParser
from os.path import exists
import os
{% if swift_venv_enabled | bool %}
activate_this = os.path.expanduser("{{ swift_venv_bin }}/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
{% endif %}
import json
import pickle
import sys