From 22c60182a007905c346ca50357c1a8c8409c7ca4 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 4 May 2020 15:30:41 +0900 Subject: [PATCH] Use anchor to require necessary packages ... so that correct packages are required without re-defining them in resource implementations. Change-Id: Id99c1f8343180fb46188dd6ebe0cf9a8414e7436 --- lib/puppet/type/vitrage_api_paste_ini.rb | 4 ++-- lib/puppet/type/vitrage_config.rb | 4 ++-- spec/unit/type/vitrage_api_paste_ini_spec.rb | 22 ++++++-------------- spec/unit/type/vitrage_config_spec.rb | 8 +++---- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/lib/puppet/type/vitrage_api_paste_ini.rb b/lib/puppet/type/vitrage_api_paste_ini.rb index 591f935..7bce11f 100644 --- a/lib/puppet/type/vitrage_api_paste_ini.rb +++ b/lib/puppet/type/vitrage_api_paste_ini.rb @@ -45,8 +45,8 @@ Puppet::Type.newtype(:vitrage_api_paste_ini) do defaultto('') end - autorequire(:package) do - 'vitrage-common' + autorequire(:anchor) do + ['vitrage::install::end'] end end diff --git a/lib/puppet/type/vitrage_config.rb b/lib/puppet/type/vitrage_config.rb index dec3c05..e25b095 100644 --- a/lib/puppet/type/vitrage_config.rb +++ b/lib/puppet/type/vitrage_config.rb @@ -46,8 +46,8 @@ Puppet::Type.newtype(:vitrage_config) do defaultto('') end - autorequire(:package) do - 'vitrage' + autorequire(:anchor) do + ['vitrage::install::end'] end end diff --git a/spec/unit/type/vitrage_api_paste_ini_spec.rb b/spec/unit/type/vitrage_api_paste_ini_spec.rb index aef24d0..291e429 100644 --- a/spec/unit/type/vitrage_api_paste_ini_spec.rb +++ b/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 diff --git a/spec/unit/type/vitrage_config_spec.rb b/spec/unit/type/vitrage_config_spec.rb index 1d9e20a..769a9bf 100644 --- a/spec/unit/type/vitrage_config_spec.rb +++ b/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