Use anchor to require necessary packages

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

Change-Id: I25f0aa5e0b8c8847627e37c396285131df6a2696
This commit is contained in:
Takashi Kajinami 2020-05-04 00:49:06 +09:00
parent da1d7ff2c0
commit 6431321eee
4 changed files with 14 additions and 23 deletions

View File

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

View File

@ -44,8 +44,8 @@ Puppet::Type.newtype(:aodh_config) do
defaultto('<SERVICE DEFAULT>')
end
autorequire(:package) do
'aodh'
autorequire(:anchor) do
['aodh::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/aodh_api_paste_ini'
describe 'Puppet::Type.type(:aodh_api_paste_ini)' do
before :each do
@aodh_api_paste_ini = Puppet::Type.type(:aodh_api_paste_ini).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should accept a valid value' do
@aodh_api_paste_ini[:value] = 'bar'
expect(@aodh_api_paste_ini[:value]).to eq('bar')
@ -23,12 +13,12 @@ describe 'Puppet::Type.type(:aodh_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 => 'aodh-common')
catalog.add_resource package, @aodh_api_paste_ini
anchor = Puppet::Type.type(:anchor).new(:name => 'aodh::install::end')
catalog.add_resource anchor, @aodh_api_paste_ini
dependency = @aodh_api_paste_ini.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@aodh_api_paste_ini)
expect(dependency[0].source).to eq(package)
expect(dependency[0].source).to eq(anchor)
end
end

View File

@ -1,5 +1,6 @@
require 'puppet'
require 'puppet/type/aodh_config'
describe 'Puppet::Type.type(:aodh_config)' do
before :each do
@aodh_config = Puppet::Type.type(:aodh_config).new(:name => 'DEFAULT/foo', :value => 'bar')
@ -52,12 +53,12 @@ describe 'Puppet::Type.type(:aodh_config)' do
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => 'aodh')
catalog.add_resource package, @aodh_config
anchor = Puppet::Type.type(:anchor).new(:name => 'aodh::install::end')
catalog.add_resource anchor, @aodh_config
dependency = @aodh_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@aodh_config)
expect(dependency[0].source).to eq(package)
expect(dependency[0].source).to eq(anchor)
end
end