From f7dde157f2e4b0dcd3466c417b0d036f9ddb0d3f Mon Sep 17 00:00:00 2001 From: Jake Spain Date: Mon, 11 Sep 2023 16:35:51 -0400 Subject: [PATCH 1/2] Add Debian 12 - 14 support --- lib/beaker/platform.rb | 32 +++++++++++++++++--------------- spec/beaker/platform_spec.rb | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/lib/beaker/platform.rb b/lib/beaker/platform.rb index 7754e02d4..053d539ea 100644 --- a/lib/beaker/platform.rb +++ b/lib/beaker/platform.rb @@ -6,21 +6,23 @@ class Platform < String 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)\-.+\-.+$/ # 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", diff --git a/spec/beaker/platform_spec.rb b/spec/beaker/platform_spec.rb index a1f6f0684..c2d3a5512 100644 --- a/spec/beaker/platform_spec.rb +++ b/spec/beaker/platform_spec.rb @@ -66,6 +66,20 @@ module Beaker end context 'with_version_codename' do + it "can convert debian-14-xxx to debian-forky-xxx" do + @name = 'debian-14-xxx' + expect(platform.with_version_codename).to be === 'debian-forky-xxx' + end + + it "can convert debian-13-xxx to debian-trixie-xxx" do + @name = 'debian-13-xxx' + expect(platform.with_version_codename).to be === 'debian-trixie-xxx' + end + + it "can convert debian-12-xxx to debian-bookworm-xxx" do + @name = 'debian-12-xxx' + expect(platform.with_version_codename).to be === 'debian-bookworm-xxx' + end it "can convert debian-11-xxx to debian-bullseye-xxx" do @name = 'debian-11-xxx' From 6d6b7b24fdd946886d75be98b2fb05743bf2d26e Mon Sep 17 00:00:00 2001 From: Jake Spain Date: Mon, 25 Sep 2023 09:07:02 -0400 Subject: [PATCH 2/2] Allow amazon as a platform --- .rubocop_todo.yml | 2 +- lib/beaker/host/unix/exec.rb | 6 +- lib/beaker/host/unix/file.rb | 4 +- lib/beaker/host/unix/pkg.rb | 237 ++++++++++++------------ lib/beaker/host_prebuilt_steps.rb | 25 ++- lib/beaker/perf.rb | 6 +- lib/beaker/platform.rb | 5 +- spec/beaker/host/unix/file_spec.rb | 6 +- spec/beaker/host/unix/pkg_spec.rb | 29 ++- spec/beaker/host_prebuilt_steps_spec.rb | 81 +++++--- spec/helpers.rb | 21 ++- 11 files changed, 236 insertions(+), 186 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1f69d9084..3dbe5b0dd 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -151,7 +151,7 @@ RSpec/MultipleDescribes: # Configuration parameters: AllowSubject. RSpec/MultipleMemoizedHelpers: - Max: 19 + Max: 18 # Configuration parameters: IgnoreSharedExamples. RSpec/NamedSubject: diff --git a/lib/beaker/host/unix/exec.rb b/lib/beaker/host/unix/exec.rb index 3c688f749..bdc4d5e44 100644 --- a/lib/beaker/host/unix/exec.rb +++ b/lib/beaker/host/unix/exec.rb @@ -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")) @@ -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']) diff --git a/lib/beaker/host/unix/file.rb b/lib/beaker/host/unix/file.rb index 6db5e54d7..89ee3127b 100644 --- a/lib/beaker/host/unix/file.rb +++ b/lib/beaker/host/unix/file.rb @@ -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/' @@ -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' diff --git a/lib/beaker/host/unix/pkg.rb b/lib/beaker/host/unix/pkg.rb index 59becf90e..b2c798719 100644 --- a/lib/beaker/host/unix/pkg.rb +++ b/lib/beaker/host/unix/pkg.rb @@ -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 @@ -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 @@ -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 @@ -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}") @@ -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 diff --git a/lib/beaker/host_prebuilt_steps.rb b/lib/beaker/host_prebuilt_steps.rb index 5c5b576f5..afdb9bbd3 100644 --- a/lib/beaker/host_prebuilt_steps.rb +++ b/lib/beaker/host_prebuilt_steps.rb @@ -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'] @@ -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']) ntp_command = "sntp #{ntp_server}" @@ -114,6 +114,8 @@ def validate_host host, opts # @return [Array] 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/ @@ -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']) @@ -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 diff --git a/lib/beaker/perf.rb b/lib/beaker/perf.rb index 385bc82fd..15978d410 100644 --- a/lib/beaker/perf.rb +++ b/lib/beaker/perf.rb @@ -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 @@ -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 diff --git a/lib/beaker/platform.rb b/lib/beaker/platform.rb index 053d539ea..bd39a759c 100644 --- a/lib/beaker/platform.rb +++ b/lib/beaker/platform.rb @@ -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", @@ -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 diff --git a/spec/beaker/host/unix/file_spec.rb b/spec/beaker/host/unix/file_spec.rb index 8743c9ae5..fd792c437 100644 --- a/spec/beaker/host/unix/file_spec.rb +++ b/spec/beaker/host/unix/file_spec.rb @@ -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' @@ -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/' diff --git a/spec/beaker/host/unix/pkg_spec.rb b/spec/beaker/host/unix/pkg_spec.rb index c63cb2333..73ba6d83c 100644 --- a/spec/beaker/host/unix/pkg_spec.rb +++ b/spec/beaker/host/unix/pkg_spec.rb @@ -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" @@ -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 + @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 @opts = {'platform' => 'archlinux-is-me'} pkg = 'archlinux_package' @@ -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 @@ -654,4 +678,3 @@ def exec end end end - diff --git a/spec/beaker/host_prebuilt_steps_spec.rb b/spec/beaker/host_prebuilt_steps_spec.rb index 23a9e6738..d047ffbfa 100644 --- a/spec/beaker/host_prebuilt_steps_spec.rb +++ b/spec/beaker/host_prebuilt_steps_spec.rb @@ -1,27 +1,28 @@ require 'spec_helper' describe Beaker do - let( :options ) { make_opts.merge({ 'logger' => double().as_null_object }) } - let( :ntpserver_set ) { "ntp_server_set" } - let( :options_ntp ) { make_opts.merge({ 'ntp_server' => ntpserver_set }) } - let( :ntpserver ) { Beaker::HostPrebuiltSteps::NTPSERVER } - let( :apt_cfg ) { Beaker::HostPrebuiltSteps::APT_CFG } - let( :ips_pkg_repo ) { Beaker::HostPrebuiltSteps::IPS_PKG_REPO } - let( :sync_cmd ) { Beaker::HostPrebuiltSteps::ROOT_KEYS_SYNC_CMD } - let( :windows_pkgs ) { Beaker::HostPrebuiltSteps::WINDOWS_PACKAGES } - let( :unix_only_pkgs ) { Beaker::HostPrebuiltSteps::UNIX_PACKAGES } - let( :sles_only_pkgs ) { Beaker::HostPrebuiltSteps::SLES_PACKAGES } - let( :rhel8_packages ) { Beaker::HostPrebuiltSteps::RHEL8_PACKAGES } - let( :fedora_packages) { Beaker::HostPrebuiltSteps::FEDORA_PACKAGES } - let( :platform ) { @platform || 'unix' } - let( :ip ) { "ip.address.0.0" } - let( :stdout) { @stdout || ip } - let( :hosts ) { hosts = make_hosts( { :stdout => stdout, :platform => platform } ) - hosts[0][:roles] = ['agent'] - hosts[1][:roles] = ['master', 'dashboard', 'agent', 'database'] - hosts[2][:roles] = ['agent'] - hosts } - let( :dummy_class ) { Class.new { include Beaker::HostPrebuiltSteps } } + let(:options) { make_opts.merge({ 'logger' => double.as_null_object }) } + let(:ntpserver_set) { "ntp_server_set" } + let(:options_ntp) { make_opts.merge({ 'ntp_server' => ntpserver_set }) } + let(:ntpserver) { Beaker::HostPrebuiltSteps::NTPSERVER } + let(:sync_cmd) { Beaker::HostPrebuiltSteps::ROOT_KEYS_SYNC_CMD } + let(:windows_pkgs) { Beaker::HostPrebuiltSteps::WINDOWS_PACKAGES } + let(:unix_only_pkgs) { Beaker::HostPrebuiltSteps::UNIX_PACKAGES } + 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 } + let(:hosts) do + hosts = make_hosts({ :stdout => stdout, :platform => platform }) + hosts[0][:roles] = ['agent'] + hosts[1][:roles] = %w[master dashboard agent database] + hosts[2][:roles] = ['agent'] + hosts + end + let(:dummy_class) { Class.new { include Beaker::HostPrebuiltSteps } } shared_examples 'enables_root_login' do |platform, commands, non_cygwin| subject { dummy_class.new } @@ -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\"" @@ -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 @@ -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 @@ -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, @@ -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 } ) diff --git a/spec/helpers.rb b/spec/helpers.rb index 310087d3a..65d4b6219 100644 --- a/spec/helpers.rb +++ b/spec/helpers.rb @@ -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}" }