Browse Source

Use anchor to require necessary packages

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

Change-Id: Icaae881f5d074ad388eaddd26eb82261ea78937d
changes/23/725123/4
Takashi Kajinami 2 years ago
parent
commit
f1e98f1585
  1. 4
      lib/puppet/type/ceilometer_api_paste_ini.rb
  2. 4
      lib/puppet/type/ceilometer_config.rb
  3. 22
      spec/unit/type/ceilometer_api_paste_ini_spec.rb
  4. 8
      spec/unit/type/ceilometer_config_spec.rb

4
lib/puppet/type/ceilometer_api_paste_ini.rb

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

4
lib/puppet/type/ceilometer_config.rb

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

22
spec/unit/type/ceilometer_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/ceilometer_api_paste_ini'
describe 'Puppet::Type.type(:ceilometer_api_paste_ini)' do
before :each do
@ceilometer_api_paste_ini = Puppet::Type.type(:ceilometer_api_paste_ini).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should accept a valid value' do
@ceilometer_api_paste_ini[:value] = 'bar'
expect(@ceilometer_api_paste_ini[:value]).to eq('bar')
@ -23,12 +13,12 @@ describe 'Puppet::Type.type(:ceilometer_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 => 'ceilometer')
catalog.add_resource package, @ceilometer_api_paste_ini
anchor = Puppet::Type.type(:anchor).new(:name => 'ceilometer::install::end')
catalog.add_resource anchor, @ceilometer_api_paste_ini
dependency = @ceilometer_api_paste_ini.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@ceilometer_api_paste_ini)
expect(dependency[0].source).to eq(package)
expect(dependency[0].source).to eq(anchor)
end
end

8
spec/unit/type/ceilometer_config_spec.rb

@ -51,14 +51,14 @@ describe 'Puppet::Type.type(:ceilometer_config)' do
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should autorequire the package that install the file' do
it 'should autorequire the pachage that install the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => 'ceilometer-common')
catalog.add_resource package, @ceilometer_config
anchor = Puppet::Type.type(:anchor).new(:name => 'ceilometer::install::end')
catalog.add_resource anchor, @ceilometer_config
dependency = @ceilometer_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@ceilometer_config)
expect(dependency[0].source).to eq(package)
expect(dependency[0].source).to eq(anchor)
end
end

Loading…
Cancel
Save