Browse Source

Use anchor to require necessary packages

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

Change-Id: Id99c1f8343180fb46188dd6ebe0cf9a8414e7436
changes/83/725183/1
Takashi Kajinami 1 year ago
parent
commit
22c60182a0
  1. 4
      lib/puppet/type/vitrage_api_paste_ini.rb
  2. 4
      lib/puppet/type/vitrage_config.rb
  3. 22
      spec/unit/type/vitrage_api_paste_ini_spec.rb
  4. 8
      spec/unit/type/vitrage_config_spec.rb

4
lib/puppet/type/vitrage_api_paste_ini.rb

@ -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

4
lib/puppet/type/vitrage_config.rb

@ -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

22
spec/unit/type/vitrage_api_paste_ini_spec.rb

@ -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

8
spec/unit/type/vitrage_config_spec.rb

@ -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
Loading…
Cancel
Save