Skip to content

Commit

Permalink
Move platform specific package logic to Beaker::Platform
Browse files Browse the repository at this point in the history
This is really platform specific logic, so it should live in the
platform class.
  • Loading branch information
ekohl committed Mar 13, 2024
1 parent 423fb62 commit 6700df9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 97 deletions.
100 changes: 3 additions & 97 deletions lib/beaker/host_prebuilt_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}"
Expand Down Expand Up @@ -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<Host>, 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
Expand All @@ -109,81 +85,11 @@ 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 = host['platform'].base_packages
packages += host['platform'].timesync_packages if host[:timesync]
packages

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

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L88-L90

Added lines #L88 - L90 were not covered by tests
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
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<String>] 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
Expand Down
61 changes: 61 additions & 0 deletions lib/beaker/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Check warning on line 133 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L133

Added line #L133 was not covered by tests
true
when 'el'

Check warning on line 135 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L135

Added line #L135 was not covered by tests
@version.to_i >= 8
else

Check warning on line 137 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L137

Added line #L137 was not covered by tests
false
end

Check warning on line 139 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L139

Added line #L139 was not covered by tests
end

# Return a list of packages that should always be present.
#
# @return [Array<String>] A list of packages to install
def base_packages
case @variant
when 'el'

Check warning on line 147 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L147

Added line #L147 was not covered by tests
@version.to_i >= 8 ? [] : %w[curl]
when 'debian'

Check warning on line 149 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L149

Added line #L149 was not covered by tests
%w[curl lsb-release apt-transport-https]
when 'windows'

Check warning on line 151 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L151

Added line #L151 was not covered by tests
if host.is_cygwin?
raise RuntimeError, "cygwin is not installed on #{host}" if !host.cygwin_installed?

Check warning on line 154 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L153-L154

Added lines #L153 - L154 were not covered by tests
%w[curl]
else

Check warning on line 156 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L156

Added line #L156 was not covered by tests
[]
end

Check warning on line 158 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L158

Added line #L158 was not covered by tests
when 'freebsd'
%w[curl perl5|perl]
when 'solaris'

Check warning on line 161 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L161

Added line #L161 was not covered by tests
@version.to_i >= 11 ? %w[curl] : %w[CSWcurl wget]
when 'archlinux'

Check warning on line 163 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L163

Added line #L163 was not covered by tests
%w[curl net-tools openssh]
when 'amazon', 'fedora', 'aix', 'osx', 'f5', 'netscaler', /cisco_/

Check warning on line 165 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L165

Added line #L165 was not covered by tests
[]
else

Check warning on line 167 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L167

Added line #L167 was not covered by tests
%w[curl]
end

Check warning on line 169 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L169

Added line #L169 was not covered by tests
end

# Return a list of packages that are needed for timesync
#
# @return [Array<String>] A list of packages to install for timesync
def timesync_packages
return ['chrony'] if uses_chrony?

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

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L177

Added line #L177 was not covered by tests
case @variant
when 'freebsd', 'openbsd', 'windows', 'aix', 'osx', 'f5', 'netscaler', /cisco_/

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

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L179

Added line #L179 was not covered by tests
[]
when 'archlinux', 'opensuse',

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

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L181

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

Check failure on line 182 in lib/beaker/platform.rb

View workflow job for this annotation

GitHub Actions / rubocop

Lint/EmptyWhen: Avoid `when` branches without a body.
when 'sles'
@version.to_i >= 11 ? %w[ntp] : []
when 'solaris'

Check warning on line 185 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L185

Added line #L185 was not covered by tests
@version.to_i >= 11 ? %w[ntp] : %w[CSWntp]
else

Check warning on line 187 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L187

Added line #L187 was not covered by tests
%w[ntpdate]
end

Check warning on line 189 in lib/beaker/platform.rb

View check run for this annotation

Codecov / codecov/patch

lib/beaker/platform.rb#L189

Added line #L189 was not covered by tests
end
end
end

0 comments on commit 6700df9

Please sign in to comment.