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 committed Sep 25, 2023
1 parent cc5fd87 commit c87e74e
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ RSpec/MultipleDescribes:
# Offense count: 134
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 17
Max: 18

# Offense count: 500
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
Expand Down
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|centos|redhat|oracle|scientific)-[7-9]|eos-7|fedora-(1[4-9]|2[0-9]|3[0-9])|archlinux-/
when /amazon-\d{4,}|(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,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 @@ -149,7 +149,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 @@ -87,7 +87,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])/
name = "#{name}-#{version}" if version
execute("dnf -y #{cmdline_args} install #{name}", opts)
when /cisco|fedora|centos|redhat|eos|el-/
Expand Down Expand Up @@ -172,7 +172,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 @@ -264,9 +264,9 @@ def extract_rpm_proxy_options(url)
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 @@ -294,7 +294,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
9 changes: 6 additions & 3 deletions lib/beaker/host_prebuilt_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module HostPrebuiltSteps
NTPSERVER = 'pool.ntp.org'
SLEEPWAIT = 5
TRIES = 5
AMAZON2023_PACKAGES = %w[curl-minimal chrony]
RHEL8_PACKAGES = %w[curl chrony]
RHEL9_PACKAGES = ['chrony']
FEDORA_PACKAGES = %w[curl chrony]
Expand Down Expand Up @@ -49,7 +50,7 @@ def timesync host, opts
host.exec(Command.new("w32tm /resync"))
logger.notify "NTP date succeeded on #{host}"
else
if /el-[89]|fedora/.match?(host['platform'])
if /amazon-\d{4,}|el-[89]|fedora/.match?(host['platform'])
ntp_command = "chronyc add server #{ntp_server} prefer trust;chronyc makestep;chronyc burst 1/2"
elsif /opensuse-|sles-/.match?(host['platform'])
ntp_command = "sntp #{ntp_server}"
Expand Down Expand Up @@ -108,6 +109,8 @@ def validate_host host, opts
# @return [Array<String>] A list of packages to install
def host_packages(host)
case host['platform']
when /amazon-\d{4,}/
AMAZON2023_PACKAGES
when /el-8/
RHEL8_PACKAGES
when /el-9/
Expand Down Expand Up @@ -387,7 +390,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-\d{4,}|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 @@ -431,7 +434,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"))
when /solaris-11/
host.exec(Command.new("/usr/bin/pkg unset-publisher solaris || :"))
Expand Down
6 changes: 3 additions & 3 deletions lib/beaker/perf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module Beaker
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 @@ -47,7 +47,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
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 @@ -56,6 +58,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
4 changes: 2 additions & 2 deletions spec/beaker/host/unix/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def to_s
let(:instance) { UnixFileTest.new(opts.merge(platform), logger) }

describe '#repo_type' do
%w[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 @@ -54,7 +54,7 @@ def to_s
end

describe '#package_config_dir' do
%w[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 @@ -58,7 +58,7 @@ def exec
expect(instance.check_for_package(pkg)).to be === true
end

%w[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 @@ -195,6 +195,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 @@ -291,6 +299,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
32 changes: 30 additions & 2 deletions spec/beaker/host_prebuilt_steps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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 @@ -85,6 +86,11 @@
"if grep \"root::::type=role\" /etc/user_attr; then sudo rolemod -K type=normal root; else echo \"root user already type=normal\"; fi",
], true

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\"",
Expand Down Expand Up @@ -147,6 +153,15 @@
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
hosts = make_hosts(:platform => 'el-8-x86_x64')
expect(Beaker::Command).to receive(:new)
Expand Down Expand Up @@ -358,6 +373,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 @@ -404,7 +432,7 @@
end
end

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

%w[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
3 changes: 2 additions & 1 deletion spec/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ module PlatformHelpers

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

SYSTEMDPLATFORMS = %w[el-7
SYSTEMDPLATFORMS = %w[amazon-2023
el-7
centos-7
redhat-7
oracle-7
Expand Down

0 comments on commit c87e74e

Please sign in to comment.