From 26944d9e50536d506ade918e040e946828d872e6 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 4 May 2020 15:26:32 +0900 Subject: [PATCH] Use anchor to require necessary packages ... so that correct packages are required without re-defining them in resource implementations. Change-Id: I9e1e3443659c41fbacb50639cb605686729eb2a2 --- lib/puppet/type/trove_api_paste_ini.rb | 4 ++-- lib/puppet/type/trove_conductor_config.rb | 4 ++-- lib/puppet/type/trove_config.rb | 4 ++-- lib/puppet/type/trove_guestagent_config.rb | 4 ++-- spec/unit/type/trove_api_paste_ini_spec.rb | 24 +++++++++++++++++++ spec/unit/type/trove_conductor_config_spec.rb | 7 +++--- .../type/trove_conductor_guestagent_spec.rb | 7 +++--- spec/unit/type/trove_config_spec.rb | 7 +++--- 8 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 spec/unit/type/trove_api_paste_ini_spec.rb diff --git a/lib/puppet/type/trove_api_paste_ini.rb b/lib/puppet/type/trove_api_paste_ini.rb index 8c402091..90307c64 100644 --- a/lib/puppet/type/trove_api_paste_ini.rb +++ b/lib/puppet/type/trove_api_paste_ini.rb @@ -45,7 +45,7 @@ Puppet::Type.newtype(:trove_api_paste_ini) do defaultto('') end - autorequire(:package) do - 'trove-api' + autorequire(:anchor) do + ['trove::install::end'] end end diff --git a/lib/puppet/type/trove_conductor_config.rb b/lib/puppet/type/trove_conductor_config.rb index d5ab3426..07663068 100644 --- a/lib/puppet/type/trove_conductor_config.rb +++ b/lib/puppet/type/trove_conductor_config.rb @@ -46,7 +46,7 @@ Puppet::Type.newtype(:trove_conductor_config) do defaultto('') end - autorequire(:package) do - 'trove-conductor' + autorequire(:anchor) do + ['trove::install::end'] end end diff --git a/lib/puppet/type/trove_config.rb b/lib/puppet/type/trove_config.rb index 81491ebe..5351f484 100644 --- a/lib/puppet/type/trove_config.rb +++ b/lib/puppet/type/trove_config.rb @@ -46,7 +46,7 @@ Puppet::Type.newtype(:trove_config) do defaultto('') end - autorequire(:package) do - 'trove-api' + autorequire(:anchor) do + ['trove::install::end'] end end diff --git a/lib/puppet/type/trove_guestagent_config.rb b/lib/puppet/type/trove_guestagent_config.rb index a15e17dc..82ba3366 100644 --- a/lib/puppet/type/trove_guestagent_config.rb +++ b/lib/puppet/type/trove_guestagent_config.rb @@ -46,7 +46,7 @@ Puppet::Type.newtype(:trove_guestagent_config) do defaultto('') end - autorequire(:package) do - 'trove-guestagent' + autorequire(:anchor) do + ['trove::install::end'] end end diff --git a/spec/unit/type/trove_api_paste_ini_spec.rb b/spec/unit/type/trove_api_paste_ini_spec.rb new file mode 100644 index 00000000..b503c0f9 --- /dev/null +++ b/spec/unit/type/trove_api_paste_ini_spec.rb @@ -0,0 +1,24 @@ +require 'puppet' +require 'puppet/type/trove_api_paste_ini' + +describe 'Puppet::Type.type(:trove_api_paste_ini)' do + before :each do + @trove_api_paste_ini = Puppet::Type.type(:trove_api_paste_ini).new(:name => 'DEFAULT/foo', :value => 'bar') + end + + it 'should accept a valid value' do + @trove_api_paste_ini[:value] = 'bar' + expect(@trove_api_paste_ini[:value]).to eq('bar') + end + + it 'should autorequire the package that install the file' do + catalog = Puppet::Resource::Catalog.new + anchor = Puppet::Type.type(:anchor).new(:name => 'trove::install::end') + catalog.add_resource anchor, @trove_api_paste_ini + dependency = @trove_api_paste_ini.autorequire + expect(dependency.size).to eq(1) + expect(dependency[0].target).to eq(@trove_api_paste_ini) + expect(dependency[0].source).to eq(anchor) + end + +end diff --git a/spec/unit/type/trove_conductor_config_spec.rb b/spec/unit/type/trove_conductor_config_spec.rb index b63978a3..e8eeaf9a 100644 --- a/spec/unit/type/trove_conductor_config_spec.rb +++ b/spec/unit/type/trove_conductor_config_spec.rb @@ -1,3 +1,4 @@ +require 'puppet' require 'puppet/type/trove_conductor_config' describe 'Puppet::Type.type(:trove_conductor_config)' do @@ -7,11 +8,11 @@ describe 'Puppet::Type.type(:trove_conductor_config)' do it 'should autorequire the package that installs the file' do catalog = Puppet::Resource::Catalog.new - package = Puppet::Type.type(:package).new(:name => 'trove-conductor') - catalog.add_resource package, @trove_conductor_config + anchor = Puppet::Type.type(:anchor).new(:name => 'trove::install::end') + catalog.add_resource anchor, @trove_conductor_config dependency = @trove_conductor_config.autorequire expect(dependency.size).to eq(1) expect(dependency[0].target).to eq(@trove_conductor_config) - expect(dependency[0].source).to eq(package) + expect(dependency[0].source).to eq(anchor) end end diff --git a/spec/unit/type/trove_conductor_guestagent_spec.rb b/spec/unit/type/trove_conductor_guestagent_spec.rb index 77e1ff7a..184a3f0b 100644 --- a/spec/unit/type/trove_conductor_guestagent_spec.rb +++ b/spec/unit/type/trove_conductor_guestagent_spec.rb @@ -1,3 +1,4 @@ +require 'puppet' require 'puppet/type/trove_guestagent_config' describe 'Puppet::Type.type(:trove_guestagent_config)' do @@ -7,11 +8,11 @@ describe 'Puppet::Type.type(:trove_guestagent_config)' do it 'should autorequire the package that installs the file' do catalog = Puppet::Resource::Catalog.new - package = Puppet::Type.type(:package).new(:name => 'trove-guestagent') - catalog.add_resource package, @trove_guestagent_config + anchor = Puppet::Type.type(:anchor).new(:name => 'trove::install::end') + catalog.add_resource anchor, @trove_guestagent_config dependency = @trove_guestagent_config.autorequire expect(dependency.size).to eq(1) expect(dependency[0].target).to eq(@trove_guestagent_config) - expect(dependency[0].source).to eq(package) + expect(dependency[0].source).to eq(anchor) end end diff --git a/spec/unit/type/trove_config_spec.rb b/spec/unit/type/trove_config_spec.rb index 2df28597..72b74dc9 100644 --- a/spec/unit/type/trove_config_spec.rb +++ b/spec/unit/type/trove_config_spec.rb @@ -1,5 +1,6 @@ require 'puppet' require 'puppet/type/trove_config' + describe 'Puppet::Type.type(:trove_config)' do before :each do @trove_config = Puppet::Type.type(:trove_config).new(:name => 'DEFAULT/foo', :value => 'bar') @@ -52,11 +53,11 @@ describe 'Puppet::Type.type(:trove_config)' do it 'should autorequire the package that installs the file' do catalog = Puppet::Resource::Catalog.new - package = Puppet::Type.type(:package).new(:name => 'trove-api') - catalog.add_resource package, @trove_config + anchor = Puppet::Type.type(:anchor).new(:name => 'trove::install::end') + catalog.add_resource anchor, @trove_config dependency = @trove_config.autorequire expect(dependency.size).to eq(1) expect(dependency[0].target).to eq(@trove_config) - expect(dependency[0].source).to eq(package) + expect(dependency[0].source).to eq(anchor) end end