Skip to content

Commit

Permalink
Merge 0b277c6 into 3f94e94
Browse files Browse the repository at this point in the history
  • Loading branch information
cthorn42 authored Feb 15, 2022
2 parents 3f94e94 + 0b277c6 commit 406224d
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/beaker-puppet/install_utils/foss_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,9 @@ def install_puppet_from_dmg_on( hosts, opts )
raise "You need to specify versions for OSX host\n eg. install_puppet({:version => '3.6.2',:facter_version => '2.1.0',:hiera_version => '1.3.4',})"
end

on host, "curl -O #{opts[:mac_download_url]}/puppet-#{puppet_ver}.dmg"
on host, "curl -O #{opts[:mac_download_url]}/facter-#{facter_ver}.dmg"
on host, "curl -O #{opts[:mac_download_url]}/hiera-#{hiera_ver}.dmg"
on host, "curl --location --remote-name #{opts[:mac_download_url]}/puppet-#{puppet_ver}.dmg"
on host, "curl --location --remote-name #{opts[:mac_download_url]}/facter-#{facter_ver}.dmg"
on host, "curl --location --remote-name #{opts[:mac_download_url]}/hiera-#{hiera_ver}.dmg"

host.install_package("puppet-#{puppet_ver}")
host.install_package("facter-#{facter_ver}")
Expand Down Expand Up @@ -815,7 +815,7 @@ def install_puppet_agent_from_dmg_on(hosts, opts)

pkg_name = "puppet-agent-#{agent_version}*"
dmg_name = "puppet-agent-#{agent_version}-1.osx#{version}.dmg"
on host, "curl -O #{download_url}/#{dmg_name}"
on host, "curl --location --remote-name #{download_url}/#{dmg_name}"

host.install_package(pkg_name)

Expand All @@ -826,16 +826,28 @@ def install_puppet_agent_from_dmg_on(hosts, opts)
# Returns the latest puppet-agent version number from a given url.
#
# @param [String] url URL containing list of puppet-agent packages.
# Example: https://downloads.puppetlabs.com/mac/10.11/PC1/x86_64
# Example: https://downloads.puppetlabs.com/mac/puppet7/10.15/x86_64/
#
# @return [String] version puppet-agent version number (e.g. 1.4.1)
# Empty string if none found.
# @api private
def get_latest_puppet_agent_build_from_url(url)
require 'oga'
require 'net/http'
body = Net::HTTP.get(URI.parse("#{url}/index_by_lastModified_reverse.html"))
document = Oga.parse_html(body)

full_url = "#{url}/index_by_lastModified_reverse.html"
response = Net::HTTP.get_response(URI(full_url))
counter = 0

# Redirect following
while response.code == '301' && counter < 15
response = Net::HTTP.get_response(URI.parse(Net::HTTP.get_response(URI(full_url))['location']))
counter = counter + 1
end

raise "The URL for puppet-agent download, #{full_url}, hit the limit on the number of redirects, #{counter}" if response.code == '301'

document = Oga.parse_html(response.body)
agents = document.xpath('//a[contains(@href, "puppet-agent")]')

latest_match = agents.shift.attributes[0].value
Expand Down

0 comments on commit 406224d

Please sign in to comment.