Browse Source

Use anchor to require necessary packages

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

Change-Id: I6ff6b8c77a37c85cb7b80d7b9b7dba78e9aa6668
changes/26/725126/3
Takashi Kajinami 1 year ago
parent
commit
f8ff0d98b4
4 changed files with 15 additions and 24 deletions
  1. +2
    -2
      lib/puppet/type/gnocchi_api_paste_ini.rb
  2. +2
    -2
      lib/puppet/type/gnocchi_config.rb
  3. +7
    -17
      spec/unit/type/gnocchi_api_paste_ini_spec.rb
  4. +4
    -3
      spec/unit/type/gnocchi_config_spec.rb

+ 2
- 2
lib/puppet/type/gnocchi_api_paste_ini.rb View File

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

+ 2
- 2
lib/puppet/type/gnocchi_config.rb View File

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

+ 7
- 17
spec/unit/type/gnocchi_api_paste_ini_spec.rb View File

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

+ 4
- 3
spec/unit/type/gnocchi_config_spec.rb View File

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

Loading…
Cancel
Save