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

[PA-5938] Add support for debian & amazon linux in beaker 4.x #1828

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
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: 20

# 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-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,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|fedora-(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
21 changes: 12 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,10 @@ 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"))
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
35 changes: 19 additions & 16 deletions lib/beaker/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@ 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)\-.+\-.+$/
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)\-.+\-.+$/
# Platform version numbers vs. codenames conversion hash
PLATFORM_VERSION_CODES =
{ :debian => { "bullseye" => "11",
"buster" => "10",
"stretch" => "9",
"jessie" => "8",
"wheezy" => "7",
"squeeze" => "6",
},
:ubuntu => { "jammy" => "2204",
"focal" => "2004",
"eoan" => "1910",
"disco" => "1904",
"cosmic" => "1810",
"bionic" => "1804",
"artful" => "1710",
"zesty" => "1704",
{ :debian => { "forky" => "14",
"trixie" => "13",
"bookworm" => "12",
"bullseye" => "11",
"buster" => "10",
"stretch" => "9",
"jessie" => "8",
"wheezy" => "7",
"squeeze" => "6", },
:ubuntu => { "jammy" => "2204",
"focal" => "2004",
"eoan" => "1910",
"disco" => "1904",
"cosmic" => "1810",
"bionic" => "1804",
"artful" => "1710",
"zesty" => "1704",
"yakkety" => "1610",
"xenial" => "1604",
"wily" => "1510",
Expand Down Expand Up @@ -57,6 +59,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: 22 additions & 7 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,12 +267,20 @@ 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("yum -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'}
@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"
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
end

Expand Down Expand Up @@ -531,7 +539,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 +670,3 @@ def exec
end
end
end

Loading
Loading