From efe125f5eba2ba419f4282a97e07a1aae2d3c1e5 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Fri, 4 Jul 2014 19:23:16 +0200 Subject: [PATCH] Glance: add "local" backend As an option, allow to configure Glance with "local" backend. It is a option to use when not having Ceph in the environment. For backward compatibility, we set 'rbd' as default backend. Signed-off-by: Emilien Macchi --- manifests/image/api.pp | 41 +++++++++++++++++++--------- spec/classes/cloud_image_api_spec.rb | 20 ++++++++++++++ 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/manifests/image/api.pp b/manifests/image/api.pp index 4bd76c89..4f5de3e9 100644 --- a/manifests/image/api.pp +++ b/manifests/image/api.pp @@ -67,6 +67,11 @@ # (optional) Syslog facility to receive log lines # Defaults to 'LOG_LOCAL0' # +# [*backend*] +# (optionnal) Backend to use to store images +# Can be 'rbd' or 'file'. +# Defaults to 'rbd' to maintain backward compatibility +# class cloud::image::api( $glance_db_host = '127.0.0.1', @@ -88,7 +93,9 @@ class cloud::image::api( $verbose = true, $debug = true, $log_facility = 'LOG_LOCAL0', - $use_syslog = true + $use_syslog = true, + $backend = 'rbd', + $filesystem_store_datadir = undef ) { # Disable twice logging if syslog is enabled @@ -138,20 +145,28 @@ class cloud::image::api( 'DEFAULT/notifier_driver': value => 'noop'; } - class { 'glance::backend::rbd': - rbd_store_user => $glance_rbd_user, - rbd_store_pool => $glance_rbd_pool - } + if ($backend == 'rbd') { + class { 'glance::backend::rbd': + rbd_store_user => $glance_rbd_user, + rbd_store_pool => $glance_rbd_pool + } - Ceph::Key <<| title == $glance_rbd_user |>> - file { '/etc/ceph/ceph.client.glance.keyring': - owner => 'glance', - group => 'glance', - mode => '0400', - require => Ceph::Key[$glance_rbd_user], - notify => Service['glance-api','glance-registry'] + Ceph::Key <<| title == $glance_rbd_user |>> + file { '/etc/ceph/ceph.client.glance.keyring': + owner => 'glance', + group => 'glance', + mode => '0400', + require => Ceph::Key[$glance_rbd_user], + notify => Service['glance-api','glance-registry'] + } + Concat::Fragment <<| title == 'ceph-client-os' |>> + } elsif ($backend == 'file') { + class { 'glance::backend::file': + filesystem_store_datadir => $filesystem_store_datadir + } + } else { + fail("${backend} is not a Glance supported backend.") } - Concat::Fragment <<| title == 'ceph-client-os' |>> class { 'glance::cache::cleaner': } class { 'glance::cache::pruner': } diff --git a/spec/classes/cloud_image_api_spec.rb b/spec/classes/cloud_image_api_spec.rb index 95550c00..a367505f 100644 --- a/spec/classes/cloud_image_api_spec.rb +++ b/spec/classes/cloud_image_api_spec.rb @@ -35,6 +35,7 @@ describe 'cloud::image::api' do :rabbit_password => 'secrete', :glance_rbd_user => 'glance', :glance_rbd_pool => 'images', + :backend => 'rbd', :debug => true, :verbose => true, :use_syslog => true, @@ -92,6 +93,25 @@ describe 'cloud::image::api' do should contain_class('glance::cache::pruner') end + context 'with file Glance backend' do + before :each do + params.merge!(:backend => 'file') + end + + it 'configure Glance with file 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' => '/var/lib/glance/images/') + should contain_glance_api_config('DEFAULT/default_store').with('value' => 'file') + end + end + + context 'with wrong Glance backend' do + before :each do + params.merge!(:backend => 'Something') + end + it { should compile.and_raise_error(/Something is not a Glance supported backend./) } + end end context 'on Debian platforms' do