Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only install timesync related packages if enabled #1852

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 45 additions & 42 deletions lib/beaker/host_prebuilt_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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>] host One or more hosts to act upon
Expand Down Expand Up @@ -108,48 +109,50 @@
# @param [Host] host A host return the packages for
# @return [Array<String>] 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

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

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L118

Added line #L118 was not covered by tests
when /sles-10/
SLES10_PACKAGES

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

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L120

Added line #L120 was not covered by tests
when /opensuse|sles-/
SLES_PACKAGES
when /debian/
DEBIAN_PACKAGES

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

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L124

Added line #L124 was not covered by tests
when /cumulus/
CUMULUS_PACKAGES

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

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L126

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

WINDOWS_PACKAGES
else
PSWINDOWS_PACKAGES

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

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L133

Added line #L133 was not covered by tests
end
when /freebsd/
FREEBSD_PACKAGES

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

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L136

Added line #L136 was not covered by tests
when /openbsd/
OPENBSD_PACKAGES

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

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L138

Added line #L138 was not covered by tests
when /solaris-10/
SOLARIS10_PACKAGES

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

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L140

Added line #L140 was not covered by tests
when /solaris-1[1-9]/
SOLARIS11_PACKAGES

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

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L142

Added line #L142 was not covered by tests
when /archlinux/
ARCHLINUX_PACKAGES

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

View check run for this annotation

Codecov / codecov/patch

lib/beaker/host_prebuilt_steps.rb#L144

Added line #L144 was not covered by tests
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
Expand Down
15 changes: 14 additions & 1 deletion spec/beaker/host_prebuilt_steps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -293,7 +295,8 @@
end

context "validate_host" do
subject { dummy_class.new }

Check failure on line 298 in spec/beaker/host_prebuilt_steps_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/EmptyLineAfterSubject: Add an empty line after `subject`. (https://rspec.rubystyle.guide/#empty-line-after-let, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterSubject)
let(:timesync) { true }

it "can validate unix hosts" do
hosts.each do |host|
Expand Down Expand Up @@ -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 }

Expand All @@ -402,7 +415,7 @@
end
end

context "on windows" do

Check failure on line 418 in spec/beaker/host_prebuilt_steps_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/MultipleMemoizedHelpers: Example group has too many memoized helpers [19/18] (https://rspec.rubystyle.guide/#let-blocks, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers)
let(:host) do
make_host('name', {
:platform => 'windows',
Expand All @@ -411,7 +424,7 @@
})
end

context "with cygwin" do

Check failure on line 427 in spec/beaker/host_prebuilt_steps_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/MultipleMemoizedHelpers: Example group has too many memoized helpers [20/18] (https://rspec.rubystyle.guide/#let-blocks, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers)
let(:cygwin) { true }

before do
Expand All @@ -421,7 +434,7 @@
include_examples 'find domain name'
end

context "without cygwin" do

Check failure on line 437 in spec/beaker/host_prebuilt_steps_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/MultipleMemoizedHelpers: Example group has too many memoized helpers [20/18] (https://rspec.rubystyle.guide/#let-blocks, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers)
let(:cygwin) { false }

before do
Expand All @@ -433,7 +446,7 @@
end

%w[amazon centos redhat].each do |platform|
context "on platform '#{platform}'" do

Check failure on line 449 in spec/beaker/host_prebuilt_steps_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/MultipleMemoizedHelpers: Example group has too many memoized helpers [19/18] (https://rspec.rubystyle.guide/#let-blocks, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers)
let(:host) do
make_host('name', {
:platform => platform,
Expand All @@ -445,25 +458,25 @@
expect(Beaker::Command).to receive(:new).with("cat /etc/resolv.conf").once
end

context "with a domain entry" do

Check failure on line 461 in spec/beaker/host_prebuilt_steps_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/MultipleMemoizedHelpers: Example group has too many memoized helpers [19/18] (https://rspec.rubystyle.guide/#let-blocks, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers)
let(:stdout) { "domain labs.lan d.labs.net dc1.labs.net labs.com\nnameserver 10.16.22.10\nnameserver 10.16.22.11" }

include_examples 'find domain name'
end

context "with a search entry" do

Check failure on line 467 in spec/beaker/host_prebuilt_steps_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/MultipleMemoizedHelpers: Example group has too many memoized helpers [19/18] (https://rspec.rubystyle.guide/#let-blocks, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers)
let(:stdout) { "search labs.lan d.labs.net dc1.labs.net labs.com\nnameserver 10.16.22.10\nnameserver 10.16.22.11" }

include_examples 'find domain name'
end

context "with a both a domain and a search entry" do

Check failure on line 473 in spec/beaker/host_prebuilt_steps_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/MultipleMemoizedHelpers: Example group has too many memoized helpers [19/18] (https://rspec.rubystyle.guide/#let-blocks, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers)
let(:stdout) { "domain labs.lan\nsearch d.labs.net dc1.labs.net labs.com\nnameserver 10.16.22.10\nnameserver 10.16.22.11" }

include_examples 'find domain name'
end

context "with a both a domain and a search entry, the search entry first" do

Check failure on line 479 in spec/beaker/host_prebuilt_steps_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/MultipleMemoizedHelpers: Example group has too many memoized helpers [19/18] (https://rspec.rubystyle.guide/#let-blocks, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers)
let(:stdout) { "search foo.example.net\ndomain labs.lan d.labs.net dc1.labs.net labs.com\nnameserver 10.16.22.10\nnameserver 10.16.22.11" }

include_examples 'find domain name'
Expand Down
Loading