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
This commit is contained in:
Giulio Fidente
2016-04-27 16:58:03 +02:00
parent be66ab5543
commit 3d0732c2c0
6 changed files with 47 additions and 17 deletions

View File

@@ -82,11 +82,11 @@
# Defaults to 0.0.0.0 # Defaults to 0.0.0.0
# #
# [*enabled*] # [*enabled*]
# (optional) The state of the service # (optional) The state of the service (boolean value)
# Defaults to true # Defaults to true
# #
# [*manage_service*] # [*manage_service*]
# (optional) Whether to start/stop the service # (optional) Whether to start/stop the service (boolean value)
# Defaults to true # Defaults to true
# #
# [*ratelimits*] # [*ratelimits*]
@@ -188,6 +188,9 @@ class cinder::api (
include ::cinder::params include ::cinder::params
include ::cinder::policy include ::cinder::policy
validate_bool($manage_service)
validate_bool($enabled)
Cinder_config<||> ~> Service[$service_name] Cinder_config<||> ~> Service[$service_name]
Cinder_api_paste_ini<||> ~> Service[$service_name] Cinder_api_paste_ini<||> ~> Service[$service_name]
Class['cinder::policy'] ~> Service[$service_name] Class['cinder::policy'] ~> Service[$service_name]

View File

@@ -5,8 +5,12 @@
# === Parameters # === Parameters
# #
# [*enabled*] # [*enabled*]
# (Optional) Should the service be enabled. # (Optional) Should the service be enabled (boolean value)
# Defaults to 'true'. # Defaults to true.
#
# [*manage_service*]
# (Optional) Whether to start/stop the service (boolean value)
# Defaults to true.
# #
# [*package_ensure*] # [*package_ensure*]
# (Optional) Ensure state for package. # (Optional) Ensure state for package.
@@ -51,6 +55,7 @@
# #
class cinder::backup ( class cinder::backup (
$enabled = true, $enabled = true,
$manage_service = true,
$package_ensure = 'present', $package_ensure = 'present',
$backup_topic = $::os_service_default, $backup_topic = $::os_service_default,
$backup_manager = $::os_service_default, $backup_manager = $::os_service_default,
@@ -60,6 +65,9 @@ class cinder::backup (
include ::cinder::params include ::cinder::params
validate_bool($manage_service)
validate_bool($enabled)
Cinder_config<||> ~> Service['cinder-backup'] Cinder_config<||> ~> Service['cinder-backup']
Exec<| title == 'cinder-manage db_sync' |> ~> Service['cinder-backup'] Exec<| title == 'cinder-manage db_sync' |> ~> Service['cinder-backup']
@@ -73,10 +81,12 @@ class cinder::backup (
} }
} }
if $enabled { if $manage_service {
$ensure = 'running' if $enabled {
} else { $ensure = 'running'
$ensure = 'stopped' } else {
$ensure = 'stopped'
}
} }
service { 'cinder-backup': service { 'cinder-backup':

View File

@@ -13,12 +13,12 @@
# Defaults to 'present'. # Defaults to 'present'.
# #
# [*enabled*] # [*enabled*]
# (Optional) The state of the service # (Optional) The state of the service (boolean value)
# Defaults to 'true'. # Defaults to true.
# #
# [*manage_service*] # [*manage_service*]
# (Optional) Whether to start/stop the service # (Optional) Whether to start/stop the service (boolean value)
# Defaults to 'true'. # Defaults to true.
# #
# #
class cinder::scheduler ( class cinder::scheduler (
@@ -30,6 +30,9 @@ class cinder::scheduler (
include ::cinder::params include ::cinder::params
validate_bool($manage_service)
validate_bool($enabled)
Cinder_config<||> ~> Service['cinder-scheduler'] Cinder_config<||> ~> Service['cinder-scheduler']
Cinder_api_paste_ini<||> ~> Service['cinder-scheduler'] Cinder_api_paste_ini<||> ~> Service['cinder-scheduler']
Exec<| title == 'cinder-manage db_sync' |> ~> Service['cinder-scheduler'] Exec<| title == 'cinder-manage db_sync' |> ~> Service['cinder-scheduler']

View File

@@ -7,12 +7,12 @@
# Defaults to 'present'. # Defaults to 'present'.
# #
# [*enabled*] # [*enabled*]
# (Optional) The state of the service # (Optional) The state of the service (boolean value)
# Defaults to 'true'. # Defaults to true.
# #
# [*manage_service*] # [*manage_service*]
# (Optional) Whether to start/stop the service. # (Optional) Whether to start/stop the service (boolean value)
# Defaults to 'true'. # Defaults to true.
# #
# [*volume_clear*] # [*volume_clear*]
# (Optional) Method used to wipe old volumes. # (Optional) Method used to wipe old volumes.
@@ -40,6 +40,9 @@ class cinder::volume (
include ::cinder::params include ::cinder::params
validate_bool($manage_service)
validate_bool($enabled)
Cinder_config<||> ~> Service['cinder-volume'] Cinder_config<||> ~> Service['cinder-volume']
Cinder_api_paste_ini<||> ~> Service['cinder-volume'] Cinder_api_paste_ini<||> ~> Service['cinder-volume']
Exec<| title == 'cinder-manage db_sync' |> ~> Service['cinder-volume'] Exec<| title == 'cinder-manage db_sync' |> ~> Service['cinder-volume']

View File

@@ -190,7 +190,7 @@ describe 'cinder::api' do
let :params do let :params do
{ {
:keystone_password => 'dummy', :keystone_password => 'dummy',
:enabled => 'true', :enabled => true,
:sync_db => false, :sync_db => false,
} }
end end

View File

@@ -24,6 +24,7 @@ describe 'cinder::backup' do
let :default_params do let :default_params do
{ :enable => true, { :enable => true,
:manage_service => true,
:backup_topic => '<SERVICE DEFAULT>', :backup_topic => '<SERVICE DEFAULT>',
:backup_manager => '<SERVICE DEFAULT>', :backup_manager => '<SERVICE DEFAULT>',
:backup_api_class => '<SERVICE DEFAULT>', :backup_api_class => '<SERVICE DEFAULT>',
@@ -74,6 +75,16 @@ describe 'cinder::backup' do
is_expected.to contain_cinder_config('DEFAULT/backup_name_template').with_value(p[:backup_name_template]) is_expected.to contain_cinder_config('DEFAULT/backup_name_template').with_value(p[:backup_name_template])
end end
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 end
on_supported_os({ on_supported_os({