nfs: Ensure nfs client is installed

The nfs volume driver requires nfs client (especially the mount.nfs
command installed by it). Ensure the package is installed.

Closes-Bug: #2100712
Depends-on: https://review.opendev.org/943119
Change-Id: I291f8592ca95636e16d73c1de71a378b36618c5a
This commit is contained in:
Takashi Kajinami 2025-03-03 01:44:28 +09:00
parent b5cbc9947b
commit 75e727dea8
4 changed files with 35 additions and 0 deletions

View File

@ -99,6 +99,9 @@
# (Optional) Create volumes as QCOW2 files rather than raw files. # (Optional) Create volumes as QCOW2 files rather than raw files.
# Defaults to $facts['os_service_default'] # Defaults to $facts['os_service_default']
# #
# [*package_ensure*]
# (optional) Ensure state for package. Defaults to 'present'.
#
# [*extra_options*] # [*extra_options*]
# (optional) Hash of extra options to pass to the backend stanza # (optional) Hash of extra options to pass to the backend stanza
# Defaults to: {} # Defaults to: {}
@ -124,11 +127,13 @@ define cinder::backend::nfs (
$nas_secure_file_permissions = $facts['os_service_default'], $nas_secure_file_permissions = $facts['os_service_default'],
$nfs_snapshot_support = $facts['os_service_default'], $nfs_snapshot_support = $facts['os_service_default'],
$nfs_qcow2_volumes = $facts['os_service_default'], $nfs_qcow2_volumes = $facts['os_service_default'],
$package_ensure = 'present',
Boolean $manage_volume_type = false, Boolean $manage_volume_type = false,
Hash $extra_options = {}, Hash $extra_options = {},
) { ) {
include cinder::deps include cinder::deps
include cinder::params
file { $nfs_shares_config: file { $nfs_shares_config:
content => join($nfs_servers, "\n"), content => join($nfs_servers, "\n"),
@ -164,6 +169,12 @@ define cinder::backend::nfs (
} }
} }
ensure_packages('nfs-client', {
name => $::cinder::params::nfs_client_package_name,
ensure => $package_ensure,
})
Package<| title == 'nfs-client' |> { tag +> 'cinder-support-package' }
create_resources('cinder_config', $extra_options) create_resources('cinder_config', $extra_options)
} }

View File

@ -24,6 +24,7 @@ class cinder::params {
$db_sync_command = 'cinder-manage db sync' $db_sync_command = 'cinder-manage db sync'
$tgt_package_name = 'tgt' $tgt_package_name = 'tgt'
$tgt_service_name = 'tgt' $tgt_service_name = 'tgt'
$nfs_client_package_name = 'nfs-common'
$ceph_common_package_name = 'ceph-common' $ceph_common_package_name = 'ceph-common'
$target_helper = 'tgtadm' $target_helper = 'tgtadm'
$lio_package_name = 'targetcli' $lio_package_name = 'targetcli'
@ -45,6 +46,7 @@ class cinder::params {
$db_sync_command = 'cinder-manage db sync' $db_sync_command = 'cinder-manage db sync'
$tgt_package_name = 'scsi-target-utils' $tgt_package_name = 'scsi-target-utils'
$tgt_service_name = 'tgtd' $tgt_service_name = 'tgtd'
$nfs_client_package_name = 'nfs-utils'
$ceph_common_package_name = 'ceph-common' $ceph_common_package_name = 'ceph-common'
$target_helper = 'lioadm' $target_helper = 'lioadm'
$lio_package_name = 'targetcli' $lio_package_name = 'targetcli'

View File

@ -0,0 +1,6 @@
---
features:
- |
The ``cinder::backend::nfs`` defined resource type now ensures that the nfs
client package is installed. The new ``package_ensure`` parameter has been
added so that the package state can be customized.

View File

@ -29,6 +29,13 @@ describe 'cinder::backend::nfs' do
is_expected.to contain_cinder_config('hippo/nfs_qcow2_volumes').with_value('<SERVICE DEFAULT>') is_expected.to contain_cinder_config('hippo/nfs_qcow2_volumes').with_value('<SERVICE DEFAULT>')
} }
it {
is_expected.to contain_package('nfs-client').with(
:name => platform_params[:nfs_client_package_name],
:ensure => 'installed',
)
}
it { is_expected.to contain_file('/etc/cinder/shares.conf').with( it { is_expected.to contain_file('/etc/cinder/shares.conf').with(
:content => "10.10.10.10:/shares\n10.10.10.10:/shares2", :content => "10.10.10.10:/shares\n10.10.10.10:/shares2",
:require => 'Anchor[cinder::install::end]', :require => 'Anchor[cinder::install::end]',
@ -108,6 +115,15 @@ describe 'cinder::backend::nfs' do
facts.merge!(OSDefaults.get_facts()) facts.merge!(OSDefaults.get_facts())
end end
let :platform_params do
case facts[:os]['family']
when 'Debian'
{ :nfs_client_package_name => 'nfs-common' }
when 'RedHat'
{ :nfs_client_package_name => 'nfs-utils' }
end
end
it_behaves_like 'cinder::backend::nfs' it_behaves_like 'cinder::backend::nfs'
end end
end end