Use anchor to require necessary packages

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

Change-Id: Ife5e91471449f27817297a9f7d35c6e0dc4fa82c
This commit is contained in:
Takashi Kajinami 2020-05-04 14:59:18 +09:00
parent b2a061c380
commit 9098cf80a6
4 changed files with 11 additions and 64 deletions

View File

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

View File

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

View File

@ -1,31 +1,5 @@
#
# these tests are a little concerning b/c they are hacking around the
# modulepath, so these tests will not catch issues that may eventually arise
# related to loading these plugins.
# I could not, for the life of me, figure out how to programatcally set the modulepath
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'fixtures',
'modules',
'inifile',
'lib')
)
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'fixtures',
'modules',
'openstacklib',
'lib')
)
require 'spec_helper'
require 'puppet'
require 'puppet/type/ec2api_api_paste_ini'
describe Puppet::Type.type(:ec2api_api_paste_ini) do
before :each do
@ -79,12 +53,12 @@ describe Puppet::Type.type(:ec2api_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 => 'ec2api')
catalog.add_resource package, @ec2api_api_paste_ini
anchor = Puppet::Type.type(:anchor).new(:name => 'ec2api::install::end')
catalog.add_resource anchor, @ec2api_api_paste_ini
dependency = @ec2api_api_paste_ini.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@ec2api_api_paste_ini)
expect(dependency[0].source).to eq(package)
expect(dependency[0].source).to eq(anchor)
end
end

View File

@ -1,32 +1,5 @@
require 'puppet'
require 'puppet/type/ec2api_config'
require 'spec_helper'
#
# these tests are a little concerning b/c they are hacking around the
# modulepath, so these tests will not catch issues that may eventually arise
# related to loading these plugins.
# I could not, for the life of me, figure out how to programatcally set the modulepath
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'fixtures',
'modules',
'inifile',
'lib')
)
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'fixtures',
'modules',
'openstacklib',
'lib')
)
describe Puppet::Type.type(:ec2api_config) do
before :each do
@ -80,11 +53,11 @@ describe Puppet::Type.type(:ec2api_config) do
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => 'ec2api')
catalog.add_resource package, @ec2api_config
anchor = Puppet::Type.type(:anchor).new(:name => 'ec2api::install::end')
catalog.add_resource anchor, @ec2api_config
dependency = @ec2api_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@ec2api_config)
expect(dependency[0].source).to eq(package)
expect(dependency[0].source).to eq(anchor)
end
end