Skip to content

Commit

Permalink
Allow amazon as a platform
Browse files Browse the repository at this point in the history
  • Loading branch information
yachub authored and span786 committed Nov 7, 2023
1 parent f7dde15 commit 6d6b7b2
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 186 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ RSpec/MultipleDescribes:

# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 19
Max: 18

# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Expand Down
6 changes: 3 additions & 3 deletions lib/beaker/host/unix/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def ssh_service_restart
case self['platform']
when /debian|ubuntu|cumulus|huaweios/
exec(Beaker::Command.new("service ssh restart"))
when /el-7|centos-7|redhat-7|oracle-7|scientific-7|eos-7|el-8|centos-8|redhat-8|oracle-8|fedora-(1[4-9]|2[0-9]|3[0-9])|archlinux-/
when /amazon|(el|centos|redhat|oracle|scientific)-[7-9]|eos-7|fedora-(1[4-9]|2[0-9]|3[0-9])|archlinux-/
exec(Beaker::Command.new("systemctl restart sshd.service"))
when /el-|centos|fedora|redhat|oracle|scientific|eos/
exec(Beaker::Command.new("/sbin/service sshd restart"))
Expand All @@ -302,8 +302,8 @@ def ssh_service_restart
# (from {#ssh_service_restart}).
def ssh_permit_user_environment
case self['platform']
when /debian|ubuntu|cumulus|huaweios|archlinux|el-|centos|fedora|redhat|oracle|scientific|eos|opensuse|sles|solaris/
directory = tmpdir()
when /amazon|debian|ubuntu|cumulus|huaweios|archlinux|el-|centos|fedora|redhat|oracle|scientific|eos|opensuse|sles|solaris/
directory = tmpdir
exec(Beaker::Command.new("echo 'PermitUserEnvironment yes' | cat - /etc/ssh/sshd_config > #{directory}/sshd_config.permit"))
exec(Beaker::Command.new("mv #{directory}/sshd_config.permit /etc/ssh/sshd_config"))
exec(Beaker::Command.new("echo '' >/etc/environment")) if /ubuntu-2(0|2).04/.match?(self['platform'])
Expand Down
4 changes: 2 additions & 2 deletions lib/beaker/host/unix/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def file_exist?(path)
# @return [String] Path to package config dir
def package_config_dir
case self['platform']
when /fedora|el-|redhat|centos/
when /amazon|fedora|el-|redhat|centos/
'/etc/yum.repos.d/'
when /opensuse|sles/
'/etc/zypp/repos.d/'
Expand Down Expand Up @@ -154,7 +154,7 @@ def repo_filename(package_name, build_version)
# @return [String] Type of repo (rpm|deb)
def repo_type
case self['platform']
when /fedora|el-|redhat|centos|opensuse|sles/
when /amazon|fedora|el-|redhat|centos|opensuse|sles/
'rpm'
when /debian|ubuntu|cumulus|huaweios/
'deb'
Expand Down
237 changes: 115 additions & 122 deletions lib/beaker/host/unix/pkg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,36 @@ def check_for_command(name)
def check_for_package(name, opts = {})
opts = {:accept_all_exit_codes => true}.merge(opts)
case self['platform']
when /sles-10/
result = execute("zypper se -i --match-exact #{name}", opts) { |result| result }
result.stdout.include?('No packages found') ? (return false) : (return result.exit_code == 0)
when /opensuse|sles-/
if !self[:sles_rpmkeys_nightly_pl_imported]
# The `:sles_rpmkeys_nightly_pl_imported` key is only read here at this
# time. It's just to make sure that we only do the key import once, &
# isn't for setting or use outside of beaker.
execute('rpmkeys --import http://nightlies.puppetlabs.com/07BB6C57', opts)
self[:sles_rpmkeys_nightly_pl_imported] = true
end
result = execute("zypper --gpg-auto-import-keys se -i --match-exact #{name}", opts) { |result| result }
when /el-4/
@logger.debug("Package query not supported on rhel4")
return false
when /cisco|fedora|centos|redhat|eos|el-/
result = execute("rpm -q #{name}", opts) { |result| result }
when /ubuntu|debian|cumulus|huaweios/
result = execute("dpkg -s #{name}", opts) { |result| result }
when /solaris-11/
result = execute("pkg info #{name}", opts) { |result| result }
when /solaris-10/
result = execute("pkginfo #{name}", opts) { |result| result }
if result.exit_code == 1
result = execute("pkginfo CSW#{name}", opts) { |result| result }
end
when /openbsd/
result = execute("pkg_info #{name}", opts) { |result| result }
when /archlinux/
result = execute("pacman -Q #{name}", opts) { |result| result }
else
raise "Package #{name} cannot be queried on #{self}"
when /sles-10/
result = execute("zypper se -i --match-exact #{name}", opts) { |result| result }
result.stdout.include?('No packages found') ? (return false) : (return result.exit_code == 0)
when /opensuse|sles-/
if !self[:sles_rpmkeys_nightly_pl_imported]
# The `:sles_rpmkeys_nightly_pl_imported` key is only read here at this
# time. It's just to make sure that we only do the key import once, &
# isn't for setting or use outside of beaker.
execute('rpmkeys --import http://nightlies.puppetlabs.com/07BB6C57', opts)
self[:sles_rpmkeys_nightly_pl_imported] = true
end
result = execute("zypper --gpg-auto-import-keys se -i --match-exact #{name}", opts) { |result| result }
when /el-4/
@logger.debug("Package query not supported on rhel4")
return false
when /amazon|cisco|fedora|centos|redhat|eos|el-/
result = execute("rpm -q #{name}", opts) { |result| result }
when /ubuntu|debian|cumulus|huaweios/
result = execute("dpkg -s #{name}", opts) { |result| result }
when /solaris-11/
result = execute("pkg info #{name}", opts) { |result| result }
when /solaris-10/
result = execute("pkginfo #{name}", opts) { |result| result }
result = execute("pkginfo CSW#{name}", opts) { |result| result } if result.exit_code == 1
when /openbsd/
result = execute("pkg_info #{name}", opts) { |result| result }
when /archlinux/
result = execute("pacman -Q #{name}", opts) { |result| result }
else
raise "Package #{name} cannot be queried on #{self}"
end
result.exit_code == 0
end
Expand Down Expand Up @@ -87,75 +85,70 @@ def update_pacman_if_needed

def install_package(name, cmdline_args = '', version = nil, opts = {})
case self['platform']
when /opensuse|sles-/
execute("zypper --non-interactive --gpg-auto-import-keys in #{name}", opts)
when /el-4/
@logger.debug("Package installation not supported on rhel4")
when /fedora-(2[2-9]|3[0-9])/
if version
name = "#{name}-#{version}"
end
execute("dnf -y #{cmdline_args} install #{name}", opts)
when /cisco|fedora|centos|redhat|eos|el-/
if version
name = "#{name}-#{version}"
end
execute("yum -y #{cmdline_args} install #{name}", opts)
when /ubuntu|debian|cumulus|huaweios/
if version
name = "#{name}=#{version}"
end
update_apt_if_needed
execute("apt-get install --force-yes #{cmdline_args} -y #{name}", opts)
when /solaris-11/
if opts[:acceptable_exit_codes]
opts[:acceptable_exit_codes] << 4
else
opts[:acceptable_exit_codes] = [0, 4] unless opts[:accept_all_exit_codes]
end
execute("pkg #{cmdline_args} install #{name}", opts)
when /solaris-10/
if ! check_for_command('pkgutil')
# https://www.opencsw.org/package/pkgutil/
noask_text = self.noask_file_text
noask_file = File.join(external_copy_base, 'noask')
create_remote_file(self, noask_file, noask_text)
execute("pkgadd -d http://get.opencsw.org/now -a #{noask_file} -n all", opts)
execute('/opt/csw/bin/pkgutil -U', opts)
execute('/opt/csw/bin/pkgutil -y -i pkgutil', opts)
end
execute("pkgutil -i -y #{cmdline_args} #{name}", opts)
when /openbsd/
begin
execute("pkg_add -I #{cmdline_args} #{name}", opts) do |command|
# Handles where there are multiple rubies, installs the latest one
if command.stderr =~ /^Ambiguous: #{name} could be (.+)$/
name = $1.chomp.split(' ').collect { |x|
x =~ /-(\d[^-p]+)/
[x, $1]
}.select { |x|
# Blacklist Ruby 2.2.0+ for the sake of Puppet 3.x
Gem::Version.new(x[1]) < Gem::Version.new('2.2.0')
}.sort { |a,b|
Gem::Version.new(b[1]) <=> Gem::Version.new(a[1])
}.collect { |x|
x[0]
}.first
raise ArgumentException
end
# If the package advises symlinks to be created, do it
command.stdout.split("\n").select { |x| /^\s+ln\s/.match?(x) }.each do |ln|
execute(ln, opts)
end
when /opensuse|sles-/
execute("zypper --non-interactive --gpg-auto-import-keys in #{name}", opts)
when /el-4/
@logger.debug("Package installation not supported on rhel4")
when /amazon|fedora-(2[2-9]|3[0-9])/
name = "#{name}-#{version}" if version
execute("dnf -y #{cmdline_args} install #{name}", opts)
when /cisco|fedora|centos|redhat|eos|el-/
name = "#{name}-#{version}" if version
execute("yum -y #{cmdline_args} install #{name}", opts)
when /ubuntu|debian|cumulus|huaweios/
name = "#{name}=#{version}" if version
update_apt_if_needed
execute("apt-get install --force-yes #{cmdline_args} -y #{name}", opts)
when /solaris-11/
if opts[:acceptable_exit_codes]
opts[:acceptable_exit_codes] << 4
else
opts[:acceptable_exit_codes] = [0, 4] unless opts[:accept_all_exit_codes]
end
execute("pkg #{cmdline_args} install #{name}", opts)
when /solaris-10/
if !check_for_command('pkgutil')
# https://www.opencsw.org/package/pkgutil/
noask_text = self.noask_file_text
noask_file = File.join(external_copy_base, 'noask')
create_remote_file(self, noask_file, noask_text)
execute("pkgadd -d http://get.opencsw.org/now -a #{noask_file} -n all", opts)
execute('/opt/csw/bin/pkgutil -U', opts)
execute('/opt/csw/bin/pkgutil -y -i pkgutil', opts)
end
execute("pkgutil -i -y #{cmdline_args} #{name}", opts)
when /openbsd/
begin
execute("pkg_add -I #{cmdline_args} #{name}", opts) do |command|
# Handles where there are multiple rubies, installs the latest one
if (match = /^Ambiguous: #{name} could be (.+)$/.match(command.stderr))
name = match[1].chomp.split(' ').collect do |x|
# FIXME: Ruby 3.2 compatibility?
x =~ /-(\d[^-p]+)/
[x, $1]
end.select do |x|
# Blacklist Ruby 2.2.0+ for the sake of Puppet 3.x
Gem::Version.new(x[1]) < Gem::Version.new('2.2.0')
end.sort do |a, b|
Gem::Version.new(b[1]) <=> Gem::Version.new(a[1])
end.collect do |x|
x[0]
end.first
raise ArgumentException
end
# If the package advises symlinks to be created, do it
command.stdout.split("\n").select { |x| /^\s+ln\s/.match?(x) }.each do |ln|
execute(ln, opts)
end
rescue
retry
end
when /archlinux/
update_pacman_if_needed
execute("pacman -S --noconfirm #{cmdline_args} #{name}", opts)
else
raise "Package #{name} cannot be installed on #{self}"
rescue
retry
end
when /archlinux/
update_pacman_if_needed
execute("pacman -S --noconfirm #{cmdline_args} #{name}", opts)
else
raise "Package #{name} cannot be installed on #{self}"
end
end

Expand All @@ -179,26 +172,26 @@ def install_package_with_rpm(name, cmdline_args = '', opts = {})

def uninstall_package(name, cmdline_args = '', opts = {})
case self['platform']
when /opensuse|sles-/
execute("zypper --non-interactive rm #{name}", opts)
when /el-4/
@logger.debug("Package uninstallation not supported on rhel4")
when /edora-(2[2-9]|3[0-9])/
execute("dnf -y #{cmdline_args} remove #{name}", opts)
when /cisco|fedora|centos|redhat|eos|el-/
execute("yum -y #{cmdline_args} remove #{name}", opts)
when /ubuntu|debian|cumulus|huaweios/
execute("apt-get purge #{cmdline_args} -y #{name}", opts)
when /solaris-11/
execute("pkg #{cmdline_args} uninstall #{name}", opts)
when /solaris-10/
execute("pkgrm -n #{cmdline_args} #{name}", opts)
when /aix/
execute("rpm #{cmdline_args} -e #{name}", opts)
when /archlinux/
execute("pacman -R --noconfirm #{cmdline_args} #{name}", opts)
else
raise "Package #{name} cannot be installed on #{self}"
when /opensuse|sles-/
execute("zypper --non-interactive rm #{name}", opts)
when /el-4/
@logger.debug("Package uninstallation not supported on rhel4")
when /amazon|edora-(2[2-9]|3[0-9])/
execute("dnf -y #{cmdline_args} remove #{name}", opts)
when /cisco|fedora|centos|redhat|eos|el-/
execute("yum -y #{cmdline_args} remove #{name}", opts)
when /ubuntu|debian|cumulus|huaweios/
execute("apt-get purge #{cmdline_args} -y #{name}", opts)
when /solaris-11/
execute("pkg #{cmdline_args} uninstall #{name}", opts)
when /solaris-10/
execute("pkgrm -n #{cmdline_args} #{name}", opts)
when /aix/
execute("rpm #{cmdline_args} -e #{name}", opts)
when /archlinux/
execute("pacman -R --noconfirm #{cmdline_args} #{name}", opts)
else
raise "Package #{name} cannot be installed on #{self}"
end
end

Expand Down Expand Up @@ -527,9 +520,9 @@ def pe_puppet_agent_promoted_package_install(
def install_local_package(onhost_package_file, onhost_copy_dir = nil)
variant, version, _arch, _codename = self['platform'].to_array
case variant
when /^(fedora|el|redhat|centos)$/
when /^(amazon|fedora|el|redhat|centos)$/
command_name = 'yum'
command_name = 'dnf' if variant == 'fedora' && version.to_i > 21
command_name = 'dnf' if (variant == 'fedora' && version.to_i > 21) || (variant == 'amazon' && version.to_i >= 2023)
execute("#{command_name} --nogpgcheck localinstall -y #{onhost_package_file}")
when /^(opensuse|sles)$/
execute("zypper --non-interactive --no-gpg-checks in #{onhost_package_file}")
Expand Down Expand Up @@ -557,7 +550,7 @@ def install_local_package(onhost_package_file, onhost_copy_dir = nil)
def uncompress_local_tarball(onhost_tar_file, onhost_base_dir, download_file)
variant, version, _arch, _codename = self['platform'].to_array
case variant
when /^(fedora|el|centos|redhat|opensuse|sles|debian|ubuntu|cumulus)$/
when /^(amazon|fedora|el|centos|redhat|opensuse|sles|debian|ubuntu|cumulus)$/
execute("tar -zxvf #{onhost_tar_file} -C #{onhost_base_dir}")
when /^solaris$/
# uncompress PE puppet-agent tarball
Expand Down
25 changes: 15 additions & 10 deletions lib/beaker/host_prebuilt_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module HostPrebuiltSteps
NTPSERVER = 'pool.ntp.org'
SLEEPWAIT = 5
TRIES = 5
RHEL8_PACKAGES = ['curl', 'chrony']
AMAZON2023_PACKAGES = %w[curl-minimal chrony]
RHEL8_PACKAGES = %w[curl chrony]
RHEL9_PACKAGES = ['chrony']
FEDORA_PACKAGES = ['curl', 'chrony']
UNIX_PACKAGES = ['curl', 'ntpdate']
Expand Down Expand Up @@ -53,8 +54,7 @@ def timesync host, opts
host.exec(Command.new("w32tm /resync"))
logger.notify "NTP date succeeded on #{host}"
else
case
when /el-[89]|fedora/.match?(host['platform'])
if /amazon|el-[89]|fedora/.match?(host['platform'])
ntp_command = "chronyc add server #{ntp_server} prefer trust;chronyc makestep;chronyc burst 1/2"
when /opensuse-|sles-/.match?(host['platform'])

Check failure on line 59 in lib/beaker/host_prebuilt_steps.rb

View workflow job for this annotation

GitHub Actions / rubocop

Lint/Syntax: unexpected token kWHEN (Using Ruby 2.4 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
ntp_command = "sntp #{ntp_server}"
Expand Down Expand Up @@ -114,6 +114,8 @@ def validate_host host, opts
# @return [Array<String>] A list of packages to install
def host_packages(host)
case host['platform']
when /amazon/
AMAZON2023_PACKAGES
when /el-8/
RHEL8_PACKAGES
when /el-9/
Expand Down Expand Up @@ -461,9 +463,9 @@ def enable_root_login host, opts
end
#restart sshd
if /debian|ubuntu|cumulus/.match?(host['platform'])
host.exec(Command.new("sudo su -c \"service ssh restart\""), {:pty => true})
elsif /arch|(centos|el|redhat)-[789]|fedora-(1[4-9]|2[0-9]|3[0-9])/.match?(host['platform'])
host.exec(Command.new("sudo -E systemctl restart sshd.service"), {:pty => true})
host.exec(Command.new("sudo su -c \"service ssh restart\""), { :pty => true })
elsif /amazon|arch|(centos|el|redhat)-[789]|fedora-(1[4-9]|2[0-9]|3[0-9])/.match?(host['platform'])
host.exec(Command.new("sudo -E systemctl restart sshd.service"), { :pty => true })
elsif /centos|el-|redhat|fedora|eos/.match?(host['platform'])
host.exec(Command.new("sudo -E /sbin/service sshd reload"), {:pty => true})
elsif /(free|open)bsd/.match?(host['platform'])
Expand Down Expand Up @@ -520,10 +522,13 @@ def package_proxy host, opts
block_on host do |host|
logger.debug("enabling proxy support on #{host.name}")
case host['platform']
when /ubuntu/, /debian/, /cumulus/
host.exec(Command.new("echo 'Acquire::http::Proxy \"#{opts[:package_proxy]}/\";' >> /etc/apt/apt.conf.d/10proxy"))
when /^el-/, /centos/, /fedora/, /redhat/, /eos/
host.exec(Command.new("echo 'proxy=#{opts[:package_proxy]}/' >> /etc/yum.conf"))
when /ubuntu/, /debian/, /cumulus/
host.exec(Command.new("echo 'Acquire::http::Proxy \"#{opts[:package_proxy]}/\";' >> /etc/apt/apt.conf.d/10proxy"))
when /amazon/, /^el-/, /centos/, /fedora/, /redhat/, /eos/
host.exec(Command.new("echo 'proxy=#{opts[:package_proxy]}/' >> /etc/yum.conf"))
when /solaris-11/
host.exec(Command.new("/usr/bin/pkg unset-publisher solaris || :"))
host.exec(Command.new("/usr/bin/pkg set-publisher -g %s solaris" % opts[:package_proxy]))
else
logger.debug("Attempting to enable package manager proxy support on non-supported platform: #{host.name}: #{host['platform']}")
end
Expand Down
Loading

0 comments on commit 6d6b7b2

Please sign in to comment.