From 2c6e685768ff23a92350c2cc999c3b7d48914464 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Fri, 6 Oct 2023 12:30:55 +0900 Subject: [PATCH] Add support for share backup/restore options This introduces support for options used by share backup and restore feature, which was introduced to manila recently. This also adds support for NFS share backup driver. Change-Id: Idf187458b62e81999874f9582f932d9707c0d8c1 --- manifests/data.pp | 56 ++++++++++++++++--- manifests/data/backup/nfs.pp | 55 ++++++++++++++++++ manifests/share.pp | 12 ++++ ...share-backup-options-0efb0648029cb19a.yaml | 8 +++ spec/classes/manila_data_backup_nfs_spec.rb | 56 +++++++++++++++++++ spec/classes/manila_data_spec.rb | 37 ++++++++++-- spec/classes/manila_share_spec.rb | 6 ++ 7 files changed, 217 insertions(+), 13 deletions(-) create mode 100644 manifests/data/backup/nfs.pp create mode 100644 releasenotes/notes/share-backup-options-0efb0648029cb19a.yaml create mode 100644 spec/classes/manila_data_backup_nfs_spec.rb diff --git a/manifests/data.pp b/manifests/data.pp index f838e979..27b18022 100644 --- a/manifests/data.pp +++ b/manifests/data.pp @@ -20,17 +20,52 @@ # (Optional) Temporary path to create and mount shares during migration. # Defaults to $facts['os_service_default']. # +# [*backup_mount_tmp_location*] +# (Optional) Temporary path to create and mount shares during share backup. +# Defaults to $facts['os_service_default']. +# # [*check_hash*] # (Optional) Chooses whether hash of each file should be checked on data # copying. # Defaults to $facts['os_service_default']. # +# [*backup_continue_update_interval*] +# (Optional) Interval to poll to perform the next steps of backup. +# Defaults to $facts['os_service_default']. +# +# [*restore_continue_update_interval*] +# (Optional) Interval to poll to perform the next steps of restore. +# Defaults to $facts['os_service_default']. +# +# [*backup_driver*] +# (Optional) Driver to use for backups +# Defaults to $facts['os_service_default']. +# +# [*backup_share_mount_template*] +# (Optional) The template for mounting shares during backup. +# Defaults to $facts['os_service_default']. +# +# [*backup_share_unmount_template*] +# (Optional) The template for unmounting shares during backup. +# Defaults to $facts['os_service_default']. +# +# [*backup_ignore_files*] +# (Optional) List of files and folders to be ignored when backing up shares. +# Defaults to $facts['os_service_default']. +# class manila::data ( - $package_ensure = 'present', - Boolean $enabled = true, - Boolean $manage_service = true, - $mount_tmp_location = $facts['os_service_default'], - $check_hash = $facts['os_service_default'], + $package_ensure = 'present', + Boolean $enabled = true, + Boolean $manage_service = true, + $mount_tmp_location = $facts['os_service_default'], + $backup_mount_tmp_location = $facts['os_service_default'], + $check_hash = $facts['os_service_default'], + $backup_continue_update_interval = $facts['os_service_default'], + $restore_continue_update_interval = $facts['os_service_default'], + $backup_driver = $facts['os_service_default'], + $backup_share_mount_template = $facts['os_service_default'], + $backup_share_unmount_template = $facts['os_service_default'], + $backup_ignore_files = $facts['os_service_default'], ) { include manila::deps @@ -45,8 +80,15 @@ class manila::data ( } manila_config { - 'DEFAULT/mount_tmp_location': value => $mount_tmp_location; - 'DEFAULT/check_hash': value => $check_hash; + 'DEFAULT/mount_tmp_location': value => $mount_tmp_location; + 'DEFAULT/backup_mount_tmp_location': value => $backup_mount_tmp_location; + 'DEFAULT/check_hash': value => $check_hash; + 'DEFAULT/backup_continue_update_interval': value => $backup_continue_update_interval; + 'DEFAULT/restore_continue_update_interval': value => $restore_continue_update_interval; + 'DEFAULT/backup_driver': value => $backup_driver; + 'DEFAULT/backup_share_mount_template': value => $backup_share_mount_template; + 'DEFAULT/backup_share_unmount_template': value => $backup_share_unmount_template; + 'DEFAULT/backup_ignore_files': value => join(any2array($backup_ignore_files), ','); } if $manage_service { diff --git a/manifests/data/backup/nfs.pp b/manifests/data/backup/nfs.pp new file mode 100644 index 00000000..1fa66ea8 --- /dev/null +++ b/manifests/data/backup/nfs.pp @@ -0,0 +1,55 @@ +# == Class: manila::data::backup::nfs +# +# Setup Manila to backup shares into NFS +# +# === Parameters +# +# [*backup_mount_export*] +# (Required) NFS backup export location. +# Defaults to $facts['os_service_default'] +# +# [*backup_mount_template*] +# (Optional) The template for mounting NFS shares. +# Defaults to $facts['os_service_default'] +# +# [*backup_unmount_template*] +# (Optional) The template for unmounting NFS shares. +# Defaults to $facts['os_service_default'] +# +# [*backup_mount_proto*] +# (Optional) Mount Protocol for mounting NFS shares. +# Defaults to $facts['os_service_default'] +# +# [*backup_mount_options*] +# (Optional) Mount ptions passed to the NFS client. +# Defaults to $facts['os_service_default'] +# +# [*package_ensure*] +# (optional) Ensure state for package. Defaults to 'present'. +# +class manila::data::backup::nfs ( + String[1] $backup_mount_export, + $backup_mount_template = $facts['os_service_default'], + $backup_unmount_template = $facts['os_service_default'], + $backup_mount_proto = $facts['os_service_default'], + $backup_mount_options = $facts['os_service_default'], + $package_ensure = 'present', +) { + + include manila::deps + include manila::params + + manila_config { + 'DEFAULT/backup_mount_template': value => $backup_mount_template; + 'DEFAULT/backup_unmount_template': value => $backup_unmount_template; + 'DEFAULT/backup_mount_export': value => $backup_mount_export; + 'DEFAULT/backup_mount_proto': value => $backup_mount_proto; + 'DEFAULT/backup_mount_options': value => $backup_mount_options; + } + + ensure_packages('nfs-client', { + name => $::manila::params::nfs_client_package_name, + ensure => $package_ensure, + tag => 'manila-support-package', + }) +} diff --git a/manifests/share.pp b/manifests/share.pp index 220850eb..cce0ba63 100644 --- a/manifests/share.pp +++ b/manifests/share.pp @@ -70,6 +70,14 @@ # roll back share state. # Defaults to $facts['os_service_default']. # +# [*driver_backup_continue_update_interval*] +# (Optional) Interval to poll to perform the next steps of backup. +# Defaults to $facts['os_service_default']. +# +# [*driver_restore_continue_update_interval*] +# (Optional) Interval to poll to perform the next steps of restore. +# Defaults to $facts['os_service_default']. +# class manila::share ( $package_ensure = 'present', Boolean $enabled = true, @@ -86,6 +94,8 @@ class manila::share ( $share_service_inithost_offload = $facts['os_service_default'], $check_for_expired_shares_in_recycle_bin_interval = $facts['os_service_default'], $check_for_expired_transfers = $facts['os_service_default'], + $driver_backup_continue_update_interval = $facts['os_service_default'], + $driver_restore_continue_update_interval = $facts['os_service_default'], ) { include manila::deps @@ -112,6 +122,8 @@ class manila::share ( 'DEFAULT/share_service_inithost_offload': value => $share_service_inithost_offload; 'DEFAULT/check_for_expired_shares_in_recycle_bin_interval': value => $check_for_expired_shares_in_recycle_bin_interval; 'DEFAULT/check_for_expired_transfers': value => $check_for_expired_transfers; + 'DEFAULT/driver_backup_continue_update_interval': value => $driver_backup_continue_update_interval; + 'DEFAULT/driver_restore_continue_update_interval': value => $driver_restore_continue_update_interval; } if $manage_service { diff --git a/releasenotes/notes/share-backup-options-0efb0648029cb19a.yaml b/releasenotes/notes/share-backup-options-0efb0648029cb19a.yaml new file mode 100644 index 00000000..3669bd49 --- /dev/null +++ b/releasenotes/notes/share-backup-options-0efb0648029cb19a.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + The ``manila::share`` class and the ``manila::data`` class now support + options for share backup and restore. + + - | + The new ``manila::data::backup::nfs`` class has been added. diff --git a/spec/classes/manila_data_backup_nfs_spec.rb b/spec/classes/manila_data_backup_nfs_spec.rb new file mode 100644 index 00000000..25ec2774 --- /dev/null +++ b/spec/classes/manila_data_backup_nfs_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe 'manila::data::backup::nfs' do + + shared_examples_for 'manila::data::backup::nfs' do + + let :params do + { + :backup_mount_export => '192.0.2.1:/backup', + } + end + + context 'with default parameters' do + + it 'should configure manila-data options' do + is_expected.to contain_manila_config('DEFAULT/backup_mount_template').with_value('') + is_expected.to contain_manila_config('DEFAULT/backup_unmount_template').with_value('') + is_expected.to contain_manila_config('DEFAULT/backup_mount_export').with_value('192.0.2.1:/backup') + is_expected.to contain_manila_config('DEFAULT/backup_mount_proto').with_value('') + is_expected.to contain_manila_config('DEFAULT/backup_mount_options').with_value('') + end + + end + + context 'with parameters' do + before :each do + params.merge!({ + :backup_mount_template => 'mount -vt %(proto)s %(options)s %(export)s %(path)s', + :backup_unmount_template => 'umount -v %(path)s', + :backup_mount_proto => 'nfs', + :backup_mount_options => '', + }) + end + + it 'should configure manila-data options' do + is_expected.to contain_manila_config('DEFAULT/backup_mount_template').with_value('mount -vt %(proto)s %(options)s %(export)s %(path)s') + is_expected.to contain_manila_config('DEFAULT/backup_unmount_template').with_value('umount -v %(path)s') + is_expected.to contain_manila_config('DEFAULT/backup_mount_proto').with_value('nfs') + is_expected.to contain_manila_config('DEFAULT/backup_mount_options').with_value('') + end + end + end + + on_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 'manila::data::backup::nfs' + end + end + +end diff --git a/spec/classes/manila_data_spec.rb b/spec/classes/manila_data_spec.rb index 429f2f71..33c0d12f 100644 --- a/spec/classes/manila_data_spec.rb +++ b/spec/classes/manila_data_spec.rb @@ -8,8 +8,17 @@ describe 'manila::data' do it { is_expected.to contain_class('manila::params') } - it { is_expected.to contain_manila_config('DEFAULT/mount_tmp_location').with_value('') } - it { is_expected.to contain_manila_config('DEFAULT/check_hash').with_value('') } + it 'should configure manila-data options' do + is_expected.to contain_manila_config('DEFAULT/mount_tmp_location').with_value('') + is_expected.to contain_manila_config('DEFAULT/backup_mount_tmp_location').with_value('') + is_expected.to contain_manila_config('DEFAULT/check_hash').with_value('') + is_expected.to contain_manila_config('DEFAULT/backup_continue_update_interval').with_value('') + is_expected.to contain_manila_config('DEFAULT/restore_continue_update_interval').with_value('') + is_expected.to contain_manila_config('DEFAULT/backup_driver').with_value('') + is_expected.to contain_manila_config('DEFAULT/backup_share_mount_template').with_value('') + is_expected.to contain_manila_config('DEFAULT/backup_share_unmount_template').with_value('') + is_expected.to contain_manila_config('DEFAULT/backup_ignore_files').with_value('') + end it { is_expected.to contain_service('manila-data').with( :name => platform_params[:data_service], @@ -23,13 +32,29 @@ describe 'manila::data' do context 'with parameters' do let :params do { - :mount_tmp_location => '/tmp/', - :check_hash => false, + :mount_tmp_location => '/tmp/', + :backup_mount_tmp_location => '/tmp/backup/', + :check_hash => false, + :backup_continue_update_interval => 10, + :restore_continue_update_interval => 11, + :backup_driver => 'manila.data.drivers.nfs.NFSBackupDriver', + :backup_share_mount_template => 'mount -vt %(proto)s %(options)s %(export)s %(path)s', + :backup_share_unmount_template => 'umount -v %(path)s', + :backup_ignore_files => ['lost+found'], } end - it { is_expected.to contain_manila_config('DEFAULT/mount_tmp_location').with_value('/tmp/') } - it { is_expected.to contain_manila_config('DEFAULT/check_hash').with_value(false) } + it 'should configure manila-data options' do + is_expected.to contain_manila_config('DEFAULT/mount_tmp_location').with_value('/tmp/') + is_expected.to contain_manila_config('DEFAULT/backup_mount_tmp_location').with_value('/tmp/backup/') + is_expected.to contain_manila_config('DEFAULT/check_hash').with_value(false) + is_expected.to contain_manila_config('DEFAULT/backup_continue_update_interval').with_value(10) + is_expected.to contain_manila_config('DEFAULT/restore_continue_update_interval').with_value(11) + is_expected.to contain_manila_config('DEFAULT/backup_driver').with_value('manila.data.drivers.nfs.NFSBackupDriver') + is_expected.to contain_manila_config('DEFAULT/backup_share_mount_template').with_value('mount -vt %(proto)s %(options)s %(export)s %(path)s') + is_expected.to contain_manila_config('DEFAULT/backup_share_unmount_template').with_value('umount -v %(path)s') + is_expected.to contain_manila_config('DEFAULT/backup_ignore_files').with_value('lost+found') + end end context 'with manage_service false' do diff --git a/spec/classes/manila_share_spec.rb b/spec/classes/manila_share_spec.rb index f73fe39d..54d4e4c3 100644 --- a/spec/classes/manila_share_spec.rb +++ b/spec/classes/manila_share_spec.rb @@ -27,6 +27,8 @@ describe 'manila::share' do is_expected.to contain_manila_config('DEFAULT/share_service_inithost_offload').with_value('') is_expected.to contain_manila_config('DEFAULT/check_for_expired_shares_in_recycle_bin_interval').with_value('') is_expected.to contain_manila_config('DEFAULT/check_for_expired_transfers').with_value('') + is_expected.to contain_manila_config('DEFAULT/driver_backup_continue_update_interval').with_value('') + is_expected.to contain_manila_config('DEFAULT/driver_restore_continue_update_interval').with_value('') end end @@ -45,6 +47,8 @@ describe 'manila::share' do :share_service_inithost_offload => false, :check_for_expired_shares_in_recycle_bin_interval => 3600, :check_for_expired_transfers => 300, + :driver_backup_continue_update_interval => 60, + :driver_restore_continue_update_interval => 60, } end @@ -61,6 +65,8 @@ describe 'manila::share' do is_expected.to contain_manila_config('DEFAULT/share_service_inithost_offload').with_value(false) is_expected.to contain_manila_config('DEFAULT/check_for_expired_shares_in_recycle_bin_interval').with_value(3600) is_expected.to contain_manila_config('DEFAULT/check_for_expired_transfers').with_value(300) + is_expected.to contain_manila_config('DEFAULT/driver_backup_continue_update_interval').with_value(60) + is_expected.to contain_manila_config('DEFAULT/driver_restore_continue_update_interval').with_value(60) end end