Skip to content

Commit

Permalink
Only install timesync packages if needed
Browse files Browse the repository at this point in the history
Chrony/NTP is only needed if timesync is requested. In some cases (like
containers) it never makes sense.
  • Loading branch information
ekohl committed Mar 13, 2024
1 parent c32b6d2 commit 423fb62
Showing 1 changed file with 43 additions and 11 deletions.
54 changes: 43 additions & 11 deletions lib/beaker/host_prebuilt_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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'])
Expand Down Expand Up @@ -108,6 +109,16 @@ def validate_host host, opts
# @param [Host] host A host return the packages for
# @return [Array<String>] 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<String>] A list of packages to install
def host_base_packages(host)
case host['platform']
when /amazon/
AMAZON2023_PACKAGES
Expand Down Expand Up @@ -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<String>] A list of packages to install
def host_timesync_packages(host)
case host['platform']

Check warning on line 171 in lib/beaker/host_prebuilt_steps.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L171

Added line #L171 was not covered by tests
when /amazon/, /el-[89]/, /fedora/
['chrony']

Check warning on line 173 in lib/beaker/host_prebuilt_steps.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L173

Added line #L173 was not covered by tests
when /freebsd/, /openbsd/, /sles-10/, /windows/, /aix|solaris|osx-|f5-|netscaler|cisco_/
[]

Check warning on line 175 in lib/beaker/host_prebuilt_steps.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L175

Added line #L175 was not covered by tests
when /archlinux/, /opensuse|sles-/, /solaris-1[1-9]/
['ntp']

Check warning on line 177 in lib/beaker/host_prebuilt_steps.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L177

Added line #L177 was not covered by tests
when /debian/, /cumulus/
'ntpdate'

Check warning on line 179 in lib/beaker/host_prebuilt_steps.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L179

Added line #L179 was not covered by tests
when /solaris-10/
['CSWntp']

Check warning on line 181 in lib/beaker/host_prebuilt_steps.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L181

Added line #L181 was not covered by tests
else
['ntpdate']

Check warning on line 183 in lib/beaker/host_prebuilt_steps.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L183

Added line #L183 was not covered by tests
end
end

# Installs the given packages if they aren't already on a host
#
# @param [Host] host Host to act on
Expand Down

0 comments on commit 423fb62

Please sign in to comment.