Merge "Support configuring multiple NFS cinder backends"

This commit is contained in:
Zuul 2022-06-07 11:33:24 +00:00 committed by Gerrit Code Review
commit 7f89e98223
5 changed files with 76 additions and 17 deletions

View File

@ -264,7 +264,9 @@ class tripleo::profile::base::cinder::volume (
if $cinder_enable_nfs_backend {
include tripleo::profile::base::cinder::volume::nfs
$cinder_nfs_backend_name = lookup('cinder::backend::nfs::volume_backend_name', undef, undef, 'tripleo_nfs')
$cinder_nfs_backend_name = lookup('tripleo::profile::base::cinder::volume::nfs::backend_name',
undef, undef, lookup('cinder::backend::nfs::volume_backend_name',
undef, undef, 'tripleo_nfs'))
} else {
$cinder_nfs_backend_name = undef
}

View File

@ -22,8 +22,8 @@
# List of NFS shares to mount
#
# [*backend_name*]
# (Optional) Name given to the Cinder backend stanza
# Defaults to lookup('cinder::backend::nfs::volume_backend_name', undef, undef, 'tripleo_nfs')
# (Optional) List of names given to the Cinder backend stanza.
# Defaults to lookup('cinder::backend::nfs::volume_backend_name', undef, undef, ['tripleo_nfs'])
#
# [*backend_availability_zone*]
# (Optional) Availability zone for this volume backend
@ -33,6 +33,10 @@
# (Optional) List of mount options for the NFS share
# Defaults to ''
#
# [*cinder_nfs_shares_config*]
# (Optional) NFS shares configuration file
# Defaults to '/etc/cinder/shares-nfs.conf'
#
# [*cinder_nfs_snapshot_support*]
# (Optional) Whether to enable support for snapshots in the NFS driver.
# Defaults to $::os_service_default
@ -54,6 +58,10 @@
# used if so, otherwise False. Default is auto.
# Defaults to $::os_service_default
#
# [*multi_config*]
# (Optional) A config hash when multiple backends are used.
# Defaults to {}
#
# [*step*]
# (Optional) The current step in deployment. See tripleo-heat-templates
# for more details.
@ -61,30 +69,42 @@
#
class tripleo::profile::base::cinder::volume::nfs (
$cinder_nfs_servers,
$backend_name = lookup('cinder::backend::nfs::volume_backend_name', undef, undef, 'tripleo_nfs'),
$backend_name = lookup('cinder::backend::nfs::volume_backend_name', undef, undef, ['tripleo_nfs']),
$backend_availability_zone = lookup('cinder::backend::nfs::backend_availability_zone', undef, undef, undef),
$cinder_nfs_mount_options = '',
$cinder_nfs_shares_config = '/etc/cinder/shares-nfs.conf',
$cinder_nfs_snapshot_support = $::os_service_default,
$cinder_nas_secure_file_operations = $::os_service_default,
$cinder_nas_secure_file_permissions = $::os_service_default,
$multi_config = {},
$step = Integer(lookup('step')),
) {
include tripleo::profile::base::cinder::volume
if $step >= 4 {
package {'nfs-utils': }
create_resources('cinder::backend::nfs', { $backend_name => delete_undef_values({
'backend_availability_zone' => $backend_availability_zone,
'nfs_servers' => $cinder_nfs_servers,
'nfs_mount_options' => $cinder_nfs_mount_options,
'nfs_shares_config' => '/etc/cinder/shares-nfs.conf',
'nfs_snapshot_support' => $cinder_nfs_snapshot_support,
'nas_secure_file_operations' => $cinder_nas_secure_file_operations,
'nas_secure_file_permissions' => $cinder_nas_secure_file_permissions,
})})
Package['nfs-utils'] -> Cinder::Backend::Nfs[$backend_name]
$backend_defaults = {
'CinderNfsAvailabilityZone' => $backend_availability_zone,
'CinderNfsServers' => $cinder_nfs_servers,
'CinderNfsMountOptions' => $cinder_nfs_mount_options,
'CinderNfsSharesConfig' => $cinder_nfs_shares_config,
'CinderNfsSnapshotSupport' => $cinder_nfs_snapshot_support,
'CinderNasSecureFileOperations' => $cinder_nas_secure_file_operations,
'CinderNasSecureFilePermissions' => $cinder_nas_secure_file_permissions,
}
any2array($backend_name).each |String $backend| {
$backend_config = merge($backend_defaults, pick($multi_config[$backend], {}))
create_resources('cinder::backend::nfs', { $backend => delete_undef_values({
'backend_availability_zone' => $backend_config['CinderNfsAvailabilityZone'],
'nfs_servers' => $backend_config['CinderNfsServers'],
'nfs_mount_options' => $backend_config['CinderNfsMountOptions'],
'nfs_shares_config' => $backend_config['CinderNfsSharesConfig'],
'nfs_snapshot_support' => $backend_config['CinderNfsSnapshotSupport'],
'nas_secure_file_operations' => $backend_config['CinderNasSecureFileOperations'],
'nas_secure_file_permissions' => $backend_config['CinderNasSecureFilePermissions'],
})})
Package['nfs-utils'] -> Cinder::Backend::Nfs[$backend]
}
if str2bool($::selinux) {
selboolean { 'virt_use_nfs':
value => on,
@ -93,5 +113,4 @@ class tripleo::profile::base::cinder::volume::nfs (
}
}
}
}

View File

@ -74,6 +74,27 @@ describe 'tripleo::profile::base::cinder::volume::nfs' do
)
end
end
context 'with multiple backends' do
let(:params) { {
:backend_name => ['tripleo_nfs_1', 'tripleo_nfs_2'],
:multi_config => { 'tripleo_nfs_1' => {
'CinderNfsSnapshotSupport' => 'true',
},
'tripleo_nfs_2' => {
'CinderNfsSharesConfig' => '/etc/cinder/shares-nfs_2.conf',
},
},
:step => 4,
} }
it 'should configure each backend' do
is_expected.to contain_cinder__backend__nfs('tripleo_nfs_1')
is_expected.to contain_cinder_config('tripleo_nfs_1/nfs_snapshot_support').with_value('true')
is_expected.to contain_cinder_config('tripleo_nfs_1/nfs_shares_config').with_value('/etc/cinder/shares-nfs.conf')
is_expected.to contain_cinder__backend__nfs('tripleo_nfs_2')
is_expected.to contain_cinder_config('tripleo_nfs_2/nfs_snapshot_support').with_value('<SERVICE DEFAULT>')
is_expected.to contain_cinder_config('tripleo_nfs_2/nfs_shares_config').with_value('/etc/cinder/shares-nfs_2.conf')
end
end
context 'with selinux' do
before :each do

View File

@ -344,6 +344,15 @@ describe 'tripleo::profile::base::cinder::volume' do
:enabled_backends => ['tripleo_nfs']
)
end
context 'with multiple nfs backends' do
# Step 5's hiera specifies two nfs backend names
let(:params) { { :step => 5 } }
it 'should enable each backend' do
is_expected.to contain_class('cinder::backends').with(
:enabled_backends => ['tripleo_nfs_1', 'tripleo_nfs_2']
)
end
end
end
context 'with only rbd' do

View File

@ -37,3 +37,11 @@ cinder::backend::netapp::volume_backend_name:
tripleo::profile::base::cinder::volume::netapp::multi_config:
tripleo_netapp_2:
CinderNetappNfsSharesConfig: '/etc/cinder/shares_2.conf'
tripleo::profile::base::cinder::volume::nfs::backend_name:
- 'tripleo_nfs_1'
- 'tripleo_nfs_2'
tripleo::profile::base::cinder::volume::nfs::cinder_nfs_servers:
- '127.0.0.1'
tripleo::profile::base::cinder::volume::nfs::multi_config:
tripleo_nfs_2:
CinderNfsSharesConfig: '/etc/cinder/shares-nfs_2.conf'