From e2a7d0da4db3f92036ff3314b2b02f76a8eff881 Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Wed, 12 Aug 2015 10:53:19 +0200 Subject: [PATCH] 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: Ide679a11b1ebb7609f97f75fd93dc53be5eb92f3 --- lib/puppet/type/nova_config.rb | 5 +++++ lib/puppet/type/nova_paste_api_ini.rb | 4 ++++ manifests/api.pp | 2 -- manifests/init.pp | 6 ------ spec/unit/type/nova_config_spec.rb | 12 ++++++++++++ 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/puppet/type/nova_config.rb b/lib/puppet/type/nova_config.rb index 007546dee..0cb5c44c8 100644 --- a/lib/puppet/type/nova_config.rb +++ b/lib/puppet/type/nova_config.rb @@ -39,4 +39,9 @@ Puppet::Type.newtype(:nova_config) do defaultto false end + + autorequire(:package) do + 'nova-common' + end + end diff --git a/lib/puppet/type/nova_paste_api_ini.rb b/lib/puppet/type/nova_paste_api_ini.rb index 095fa210c..ff9e3b495 100644 --- a/lib/puppet/type/nova_paste_api_ini.rb +++ b/lib/puppet/type/nova_paste_api_ini.rb @@ -40,4 +40,8 @@ Puppet::Type.newtype(:nova_paste_api_ini) do defaultto false end + autorequire(:package) do + 'nova-common' + end + end diff --git a/manifests/api.pp b/manifests/api.pp index 994abdd35..092cf4e3c 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -188,8 +188,6 @@ class nova::api( require ::keystone::python include ::cinder::client - Package<| title == 'nova-api' |> -> Nova_paste_api_ini<| |> - Package<| title == 'nova-common' |> -> Class['nova::api'] Package<| title == 'nova-common' |> -> Class['nova::policy'] diff --git a/manifests/init.pp b/manifests/init.pp index e5ece69bc..a62271b6f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -411,12 +411,6 @@ class nova( } } - - # all nova_config resources should be applied - # after the nova common package - # before the file resource for nova.conf is managed - # and before the post config resource - Package['nova-common'] -> Nova_config<| |> -> File['/etc/nova/nova.conf'] Nova_config<| |> ~> Exec['post-nova_config'] # TODO - see if these packages can be removed diff --git a/spec/unit/type/nova_config_spec.rb b/spec/unit/type/nova_config_spec.rb index 0d09e826a..c9895b69d 100644 --- a/spec/unit/type/nova_config_spec.rb +++ b/spec/unit/type/nova_config_spec.rb @@ -49,4 +49,16 @@ describe 'Puppet::Type.type(:nova_config)' do @nova_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 => 'nova-common') + catalog.add_resource package, @nova_config + dependency = @nova_config.autorequire + expect(dependency.size).to eq(1) + expect(dependency[0].target).to eq(@nova_config) + expect(dependency[0].source).to eq(package) + end + + end