Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(QA-2620) update install_pe_client_tools_on to use package repo #26

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 71 additions & 44 deletions lib/beaker-pe/pe-client-tools/install_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,97 @@ module InstallUtils
module PEClientTools

def install_pe_client_tools_on(hosts, opts = {})
# FIXME: accomodate production released location(s)
#{{{
product = 'pe-client-tools'
required_keys = [:puppet_collection, :pe_client_tools_sha, :pe_client_tools_version]

unless required_keys.all? { |opt| opts.keys.include?(opt) }
unless required_keys.all? { |opt| opts.keys.include?(opt) && opts[opt]}
raise ArgumentError, "The keys #{required_keys.to_s} are required in the opts hash"
end
urls = { :dev_builds_url => "http://builds.delivery.puppetlabs.net",
}

opts = urls.merge(opts)

block_on hosts do |host|
package_name = nil
variant, version, arch, codename = host['platform'].to_array
package_name = ''
case host['platform']
when /el-|fedora|sles|centos|cisco_/
release_path = "#{opts[:dev_builds_url]}/#{product}/#{ opts[:pe_client_tools_sha] }/artifacts/#{variant}/#{version}/#{opts[:puppet_collection]}/#{arch}"
package_name = product.dup
package_name << "-#{opts[:pe_client_tools_version]}-1.#{variant}#{version}.#{arch}.rpm" if opts[:pe_client_tools_version]
when /debian|ubuntu|cumulus|huaweios/
release_path = "#{opts[:dev_builds_url]}/#{product}/#{ opts[:pe_client_tools_sha] }/artifacts/deb/#{codename}/#{opts[:puppet_collection]}"
package_name = product.dup
package_name << "_#{opts[:pe_client_tools_version]}-1#{host['platform'].codename}_#{arch}.deb" if opts[:pe_client_tools_version]
when /windows/
release_path = "#{opts[:dev_builds_url]}/#{product}/#{ opts[:pe_client_tools_sha] }/artifacts/#{variant}"
package_name = product.dup
package_name << "-#{opts[:pe_client_tools_version]}-x#{arch}.msi" if opts[:pe_client_tools_version]
when /osx/
release_path = "#{opts[:dev_builds_url]}/#{product}/#{ opts[:pe_client_tools_sha] }/artifacts/apple/#{version}/#{opts[:puppet_collection]}/#{arch}"
package_base = product.dup
package_base << "-#{opts[:pe_client_tools_version]}" if opts[:pe_client_tools_version]
package_name = package_base.dup
package_name << '-1' if opts[:pe_client_tools_version]
installer = package_name + '-installer.pkg'
package_name << ".#{variant}#{version}.dmg" if opts[:pe_client_tools_version]
else
raise "install_puppet_agent_on() called for unsupported " +
"platform '#{host['platform']}' on '#{host.name}'"
end

if package_name
case host['platform']
when /windows/
when /win/
package_name << product
release_path = "#{opts[:dev_builds_url]}/#{product}/#{ opts[:pe_client_tools_sha] }/artifacts/#{variant}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variant is not in scope here.

package_name << "-#{opts[:pe_client_tools_version]}-x#{arch}.msi"
generic_install_msi_on(host, File.join(release_path, package_name), {}, {:debug => true})
else
when /osx/
release_path = "#{opts[:dev_builds_url]}/#{product}/#{ opts[:pe_client_tools_sha] }/artifacts/apple/#{version}/#{opts[:puppet_collection]}/#{arch}"
package_base = product.dup
package_base << "-#{opts[:pe_client_tools_version]}"
package_name = package_base.dup
package_name << '-1' if opts[:pe_client_tools_version]
installer = package_name + '-installer.pkg'
package_name << ".#{variant}#{version}.dmg"
copy_dir_local = File.join('tmp', 'repo_configs')
fetch_http_file(release_path, package_name, copy_dir_local)
scp_to host, File.join(copy_dir_local, package_name), host.external_copy_base

if host['platform'] =~ /debian|ubuntu|cumulus|huaweios/
on host, "dpkg -i #{package_name}"
elsif host['platform'] =~ /osx/
host.generic_install_dmg(package_name, package_base, installer)
else
host.install_package( product )
end
end
host.generic_install_dmg(package_name, package_base, installer)
else
install_dev_repos_on(product, host, opts[:pe_client_tools_sha], '/tmp/repo_configs',{:dev_builds_url => opts[:dev_builds_url]})
host.install_package('pe-client-tools')
end
end
#}}}
end

# Taken from puppet acceptance lib
# Install development repos
def install_dev_repos_on(package, host, sha, repo_configs_dir, opts={})
platform = host['platform'] =~ /^(debian|ubuntu)/ ? host['platform'].with_version_codename : host['platform']
platform_configs_dir = File.join(repo_configs_dir, platform)

case platform
when /^(fedora|el|centos|sles)-(\d+)-(.+)$/
variant = (($1 == 'centos') ? 'el' : $1)
fedora_prefix = ((variant == 'fedora') ? 'f' : '')
version = $2
arch = $3

pattern = 'pl-%s-%s-%s-%s%s-%s.repo'

repo_filename = pattern % [
package,
sha,
variant,
fedora_prefix,
version,
arch
]

repo = fetch_http_file(
"%s/%s/%s/repo_configs/rpm/" % [opts[:dev_builds_url],package, sha],
repo_filename,
platform_configs_dir
)

if /sles/i.match(platform)
scp_to(host, repo, '/etc/zypp/repos.d/')
else
scp_to(host, repo, '/etc/yum.repos.d/')
end

when /^(debian|ubuntu)-([^-]+)-(.+)$/
variant = $1
version = $2
arch = $3

list = fetch_http_file(
"%s/%s/%s/repo_configs/deb/" % [opts[:dev_builds_url],package, sha],
"pl-%s-%s-%s.list" % [package, sha, version],
platform_configs_dir
)

scp_to host, list, '/etc/apt/sources.list.d'
on host, 'apt-get update'
else
host.logger.notify("No repository installation step for #{platform} yet...")
end
end
end
end
end
Expand Down
7 changes: 4 additions & 3 deletions spec/beaker-pe/pe-client-tools/installer_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ClassPEClientToolsMixedWithPatterns
let(:platform) { Beaker::Platform.new('el-6-x86_64') }
it 'installs' do
hosts.each do |host|
allow(subject). to receive(:fetch_http_file).with("http://builds.delivery.puppetlabs.net/pe-client-tools/#{opts[:pe_client_tools_sha]}/artifacts/el/6/PC1/x86_64", "pe-client-tools-#{opts[:pe_client_tools_version]}-1.el6.x86_64.rpm", "tmp/repo_configs")
allow(subject). to receive(:fetch_http_file).with("http://builds.delivery.puppetlabs.net/pe-client-tools/#{opts[:pe_client_tools_sha]}/repo_configs/rpm/", "pl-pe-client-tools-#{opts[:pe_client_tools_sha]}-el-6-x86_64.repo", "/tmp/repo_configs/el-6-x86_64")
allow(host). to receive(:external_copy_base)
expect(host).to receive(:install_package).with("pe-client-tools")
subject.install_pe_client_tools_on(host, opts)
Expand All @@ -35,9 +35,10 @@ class ClassPEClientToolsMixedWithPatterns
let(:platform) { Beaker::Platform.new('ubuntu-1604-x86_64') }
it 'installs' do
hosts.each do |host|
allow(subject). to receive(:fetch_http_file).with("http://builds.delivery.puppetlabs.net/pe-client-tools/#{opts[:pe_client_tools_sha]}/artifacts/deb/xenial/PC1", "pe-client-tools_#{opts[:pe_client_tools_version]}-1xenial_x86_64.deb", "tmp/repo_configs")
allow(subject). to receive(:fetch_http_file).with("http://builds.delivery.puppetlabs.net/pe-client-tools/#{opts[:pe_client_tools_sha]}/repo_configs/deb/", "pl-pe-client-tools-#{opts[:pe_client_tools_sha]}-xenial.list", "/tmp/repo_configs/ubuntu-xenial-x86_64")
allow(host). to receive(:external_copy_base)
expect(subject).to receive(:on).with(host, "dpkg -i pe-client-tools_#{opts[:pe_client_tools_version]}-1xenial_x86_64.deb")
expect(subject).to receive(:on).with(host, 'apt-get update')
expect(host).to receive(:install_package).with('pe-client-tools')
subject.install_pe_client_tools_on(host, opts)
end
end
Expand Down