From 019158284f73974804d6505343c26fb16eee2640 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 4 May 2020 02:44:30 +0900 Subject: [PATCH] Use anchor to require necessary packages/services ... so that correct packages and services are required according without re-defining them in resource implementations. Change-Id: I7e6a32128c0d652b7d69d676f4dfe4363f808c9b --- lib/puppet/type/mistral_config.rb | 4 ++-- lib/puppet/type/mistral_workflow.rb | 4 ++-- spec/unit/type/mistral_config_spec.rb | 11 +++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/puppet/type/mistral_config.rb b/lib/puppet/type/mistral_config.rb index 2447dc3..bb95186 100644 --- a/lib/puppet/type/mistral_config.rb +++ b/lib/puppet/type/mistral_config.rb @@ -46,8 +46,8 @@ Puppet::Type.newtype(:mistral_config) do defaultto('') end - autorequire(:package) do - 'mistral-common' + autorequire(:anchor) do + ['mistral::install::end'] end end diff --git a/lib/puppet/type/mistral_workflow.rb b/lib/puppet/type/mistral_workflow.rb index 4c85978..cd3f665 100644 --- a/lib/puppet/type/mistral_workflow.rb +++ b/lib/puppet/type/mistral_workflow.rb @@ -57,7 +57,7 @@ Puppet::Type.newtype(:mistral_workflow) do end # Require the Mistral API service to be running - autorequire(:service) do - ['mistral-api'] + autorequire(:anchor) do + ['mistral::service::end'] end end diff --git a/spec/unit/type/mistral_config_spec.rb b/spec/unit/type/mistral_config_spec.rb index 7e21a3f..43d8af0 100644 --- a/spec/unit/type/mistral_config_spec.rb +++ b/spec/unit/type/mistral_config_spec.rb @@ -49,4 +49,15 @@ describe 'Puppet::Type.type(:mistral_config)' do @mistral_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 + anchor = Puppet::Type.type(:anchor).new(:name => 'mistral::install::end') + catalog.add_resource anchor, @mistral_config + dependency = @mistral_config.autorequire + expect(dependency.size).to eq(1) + expect(dependency[0].target).to eq(@mistral_config) + expect(dependency[0].source).to eq(anchor) + end + end