diff --git a/manifests/api.pp b/manifests/api.pp index 2ff12b25..5afc8a36 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -173,17 +173,7 @@ class cinder::api ( } if $sync_db { - Cinder_config<||> ~> Exec['cinder-manage db_sync'] - - exec { 'cinder-manage db_sync': - command => $::cinder::params::db_sync_command, - path => '/usr/bin', - user => 'cinder', - refreshonly => true, - logoutput => 'on_failure', - subscribe => Package['cinder'], - before => Service['cinder-api'], - } + include ::cinder::db::sync } if $enabled { diff --git a/manifests/db/sync.pp b/manifests/db/sync.pp index e9fff142..58644243 100644 --- a/manifests/db/sync.pp +++ b/manifests/db/sync.pp @@ -1,14 +1,22 @@ # +# Class to execute cinder dbsync +# class cinder::db::sync { include ::cinder::params + Package <| tag == 'cinder-package' |> ~> Exec['cinder-manage db_sync'] + Exec['cinder-manage db_sync'] ~> Service <| tag == 'cinder-service' |> + + Cinder_config <||> ~> Exec['cinder-manage db_sync'] + Cinder_config <| title == 'database/connection' |> ~> Exec['cinder-manage db_sync'] + exec { 'cinder-manage db_sync': command => $::cinder::params::db_sync_command, path => '/usr/bin', user => 'cinder', refreshonly => true, - require => Class['cinder'], logoutput => 'on_failure', } + } diff --git a/spec/classes/cinder_api_spec.rb b/spec/classes/cinder_api_spec.rb index 8a1f324f..5db81d3c 100644 --- a/spec/classes/cinder_api_spec.rb +++ b/spec/classes/cinder_api_spec.rb @@ -126,7 +126,7 @@ describe 'cinder::api' do :sync_db => false, } end - it { is_expected.not_to contain_exec('cinder-manage db_sync') } + it { is_expected.not_to contain_class('cinder::db::sync') } end [ '/keystone', '/keystone/admin' ].each do |keystone_auth_admin_prefix| @@ -183,8 +183,8 @@ describe 'cinder::api' do it 'should stop the service' do is_expected.to contain_service('cinder-api').with_ensure('stopped') end - it 'should contain db_sync exec' do - is_expected.to contain_exec('cinder-manage db_sync') + it 'includes cinder::db::sync' do + is_expected.to contain_class('cinder::db::sync') end end @@ -195,8 +195,8 @@ describe 'cinder::api' do it 'should not change the state of the service' do is_expected.to contain_service('cinder-api').without_ensure end - it 'should contain db_sync exec' do - is_expected.to contain_exec('cinder-manage db_sync') + it 'includes cinder::db::sync' do + is_expected.to contain_class('cinder::db::sync') end end diff --git a/spec/classes/cinder_db_sync_spec.rb b/spec/classes/cinder_db_sync_spec.rb index f45350f1..98761d4a 100644 --- a/spec/classes/cinder_db_sync_spec.rb +++ b/spec/classes/cinder_db_sync_spec.rb @@ -2,15 +2,43 @@ require 'spec_helper' describe 'cinder::db::sync' do - let :facts do - {:osfamily => 'Debian'} + shared_examples_for 'cinder-dbsync' do + + it 'runs cinder-manage db_sync' do + is_expected.to contain_exec('cinder-manage db_sync').with( + :command => 'cinder-manage db sync', + :user => 'cinder', + :path => '/usr/bin', + :refreshonly => 'true', + :logoutput => 'on_failure' + ) + end + + end + + context 'on a RedHat osfamily' do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + :concat_basedir => '/var/lib/puppet/concat' + } + end + + it_configures 'cinder-dbsync' + end + + context 'on a Debian osfamily' do + let :facts do + { + :operatingsystemrelease => '7.8', + :operatingsystem => 'Debian', + :osfamily => 'Debian', + :concat_basedir => '/var/lib/puppet/concat' + } + end + + it_configures 'cinder-dbsync' end - it { is_expected.to contain_exec('cinder-manage db_sync').with( - :command => 'cinder-manage db sync', - :path => '/usr/bin', - :user => 'cinder', - :refreshonly => true, - :logoutput => 'on_failure' - ) } end