Use anchor to require necessary packages

... so that correct packages are required according without re-defining
them in resource implementations.

Change-Id: Ia8e6256af44b29b9f3e5aa2ff3c7eeb6e7835a15
This commit is contained in:
Takashi Kajinami
2020-05-04 01:46:25 +09:00
parent 0a7ee27021
commit 4e760d477c
4 changed files with 13 additions and 23 deletions

View File

@@ -45,8 +45,8 @@ Puppet::Type.newtype(:heat_api_paste_ini) do
defaultto('<SERVICE DEFAULT>')
end
autorequire(:package) do
'heat-common'
autorequire(:anchor) do
['heat::install::end']
end
end

View File

@@ -46,8 +46,8 @@ Puppet::Type.newtype(:heat_config) do
defaultto('<SERVICE DEFAULT>')
end
autorequire(:package) do
'heat-common'
autorequire(:anchor) do
['heat::install::end']
end
end

View File

@@ -1,21 +1,11 @@
require 'spec_helper'
# this hack is required for now to ensure that the path is set up correctly
# to retrieve the parent provider
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'fixtures',
'modules',
'inifile',
'lib')
)
require 'puppet'
require 'puppet/type/heat_api_paste_ini'
describe 'Puppet::Type.type(:heat_api_paste_ini)' do
before :each do
@heat_api_paste_ini = Puppet::Type.type(:heat_api_paste_ini).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should accept a valid value' do
@heat_api_paste_ini[:value] = 'bar'
expect(@heat_api_paste_ini[:value]).to eq('bar')
@@ -23,12 +13,12 @@ describe 'Puppet::Type.type(:heat_api_paste_ini)' do
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => 'heat-common')
catalog.add_resource package, @heat_api_paste_ini
anchor = Puppet::Type.type(:anchor).new(:name => 'heat::install::end')
catalog.add_resource anchor, @heat_api_paste_ini
dependency = @heat_api_paste_ini.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@heat_api_paste_ini)
expect(dependency[0].source).to eq(package)
expect(dependency[0].source).to eq(anchor)
end
end

View File

@@ -54,12 +54,12 @@ describe 'Puppet::Type.type(:heat_config)' do
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => 'heat-common')
catalog.add_resource package, @heat_config
anchor = Puppet::Type.type(:anchor).new(:name => 'heat::install::end')
catalog.add_resource anchor, @heat_config
dependency = @heat_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@heat_config)
expect(dependency[0].source).to eq(package)
expect(dependency[0].source).to eq(anchor)
end
end