diff --git a/examples/cinder_volume_with_pacemaker.pp b/examples/cinder_volume_with_pacemaker.pp new file mode 100644 index 00000000..4277df3d --- /dev/null +++ b/examples/cinder_volume_with_pacemaker.pp @@ -0,0 +1,40 @@ +# Example: managing cinder controller services with pacemaker +# +# By setting enabled to false, these services will not be started at boot. By setting +# manage_service to false, puppet will not kill these services on every run. This +# allows the Pacemaker resource manager to dynamically determine on which node each +# service should run. +# +# The puppet commands below would ideally be applied to at least three nodes. +# +# Note that cinder-api is associated with the virtual IP address as +# it is called from external services. The remaining services connect to the +# database and/or message broker independently. +# +# Example pacemaker resource configuration commands (configured once per cluster): +# +# sudo pcs resource create cinder_vip ocf:heartbeat:IPaddr2 params ip=192.0.2.3 \ +# cidr_netmask=24 op monitor interval=10s +# +# sudo pcs resource create cinder_api_service lsb:openstack-cinder-api +# sudo pcs resource create cinder_scheduler_service lsb:openstack-cinder-scheduler +# +# sudo pcs constraint colocation add cinder_api_service with cinder_vip + +class { 'cinder': + sql_connection => 'mysql://cinder:secret_block_password@openstack-controller.example.com/cinder', +} + +class { 'cinder::api': + keystone_password => 'CINDER_PW', + keystone_user => 'cinder', + enabled => false, + manage_service => false, +} + +class { 'cinder::scheduler': + scheduler_driver => 'cinder.scheduler.simple.SimpleScheduler', + enabled => false, + manage_service => false, +} + diff --git a/manifests/api.pp b/manifests/api.pp index e630113c..d7cca900 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -60,6 +60,10 @@ # (optional) The state of the service # Defaults to true # +# [*manage_service*] +# (optional) Whether to start/stop the service +# Defaults to true +# # [*ratelimits*] # (optional) The state of the service # Defaults to undef. If undefined the default ratelimiting values are used. @@ -83,6 +87,7 @@ class cinder::api ( $package_ensure = 'present', $bind_host = '0.0.0.0', $enabled = true, + $manage_service = true, $ratelimits = undef, $ratelimits_factory = 'cinder.api.v1.limits:RateLimitingMiddleware.factory' @@ -115,9 +120,13 @@ class cinder::api ( logoutput => 'on_failure', require => Package['cinder'], } - $ensure = 'running' + if $manage_service { + $ensure = 'running' + } } else { - $ensure = 'stopped' + if $manage_service { + $ensure = 'stopped' + } } service { 'cinder-api': diff --git a/manifests/scheduler.pp b/manifests/scheduler.pp index abb87470..26b1e585 100644 --- a/manifests/scheduler.pp +++ b/manifests/scheduler.pp @@ -2,7 +2,8 @@ class cinder::scheduler ( $scheduler_driver = false, $package_ensure = 'present', - $enabled = true + $enabled = true, + $manage_service = true ) { include cinder::params @@ -27,10 +28,12 @@ class cinder::scheduler ( } } - if $enabled { - $ensure = 'running' - } else { - $ensure = 'stopped' + if $manage_service { + if $enabled { + $ensure = 'running' + } else { + $ensure = 'stopped' + } } service { 'cinder-scheduler': diff --git a/manifests/volume.pp b/manifests/volume.pp index d53510d4..6617991e 100644 --- a/manifests/volume.pp +++ b/manifests/volume.pp @@ -1,7 +1,8 @@ # $volume_name_template = volume-%s class cinder::volume ( $package_ensure = 'present', - $enabled = true + $enabled = true, + $manage_service = true ) { include cinder::params @@ -21,10 +22,12 @@ class cinder::volume ( } } - if $enabled { - $ensure = 'running' - } else { - $ensure = 'stopped' + if $manage_service { + if $enabled { + $ensure = 'running' + } else { + $ensure = 'stopped' + } } service { 'cinder-volume': @@ -34,5 +37,4 @@ class cinder::volume ( hasstatus => true, require => Package['cinder'], } - } diff --git a/spec/classes/cinder_api_spec.rb b/spec/classes/cinder_api_spec.rb index d6e0e94c..640af215 100644 --- a/spec/classes/cinder_api_spec.rb +++ b/spec/classes/cinder_api_spec.rb @@ -15,7 +15,8 @@ describe 'cinder::api' do end it { should contain_service('cinder-api').with( - 'hasstatus' => true + 'hasstatus' => true, + 'ensure' => 'running' )} it 'should configure cinder api correctly' do @@ -138,11 +139,23 @@ describe 'cinder::api' do let :params do req_params.merge({'enabled' => false}) end + it 'should stop the service' do + should contain_service('cinder-api').with_ensure('stopped') + end it 'should contain db_sync exec' do should_not contain_exec('cinder-manage db_sync') end end + describe 'with manage_service false' do + let :params do + req_params.merge({'manage_service' => false}) + end + it 'should not change the state of the service' do + should contain_service('cinder-api').without_ensure + end + end + describe 'with ratelimits' do let :params do req_params.merge({ :ratelimits => '(GET, "*", .*, 100, MINUTE);(POST, "*", .*, 200, MINUTE)' }) diff --git a/spec/classes/cinder_scheduler_spec.rb b/spec/classes/cinder_scheduler_spec.rb index 62f2a57e..4ce066a0 100644 --- a/spec/classes/cinder_scheduler_spec.rb +++ b/spec/classes/cinder_scheduler_spec.rb @@ -38,6 +38,16 @@ describe 'cinder::scheduler' do it { should contain_cinder_config('DEFAULT/scheduler_driver').with_value('cinder.scheduler.filter_scheduler.FilterScheduler') } it { should contain_package('cinder-scheduler').with_ensure('present') } end + + describe 'with manage_service false' do + let :params do + { 'manage_service' => false + } + end + it 'should not change the state of the service' do + should contain_service('cinder-scheduler').without_ensure + end + end end diff --git a/spec/classes/cinder_volume_spec.rb b/spec/classes/cinder_volume_spec.rb index 725cfa34..c87e76d2 100644 --- a/spec/classes/cinder_volume_spec.rb +++ b/spec/classes/cinder_volume_spec.rb @@ -15,4 +15,12 @@ describe 'cinder::volume' do 'hasstatus' => true )} + describe 'with manage_service false' do + let :params do + { 'manage_service' => false } + end + it 'should not change the state of the service' do + should contain_service('cinder-volume').without_ensure + end + end end