From 20d3cfe08918d166b7e58322c3e54202584ce041 Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Tue, 9 Apr 2024 14:37:57 +0200 Subject: [PATCH] Stop hardcoding defaults in cinder::backup::ceph ... because they are the default values. Change-Id: Ib635bad5d4a6a18cc8f2be6f4df7e0101b23d4c7 --- manifests/backup/ceph.pp | 39 ++++++++-------- spec/classes/cinder_backup_ceph_spec.rb | 60 +++++++++++-------------- 2 files changed, 44 insertions(+), 55 deletions(-) diff --git a/manifests/backup/ceph.pp b/manifests/backup/ceph.pp index 8d46ee75..fa3f7d27 100644 --- a/manifests/backup/ceph.pp +++ b/manifests/backup/ceph.pp @@ -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 diff --git a/spec/classes/cinder_backup_ceph_spec.rb b/spec/classes/cinder_backup_ceph_spec.rb index 4a9c6780..e4ff3f11 100644 --- a/spec/classes/cinder_backup_ceph_spec.rb +++ b/spec/classes/cinder_backup_ceph_spec.rb @@ -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('') + is_expected.to contain_cinder_config('DEFAULT/backup_ceph_user').with_value('') + is_expected.to contain_cinder_config('DEFAULT/backup_ceph_chunk_size').with_value('') + is_expected.to contain_cinder_config('DEFAULT/backup_ceph_pool').with_value('') + is_expected.to contain_cinder_config('DEFAULT/backup_ceph_stripe_unit').with_value('') + is_expected.to contain_cinder_config('DEFAULT/backup_ceph_stripe_count').with_value('') 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