diff --git a/Gemfile b/Gemfile index 5e84da7..6167a21 100644 --- a/Gemfile +++ b/Gemfile @@ -1,48 +1,3 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org" gemspec -#def location_for(place, fake_version = nil) -# if place =~ /^(git:[^#]*)#(.*)/ -# [fake_version, { :git => $1, :branch => $2, :require => false }].compact -# elsif place =~ /^file:\/\/(.*)/ -# ['>= 0', { :path => File.expand_path($1), :require => false }] -# else -# [place, { :require => false }] -# end -#end -# -#group :development, :unit_tests do -# gem 'rspec-core', '3.1.7', :require => false -# gem 'puppetlabs_spec_helper', :require => false -# gem 'simplecov', :require => false -# gem 'puppet_facts', :require => false -# gem 'json', :require => false -#end -# -#group :system_tests do -# if beaker_version = ENV['BEAKER_VERSION'] -# gem 'beaker', *location_for(beaker_version) -# end -# if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] -# gem 'beaker-rspec', *location_for(beaker_rspec_version) -# else -# gem 'beaker-rspec', :require => false -# end -# gem 'serverspec', :require => false -#end -# -# -# -#if facterversion = ENV['FACTER_GEM_VERSION'] -# gem 'facter', facterversion, :require => false -#else -# gem 'facter', :require => false -#end -# -#if puppetversion = ENV['PUPPET_GEM_VERSION'] -# gem 'puppet', puppetversion, :require => false -#else -# gem 'puppet', :require => false -#end -# -## vim:ft=ruby diff --git a/beaker-puppet_install_helper.gemspec b/beaker-puppet_install_helper.gemspec index ce1185b..5b3b486 100644 --- a/beaker-puppet_install_helper.gemspec +++ b/beaker-puppet_install_helper.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "beaker-puppet_install_helper" - s.version = '0.1.1' + s.version = '0.1.2' s.authors = ["Puppetlabs"] s.email = ["hunter@puppetlabs.com"] s.homepage = "https://github.com/puppetlabs/beaker-puppet_install_helper" diff --git a/lib/beaker/puppet_install_helper.rb b/lib/beaker/puppet_install_helper.rb index f44e738..7ac6c6a 100644 --- a/lib/beaker/puppet_install_helper.rb +++ b/lib/beaker/puppet_install_helper.rb @@ -2,7 +2,7 @@ module Beaker::PuppetInstallHelper def run_puppet_install_helper(type_arg=find_install_type,version=ENV["PUPPET_VERSION"]) - run_puppet_install_helper_on(hosts,type_arg,version) + run_puppet_install_helper_on(default,type_arg,version) end # Takes a host(s) object, install type string, and install version string. @@ -26,9 +26,7 @@ def run_puppet_install_helper_on(hosts,type_arg=find_install_type,version=ENV["P case type when "pe" # This will skip hosts that are not supported - install_pe_on(hosts,{"pe_ver" => version}) - add_pe_defaults_on(hosts) - add_puppet_paths_on(hosts) + install_pe_on(Array(hosts),{"pe_ver" => version}) when "foss" opts = { :version => version, @@ -36,16 +34,18 @@ def run_puppet_install_helper_on(hosts,type_arg=find_install_type,version=ENV["P } install_puppet_on(hosts, opts) + # XXX install_puppet_on() will only add_aio_defaults_on when the nodeset + # type == 'aio', but we don't want to depend on that. if opts[:version] and not version_is_less(opts[:version], '4.0.0') add_aio_defaults_on(hosts) - else - add_foss_defaults_on(hosts) + add_puppet_paths_on(hosts) end - add_puppet_paths_on(hosts) Array(hosts).each do |host| if fact_on(host,"osfamily") != "windows" on host, "mkdir -p #{host["distmoduledir"]}" - on host, "touch #{host["hieraconf"]}" + # XXX Maybe this can just be removed? What PE/puppet version needs + # it? + on host, "touch #{host.puppet["hiera_config"]}" end if fact_on(host, "operatingsystem") == "Debian" on host, "echo 'export PATH=/var/lib/gems/1.8/bin/:${PATH}' >> ~/.bashrc" @@ -57,6 +57,8 @@ def run_puppet_install_helper_on(hosts,type_arg=find_install_type,version=ENV["P when "agent" # This will fail on hosts that are not supported; use foss and specify a 4.x version instead install_puppet_agent_on(hosts, {:version => version}) + # XXX install_puppet_agent_on() will only add_aio_defaults_on when the + # nodeset type == 'aio', but we don't want to depend on that. add_aio_defaults_on(hosts) add_puppet_paths_on(hosts) else diff --git a/spec/unit/beaker/puppet_install_helper_spec.rb b/spec/unit/beaker/puppet_install_helper_spec.rb index d1e03a1..db65878 100644 --- a/spec/unit/beaker/puppet_install_helper_spec.rb +++ b/spec/unit/beaker/puppet_install_helper_spec.rb @@ -5,8 +5,13 @@ Class.new { include Beaker::PuppetInstallHelper } end let :hosts do - host = { "distmoduledir" => "/dne", "hieraconf" => "/dne" } - [ host, host, host, ] + foss_host = double(:is_pe? => false) + pe_host = double(:is_pe? => true) + allow(foss_host).to receive(:[]).with("distmoduledir").and_return("/dne") + allow(foss_host).to receive(:puppet).and_return({"hiera_config" => "/dne"}) + allow(pe_host).to receive(:[]).with("distmoduledir").and_return("/dne") + allow(pe_host).to receive(:puppet).and_return({"hiera_config" => "/dne"}) + [foss_host, pe_host] end before :each do allow(subject).to receive(:on) @@ -18,33 +23,29 @@ end describe '#run_puppet_install_helper' do before :each do - allow(subject).to receive(:default).and_return(double(:is_pe? => false)) allow(subject).to receive(:hosts).and_return(hosts) + allow(subject).to receive(:default).and_return(hosts[0]) end it 'calls run_puppet_install_helper_on on each host' do - expect(subject).to receive(:run_puppet_install_helper_on).with(hosts,"foss",nil) + expect(subject).to receive(:run_puppet_install_helper_on).with(hosts[0],"foss",nil) subject.run_puppet_install_helper end it 'calls run_puppet_install_helper_on on each host with a version ' do ENV["PUPPET_VERSION"] = "4.1.0" - expect(subject).to receive(:run_puppet_install_helper_on).with(hosts,"foss","4.1.0") + expect(subject).to receive(:run_puppet_install_helper_on).with(hosts[0],"foss","4.1.0") subject.run_puppet_install_helper end end describe '#run_puppet_install_helper_on' do context "for default" do it "uses foss by default for non-pe nodes" do - expect(subject).to receive(:default).and_return(double(:is_pe? => false)) + expect(subject).to receive(:default).and_return(hosts[0]) expect(subject).to receive(:install_puppet_on).with(hosts,{:version => nil,:default_action => "gem_install"}) - expect(subject).to receive(:add_foss_defaults_on).with(hosts) - expect(subject).to receive(:add_puppet_paths_on).with(hosts) subject.run_puppet_install_helper_on(hosts) end it "uses PE by default for PE nodes" do - expect(subject).to receive(:default).and_return(double(:is_pe? => true)) + expect(subject).to receive(:default).and_return(hosts[1]) expect(subject).to receive(:install_pe_on).with(hosts,{"pe_ver" => nil}) - expect(subject).to receive(:add_pe_defaults_on).with(hosts) - expect(subject).to receive(:add_puppet_paths_on).with(hosts) subject.run_puppet_install_helper_on(hosts) end end @@ -52,16 +53,12 @@ it "uses foss explicitly" do ENV["PUPPET_INSTALL_TYPE"] = "foss" expect(subject).to receive(:install_puppet_on).with(hosts,{:version => nil,:default_action => "gem_install"}) - expect(subject).to receive(:add_foss_defaults_on).with(hosts) - expect(subject).to receive(:add_puppet_paths_on).with(hosts) subject.run_puppet_install_helper_on(hosts) end it "uses foss with a version" do ENV["PUPPET_INSTALL_TYPE"] = "foss" ENV["PUPPET_VERSION"] = "3.8.1" expect(subject).to receive(:install_puppet_on).with(hosts,{:version => "3.8.1",:default_action => "gem_install"}) - expect(subject).to receive(:add_foss_defaults_on).with(hosts) - expect(subject).to receive(:add_puppet_paths_on).with(hosts) subject.run_puppet_install_helper_on(hosts) end it "uses foss with a >4 version detects AIO" do @@ -77,16 +74,12 @@ it "uses PE explicitly" do ENV["PUPPET_INSTALL_TYPE"] = "pe" expect(subject).to receive(:install_pe_on).with(hosts,{"pe_ver" => nil}) - expect(subject).to receive(:add_pe_defaults_on).with(hosts) - expect(subject).to receive(:add_puppet_paths_on).with(hosts) subject.run_puppet_install_helper_on(hosts) end it "uses PE with a version" do ENV["PUPPET_INSTALL_TYPE"] = "pe" ENV["PUPPET_VERSION"] = "3.8.1" expect(subject).to receive(:install_pe_on).with(hosts,{"pe_ver" => "3.8.1"}) - expect(subject).to receive(:add_pe_defaults_on).with(hosts) - expect(subject).to receive(:add_puppet_paths_on).with(hosts) subject.run_puppet_install_helper_on(hosts) end end