diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 162187b1e..a91ff658c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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. diff --git a/lib/beaker/host/unix/exec.rb b/lib/beaker/host/unix/exec.rb index a000492b6..ff103aaee 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|centos|redhat|oracle|scientific)-[7-9]|eos-7|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,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")) diff --git a/lib/beaker/host/unix/file.rb b/lib/beaker/host/unix/file.rb index 88fd4230f..97f86313c 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/' @@ -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' diff --git a/lib/beaker/host/unix/pkg.rb b/lib/beaker/host/unix/pkg.rb index 819b89e85..15e19002f 100644 --- a/lib/beaker/host/unix/pkg.rb +++ b/lib/beaker/host/unix/pkg.rb @@ -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 } @@ -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-/ @@ -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) @@ -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}") @@ -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 diff --git a/lib/beaker/host_prebuilt_steps.rb b/lib/beaker/host_prebuilt_steps.rb index 8157d6d4a..1b3592b1f 100644 --- a/lib/beaker/host_prebuilt_steps.rb +++ b/lib/beaker/host_prebuilt_steps.rb @@ -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] @@ -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|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}" @@ -108,6 +109,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/ @@ -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|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 }) @@ -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 || :")) diff --git a/lib/beaker/perf.rb b/lib/beaker/perf.rb index 4b0f93b67..5d4e90b1c 100644 --- a/lib/beaker/perf.rb +++ b/lib/beaker/perf.rb @@ -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 @@ -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 diff --git a/lib/beaker/platform.rb b/lib/beaker/platform.rb index 138767480..f83b39d8c 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", @@ -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 diff --git a/spec/beaker/host/unix/file_spec.rb b/spec/beaker/host/unix/file_spec.rb index 81382ad7b..b1c4a7161 100644 --- a/spec/beaker/host/unix/file_spec.rb +++ b/spec/beaker/host/unix/file_spec.rb @@ -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' @@ -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/' diff --git a/spec/beaker/host/unix/pkg_spec.rb b/spec/beaker/host/unix/pkg_spec.rb index 3b3b35b04..f7b4454f4 100644 --- a/spec/beaker/host/unix/pkg_spec.rb +++ b/spec/beaker/host/unix/pkg_spec.rb @@ -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" @@ -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' @@ -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 diff --git a/spec/beaker/host_prebuilt_steps_spec.rb b/spec/beaker/host_prebuilt_steps_spec.rb index 1f2f0fcc2..4e7d47702 100644 --- a/spec/beaker/host_prebuilt_steps_spec.rb +++ b/spec/beaker/host_prebuilt_steps_spec.rb @@ -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 } @@ -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\"", @@ -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) @@ -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 @@ -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', { @@ -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 }) diff --git a/spec/helpers.rb b/spec/helpers.rb index 6db763e5e..438056c11 100644 --- a/spec/helpers.rb +++ b/spec/helpers.rb @@ -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