From cba98483b21c4e35d771977ac9bee25bece73634 Mon Sep 17 00:00:00 2001 From: Lan Qi song Date: Tue, 5 May 2015 16:16:59 +0800 Subject: [PATCH] Add support for cinder-backup service Partially-implements: blueprint chef-cinder-backup Change-Id: I961d8875e35c26efa2ff9e7be0bb576cb8e345fa --- README.md | 17 +++++++ attributes/default.rb | 40 ++++++++++++++++ metadata.rb | 3 +- recipes/backup.rb | 44 +++++++++++++++++ spec/backup-redhat_spec.rb | 48 +++++++++++++++++++ spec/backup-suse_spec.rb | 43 +++++++++++++++++ spec/backup_spec.rb | 80 +++++++++++++++++++++++++++++++ spec/cinder_common_spec.rb | 44 +++++++++++++++++ templates/default/cinder.conf.erb | 75 +++++++++++++++++++++++++++++ 9 files changed, 393 insertions(+), 1 deletion(-) create mode 100644 recipes/backup.rb create mode 100644 spec/backup-redhat_spec.rb create mode 100644 spec/backup-suse_spec.rb create mode 100644 spec/backup_spec.rb diff --git a/README.md b/README.md index 47fa172..d645315 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,23 @@ The following attributes are defined in attributes/default.rb of the common cook * `openstack['endpoints']['block-storage-api-bind']['port']` - The port to bind the api service to * `openstack['endpoints']['block-storage-api-bind']['bind_interface']` - The interface name to bind the api service to +### Backup service attributes ### +* `openstack['block-storage']['backup']['enabled']` - Whether to enable cinder backup service or not. +* `openstack['block-storage']['backup']['driver']` - The driver for cinder backup service. +* `openstack['block-storage']['backup']['swift']['url']` - The URL of Swift endpoint. +* `openstack['block-storage']['backup']['swift']['catalog_info']` - Info to match when looking for swift in the service catalog. +* `openstack['block-storage']['backup']['swift']['auth']` - Swift authentication mechanism. +* `openstack['block-storage']['backup']['swift']['auth_version']` - Swift authentication version. +* `openstack['block-storage']['backup']['swift']['user']` - Swift user name. +* `openstack['block-storage']['backup']['swift']['tenant']` - Swift tenant/account name. Required when connecting. +* `openstack['block-storage']['backup']['swift']['key']` - Swift key for authentication. +* `openstack['block-storage']['backup']['swift']['container']` - The default Swift container to use. +* `openstack['block-storage']['backup']['swift']['object_size']` - The size in bytes of Swift backup objects. +* `openstack['block-storage']['backup']['swift']['block_size']` - The size in bytes that changes are tracked for incremental backups. +* `openstack['block-storage']['backup']['swift']['retry_attempts']` - The number of retries to make for Swift operations. +* `openstack['block-storage']['backup']['swift']['retry_backoff']` - The backoff time in seconds between Swift retries. +* `openstack['block-storage']['backup']['swift']['enable_progress_timer']` - Enable or Disable the timer to send the periodic progress notifications to Ceilometer when backing up the volume to the Swift backend storage. + If the value of the 'bind_interface' attribute is non-nil, then the block-storage service will be bound to the first IP address on that interface. If the value of the 'bind_interface' attribute is nil, then the block-storage service will be bound to the IP address specified in the host attribute. Testing diff --git a/attributes/default.rb b/attributes/default.rb index 348c265..eecb32e 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -63,6 +63,9 @@ default['openstack']['block-storage']['rabbit_server_chef_role'] = 'os-ops-messa # This is the name of the Chef role that will install the Keystone Service API default['openstack']['block-storage']['keystone_service_chef_role'] = 'keystone' +# Whether to enable cinder-backup service or not +default['openstack']['block-storage']['backup']['enabled'] = false + # Keystone PKI signing directory default['openstack']['block-storage']['api']['auth']['cache_dir'] = '/var/cache/cinder/api' @@ -335,6 +338,8 @@ when 'fedora', 'rhel' # :pragma-foodcritic: ~FC024 - won't fix this 'cinder_volume_service' => 'openstack-cinder-volume', 'cinder_scheduler_packages' => [], 'cinder_scheduler_service' => 'openstack-cinder-scheduler', + 'cinder_backup_packages' => [], + 'cinder_backup_service' => 'openstack-cinder-backup', 'cinder_iscsitarget_packages' => ['targetcli'], 'cinder_iscsitarget_service' => 'target', 'cinder_ceph_packages' => ['python-ceph', 'ceph-common'], @@ -356,6 +361,8 @@ when 'suse' 'cinder_client_packages' => ['python-cinderclient'], 'cinder_scheduler_packages' => ['openstack-cinder-scheduler'], 'cinder_scheduler_service' => 'openstack-cinder-scheduler', + 'cinder_backup_packages' => ['openstack-cinder-backup'], + 'cinder_backup_service' => 'openstack-cinder-backup', 'cinder_volume_packages' => ['openstack-cinder-volume', 'qemu-img'], 'cinder_volume_service' => 'openstack-cinder-volume', 'cinder_ceph_packages' => ['python-ceph', 'ceph-common'], @@ -380,6 +387,8 @@ when 'debian' 'cinder_volume_service' => 'cinder-volume', 'cinder_scheduler_packages' => ['cinder-scheduler'], 'cinder_scheduler_service' => 'cinder-scheduler', + 'cinder_backup_packages' => ['cinder-backup'], + 'cinder_backup_service' => 'cinder-backup', 'cinder_ceph_packages' => ['python-ceph', 'ceph-common'], 'cinder_iscsitarget_packages' => ['tgt'], 'cinder_iscsitarget_service' => 'tgt', @@ -391,3 +400,34 @@ when 'debian' 'package_overrides' => "-o Dpkg::Options::='--force-confold' -o Dpkg::Options::='--force-confdef'" } end + +# Attributes for cinder-backup service +default['openstack']['block-storage']['backup']['driver'] = 'cinder.backup.drivers.swift' + +# Swift support +# The URL of Swift endpoint (string value) +default['openstack']['block-storage']['backup']['swift']['url'] = nil +# Info to match when looking for swift in the service catalog +default['openstack']['block-storage']['backup']['swift']['catalog_info'] = 'object-store:swift:publicURL' +# Swift authentication mechanism (string value) +default['openstack']['block-storage']['backup']['swift']['auth'] = 'per_user' +# Swift authentication version +default['openstack']['block-storage']['backup']['swift']['auth_version'] = 1 +# Swift user name +default['openstack']['block-storage']['backup']['swift']['user'] = nil +# Swift tenant/account name. Required when connecting +default['openstack']['block-storage']['backup']['swift']['tenant'] = nil +# Swift key for authentication (string value) +default['openstack']['block-storage']['backup']['swift']['key'] = nil +# The default Swift container to use +default['openstack']['block-storage']['backup']['swift']['container'] = 'volumebackups' +# The size in bytes of Swift backup objects +default['openstack']['block-storage']['backup']['swift']['object_size'] = 52428800 +# The size in bytes that changes are tracked for incremental backups +default['openstack']['block-storage']['backup']['swift']['block_size'] = 32768 +# The number of retries to make for Swift operations +default['openstack']['block-storage']['backup']['swift']['retry_attempts'] = 3 +# The backoff time in seconds between Swift retries +default['openstack']['block-storage']['backup']['swift']['retry_backoff'] = 2 +# Enable or Disable the timer to send the periodic progress notifications to Ceilometer when backing up the volume to the Swift backend storage. +default['openstack']['block-storage']['backup']['swift']['enable_progress_timer'] = 'True' diff --git a/metadata.rb b/metadata.rb index 15e0403..2967135 100644 --- a/metadata.rb +++ b/metadata.rb @@ -5,7 +5,7 @@ maintainer_email 'opscode-chef-openstack@googlegroups.com' license 'Apache 2.0' description 'The OpenStack Advanced Volume Management service Cinder.' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '11.0.0' +version '11.1.0' recipe 'openstack-block-storage::api', 'Installs the cinder-api, sets up the cinder database, and cinder service/user/endpoints in keystone' recipe 'openstack-block-storage::client', 'Install packages required for cinder client' @@ -13,6 +13,7 @@ recipe 'openstack-block-storage::common', 'Defines the common pieces o recipe 'openstack-block-storage::keystone_registration', 'Registers cinder service/user/endpoints in keystone' recipe 'openstack-block-storage::scheduler', 'Installs the cinder-scheduler service' recipe 'openstack-block-storage::volume', 'Installs the cinder-volume service and sets up the iscsi helper' +recipe 'openstack-block-storage::backup', 'Installs the cinder-backup service' %w{ ubuntu fedora redhat centos suse }.each do |os| supports os diff --git a/recipes/backup.rb b/recipes/backup.rb new file mode 100644 index 0000000..2206580 --- /dev/null +++ b/recipes/backup.rb @@ -0,0 +1,44 @@ +# encoding: UTF-8 +# +# Cookbook Name:: openstack-block-storage +# Recipe:: backup +# +# 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. +# + +return unless node['openstack']['block-storage']['backup']['enabled'] + +include_recipe 'openstack-block-storage::cinder-common' + +platform_options = node['openstack']['block-storage']['platform'] + +platform_options['cinder_backup_packages'].each do |pkg| + package pkg do + options platform_options['package_overrides'] + action :upgrade + end +end + +db_type = node['openstack']['db']['block-storage']['service_type'] +node['openstack']['db']['python_packages'][db_type].each do |pkg| + package pkg do + action :upgrade + end +end + +service 'cinder-backup' do + service_name platform_options['cinder_backup_service'] + supports status: true, restart: true + action [:enable, :start] + subscribes :restart, 'template[/etc/cinder/cinder.conf]' +end diff --git a/spec/backup-redhat_spec.rb b/spec/backup-redhat_spec.rb new file mode 100644 index 0000000..de27e26 --- /dev/null +++ b/spec/backup-redhat_spec.rb @@ -0,0 +1,48 @@ +# encoding: UTF-8 +# +# Cookbook Name:: openstack-block-storage + +require_relative 'spec_helper' + +describe 'openstack-block-storage::backup' do + describe 'redhat' do + let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) } + let(:node) { runner.node } + let(:chef_run) { runner.converge(described_recipe) } + + include_context 'block-storage-stubs' + + describe 'enable cinder backup service' do + before do + node.set['openstack']['block-storage']['backup']['enabled'] = true + end + + it 'starts cinder backup' do + expect(chef_run).to start_service 'openstack-cinder-backup' + end + + it 'starts cinder backup on boot' do + expect(chef_run).to enable_service 'openstack-cinder-backup' + end + + it 'upgrades mysql python package' do + expect(chef_run).to upgrade_package 'MySQL-python' + end + + it 'upgrades db2 python packages if explicitly told' do + node.set['openstack']['db']['block-storage']['service_type'] = 'db2' + + ['python-ibm-db', 'python-ibm-db-sa'].each do |pkg| + expect(chef_run).to upgrade_package pkg + end + end + + it 'upgrades postgresql python packages if explicitly told' do + node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql' + + expect(chef_run).to upgrade_package 'python-psycopg2' + expect(chef_run).not_to upgrade_package 'MySQL-python' + end + end + end +end diff --git a/spec/backup-suse_spec.rb b/spec/backup-suse_spec.rb new file mode 100644 index 0000000..8ee21c4 --- /dev/null +++ b/spec/backup-suse_spec.rb @@ -0,0 +1,43 @@ +# encoding: UTF-8 +# +# Cookbook Name:: openstack-block-storage + +require_relative 'spec_helper' + +describe 'openstack-block-storage::backup' do + describe 'suse' do + let(:runner) { ChefSpec::SoloRunner.new(SUSE_OPTS) } + let(:node) { runner.node } + let(:chef_run) { runner.converge(described_recipe) } + + include_context 'block-storage-stubs' + + describe 'enable cinder backup service' do + before do + node.set['openstack']['block-storage']['backup']['enabled'] = true + end + it 'upgrades cinder backup package' do + expect(chef_run).to upgrade_package 'openstack-cinder-backup' + end + + it 'starts cinder backup' do + expect(chef_run).to start_service 'openstack-cinder-backup' + end + + it 'starts cinder backup on boot' do + expect(chef_run).to enable_service 'openstack-cinder-backup' + end + + it 'upgrades mysql python package' do + expect(chef_run).to upgrade_package 'python-mysql' + end + + it 'upgrades postgresql python packages if explicitly told' do + node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql' + + expect(chef_run).to upgrade_package 'python-psycopg2' + expect(chef_run).not_to upgrade_package 'python-mysql' + end + end + end +end diff --git a/spec/backup_spec.rb b/spec/backup_spec.rb new file mode 100644 index 0000000..0dffd0f --- /dev/null +++ b/spec/backup_spec.rb @@ -0,0 +1,80 @@ +# encoding: UTF-8 +# +# Cookbook Name:: openstack-block-storage + +require_relative 'spec_helper' + +describe 'openstack-block-storage::backup' do + describe 'ubuntu' do + let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) } + let(:node) { runner.node } + let(:chef_run) { runner.converge(described_recipe) } + + include_context 'block-storage-stubs' + + describe 'enable cinder backup service' do + before do + node.set['openstack']['block-storage']['backup']['enabled'] = true + end + it 'upgrades cinder backup package' do + expect(chef_run).to upgrade_package 'cinder-backup' + end + + it 'starts cinder backup' do + expect(chef_run).to start_service 'cinder-backup' + end + + it 'starts cinder backup on boot' do + expect(chef_run).to enable_service 'cinder-backup' + end + + it 'subscribes to the template change' do + expect(chef_run.service('cinder-backup')).to subscribe_to('template[/etc/cinder/cinder.conf]') + end + + it 'upgrades mysql python package' do + expect(chef_run).to upgrade_package 'python-mysqldb' + end + + it 'upgrades postgresql python packages if explicitly told' do + node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql' + + expect(chef_run).to upgrade_package 'python-psycopg2' + expect(chef_run).not_to upgrade_package 'python-mysqldb' + end + end + + describe 'disable cinder backup service' do + before do + node.set['openstack']['block-storage']['backup']['enabled'] = false + end + it 'not to upgrades cinder backup package' do + expect(chef_run).not_to upgrade_package 'cinder-backup' + end + + it 'not to starts cinder backup' do + expect(chef_run).not_to start_service 'cinder-backup' + end + + it 'not to starts cinder backup on boot' do + expect(chef_run).not_to enable_service 'cinder-backup' + end + + it 'not to subscribes to the template change' do + expect(chef_run.service('cinder-backup')).not_to subscribe_to('template[/etc/cinder/cinder.conf]') + end + + it 'not to upgrades mysql python package' do + expect(chef_run).not_to upgrade_package 'python-mysqldb' + end + + it 'not to upgrades postgresql python packages if explicitly told' do + node.set['openstack']['db']['block-storage']['service_type'] = 'postgresql' + + expect(chef_run).not_to upgrade_package 'python-psycopg2' + expect(chef_run).not_to upgrade_package 'python-mysqldb' + end + end + + end +end diff --git a/spec/cinder_common_spec.rb b/spec/cinder_common_spec.rb index 8ed5454..385c80c 100644 --- a/spec/cinder_common_spec.rb +++ b/spec/cinder_common_spec.rb @@ -180,6 +180,50 @@ describe 'openstack-block-storage::cinder-common' do end end + context 'backup swift backend contents' do + before do + node.set['openstack']['block-storage']['backup']['enabled'] = true + node.set['openstack']['block-storage']['backup']['driver'] = 'cinder.backup.drivers.swift' + end + + it 'has default attributes' do + %w(swift_catalog_info=object-store:swift:publicURL + backup_swift_auth=per_user + backup_swift_auth_version=1 + backup_swift_container=volumebackups + backup_swift_object_size=52428800 + backup_swift_block_size=32768 + backup_swift_retry_attempts=3 + backup_swift_retry_backoff=2 + backup_swift_enable_progress_timer=True).each do |attr| + expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', /^#{attr}$/) + end + end + + it 'has override attributes' do + %w(url + auth + auth_version + tenant + user + key + container + object_size + block_size + retry_attempts + retry_backoff + enable_progress_timer).each do |attr| + node.set['openstack']['block-storage']['backup']['swift'][attr] = "backup_swift_#{attr}" + expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', /^backup_swift_#{attr}=backup_swift_#{attr}$/) + end + end + + it 'has a custom catalog_info' do + node.set['openstack']['block-storage']['backup']['swift']['catalog_info'] = 'swift_catalog_info' + expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', /^swift_catalog_info=swift_catalog_info$/) + end + end + context 'rdb driver' do # FIXME(galstrom21): this block needs to check all of the default # rdb_* configuration options diff --git a/templates/default/cinder.conf.erb b/templates/default/cinder.conf.erb index 7c5af29..e64fd30 100644 --- a/templates/default/cinder.conf.erb +++ b/templates/default/cinder.conf.erb @@ -269,6 +269,81 @@ osapi_volume_workers=<%= node["openstack"]["block-storage"]["osapi_volume_worker #### (BoolOpt) make deprecations fatal +######## defined in cinder.backup.manager ######## +<% if node['openstack']['block-storage']['backup']['enabled'] %> +backup_driver=<%= node['openstack']['block-storage']['backup']['driver'] %> +<% if node['openstack']['block-storage']['backup']['driver'] == 'cinder.backup.drivers.swift' %> +######## defined in cinder.backup.driver.swift ######## +# The URL of the Swift endpoint (string value) +<% if node['openstack']['block-storage']['backup']['swift']['url'] %> +backup_swift_url=<%= node['openstack']['block-storage']['backup']['swift']['url'] %> +<% else %> +# backup_swift_url= +<% end %> + +# Info to match when looking for swift in the service catalog. +# Format is: separated values of the form: +# :: - Only used if +# backup_swift_url is unset (string value) +swift_catalog_info=<%= node['openstack']['block-storage']['backup']['swift']['catalog_info'] %> + +# Swift authentication mechanism (string value) +backup_swift_auth=<%= node['openstack']['block-storage']['backup']['swift']['auth'] %> + +# Swift authentication version. Specify "1" for auth 1.0, or +# "2" for auth 2.0 (string value) +backup_swift_auth_version=<%= node['openstack']['block-storage']['backup']['swift']['auth_version'] %> + +# Swift tenant/account name. Required when connecting to an +# auth 2.0 system (string value) +<% if node['openstack']['block-storage']['backup']['swift']['tenant'] %> +backup_swift_tenant=<%= node['openstack']['block-storage']['backup']['swift']['tenant'] %> +<% else %> +# backup_swift_tenant= +<% end %> + +# Swift user name (string value) +<% if node['openstack']['block-storage']['backup']['swift']['user'] %> +backup_swift_user=<%= node['openstack']['block-storage']['backup']['swift']['user'] %> +<% else %> +# backup_swift_user= +<% end %> + +# Swift key for authentication (string value) +<% if node['openstack']['block-storage']['backup']['swift']['key'] %> +backup_swift_key=<%= node['openstack']['block-storage']['backup']['swift']['key'] %> +<% else %> +# backup_swift_key= +<% end %> + +# The default Swift container to use (string value) +backup_swift_container=<%= node['openstack']['block-storage']['backup']['swift']['container'] %> + +# The size in bytes of Swift backup objects (integer value) +backup_swift_object_size=<%= node['openstack']['block-storage']['backup']['swift']['object_size'] %> + +# The size in bytes that changes are tracked for incremental +# backups. backup_swift_object_size has to be multiple of +# backup_swift_block_size. (integer value) +backup_swift_block_size=<%= node['openstack']['block-storage']['backup']['swift']['block_size'] %> + +# The number of retries to make for Swift operations (integer +# value) +backup_swift_retry_attempts=<%= node['openstack']['block-storage']['backup']['swift']['retry_attempts'] %> + +# The backoff time in seconds between Swift retries (integer +# value) +backup_swift_retry_backoff=<%= node['openstack']['block-storage']['backup']['swift']['retry_backoff'] %> + +# Enable or Disable the timer to send the periodic progress +# notifications to Ceilometer when backing up the volume to +# the Swift backend storage. The default value is True to +# enable the timer. (boolean value) +backup_swift_enable_progress_timer=<%= node['openstack']['block-storage']['backup']['swift']['enable_progress_timer'] %> + +<% end %> +<% end %> + ######## defined in cinder.db.api ######## # enable_new_services=true