Creation of glance::db::sync

In order to standardize the way dbsync are run across our modules,
we create a new class glance::db::sync.
This class will be included if sync_db is enabled.

By making this transition the glance::db::sync class
can be returned by the ENC.

A use case would be in an highly available environment, with 3 galera
nodes, include glance::registry on every node with sync_db set to false
and have the ENC return glance::db::sync just for one node.

Change-Id: I16c8bc411bd34f720513a5d4c94e82b07105af20
This commit is contained in:
Yanis Guenane 2015-06-29 13:12:27 +02:00
parent 4e8e53bff3
commit 48a7164021
5 changed files with 68 additions and 27 deletions

View File

@ -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']

23
manifests/db/sync.pp Normal file
View File

@ -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,
}
}

View File

@ -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 {

View File

@ -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

View File

@ -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]