From 4be63933c92326f009fbf1a84566aa8e231c9861 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Mon, 22 Sep 2014 21:51:59 -0400 Subject: [PATCH] NFS backend for Glance images Bring support to mount filesystem_store_datadir to a remote NFS share. Detailed description of this patch: * add a new backend in cloud::image::api (nfs). * add a new parameter to configure the NFS device (false by default). * This parameter is required when using NFS backend, otherwise it will fail. * Mount the NFS share using a new Puppet module by using a hash to configure the share. * Add 4 new Puppet modules for NFS, common, types and rpcbind. The 3 last ones are dependencies. Note: this NFS module has been chosen because it's well tested, quite updated and support Hiera data model which will allow us great flexibility for complex deployments. * add unit tests with two new contexts when running NFS backend. --- .fixtures.yml | 12 ++++++++++ Puppetfile | 14 +++++++++++ Rakefile | 2 ++ manifests/image/api.pp | 32 +++++++++++++++++++++++-- spec/classes/cloud_image_api_spec.rb | 36 ++++++++++++++++++++++++++-- 5 files changed, 92 insertions(+), 4 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index 9869aaff..b575f76e 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -123,11 +123,23 @@ fixtures: 'ssh': repo: 'git://github.com/enovance/puppet-ssh.git' ref: '10675c0d80511a8cdd514af67b695887fa97ec40' + 'rpcbind': + repo: 'git://github.com/enovance/puppet-module-rpcbind.git' + ref: 'da943d26f09f9658159c1190e058bf1af88f465d' 'rsyslog': repo: 'git://github.com/enovance/puppet-rsyslog.git' ref: '67c7c501b916ebd1a27a8a218d49602339526c4f' 'rsync': repo: 'git://github.com/enovance/puppetlabs-rsync.git' ref: '7122983d89bf68bc4170415cc03212f6a8a4636e' + 'nfs': + repo: 'git://github.com/enovance/puppet-module-nfs.git' + ref: '65086bcc5fc5cd9ff617a425505326619a0887fc' + 'common': + repo: 'git://github.com/enovance/puppet-module-common.git' + ref: '2d0606fce1078222dd483e731ec32807f5b4ca53' + 'types': + repo: 'git://github.com/enovance/puppet-module-types.git' + ref: '4c58ae8b6cdb1a9da3da9654a35375e274019dfb' symlinks: 'cloud': '#{source_dir}' diff --git a/Puppetfile b/Puppetfile index c65a1bea..9eba6415 100644 --- a/Puppetfile +++ b/Puppetfile @@ -68,6 +68,9 @@ mod 'ceph', mod 'cloud', :git => 'git://github.com/enovance/puppet-openstack-cloud.git', :ref => 'master' +mod 'common', + :git => 'git://github.com/enovance/puppet-module-common.git', + :ref => '2d0606fce1078222dd483e731ec32807f5b4ca53' mod 'concat', :git => 'git://github.com/enovance/puppet-concat.git', :ref => '04356974f72b90a1d0f57346a00e95a717924e43' @@ -125,6 +128,11 @@ mod 'mongodb', mod 'mysql', :git => 'git://github.com/enovance/puppetlabs-mysql.git', :ref => '8b814d4d2cb5786a15e8e37fb3b7444d5d5f0d3f' +# TODO(EmilienM) Come back to upstream after +# https://github.com/ghoneycutt/puppet-module-nfs/pull/43 got merged. +mod 'nfs', + :git => 'git://github.com/enovance/puppet-module-nfs.git', + :ref => '65086bcc5fc5cd9ff617a425505326619a0887fc' mod 'ntp', :git => 'git://github.com/enovance/puppetlabs-ntp.git', :ref => 'eb02ba2937ce86fb609ae41499767244b78ec58d' @@ -137,6 +145,9 @@ mod 'rabbitmq', mod 'rhnreg_ks', :git => 'git://github.com/enovance/puppet-rhnreg_ks.git', :ref => '8fdc051992b44a09f39d3b510d7cd6db5ed5ff66' +mod 'rpcbind', + :git => 'git://github.com/enovance/puppet-module-rpcbind.git', + :ref => 'da943d26f09f9658159c1190e058bf1af88f465d' mod 'rsync', :git => 'git://github.com/enovance/puppetlabs-rsync.git', :ref => '7122983d89bf68bc4170415cc03212f6a8a4636e' @@ -154,6 +165,9 @@ mod 'stdlib', mod 'sysctl', :git => 'git://github.com/enovance/puppet-sysctl.git', :ref => '4a463384e844f51b270428643a5b8beb3628e854' +mod 'types', + :git => 'git://github.com/enovance/puppet-module-types.git', + :ref => '4c58ae8b6cdb1a9da3da9654a35375e274019dfb' mod 'vswitch', :git => 'git://github.com/enovance/puppet-vswitch.git', :ref => '49dbaff15e8f017dbe365ebf08eb505472b695a1' diff --git a/Rakefile b/Rakefile index f8c6dd36..dbbddfec 100644 --- a/Rakefile +++ b/Rakefile @@ -12,6 +12,8 @@ PuppetLint.configuration.fail_on_warnings = true PuppetLint.configuration.send('disable_80chars') # for manifest loadbalancer.pp +39 (default value as an array of variables) PuppetLint.configuration.send('disable_class_parameter_defaults') +# manifests/image/api.pp - WARNING: string containing only a variable on line 189 +PuppetLint.configuration.send('disable_only_variable_string') # For stonith-enabled (it's a string not a bool) PuppetLint.configuration.send('disable_quoted_booleans') # Ignore all upstream modules diff --git a/manifests/image/api.pp b/manifests/image/api.pp index eb23d77c..abe54ddf 100644 --- a/manifests/image/api.pp +++ b/manifests/image/api.pp @@ -69,9 +69,15 @@ # # [*backend*] # (optionnal) Backend to use to store images -# Can be 'rbd' or 'file'. +# Can be 'rbd', 'file' or 'nfs'. # Defaults to 'rbd' to maintain backward compatibility # +# [*nfs_device*] +# (optionnal) NFS device to mount +# Example: 'nfs.example.com:/vol1' +# Required when running 'nfs' backend. +# Defaults to false +# class cloud::image::api( $glance_db_host = '127.0.0.1', $glance_db_user = 'glance', @@ -94,7 +100,8 @@ class cloud::image::api( $log_facility = 'LOG_LOCAL0', $use_syslog = true, $backend = 'rbd', - $filesystem_store_datadir = undef + $filesystem_store_datadir = undef, + $nfs_device = false, ) { # Disable twice logging if syslog is enabled @@ -170,6 +177,27 @@ class cloud::image::api( class { 'glance::backend::file': filesystem_store_datadir => $filesystem_store_datadir } + } elsif ($backend == 'nfs') { + # There is no NFS backend in Glance. + # We mount the NFS share in filesystem_store_datadir to fake the + # backend. + if $nfs_device { + class { 'glance::backend::file': + filesystem_store_datadir => $filesystem_store_datadir + } + $nfs_mount = { + "${filesystem_store_datadir}" => { + 'ensure' => 'present', + 'fstype' => 'nfs', + 'device' => $nfs_device + } + } + ensure_resource('class', 'nfs', { + mounts => $nfs_mount + }) + } else { + fail('When running NFS backend, you need to provide nfs_device parameter.') + } } else { fail("${backend} is not a Glance supported backend.") } diff --git a/spec/classes/cloud_image_api_spec.rb b/spec/classes/cloud_image_api_spec.rb index a367505f..b8dc93c2 100644 --- a/spec/classes/cloud_image_api_spec.rb +++ b/spec/classes/cloud_image_api_spec.rb @@ -106,6 +106,34 @@ describe 'cloud::image::api' do end end + context 'with NFS Glance backend' do + before :each do + params.merge!(:backend => 'nfs', + :filesystem_store_datadir => '/srv/images/', + :nfs_device => 'nfs.example.com:/vol1' ) + end + + it 'configure Glance with NFS backend' do + should contain_class('glance::backend::file') + should_not contain_class('glance::backend::rbd') + should contain_glance_api_config('DEFAULT/filesystem_store_datadir').with('value' => '/srv/images/') + should contain_glance_api_config('DEFAULT/default_store').with('value' => 'file') + should contain_mount('/srv/images/').with({ + 'ensure' => 'present', + 'fstype' => 'nfs', + 'device' => 'nfs.example.com:/vol1', + }) + end + end + + context 'with missing parameter when using Glance NFS backend' do + before :each do + params.merge!(:backend => 'nfs', + :nfs_device => false ) + end + it { should compile.and_raise_error(/When running NFS backend, you need to provide nfs_device parameter./) } + end + context 'with wrong Glance backend' do before :each do params.merge!(:backend => 'Something') @@ -116,7 +144,9 @@ describe 'cloud::image::api' do context 'on Debian platforms' do let :facts do - { :osfamily => 'Debian' } + { :osfamily => 'Debian', + # required for rpcbind module + :lsbdistid => 'Debian' } end it_configures 'openstack image api' @@ -124,7 +154,9 @@ describe 'cloud::image::api' do context 'on RedHat platforms' do let :facts do - { :osfamily => 'RedHat' } + { :osfamily => 'RedHat', + # required for nfs module + :lsbmajdistrelease => '7' } end it_configures 'openstack image api'