From 37a47995e1fb77e1983800f9c44591aaae25c320 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Wed, 13 Mar 2024 20:17:14 +0100 Subject: [PATCH] Only install timesync packages if needed Chrony/NTP is only needed if timesync is requested. In some cases (like containers) it never makes sense. --- lib/beaker/host_prebuilt_steps.rb | 56 ++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/lib/beaker/host_prebuilt_steps.rb b/lib/beaker/host_prebuilt_steps.rb index 1b3592b1f..c611854a6 100644 --- a/lib/beaker/host_prebuilt_steps.rb +++ b/lib/beaker/host_prebuilt_steps.rb @@ -10,22 +10,22 @@ 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] - UNIX_PACKAGES = %w[curl ntpdate] + 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 ntp net-tools openssh] + ARCHLINUX_PACKAGES = %w[curl net-tools openssh] WINDOWS_PACKAGES = ['curl'] PSWINDOWS_PACKAGES = [] SLES10_PACKAGES = ['curl'] - SLES_PACKAGES = %w[curl ntp] - DEBIAN_PACKAGES = %w[curl ntpdate lsb-release apt-transport-https] - CUMULUS_PACKAGES = %w[curl ntpdate] - SOLARIS10_PACKAGES = %w[CSWcurl CSWntp wget] - SOLARIS11_PACKAGES = %w[curl ntp] + 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,6 +50,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']) ntp_command = "chronyc add server #{ntp_server} prefer trust;chronyc makestep;chronyc burst 1/2" elsif /opensuse-|sles-/.match?(host['platform']) @@ -108,10 +109,20 @@ 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 + 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/ + when /el-8/, /fedora/ RHEL8_PACKAGES when /el-9/ RHEL9_PACKAGES @@ -152,6 +163,27 @@ def host_packages(host) 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