Use anchor to require necessary packages

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

Change-Id: Id99c1f8343180fb46188dd6ebe0cf9a8414e7436
This commit is contained in:
Takashi Kajinami 2020-05-04 15:30:41 +09:00
parent afdc25c728
commit 22c60182a0
4 changed files with 14 additions and 24 deletions

View File

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

View File

@ -46,8 +46,8 @@ Puppet::Type.newtype(:vitrage_config) do
defaultto('<SERVICE DEFAULT>')
end
autorequire(:package) do
'vitrage'
autorequire(:anchor) do
['vitrage::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/vitrage_api_paste_ini'
describe 'Puppet::Type.type(:vitrage_api_paste_ini)' do
before :each do
@vitrage_api_paste_ini = Puppet::Type.type(:vitrage_api_paste_ini).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should accept a valid value' do
@vitrage_api_paste_ini[:value] = 'bar'
expect(@vitrage_api_paste_ini[:value]).to eq('bar')
@ -23,12 +13,12 @@ describe 'Puppet::Type.type(:vitrage_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 => 'vitrage-common')
catalog.add_resource package, @vitrage_api_paste_ini
anchor = Puppet::Type.type(:anchor).new(:name => 'vitrage::install::end')
catalog.add_resource anchor, @vitrage_api_paste_ini
dependency = @vitrage_api_paste_ini.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@vitrage_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/vitrage_config'
describe 'Puppet::Type.type(:vitrage_config)' do
before :each do
@vitrage_config = Puppet::Type.type(:vitrage_config).new(:name => 'DEFAULT/foo', :value => 'bar')
@ -52,13 +53,12 @@ describe 'Puppet::Type.type(:vitrage_config)' do
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => 'vitrage')
catalog.add_resource package, @vitrage_config
anchor = Puppet::Type.type(:anchor).new(:name => 'vitrage::install::end')
catalog.add_resource anchor, @vitrage_config
dependency = @vitrage_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@vitrage_config)
expect(dependency[0].source).to eq(package)
expect(dependency[0].source).to eq(anchor)
end
end