diff --git a/lib/beaker/host_prebuilt_steps.rb b/lib/beaker/host_prebuilt_steps.rb index 1b3592b1f..a42abb86b 100644 --- a/lib/beaker/host_prebuilt_steps.rb +++ b/lib/beaker/host_prebuilt_steps.rb @@ -31,6 +31,7 @@ module HostPrebuiltSteps ROOT_KEYS_SCRIPT = "https://raw.githubusercontent.com/puppetlabs/puppetlabs-sshkeys/master/templates/scripts/manage_root_authorized_keys" ROOT_KEYS_SYNC_CMD = "curl -k -o - -L #{ROOT_KEYS_SCRIPT} | %s" ROOT_KEYS_SYNC_CMD_AIX = "curl --tlsv1 -o - -L #{ROOT_KEYS_SCRIPT} | %s" + TIMESYNC_PACKAGES = ['CSWntp', 'ntp', 'ntpdate', 'chrony'] # Run timesync on the provided hosts # @param [Host, Array] host One or more hosts to act upon @@ -108,48 +109,50 @@ 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) - 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 + packages = 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 + packages.select! { |pkg| !TIMESYNC_PACKAGES.include?(pkg) } unless host['timesync'] + packages end # Installs the given packages if they aren't already on a host diff --git a/spec/beaker/host_prebuilt_steps_spec.rb b/spec/beaker/host_prebuilt_steps_spec.rb index 4e7d47702..d901b0a32 100644 --- a/spec/beaker/host_prebuilt_steps_spec.rb +++ b/spec/beaker/host_prebuilt_steps_spec.rb @@ -12,11 +12,13 @@ let(:rhel8_packages) { Beaker::HostPrebuiltSteps::RHEL8_PACKAGES } let(:fedora_packages) { Beaker::HostPrebuiltSteps::FEDORA_PACKAGES } let(:amazon2023_packages) { Beaker::HostPrebuiltSteps::AMAZON2023_PACKAGES } + let(:timesync_packages) { Beaker::HostPrebuiltSteps::TIMESYNC_PACKAGES } let(:platform) { @platform || 'unix' } + let(:timesync) { @timesync || false } let(:ip) { "ip.address.0.0" } let(:stdout) { @stdout || ip } let(:hosts) do - hosts = make_hosts({ :stdout => stdout, :platform => platform }) + hosts = make_hosts({ :stdout => stdout, :platform => platform, :timesync => timesync }) hosts[0][:roles] = ['agent'] hosts[1][:roles] = %w[master dashboard agent database] hosts[2][:roles] = ['agent'] @@ -294,6 +296,7 @@ context "validate_host" do subject { dummy_class.new } + let(:timesync) { true } it "can validate unix hosts" do hosts.each do |host| @@ -393,6 +396,16 @@ end end + context 'host_packages' do + subject { dummy_class.new } + + it "filters timesync packages" do + hosts.each do |host| + expect(subject.host_packages(host)).not_to include(*timesync_packages) + end + end + end + context 'get_domain_name' do subject { dummy_class.new }