Skip to content

Commit

Permalink
(maint) Update beaker to support pupppet5 style installation
Browse files Browse the repository at this point in the history
  • Loading branch information
melissa committed Oct 9, 2017
1 parent bddf204 commit 1d37dd3
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 17 deletions.
51 changes: 38 additions & 13 deletions lib/beaker-puppet/install_utils/foss_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ def configure_puppet_on(hosts, opts = {})
# @api private
def install_puppet_from_rpm_on( hosts, opts )
block_on hosts do |host|
if host[:type] == 'aio'
if opts[:puppet_collection] && opts[:puppet_collection].match(/puppet\d*/)
install_puppetlabs_release_repo(host,opts[:puppet_collection],opts)
elsif host[:type] == 'aio'
install_puppetlabs_release_repo(host,'pc1',opts)
else
install_puppetlabs_release_repo(host,nil,opts)
Expand Down Expand Up @@ -590,14 +592,22 @@ def install_puppet_agent_from_msi_on(hosts, opts)
end

# @api private
def install_a_puppet_msi_on(hosts, opts)
block_on hosts do |host|
def msi_link_path(host, opts)
if opts[:puppet_collection] && opts[:puppet_collection].match(/puppet\d*/)
link = "#{opts[:win_download_url]}/#{opts[:puppet_collection]}/#{host['dist']}.msi"
else
link = "#{opts[:win_download_url]}/#{host['dist']}.msi"
if not link_exists?( link )
raise "Puppet MSI at #{link} does not exist!"
end

end
if not link_exists?( link )
raise "Puppet MSI at #{link} does not exist!"
end
link
end

# @api private
def install_a_puppet_msi_on(hosts, opts)
block_on hosts do |host|
link = msi_link_path(host, opts)
msi_download_path = "#{host.system_temp_path}\\#{host['dist']}.msi"

if host.is_cygwin?
Expand Down Expand Up @@ -709,14 +719,18 @@ def install_puppet_from_dmg_on( hosts, opts )
# @api private
def install_puppet_agent_from_dmg_on(hosts, opts)
opts[:puppet_collection] ||= 'PC1'
opts[:puppet_collection] = opts[:puppet_collection].upcase #needs to be upcase, more lovely consistency
opts[:puppet_collection] = opts[:puppet_collection].upcase if opts[:puppet_collection].match(/pc1/i)
block_on hosts do |host|

add_role(host, 'aio') #we are installing agent, so we want aio role

variant, version, arch, codename = host['platform'].to_array

download_url = "#{opts[:mac_download_url]}/#{version}/#{opts[:puppet_collection]}/#{arch}"
if opts[:puppet_collection].match(/puppet\d*/)
download_url = "#{opts[:mac_download_url]}/#{opts[:puppet_collection]}/#{version}/#{arch}"
else
download_url = "#{opts[:mac_download_url]}/#{version}/#{opts[:puppet_collection]}/#{arch}"
end

latest = get_latest_puppet_agent_build_from_url(download_url)

Expand Down Expand Up @@ -913,7 +927,7 @@ def install_puppet_from_gem_on( hosts, opts )
def install_puppetlabs_release_repo_on( hosts, repo = nil, opts = options )
block_on hosts do |host|
variant, version, arch, codename = host['platform'].to_array
repo_name = repo.nil? ? '' : '-' + repo
repo_name = repo || opts[:puppet_collection] || ''
opts = FOSS_DEFAULT_DOWNLOAD_URLS.merge(opts)

case variant
Expand All @@ -927,8 +941,14 @@ def install_puppetlabs_release_repo_on( hosts, repo = nil, opts = options )
variant_url_value = 'cisco-wrlinux'
version = '7'
end
remote = "%s/puppetlabs-release%s-%s-%s.noarch.rpm" %
[opts[:release_yum_repo_url], repo_name, variant_url_value, version]
if repo_name.match(/puppet\d*/)
remote = "%s/%s/%s-release-%s-%s.noarch.rpm" %
[opts[:release_yum_repo_url], repo_name, repo_name, variant_url_value, version]
else
repo_name = '-' + repo_name unless repo_name.empty?
remote = "%s/puppetlabs-release%s-%s-%s.noarch.rpm" %
[opts[:release_yum_repo_url], repo_name, variant_url_value, version]
end

if variant == 'cisco_nexus'
# cisco nexus requires using yum to install the repo
Expand All @@ -943,7 +963,12 @@ def install_puppetlabs_release_repo_on( hosts, repo = nil, opts = options )
end

when /^(debian|ubuntu|cumulus|huaweios)$/
deb = "puppetlabs-release%s-%s.deb" % [repo_name, codename]
if repo_name.match(/puppet\d*/)
deb = "%s-release-%s.deb" % [repo_name, codename]
else
repo_name = '-' + repo_name unless repo_name.empty?
deb = "puppetlabs-release%s-%s.deb" % [repo_name, codename]
end

remote = URI.join( opts[:release_apt_repo_url], deb )

Expand Down
80 changes: 76 additions & 4 deletions spec/beaker-puppet/install_utils/foss_utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ def logger
end

context 'install_puppet_from_rpm_on' do
it 'installs puppet release repo when set' do
expect(subject).to receive(:install_puppetlabs_release_repo).with(el6hostaio,'puppet',{:puppet_collection => 'puppet'})

subject.install_puppet_from_rpm_on( el6hostaio, {:puppet_collection => 'puppet'} )
end

it 'installs PC1 release repo when AIO' do
expect(subject).to receive(:install_puppetlabs_release_repo).with(el6hostaio,'pc1',{})

Expand Down Expand Up @@ -688,6 +694,55 @@ def logger
allow( subject ).to receive( :options ) { opts }
end

context 'on el 7' do
let( :platform ) { Beaker::Platform.new( 'el-7-x86_64' ) }
it 'returns the correct url when repo is set to puppet8' do
expect( host ).to receive( :install_package_with_rpm ).with( /puppet8\/puppet8-release-el-7\.noarch\.rpm$/, '--replacepkgs', {:package_proxy=>false} )
subject.install_puppetlabs_release_repo_on( host, 'puppet8')
end
it 'returns the correct url when opts[:puppet_collection] is set to puppet14' do
expect( host ).to receive( :install_package_with_rpm ).with( /puppet14\/puppet14-release-el-7\.noarch\.rpm$/, '--replacepkgs', {:package_proxy=>false} )
subject.install_puppetlabs_release_repo_on( host, nil, {:puppet_collection => 'puppet14'})
end
it 'returns the correct url when both repo and opts[:puppet_collection] are nil' do
expect( host ).to receive( :install_package_with_rpm ).with( /puppetlabs-release-el-7\.noarch\.rpm$/, '--replacepkgs', {:package_proxy=>false} )
subject.install_puppetlabs_release_repo_on( host )
end
it 'returns the correct url when repo is set to pc1' do
expect( host ).to receive( :install_package_with_rpm ).with( /puppetlabs-release-pc1-el-7\.noarch\.rpm$/, '--replacepkgs', {:package_proxy=>false} )
subject.install_puppetlabs_release_repo_on( host, 'pc1' )
end
end

context 'on debian 8' do
let( :platform ) { Beaker::Platform.new( 'debian-8-i386' ) }
it 'returns the correct url when repo is set to puppet4' do
expect( subject ).to receive( :on ).with( host, /puppet4-release-jessie\.deb$/ ).once
expect( subject ).to receive( :on ).with( host, "dpkg -i --force-all /tmp/puppet.deb" ).once
expect( subject ).to receive( :on ).with( host, "apt-get update" ).once
subject.install_puppetlabs_release_repo_on( host, 'puppet4' )
end
it 'returns the correct url when opts[:puppet_collection] is set to puppet7' do
expect( subject ).to receive( :on ).with( host, /puppet7-release-jessie\.deb$/ ).once
expect( subject ).to receive( :on ).with( host, "dpkg -i --force-all /tmp/puppet.deb" ).once
expect( subject ).to receive( :on ).with( host, "apt-get update" ).once
subject.install_puppetlabs_release_repo_on( host, nil, {:puppet_collection => 'puppet7'} )
end
it 'returns the correct url when both repo and opts[:puppet_collection] are nil' do
expect( subject ).to receive( :on ).with( host, /puppetlabs-release-jessie\.deb$/ ).once
expect( subject ).to receive( :on ).with( host, "dpkg -i --force-all /tmp/puppet.deb" ).once
expect( subject ).to receive( :on ).with( host, "apt-get update" ).once
subject.install_puppetlabs_release_repo_on( host )
end
it 'returns the correct url when both repo is set to pc1' do
expect( subject ).to receive( :on ).with( host, /puppetlabs-release-pc1-jessie\.deb$/ ).once
expect( subject ).to receive( :on ).with( host, "dpkg -i --force-all /tmp/puppet.deb" ).once
expect( subject ).to receive( :on ).with( host, "apt-get update" ).once
subject.install_puppetlabs_release_repo_on( host, 'pc1' )
end
end


context 'on cisco platforms' do
context 'version 5' do
let( :platform ) { Beaker::Platform.new( 'cisco_nexus-7-x86_64' ) }
Expand Down Expand Up @@ -817,19 +872,36 @@ def stub_uninteresting_portions_of_install_puppetlabs_dev_repo!

end

describe '#install_puppet_agent_from_msi_on' do
describe '#msi_link_path' do
let( :opts ) { { :puppet_agent_version => 'VERSION', :win_download_url => 'http://downloads.puppetlabs.com/windows' } }
let( :platform ) { 'windows' }
let( :host ) { { :platform => platform } }
let( :host ) { { :platform => platform, 'dist' => 'puppet-agent-VERSION-x64' } }

it 'returns the right link when puppet collection is set' do
allow(subject).to receive(:link_exists?).with(anything()).and_return( true )

expect(subject.msi_link_path( host, opts.merge({:puppet_collection => 'puppet'}) )).to eq "#{opts[:win_download_url]}/puppet/puppet-agent-VERSION-x64.msi"
end

it 'returns the right link when puppet collection is not set' do
expect(subject).to receive(:link_exists?).with(anything()).and_return( true )

expect(subject.msi_link_path( host, opts )).to eq "#{opts[:win_download_url]}/puppet-agent-VERSION-x64.msi"
end

it 'returns error when link incorrect' do
allow(subject).to receive(:link_exists?).with(anything()).and_return( false )
expect( host ).to receive( :is_x86_64? ).and_return( true )

expect{
subject.install_puppet_agent_from_msi_on( host, opts )
subject.msi_link_path( host, opts )
}.to raise_error(RuntimeError, /Puppet MSI at http:\/\/downloads.puppetlabs.com\/windows\/puppet-agent-VERSION-x64.msi does not exist!/)
end
end

describe '#install_puppet_agent_from_msi_on' do
let( :opts ) { { :puppet_agent_version => 'VERSION', :win_download_url => 'http://downloads.puppetlabs.com/windows' } }
let( :platform ) { 'windows' }
let( :host ) { { :platform => platform } }

it 'uses x86 msi when host is_x86_64 and install_32 is set on the host' do
host['install_32'] = true
Expand Down

0 comments on commit 1d37dd3

Please sign in to comment.