diff --git a/manifests/api.pp b/manifests/api.pp index 4e8e335b..a9d45a93 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -255,9 +255,6 @@ class glance::api( # adding all of this stuff b/c it devstack says glance-api uses the # db now - Glance_api_config<||> ~> Exec<| title == 'glance-manage db_sync' |> - Glance_cache_config<||> ~> Exec<| title == 'glance-manage db_sync' |> - Exec<| title == 'glance-manage db_sync' |> ~> Service['glance-api'] Glance_api_config<||> ~> Service['glance-api'] Glance_cache_config<||> ~> Service['glance-api'] Class['glance::policy'] ~> Service['glance-api'] diff --git a/manifests/db/sync.pp b/manifests/db/sync.pp new file mode 100644 index 00000000..4a0b76f8 --- /dev/null +++ b/manifests/db/sync.pp @@ -0,0 +1,23 @@ +# +# Class to execute glance dbsync +# +class glance::db::sync { + + include ::glance::params + + Package<| tag == 'glance-package' |> ~> Exec['glance-manage db_sync'] + Exec['glance-manage db_sync'] ~> Service<| tag == 'glance-service' |> + + Glance_registry_config<||> ~> Exec['glance-manage db_sync'] + Glance_api_config<||> ~> Exec['glance-manage db_sync'] + Glance_cache_config<||> ~> Exec['glance-manage db_sync'] + + exec { 'glance-manage db_sync': + command => $::glance::params::db_sync_command, + path => '/usr/bin', + user => 'glance', + refreshonly => true, + logoutput => on_failure, + } + +} diff --git a/manifests/registry.pp b/manifests/registry.pp index 36e8f668..c1fa6fec 100644 --- a/manifests/registry.pp +++ b/manifests/registry.pp @@ -180,7 +180,6 @@ class glance::registry( Package[$glance::params::registry_package_name] -> File['/etc/glance/'] Package[$glance::params::registry_package_name] -> Glance_registry_config<||> - Glance_registry_config<||> ~> Exec<| title == 'glance-manage db_sync' |> Glance_registry_config<||> ~> Service['glance-registry'] File { @@ -364,16 +363,7 @@ class glance::registry( } if $sync_db { - Exec['glance-manage db_sync'] ~> Service['glance-registry'] - - exec { 'glance-manage db_sync': - command => $::glance::params::db_sync_command, - path => '/usr/bin', - user => 'glance', - refreshonly => true, - logoutput => on_failure, - subscribe => [Package[$glance::params::registry_package_name], File['/etc/glance/glance-registry.conf']], - } + include ::glance::db::sync } if $manage_service { diff --git a/spec/classes/glance_db_sync_spec.rb b/spec/classes/glance_db_sync_spec.rb new file mode 100644 index 00000000..c0e224ec --- /dev/null +++ b/spec/classes/glance_db_sync_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper' + +describe 'glance::db::sync' do + + shared_examples_for 'glance-dbsync' do + + it 'runs glance-manage db_sync' do + is_expected.to contain_exec('glance-manage db_sync').with( + :command => 'glance-manage --config-file=/etc/glance/glance-registry.conf db_sync', + :path => '/usr/bin', + :user => 'glance', + :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 'glance-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 'glance-dbsync' + end + +end diff --git a/spec/classes/glance_registry_spec.rb b/spec/classes/glance_registry_spec.rb index fa9aee34..dd6d02b1 100644 --- a/spec/classes/glance_registry_spec.rb +++ b/spec/classes/glance_registry_spec.rb @@ -78,19 +78,6 @@ describe 'glance::registry' do 'tag' => 'glance-service', )} - it 'is_expected.to only sync the db if sync_db is enabled' do - - if param_hash[:sync_db] - is_expected.to contain_exec('glance-manage db_sync').with( - 'path' => '/usr/bin', - 'command' => 'glance-manage --config-file=/etc/glance/glance-registry.conf db_sync', - 'refreshonly' => true, - 'logoutput' => 'on_failure', - 'subscribe' => ['Package[glance-registry]', 'File[/etc/glance/glance-registry.conf]'], - 'notify' => ["Service[glance-registry]"] - ) - end - end it 'is_expected.to not sync the db if sync_db is set to false' do if !param_hash[:sync_db]