From 141df2598d50b257c59f016b60259b667b3a0e71 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 4 May 2020 15:07:03 +0900 Subject: [PATCH] Use anchor to require necessary packages ... so that correct packages are required without re-defining them in resource implementations. Change-Id: I3b3f9268d03c3f9d6d67806fd8854b24a31ff03d --- lib/puppet/type/magnum_api_paste_ini.rb | 4 ++-- lib/puppet/type/magnum_config.rb | 4 ++-- spec/unit/type/magnum_api_paste_ini_spec.rb | 22 ++++++--------------- spec/unit/type/magnum_config_spec.rb | 8 ++++---- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/lib/puppet/type/magnum_api_paste_ini.rb b/lib/puppet/type/magnum_api_paste_ini.rb index 36b32a6..7eccdde 100644 --- a/lib/puppet/type/magnum_api_paste_ini.rb +++ b/lib/puppet/type/magnum_api_paste_ini.rb @@ -45,8 +45,8 @@ Puppet::Type.newtype(:magnum_api_paste_ini) do defaultto('') end - autorequire(:package) do - 'magnum-common' + autorequire(:anchor) do + ['magnum::install::end'] end end diff --git a/lib/puppet/type/magnum_config.rb b/lib/puppet/type/magnum_config.rb index 8b82434..2b55fca 100644 --- a/lib/puppet/type/magnum_config.rb +++ b/lib/puppet/type/magnum_config.rb @@ -46,8 +46,8 @@ Puppet::Type.newtype(:magnum_config) do defaultto('') end - autorequire(:package) do - 'magnum-common' + autorequire(:anchor) do + ['magnum::install::end'] end end diff --git a/spec/unit/type/magnum_api_paste_ini_spec.rb b/spec/unit/type/magnum_api_paste_ini_spec.rb index 8ece209..a94b500 100644 --- a/spec/unit/type/magnum_api_paste_ini_spec.rb +++ b/spec/unit/type/magnum_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/magnum_api_paste_ini' + describe 'Puppet::Type.type(:magnum_api_paste_ini)' do before :each do @magnum_api_paste_ini = Puppet::Type.type(:magnum_api_paste_ini).new(:name => 'DEFAULT/foo', :value => 'bar') end + it 'should accept a valid value' do @magnum_api_paste_ini[:value] = 'bar' expect(@magnum_api_paste_ini[:value]).to eq('bar') @@ -23,12 +13,12 @@ describe 'Puppet::Type.type(:magnum_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 => 'magnum-common') - catalog.add_resource package, @magnum_api_paste_ini + anchor = Puppet::Type.type(:anchor).new(:name => 'magnum::install::end') + catalog.add_resource anchor, @magnum_api_paste_ini dependency = @magnum_api_paste_ini.autorequire expect(dependency.size).to eq(1) expect(dependency[0].target).to eq(@magnum_api_paste_ini) - expect(dependency[0].source).to eq(package) + expect(dependency[0].source).to eq(anchor) end end diff --git a/spec/unit/type/magnum_config_spec.rb b/spec/unit/type/magnum_config_spec.rb index 0d84427..51dfc1f 100644 --- a/spec/unit/type/magnum_config_spec.rb +++ b/spec/unit/type/magnum_config_spec.rb @@ -1,5 +1,6 @@ require 'puppet' require 'puppet/type/magnum_config' + describe 'Puppet::Type.type(:magnum_config)' do before :each do @magnum_config = Puppet::Type.type(:magnum_config).new(:name => 'DEFAULT/foo', :value => 'bar') @@ -52,13 +53,12 @@ describe 'Puppet::Type.type(:magnum_config)' do it 'should autorequire the package that install the file' do catalog = Puppet::Resource::Catalog.new - package = Puppet::Type.type(:package).new(:name => 'magnum-common') - catalog.add_resource package, @magnum_config + anchor = Puppet::Type.type(:anchor).new(:name => 'magnum::install::end') + catalog.add_resource anchor, @magnum_config dependency = @magnum_config.autorequire expect(dependency.size).to eq(1) expect(dependency[0].target).to eq(@magnum_config) - expect(dependency[0].source).to eq(package) + expect(dependency[0].source).to eq(anchor) end - end