From 016ebdfc0ea9ad6161923b72bf9f823b4b19f878 Mon Sep 17 00:00:00 2001 From: Sylvain Baubeau Date: Tue, 7 Oct 2014 11:36:45 +0200 Subject: [PATCH] NFS backend for Cinder volumes --- manifests/volume/backend/nfs.pp | 88 +++++++++++++++++++++++ manifests/volume/storage.pp | 10 ++- spec/classes/cloud_volume_storage_spec.rb | 31 +++++++- 3 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 manifests/volume/backend/nfs.pp diff --git a/manifests/volume/backend/nfs.pp b/manifests/volume/backend/nfs.pp new file mode 100644 index 00000000..4b8e719a --- /dev/null +++ b/manifests/volume/backend/nfs.pp @@ -0,0 +1,88 @@ +# +# Copyright (C) 2014 eNovance SAS +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# Configure NFS backend for Cinder +# +# +# === Parameters +# +# [*nfs_servers*] +# (required) Array of NFS servers in the form 'ipaddress:/share' +# +# [*nfs_mount_options*] +# (optional) Mount options passed to the nfs client. See section +# of the nfs man page for details. +# Defaults to undef +# +# [*nfs_disk_util*] +# (optional) Use du or df for free space calculation +# Defaults to undef +# +# [*nfs_sparsed_volumes*] +# (optional) Create volumes as sparsed files which take no space. +# If set to 'false' volume is created as regular file. +# In such case volume creation takes a lot of time. +# Defaults to undef +# +# [*nfs_mount_point_base*] +# (optional) Base dir containing mount points for nfs shares. +# Defaults to undef +# +# [*nfs_shares_config*] +# (optional) File with the list of available NFS shares. +# Defaults to '/etc/cinder/shares.conf' +# +# [*nfs_used_ratio*] +# (optional) Percent of ACTUAL usage of the underlying volume +# before no new volumes can be allocated to the volume destination. +# Defaults to 0.95 +# +# [*nfs_oversub_ratio*] +# (optional) This will compare the allocated to available space on +# the volume destination. If the ratio exceeds this number, the +# destination will no longer be valid. +# Defaults to 1.0 +# + +define cloud::volume::backend::nfs( + $volume_backend_name = $name, + $nfs_servers = [], + $nfs_mount_options = undef, + $nfs_disk_util = undef, + $nfs_sparsed_volumes = undef, + $nfs_mount_point_base = undef, + $nfs_shares_config = '/etc/cinder/shares.conf', + $nfs_used_ratio = '0.95', + $nfs_oversub_ratio = '1.0', +) { + + cinder::backend::nfs { $name: + volume_backend_name => $volume_backend_name, + nfs_servers => $nfs_servers, + nfs_mount_options => $nfs_mount_options, + nfs_disk_util => $nfs_disk_util, + nfs_sparsed_volumes => $nfs_sparsed_volumes, + nfs_mount_point_base => $nfs_mount_point_base, + nfs_shares_config => $nfs_shares_config, + nfs_used_ratio => $nfs_used_ratio, + nfs_oversub_ratio => $nfs_oversub_ratio, + } + + @cinder::type { $volume_backend_name: + set_key => 'volume_backend_name', + set_value => $volume_backend_name, + notify => Service['cinder-volume'] + } +} diff --git a/manifests/volume/storage.pp b/manifests/volume/storage.pp index 702cb29f..7929a4b9 100644 --- a/manifests/volume/storage.pp +++ b/manifests/volume/storage.pp @@ -99,8 +99,16 @@ class cloud::volume::storage( $emc_vnx_backends = { } } + if has_key($cinder_backends, 'nfs') { + $nfs_backends = $cinder_backends['nfs'] + create_resources('cloud::volume::backend::nfs', $nfs_backends) + } + else { + $nfs_backends = { } + } + class { 'cinder::backends': - enabled_backends => keys(merge($rbd_backends, $netapp_backends, $iscsi_backends, $emc_vnx_backends)) + enabled_backends => keys(merge($rbd_backends, $netapp_backends, $iscsi_backends, $emc_vnx_backends, $nfs_backends)) } # Manage Volume types. diff --git a/spec/classes/cloud_volume_storage_spec.rb b/spec/classes/cloud_volume_storage_spec.rb index b6c9aaf7..2e77d4c1 100644 --- a/spec/classes/cloud_volume_storage_spec.rb +++ b/spec/classes/cloud_volume_storage_spec.rb @@ -69,6 +69,17 @@ describe 'cloud::volume::storage' do 'san_password' => 'secrete', 'storage_vnx_pool_name' => 'emc-volumes', } + }, + 'nfs' => { + 'freenas' => { + 'nfs_servers' => ['10.0.0.1:/myshare'], + 'nfs_mount_options' => 'defaults', + 'nfs_disk_util' => 'df', + 'nfs_mount_point_base' => '/mnt/shares', + 'nfs_shares_config' => '/etc/cinder/shares.conf', + 'nfs_used_ratio' => '0.6', + 'nfs_oversub_ratio' => '1.0' + } } }, :ks_keystone_internal_proto => 'http', @@ -174,6 +185,24 @@ describe 'cloud::volume::storage' do end end + context 'with NFS backend' do + it 'configures NFS volume driver' do + is_expected.to contain_cinder_config('freenas/volume_backend_name').with_value('freenas') + is_expected.to contain_cinder_config('freenas/nfs_mount_options').with_value('defaults') + is_expected.to contain_cinder_config('freenas/nfs_mount_point_base').with_value('/mnt/shares') + is_expected.to contain_cinder_config('freenas/nfs_disk_util').with_value('df') + is_expected.to contain_cinder_config('freenas/nfs_shares_config').with_value('/etc/cinder/shares.conf') + is_expected.to contain_cinder_config('freenas/nfs_used_ratio').with_value('0.6') + is_expected.to contain_cinder_config('freenas/nfs_oversub_ratio').with_value('1.0') + is_expected.to contain_cinder__type('freenas').with( + :set_key => 'volume_backend_name', + :set_value => 'freenas', + :notify => 'Service[cinder-volume]' + ) + should contain_file('/etc/cinder/shares.conf').with_content(/^10.0.0.1:\/myshare$/) + end + end + context 'with two RBD backends' do before :each do params.merge!( @@ -227,7 +256,7 @@ describe 'cloud::volume::storage' do context 'with all backends enabled' do it 'configure all cinder backends' do is_expected.to contain_class('cinder::backends').with( - :enabled_backends => ['lowcost', 'premium', 'fast', 'very-fast'] + :enabled_backends => ['lowcost', 'premium', 'fast', 'very-fast', 'freenas'] ) end end