diff --git a/lib/beaker/host_prebuilt_steps.rb b/lib/beaker/host_prebuilt_steps.rb index 2262812b0..31ace4282 100644 --- a/lib/beaker/host_prebuilt_steps.rb +++ b/lib/beaker/host_prebuilt_steps.rb @@ -10,22 +10,6 @@ module HostPrebuiltSteps NTPSERVER = 'pool.ntp.org' SLEEPWAIT = 5 TRIES = 5 - AMAZON2023_PACKAGES = %w[curl-minimal] - RHEL8_PACKAGES = %w[curl] - RHEL9_PACKAGES = [] - FEDORA_PACKAGES = %w[curl] - UNIX_PACKAGES = %w[curl] - FREEBSD_PACKAGES = ['curl', 'perl5|perl'] - OPENBSD_PACKAGES = ['curl'] - ARCHLINUX_PACKAGES = %w[curl net-tools openssh] - WINDOWS_PACKAGES = ['curl'] - PSWINDOWS_PACKAGES = [] - SLES10_PACKAGES = ['curl'] - SLES_PACKAGES = %w[curl] - DEBIAN_PACKAGES = %w[curl lsb-release apt-transport-https] - CUMULUS_PACKAGES = %w[curl] - SOLARIS10_PACKAGES = %w[CSWcurl wget] - SOLARIS11_PACKAGES = %w[curl] ETC_HOSTS_PATH = "/etc/hosts" ETC_HOSTS_PATH_SOLARIS = "/etc/inet/hosts" ROOT_KEYS_SCRIPT = "https://raw.githubusercontent.com/puppetlabs/puppetlabs-sshkeys/master/templates/scripts/manage_root_authorized_keys" @@ -50,8 +34,7 @@ def timesync host, opts host.exec(Command.new("w32tm /resync")) logger.notify "NTP date succeeded on #{host}" else - # TODO: reuse logic form host_timesync_packages? - if /amazon|el-[89]|fedora/.match?(host['platform']) + if host['platform'].uses_chrony? 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}" @@ -85,13 +68,6 @@ def timesync host, opts # Validate that hosts are prepared to be used as SUTs, if packages are missing attempt to # install them. # - # Verifies the presence of #{HostPrebuiltSteps::UNIX_PACKAGES} on unix platform hosts, - # {HostPrebuiltSteps::SLES_PACKAGES} on SUSE platform hosts, - # {HostPrebuiltSteps::DEBIAN_PACKAGES} on debian platform hosts, - # {HostPrebuiltSteps::CUMULUS_PACKAGES} on cumulus platform hosts, - # {HostPrebuiltSteps::WINDOWS_PACKAGES} on cygwin-installed windows platform hosts, - # and {HostPrebuiltSteps::PSWINDOWS_PACKAGES} on non-cygwin windows platform hosts. - # # @param [Host, Array, String, Symbol] host One or more hosts to act upon # @param [Hash{Symbol=>String}] opts Options to alter execution. # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object @@ -109,81 +85,11 @@ def validate_host host, opts # @param [Host] host A host return the packages for # @return [Array] A list of packages to install def host_packages(host) - packages = host_base_packages(host) - packages += host_timesync_packages(host) if host[:timesync] + packages = host['platform'].base_packages + packages += host['platform'].timesync_packages if host[:timesync] packages end - # Return a list of packages that should be present. - # - # @param [Host] host A host return the packages for - # @return [Array] A list of packages to install - def host_base_packages(host) - case host['platform'] - when /amazon/ - AMAZON2023_PACKAGES - when /el-8/ - RHEL8_PACKAGES - when /el-9/ - RHEL9_PACKAGES - when /sles-10/ - SLES10_PACKAGES - when /opensuse|sles-/ - SLES_PACKAGES - when /debian/ - DEBIAN_PACKAGES - when /cumulus/ - CUMULUS_PACKAGES - when /windows/ - if host.is_cygwin? - raise RuntimeError, "cygwin is not installed on #{host}" if !host.cygwin_installed? - - WINDOWS_PACKAGES - else - PSWINDOWS_PACKAGES - end - when /freebsd/ - FREEBSD_PACKAGES - when /openbsd/ - OPENBSD_PACKAGES - when /solaris-10/ - SOLARIS10_PACKAGES - when /solaris-1[1-9]/ - SOLARIS11_PACKAGES - when /archlinux/ - ARCHLINUX_PACKAGES - when /fedora/ - FEDORA_PACKAGES - else - if !/aix|solaris|osx-|f5-|netscaler|cisco_/.match?(host['platform']) - UNIX_PACKAGES - else - [] - end - end - end - - # Return a list of packages that should be present for timesync. - # - # @param [Host] host A host return the packages for - # @return [Array] A list of packages to install - def host_timesync_packages(host) - case host['platform'] - when /amazon/, /el-[89]/, /fedora/ - ['chrony'] - when /freebsd/, /openbsd/, /sles-10/, /windows/, /aix|solaris|osx-|f5-|netscaler|cisco_/ - [] - when /archlinux/, /opensuse|sles-/, /solaris-1[1-9]/ - ['ntp'] - when /debian/, /cumulus/ - 'ntpdate' - when /solaris-10/ - ['CSWntp'] - else - ['ntpdate'] - end - end - # Installs the given packages if they aren't already on a host # # @param [Host] host Host to act on diff --git a/lib/beaker/platform.rb b/lib/beaker/platform.rb index 4cb90626f..c879eb6d9 100644 --- a/lib/beaker/platform.rb +++ b/lib/beaker/platform.rb @@ -127,5 +127,66 @@ def with_version_codename def with_version_number [@variant, @version, @arch].join('-') end + + def uses_chrony? + case @variant + when 'amazon', 'fedora' + true + when 'el' + @version.to_i >= 8 + else + false + end + end + + # Return a list of packages that should always be present. + # + # @return [Array] A list of packages to install + def base_packages + case @variant + when 'el' + @version.to_i >= 8 ? [] : %w[curl] + when 'debian' + %w[curl lsb-release apt-transport-https] + when 'windows' + if host.is_cygwin? + raise RuntimeError, "cygwin is not installed on #{host}" if !host.cygwin_installed? + + %w[curl] + else + [] + end + when 'freebsd' + %w[curl perl5|perl] + when 'solaris' + @version.to_i >= 11 ? %w[curl] : %w[CSWcurl wget] + when 'archlinux' + %w[curl net-tools openssh] + when 'amazon', 'fedora', 'aix', 'osx', 'f5', 'netscaler', /cisco_/ + [] + else + %w[curl] + end + end + + # Return a list of packages that are needed for timesync + # + # @return [Array] A list of packages to install for timesync + def timesync_packages + return ['chrony'] if uses_chrony? + + case @variant + when 'freebsd', 'openbsd', 'windows', 'aix', 'osx', 'f5', 'netscaler', /cisco_/ + [] + when 'archlinux', 'opensuse', + ['ntp'] + when 'sles' + @version.to_i >= 11 ? %w[ntp] : [] + when 'solaris' + @version.to_i >= 11 ? %w[ntp] : %w[CSWntp] + else + %w[ntpdate] + end + end end end