Use anchor to require necessary packages

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

Change-Id: I9e1e3443659c41fbacb50639cb605686729eb2a2
This commit is contained in:
Takashi Kajinami 2020-05-04 15:26:32 +09:00
parent 431016708a
commit 26944d9e50
8 changed files with 44 additions and 17 deletions

View File

@ -45,7 +45,7 @@ Puppet::Type.newtype(:trove_api_paste_ini) do
defaultto('<SERVICE DEFAULT>')
end
autorequire(:package) do
'trove-api'
autorequire(:anchor) do
['trove::install::end']
end
end

View File

@ -46,7 +46,7 @@ Puppet::Type.newtype(:trove_conductor_config) do
defaultto('<SERVICE DEFAULT>')
end
autorequire(:package) do
'trove-conductor'
autorequire(:anchor) do
['trove::install::end']
end
end

View File

@ -46,7 +46,7 @@ Puppet::Type.newtype(:trove_config) do
defaultto('<SERVICE DEFAULT>')
end
autorequire(:package) do
'trove-api'
autorequire(:anchor) do
['trove::install::end']
end
end

View File

@ -46,7 +46,7 @@ Puppet::Type.newtype(:trove_guestagent_config) do
defaultto('<SERVICE DEFAULT>')
end
autorequire(:package) do
'trove-guestagent'
autorequire(:anchor) do
['trove::install::end']
end
end

View File

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

View File

@ -1,3 +1,4 @@
require 'puppet'
require 'puppet/type/trove_conductor_config'
describe 'Puppet::Type.type(:trove_conductor_config)' do
@ -7,11 +8,11 @@ describe 'Puppet::Type.type(:trove_conductor_config)' do
it 'should autorequire the package that installs the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => 'trove-conductor')
catalog.add_resource package, @trove_conductor_config
anchor = Puppet::Type.type(:anchor).new(:name => 'trove::install::end')
catalog.add_resource anchor, @trove_conductor_config
dependency = @trove_conductor_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@trove_conductor_config)
expect(dependency[0].source).to eq(package)
expect(dependency[0].source).to eq(anchor)
end
end

View File

@ -1,3 +1,4 @@
require 'puppet'
require 'puppet/type/trove_guestagent_config'
describe 'Puppet::Type.type(:trove_guestagent_config)' do
@ -7,11 +8,11 @@ describe 'Puppet::Type.type(:trove_guestagent_config)' do
it 'should autorequire the package that installs the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => 'trove-guestagent')
catalog.add_resource package, @trove_guestagent_config
anchor = Puppet::Type.type(:anchor).new(:name => 'trove::install::end')
catalog.add_resource anchor, @trove_guestagent_config
dependency = @trove_guestagent_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@trove_guestagent_config)
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/trove_config'
describe 'Puppet::Type.type(:trove_config)' do
before :each do
@trove_config = Puppet::Type.type(:trove_config).new(:name => 'DEFAULT/foo', :value => 'bar')
@ -52,11 +53,11 @@ describe 'Puppet::Type.type(:trove_config)' do
it 'should autorequire the package that installs the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => 'trove-api')
catalog.add_resource package, @trove_config
anchor = Puppet::Type.type(:anchor).new(:name => 'trove::install::end')
catalog.add_resource anchor, @trove_config
dependency = @trove_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@trove_config)
expect(dependency[0].source).to eq(package)
expect(dependency[0].source).to eq(anchor)
end
end