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 06d2ba4 commit 73edd1a
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 66 deletions.
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
50 changes: 25 additions & 25 deletions lib/beaker/host/unix/pkg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def check_for_package(name, opts = {})
when /el-4/
@logger.debug("Package query not supported on rhel4")
return false
when /cisco|fedora|centos|redhat|eos|el-/
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 }
Expand Down Expand Up @@ -96,7 +96,7 @@ def install_package(name, cmdline_args = '', version = nil, opts = {})
name = "#{name}-#{version}"
end
execute("dnf -y #{cmdline_args} install #{name}", opts)
when /cisco|fedora|centos|redhat|eos|el-/
when /amazon|cisco|fedora|centos|redhat|eos|el-/
if version
name = "#{name}-#{version}"
end
Expand Down Expand Up @@ -179,26 +179,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 +527,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 +557,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
24 changes: 15 additions & 9 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 @@ -54,7 +55,7 @@ def timesync host, opts
logger.notify "NTP date succeeded on #{host}"
else
case
when /el-[89]|fedora/.match?(host['platform'])
when /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'])
ntp_command = "sntp #{ntp_server}"
Expand Down Expand Up @@ -114,6 +115,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 +464,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 +523,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
6 changes: 3 additions & 3 deletions lib/beaker/perf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class Perf

PERF_PACKAGES = ['sysstat']
# SLES does not treat sysstat as a service that can be started
PERF_SUPPORTED_PLATFORMS = /debian|ubuntu|redhat|centos|oracle|scientific|fedora|el|eos|cumulus|opensuse|sles/
PERF_START_PLATFORMS = /debian|ubuntu|redhat|centos|oracle|scientific|fedora|el|eos|cumulus/
PERF_SUPPORTED_PLATFORMS = /amazon|debian|ubuntu|redhat|centos|oracle|scientific|fedora|el|eos|cumulus|opensuse|sles/
PERF_START_PLATFORMS = /amazon|debian|ubuntu|redhat|centos|oracle|scientific|fedora|el|eos|cumulus/

# Create the Perf instance and runs setup_perf_on_host on all hosts if --collect-perf-data
# was used as an option on the Baker command line invocation. Instances of this class do not
Expand Down Expand Up @@ -50,7 +50,7 @@ def setup_perf_on_host(host)
@logger.perf_output("Enabling aggressive sysstat polling")
if /debian|ubuntu/.match?(host['platform'])
host.exec(Command.new('sed -i s/5-55\\\/10/*/ /etc/cron.d/sysstat'))
elsif /centos|el|fedora|oracle|redhat|scientific/.match?(host['platform'])
elsif /amazon|centos|el|fedora|oracle|redhat|scientific/.match?(host['platform'])
host.exec(Command.new('sed -i s/*\\\/10/*/ /etc/cron.d/sysstat'))
end
end
Expand Down
5 changes: 4 additions & 1 deletion lib/beaker/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module Beaker
# all String methods while adding several platform-specific use cases.
class Platform < String
# Supported platforms
PLATFORMS = /^(alpine|huaweios|cisco_nexus|cisco_ios_xr|(free|open)bsd|osx|centos|fedora|debian|oracle|redhat|redhatfips|scientific|opensuse|sles|ubuntu|windows|solaris|aix|archlinux|el|eos|cumulus|f5|netscaler)\-.+\-.+$/
# rubocop:disable Layout/LineLength

Check failure on line 6 in lib/beaker/platform.rb

View workflow job for this annotation

GitHub Actions / rubocop

Lint/RedundantCopDisableDirective: Unnecessary disabling of `Layout/LineLength`.
PLATFORMS = /^(alpine|amazon|huaweios|cisco_nexus|cisco_ios_xr|(free|open)bsd|osx|centos|fedora|debian|oracle|redhat|redhatfips|scientific|opensuse|sles|ubuntu|windows|solaris|aix|archlinux|el|eos|cumulus|f5|netscaler)\-.+\-.+$/
# rubocop:enable Layout/LineLength
# Platform version numbers vs. codenames conversion hash
PLATFORM_VERSION_CODES =
{ :debian => { "forky" => "14",
Expand Down Expand Up @@ -59,6 +61,7 @@ class Platform < String
# Creates the Platform object. Checks to ensure that the platform String
# provided meets the platform formatting rules. Platforms name must be of
# the format /^OSFAMILY-VERSION-ARCH.*$/ where OSFAMILY is one of:
# * amazon
# * huaweios
# * cisco_nexus
# * cisco_ios_xr
Expand Down
6 changes: 2 additions & 4 deletions spec/beaker/host/unix/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def logger
let(:instance) { UnixFileTest.new(opts.merge(platform), logger) }

describe '#repo_type' do

['centos','redhat'].each do |platform|
%w[amazon centos redhat].each do |platform|
it "returns correctly for platform '#{platform}'" do
@platform = "#{platform}-5-x86_64"
expect( instance.repo_type ).to be === 'rpm'
Expand All @@ -58,8 +57,7 @@ def logger
end

describe '#package_config_dir' do

['centos','redhat'].each do |platform|
%w[amazon centos redhat].each do |platform|
it "returns correctly for platform '#{platform}'" do
@platform = "#{platform}-5-x86_64"
expect( instance.package_config_dir ).to be === '/etc/yum.repos.d/'
Expand Down
29 changes: 26 additions & 3 deletions spec/beaker/host/unix/pkg_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def exec
expect( instance.check_for_package(pkg) ).to be === true
end

['centos','redhat'].each do |platform|
%w[amazon centos redhat].each do |platform|
it "checks correctly on #{platform}" do
@opts = {'platform' => "#{platform}-is-me"}
pkg = "#{platform}_package"
Expand Down Expand Up @@ -267,6 +267,22 @@ def exec
end
end

it "uses dnf on amazon-2023" do
@opts = { 'platform' => "amazon-2023-is-me" }
pkg = 'amazon_package'
expect(Beaker::Command).to receive(:new).with("dnf -y install #{pkg}", [], { :prepend_cmds => nil, :cmdexe => false }).and_return('')
expect(instance).to receive(:exec).with('', {}).and_return(generate_result("hello", { :exit_code => 0 }))
expect(instance.install_package(pkg)).to be == "hello"
end

it "uses pacman on archlinux" do

Check failure on line 278 in spec/beaker/host/unix/pkg_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/RepeatedExample: Don't repeat examples within an example group.
@opts = { 'platform' => 'archlinux-is-me' }
pkg = 'archlinux_package'
expect(Beaker::Command).to receive(:new).with("pacman -S --noconfirm #{pkg}", [], { :prepend_cmds => nil, :cmdexe => false }).and_return('')
expect(instance).to receive(:exec).with('', {}).and_return(generate_result("hello", { :exit_code => 0 }))
expect(instance.install_package(pkg)).to be == "hello"
end

it "uses pacman on archlinux" do

Check failure on line 286 in spec/beaker/host/unix/pkg_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/RepeatedExample: Don't repeat examples within an example group.
@opts = {'platform' => 'archlinux-is-me'}
pkg = 'archlinux_package'
Expand Down Expand Up @@ -531,7 +547,15 @@ def exec
let( :version ) { @version || 6 }

before do
allow( instance ).to receive( :[] ).with( 'platform' ) { Beaker::Platform.new("#{platform}-#{version}-x86_64") }
allow(instance).to receive(:[]).with('platform') { Beaker::Platform.new("#{platform}-#{version}-x86_64") }
end

it 'amazon-2023: uses dnf' do
@platform = platform
@version = '2023'
package_file = 'test_123.yay'
expect(instance).to receive(:execute).with(/^dnf.*#{package_file}$/)
instance.install_local_package(package_file)
end

it 'Fedora 22-39: uses dnf' do
Expand Down Expand Up @@ -654,4 +678,3 @@ def exec
end
end
end

39 changes: 33 additions & 6 deletions spec/beaker/host_prebuilt_steps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
let( :sles_only_pkgs ) { Beaker::HostPrebuiltSteps::SLES_PACKAGES }
let( :rhel8_packages ) { Beaker::HostPrebuiltSteps::RHEL8_PACKAGES }
let( :fedora_packages) { Beaker::HostPrebuiltSteps::FEDORA_PACKAGES }
let(:amazon2023_packages) { Beaker::HostPrebuiltSteps::AMAZON2023_PACKAGES }
let( :platform ) { @platform || 'unix' }
let( :ip ) { "ip.address.0.0" }
let( :stdout) { @stdout || ip }
Expand Down Expand Up @@ -87,7 +88,12 @@
"if grep \"root::::type=role\" /etc/user_attr; then sudo rolemod -K type=normal root; else echo \"root user already type=normal\"; fi"
], true

['debian','ubuntu','cumulus'].each do | deb_like |
it_behaves_like 'enables_root_login', 'amazon-2023', [
"sudo -E systemctl restart sshd.service",
"sudo su -c \"sed -ri 's/^#?PermitRootLogin no|^#?PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config\"",
]

%w[debian ubuntu cumulus].each do |deb_like|
it_behaves_like 'enables_root_login', deb_like, [
"sudo su -c \"sed -ri 's/^#?PermitRootLogin no|^#?PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config\"",
"sudo su -c \"service ssh restart\""
Expand Down Expand Up @@ -144,12 +150,20 @@
end

it "can sync time on Sles hosts" do
hosts = make_hosts( { :platform => 'sles-13.1-x64' } )
hosts = make_hosts({ :platform => 'sles-13.1-x64' })

expect( Beaker::Command ).to receive( :new ).with("sntp #{ntpserver}").exactly( 3 ).times
expect(Beaker::Command).to receive(:new).with("sntp #{ntpserver}").exactly(3).times

subject.timesync( hosts, options )
subject.timesync(hosts, options)
end

it "can sync time on amazon2023 hosts" do
hosts = make_hosts(:platform => 'amazon-2023-x86_64')
expect(Beaker::Command).to receive(:new)
.with("chronyc add server #{ntpserver} prefer trust;chronyc makestep;chronyc burst 1/2")
.exactly(3)
.times
subject.timesync(hosts, options)
end

it "can sync time on RHEL8 hosts" do
Expand Down Expand Up @@ -489,6 +503,19 @@
subject.validate_host(hosts, options)
end

it "can validate Amazon hosts" do
@platform = 'amazon-2023-x86_64'

hosts.each do |host|
amazon2023_packages.each do |pkg|
expect(host).to receive(:check_for_package).with(pkg).once.and_return(false)
expect(host).to receive(:install_package).with(pkg).once
end
end

subject.validate_host(hosts, options)
end

it 'skips validation on cisco hosts' do
host = make_host('cisco-7', { stdout: stdout, platform: 'cisco_nexus-7-x86_64' })
expect( subject ).to receive( :check_and_install_packages_if_needed ).with(host, []).once
Expand Down Expand Up @@ -533,7 +560,7 @@
end
end

['centos','redhat'].each do |platform|
%w[amazon centos redhat].each do |platform|
context "on platform '#{platform}'" do
let(:host) { make_host( 'name', {
:platform => platform,
Expand Down Expand Up @@ -635,7 +662,7 @@
subject.package_proxy(host, options.merge( {'package_proxy' => proxyurl}) )
end

['centos','redhat'].each do |platform|
%w[amazon centos redhat].each do |platform|
it "can set proxy config on a '#{platform}' host" do
host = make_host('name', { :platform => platform } )

Expand Down
Loading

0 comments on commit 73edd1a

Please sign in to comment.