Skip to content

Commit

Permalink
Add amazon as a platform
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamshinde360 committed Nov 8, 2023
1 parent 0608946 commit 7431d51
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 36 deletions.
4 changes: 2 additions & 2 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-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-/
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,7 +302,7 @@ 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/
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"))
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
12 changes: 6 additions & 6 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 @@ -91,7 +91,7 @@ def install_package(name, cmdline_args = '', version = nil, opts = {})
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])/
when /amazon|fedora-(2[2-9]|3[0-9])/
if version
name = "#{name}-#{version}"
end
Expand Down Expand Up @@ -183,7 +183,7 @@ def uninstall_package(name, cmdline_args = '', opts = {})
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])/
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)
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
11 changes: 7 additions & 4 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 @@ -462,7 +465,7 @@ def enable_root_login host, opts
#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'])
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})
Expand Down Expand Up @@ -522,7 +525,7 @@ def package_proxy host, opts
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/
when /amazon/, /^el-/, /centos/, /fedora/, /redhat/, /eos/
host.exec(Command.new("echo 'proxy=#{opts[:package_proxy]}/' >> /etc/yum.conf"))
else
logger.debug("Attempting to enable package manager proxy support on non-supported platform: #{host.name}: #{host['platform']}")
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
18 changes: 17 additions & 1 deletion 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,14 @@ 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
@opts = {'platform' => 'archlinux-is-me'}
pkg = 'archlinux_package'
Expand Down Expand Up @@ -534,6 +542,14 @@ def exec
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
(22...39).each do |version|
@version = version
Expand Down
34 changes: 31 additions & 3 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 @@ -152,6 +158,15 @@

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
hosts = make_hosts(:platform => 'el-8-x86_x64')
expect(Beaker::Command).to receive(:new)
Expand Down Expand Up @@ -489,6 +504,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 +561,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 +663,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
21 changes: 11 additions & 10 deletions spec/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,17 @@ module PlatformHelpers

FEDORASYSTEMD = (14..39).to_a.collect! { |i| "fedora-#{i}" }

SYSTEMDPLATFORMS = ['el-7',
'centos-7',
'redhat-7',
'oracle-7',
'scientific-7',
'eos-7',
'el-8',
'centos-8',
'redhat-8',
'oracle-8'].concat(FEDORASYSTEMD)
SYSTEMDPLATFORMS = %w[amazon-2023
el-7
centos-7
redhat-7
oracle-7
scientific-7
eos-7
el-8
centos-8
redhat-8
oracle-8].concat(FEDORASYSTEMD)

FEDORASYSTEMV = (1..13).to_a.collect! { |i| "fedora-#{i}" }

Expand Down

0 comments on commit 7431d51

Please sign in to comment.