Stop hardcoding defaults in cinder::backup::ceph

... because they are the default values.

Change-Id: Ib635bad5d4a6a18cc8f2be6f4df7e0101b23d4c7
This commit is contained in:
Tobias Urdin 2024-04-09 14:37:57 +02:00
parent 9a48929ec3
commit 20d3cfe089
2 changed files with 44 additions and 55 deletions

View File

@ -22,49 +22,48 @@
# === Parameters
#
# [*backup_driver*]
# (optional) Which cinder backup driver to use
# (Optional) Which cinder backup driver to use
# Defaults to 'cinder.backup.drivers.ceph.CephBackupDriver'
#
# [*backup_ceph_conf*]
# (optional) Ceph config file to use.
# (Optional) Ceph config file to use.
# Should be a valid ceph configuration file
# Defaults to '/etc/ceph/ceph.conf'
# Defaults to $facts['os_service_default']
#
# [*backup_ceph_user*]
# (optional) The Ceph user to connect with.
# (Optional) The Ceph user to connect with.
# Should be a valid user
# Defaults to 'cinder'
# Defaults to $facts['os_service_default']
#
# [*backup_ceph_chunk_size*]
# (optional) The chunk size in bytes that a backup will be broken into
# (Optional) The chunk size in bytes that a backup will be broken into
# before transfer to backup store.
# Should be a valid integer
# Defaults to '134217728'
# Defaults to $facts['os_service_default']
#
# [*backup_ceph_pool*]
# (optional) The Ceph pool to backup to.
# (Optional) The Ceph pool to backup to.
# Should be a valid ceph pool
# Defaults to 'backups'
# Defaults to $facts['os_service_default']
#
# [*backup_ceph_stripe_unit*]
# (optional) RBD stripe unit to use when creating a backup image.
# (Optional) RBD stripe unit to use when creating a backup image.
# Should be a valid integer
# Defaults to '0'
# Defaults to $facts['os_service_default']
#
# [*backup_ceph_stripe_count*]
# (optional) RBD stripe count to use when creating a backup image.
# (Optional) RBD stripe count to use when creating a backup image.
# Should be a valid integer
# Defaults to '0'
# Defaults to $facts['os_service_default']
#
class cinder::backup::ceph (
$backup_driver = 'cinder.backup.drivers.ceph.CephBackupDriver',
$backup_ceph_conf = '/etc/ceph/ceph.conf',
$backup_ceph_user = 'cinder',
$backup_ceph_chunk_size = '134217728',
$backup_ceph_pool = 'backups',
$backup_ceph_stripe_unit = '0',
$backup_ceph_stripe_count = '0'
$backup_ceph_conf = $facts['os_service_default'],
$backup_ceph_user = $facts['os_service_default'],
$backup_ceph_chunk_size = $facts['os_service_default'],
$backup_ceph_pool = $facts['os_service_default'],
$backup_ceph_stripe_unit = $facts['os_service_default'],
$backup_ceph_stripe_count = $facts['os_service_default'],
) {
include cinder::deps

View File

@ -20,63 +20,53 @@
require 'spec_helper'
describe 'cinder::backup::ceph' do
let :default_params do
{ :backup_ceph_conf => '/etc/ceph/ceph.conf',
:backup_ceph_user => 'cinder',
:backup_ceph_chunk_size => '134217728',
:backup_ceph_pool => 'backups',
:backup_ceph_stripe_unit => '0',
:backup_ceph_stripe_count => '0' }
end
let :params do
{}
end
shared_examples 'cinder backup with ceph' do
let :p do
default_params.merge(params)
end
shared_examples 'cinder::backup::ceph' do
it 'configures cinder.conf' do
is_expected.to contain_cinder_config('DEFAULT/backup_driver').with_value('cinder.backup.drivers.ceph.CephBackupDriver')
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_conf').with_value(p[:backup_ceph_conf])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_user').with_value(p[:backup_ceph_user])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_chunk_size').with_value(p[:backup_ceph_chunk_size])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_pool').with_value(p[:backup_ceph_pool])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_stripe_unit').with_value(p[:backup_ceph_stripe_unit])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_stripe_count').with_value(p[:backup_ceph_stripe_count])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_conf').with_value('<SERVICE DEFAULT>')
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_user').with_value('<SERVICE DEFAULT>')
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_chunk_size').with_value('<SERVICE DEFAULT>')
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_pool').with_value('<SERVICE DEFAULT>')
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_stripe_unit').with_value('<SERVICE DEFAULT>')
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_stripe_count').with_value('<SERVICE DEFAULT>')
end
context 'when overriding default parameters' do
before :each do
params.merge!(:backup_ceph_conf => '/tmp/ceph.conf')
params.merge!(:backup_ceph_user => 'toto')
params.merge!(:backup_ceph_chunk_size => '123')
params.merge!(:backup_ceph_pool => 'foo')
params.merge!(:backup_ceph_stripe_unit => '56')
params.merge!(:backup_ceph_stripe_count => '67')
before do
params.merge!(
:backup_ceph_conf => '/tmp/ceph.conf',
:backup_ceph_user => 'toto',
:backup_ceph_chunk_size => '123',
:backup_ceph_pool => 'foo',
:backup_ceph_stripe_unit => '56',
:backup_ceph_stripe_count => '67'
)
end
it 'should replace default parameters with new values' do
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_conf').with_value(p[:backup_ceph_conf])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_user').with_value(p[:backup_ceph_user])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_chunk_size').with_value(p[:backup_ceph_chunk_size])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_pool').with_value(p[:backup_ceph_pool])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_stripe_unit').with_value(p[:backup_ceph_stripe_unit])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_stripe_count').with_value(p[:backup_ceph_stripe_count])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_conf').with_value(params[:backup_ceph_conf])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_user').with_value(params[:backup_ceph_user])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_chunk_size').with_value(params[:backup_ceph_chunk_size])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_pool').with_value(params[:backup_ceph_pool])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_stripe_unit').with_value(params[:backup_ceph_stripe_unit])
is_expected.to contain_cinder_config('DEFAULT/backup_ceph_stripe_count').with_value(params[:backup_ceph_stripe_count])
end
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge(OSDefaults.get_facts())
end
it_behaves_like 'cinder backup with ceph'
it_behaves_like 'cinder::backup::ceph'
end
end
end