Rely on autorequire for config resource ordering

Currently we specify the ordering of config resources wherever it is
necessary based on the presence of the file it will write to, or the
presence of the package in charge of providing the file it will write
to.

Those kind of ordering can be specified directly at the resource level
using the autorequire mechanism. With this patch, any config resource
will make sure the package in charge of providing the file will be
installed first.

Change-Id: I3b0df55fa4d827934185f8e213ad89d360fb56a0
This commit is contained in:
Yanis Guenane 2015-08-12 10:16:04 +02:00
parent a0a4ec7ebb
commit 46925dd147
3 changed files with 16 additions and 1 deletions

View File

@ -39,4 +39,9 @@ Puppet::Type.newtype(:gnocchi_config) do
defaultto false
end
autorequire(:package) do
'gnocchi-api'
end
end

View File

@ -101,7 +101,6 @@ class gnocchi::api(
Gnocchi_config<||> ~> Exec['post-gnocchi_config']
Gnocchi_config<||> ~> Service['gnocchi-api']
Package['gnocchi-api'] -> Gnocchi_config<||>
if $::gnocchi::database_connection {
if($::gnocchi::database_connection =~ /mysql:\/\/\S+:\S+@\S+\/\S+/) {

View File

@ -49,4 +49,15 @@ describe 'Puppet::Type.type(:gnocchi_config)' do
@gnocchi_config[:ensure] = :latest
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => 'gnocchi-api')
catalog.add_resource package, @gnocchi_config
dependency = @gnocchi_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@gnocchi_config)
expect(dependency[0].source).to eq(package)
end
end