From 3d0732c2c0f61c71b62805378bafb62f0d03130c Mon Sep 17 00:00:00 2001 From: Giulio Fidente Date: Wed, 27 Apr 2016 16:58:03 +0200 Subject: [PATCH] Wrap service ensure in manage_service boolean As it happens already for the other services, this will prevent puppet from enforcing the backup service into either running or stopped state when manage_service is false. Also adds validate_bool for 'enabled' and 'manage_service' to the api, scheduler, volume and backup services. Change-Id: Id78397bb9745513ba2736ec4169ae4b7657a66e0 --- manifests/api.pp | 7 +++++-- manifests/backup.pp | 22 ++++++++++++++++------ manifests/scheduler.pp | 11 +++++++---- manifests/volume.pp | 11 +++++++---- spec/classes/cinder_api_spec.rb | 2 +- spec/classes/cinder_backup_spec.rb | 11 +++++++++++ 6 files changed, 47 insertions(+), 17 deletions(-) diff --git a/manifests/api.pp b/manifests/api.pp index cd9263d5..15ea0ce8 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -82,11 +82,11 @@ # Defaults to 0.0.0.0 # # [*enabled*] -# (optional) The state of the service +# (optional) The state of the service (boolean value) # Defaults to true # # [*manage_service*] -# (optional) Whether to start/stop the service +# (optional) Whether to start/stop the service (boolean value) # Defaults to true # # [*ratelimits*] @@ -188,6 +188,9 @@ class cinder::api ( include ::cinder::params include ::cinder::policy + validate_bool($manage_service) + validate_bool($enabled) + Cinder_config<||> ~> Service[$service_name] Cinder_api_paste_ini<||> ~> Service[$service_name] Class['cinder::policy'] ~> Service[$service_name] diff --git a/manifests/backup.pp b/manifests/backup.pp index beeb7c5b..59a7d919 100644 --- a/manifests/backup.pp +++ b/manifests/backup.pp @@ -5,8 +5,12 @@ # === Parameters # # [*enabled*] -# (Optional) Should the service be enabled. -# Defaults to 'true'. +# (Optional) Should the service be enabled (boolean value) +# Defaults to true. +# +# [*manage_service*] +# (Optional) Whether to start/stop the service (boolean value) +# Defaults to true. # # [*package_ensure*] # (Optional) Ensure state for package. @@ -51,6 +55,7 @@ # class cinder::backup ( $enabled = true, + $manage_service = true, $package_ensure = 'present', $backup_topic = $::os_service_default, $backup_manager = $::os_service_default, @@ -60,6 +65,9 @@ class cinder::backup ( include ::cinder::params + validate_bool($manage_service) + validate_bool($enabled) + Cinder_config<||> ~> Service['cinder-backup'] Exec<| title == 'cinder-manage db_sync' |> ~> Service['cinder-backup'] @@ -73,10 +81,12 @@ class cinder::backup ( } } - if $enabled { - $ensure = 'running' - } else { - $ensure = 'stopped' + if $manage_service { + if $enabled { + $ensure = 'running' + } else { + $ensure = 'stopped' + } } service { 'cinder-backup': diff --git a/manifests/scheduler.pp b/manifests/scheduler.pp index 08f1732f..7f17aaf8 100644 --- a/manifests/scheduler.pp +++ b/manifests/scheduler.pp @@ -13,12 +13,12 @@ # Defaults to 'present'. # # [*enabled*] -# (Optional) The state of the service -# Defaults to 'true'. +# (Optional) The state of the service (boolean value) +# Defaults to true. # # [*manage_service*] -# (Optional) Whether to start/stop the service -# Defaults to 'true'. +# (Optional) Whether to start/stop the service (boolean value) +# Defaults to true. # # class cinder::scheduler ( @@ -30,6 +30,9 @@ class cinder::scheduler ( include ::cinder::params + validate_bool($manage_service) + validate_bool($enabled) + Cinder_config<||> ~> Service['cinder-scheduler'] Cinder_api_paste_ini<||> ~> Service['cinder-scheduler'] Exec<| title == 'cinder-manage db_sync' |> ~> Service['cinder-scheduler'] diff --git a/manifests/volume.pp b/manifests/volume.pp index 0a3d7db6..e734814a 100644 --- a/manifests/volume.pp +++ b/manifests/volume.pp @@ -7,12 +7,12 @@ # Defaults to 'present'. # # [*enabled*] -# (Optional) The state of the service -# Defaults to 'true'. +# (Optional) The state of the service (boolean value) +# Defaults to true. # # [*manage_service*] -# (Optional) Whether to start/stop the service. -# Defaults to 'true'. +# (Optional) Whether to start/stop the service (boolean value) +# Defaults to true. # # [*volume_clear*] # (Optional) Method used to wipe old volumes. @@ -40,6 +40,9 @@ class cinder::volume ( include ::cinder::params + validate_bool($manage_service) + validate_bool($enabled) + Cinder_config<||> ~> Service['cinder-volume'] Cinder_api_paste_ini<||> ~> Service['cinder-volume'] Exec<| title == 'cinder-manage db_sync' |> ~> Service['cinder-volume'] diff --git a/spec/classes/cinder_api_spec.rb b/spec/classes/cinder_api_spec.rb index 13f6c4a0..94a2b34e 100644 --- a/spec/classes/cinder_api_spec.rb +++ b/spec/classes/cinder_api_spec.rb @@ -190,7 +190,7 @@ describe 'cinder::api' do let :params do { :keystone_password => 'dummy', - :enabled => 'true', + :enabled => true, :sync_db => false, } end diff --git a/spec/classes/cinder_backup_spec.rb b/spec/classes/cinder_backup_spec.rb index 7d079030..6676ab3b 100644 --- a/spec/classes/cinder_backup_spec.rb +++ b/spec/classes/cinder_backup_spec.rb @@ -24,6 +24,7 @@ describe 'cinder::backup' do let :default_params do { :enable => true, + :manage_service => true, :backup_topic => '', :backup_manager => '', :backup_api_class => '', @@ -74,6 +75,16 @@ describe 'cinder::backup' do is_expected.to contain_cinder_config('DEFAULT/backup_name_template').with_value(p[:backup_name_template]) end end + + context 'with manage_service false' do + before :each do + params.merge!(:manage_service => false) + end + it 'should not change the state of the service' do + is_expected.to contain_service('cinder-backup').without_ensure + end + end + end on_supported_os({