From 2d9e6ffd6e505aacd6f445247772d1e7839b4199 Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Mon, 5 Feb 2024 10:31:30 -0800 Subject: [PATCH 1/7] Replace assert_no_match The assert_no_match method in Beaker was long deprecated then eventually removed altogether in voxpupuli/beaker@6282311 This commit updates assert_no_match to refute_match. --- acceptance/tests/stub_host.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acceptance/tests/stub_host.rb b/acceptance/tests/stub_host.rb index 6c7f1bc..7565e4c 100644 --- a/acceptance/tests/stub_host.rb +++ b/acceptance/tests/stub_host.rb @@ -44,7 +44,7 @@ def get_hosts_file(host) hosts.each do |host| hosts_file = get_hosts_file(host) result = on host, "cat #{hosts_file}" - assert_no_match(/sleepy/, result.stdout) + refute_match(/sleepy/, result.stdout) end end end From 3ba6cb209c781d3e7469b4f584de2c5cd594dd0a Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Wed, 7 Feb 2024 09:04:37 -0800 Subject: [PATCH 2/7] Remove passenger-related methods Passenger support was dropped in Puppet 6 and support for passenger-related methods was removed from Beaker in voxpupuli/beaker@74047d1. This commit removes all passenger-related Beaker methods. The start_puppet_from_source_on! method is unused as a result of this removal. Additionally, since this method's purpose was to control the WEBrick-based server that was removed from Puppet in Puppet 6 (see puppetlabs/puppet@9275e62), I've also removed the start_puppet_from_source_on! method. Co-authored-by: Tim Meusel --- lib/beaker-puppet/helpers/puppet_helpers.rb | 78 +----- setup/common/040_ValidateSignCert.rb | 9 +- .../helpers/puppet_helpers_spec.rb | 224 ------------------ 3 files changed, 14 insertions(+), 297 deletions(-) diff --git a/lib/beaker-puppet/helpers/puppet_helpers.rb b/lib/beaker-puppet/helpers/puppet_helpers.rb index 445f234..4621e69 100644 --- a/lib/beaker-puppet/helpers/puppet_helpers.rb +++ b/lib/beaker-puppet/helpers/puppet_helpers.rb @@ -81,21 +81,13 @@ def puppet_group(host) # Test Puppet running in a certain run mode with specific options. # This ensures the following steps are performed: # 1. The pre-test Puppet configuration is backed up - # 2. A new Puppet configuraton file is layed down + # 2. Lay down a new Puppet configuraton file # 3. Puppet is started or restarted in the specified run mode # 4. Ensure Puppet has started correctly # 5. Further tests are yielded to # 6. Revert Puppet to the pre-test state # 7. Testing artifacts are saved in a folder named for the test # - # @note Whether Puppet is started or restarted depends on what kind of - # server you're running. Passenger and puppetserver are restarted before. - # Webrick is started before and stopped after yielding, unless you're using - # service scripts, then it'll behave like passenger & puppetserver. - # Passenger and puppetserver (or webrick using service scripts) - # restart after yielding by default. You can stop this from happening - # by setting the :restart_when_done flag of the conf_opts argument. - # # @param [Host] host One object that act like Host # # @param [Hash{Symbol=>String}] conf_opts Represents puppet settings. @@ -112,22 +104,11 @@ def puppet_group(host) # # These will only be applied when starting a FOSS # master, as a pe master is just bounced. - # @option conf_opts [Hash] :__service_args__ A special setting of options - # for controlling how the puppet master service is - # handled. The only setting currently is - # :bypass_service_script, which if set true will - # force stopping and starting a webrick master - # using the start_puppet_from_source_* methods, - # even if it seems the host has passenger. - # This is needed in FOSS tests to initialize - # SSL. # @option conf_opts [Boolean] :restart_when_done determines whether a restart # should be run after the test has been yielded to. # Will stop puppet if false. Default behavior # is to restart, but you can override this on the # host or with this option. - # (Note: only works for passenger & puppetserver - # masters (or webrick using the service scripts)) # @param [File] testdir The temporary directory which will hold backup # configuration, and other test artifacts. # @@ -156,12 +137,11 @@ def with_puppet_running_on(host, conf_opts, testdir = host.tmpdir(File.basename( end cmdline_args = conf_opts[:__commandline_args__] - service_args = conf_opts[:__service_args__] || {} restart_when_done = true restart_when_done = host[:restart_when_done] if host.has_key?(:restart_when_done) restart_when_done = conf_opts.fetch(:restart_when_done, restart_when_done) conf_opts = conf_opts.reject do |k, v| - %i[__commandline_args__ __service_args__ restart_when_done].include?(k) + %i[__commandline_args__ restart_when_done].include?(k) end curl_retries = host['master-start-curl-retries'] || options['master-start-curl-retries'] @@ -202,13 +182,8 @@ def with_puppet_running_on(host, conf_opts, testdir = host.tmpdir(File.basename( puppet_config(host, 'confdir', section: 'master'), testdir, 'puppet.conf') - lay_down_new_puppet_conf host, conf_opts, testdir - - if host.use_service_scripts? && !service_args[:bypass_service_script] - bounce_service(host, host['puppetservice'], curl_retries) - else - puppet_master_started = start_puppet_from_source_on!(host, cmdline_args) - end + lay_down_new_puppet_conf(host, conf_opts, testdir) + bounce_service(host, host['puppetservice'], curl_retries) yield self if block_given? @@ -229,20 +204,11 @@ def with_puppet_running_on(host, conf_opts, testdir = host.tmpdir(File.basename( raise(original_exception) ensure begin - if host.use_service_scripts? && !service_args[:bypass_service_script] - restore_puppet_conf_from_backup(host, backup_file) - if restart_when_done - bounce_service(host, host['puppetservice'], curl_retries) - else - host.exec puppet_resource('service', host['puppetservice'], 'ensure=stopped') - end + restore_puppet_conf_from_backup(host, backup_file) + if restart_when_done + bounce_service(host, host['puppetservice'], curl_retries) else - if puppet_master_started - stop_puppet_from_source_on(host) - else - dump_puppet_log(host) - end - restore_puppet_conf_from_backup(host, backup_file) + host.exec puppet_resource('service', host['puppetservice'], 'ensure=stopped') end rescue Exception => teardown_exception begin @@ -281,19 +247,6 @@ def restore_puppet_conf_from_backup(host, backup_file) end end - # @!visibility private - def start_puppet_from_source_on!(host, args = '') - host.exec(puppet('master', args)) - - logger.debug 'Waiting for the puppet master to start' - raise Beaker::DSL::FailTest, 'Puppet master did not start in a timely fashion' unless port_open_within?( - host, 8140, 10 - ) - - logger.debug 'The puppet master has started' - true - end - # @!visibility private def stop_puppet_from_source_on(host) pid = host.exec(Command.new('cat `puppet config print --section master pidfile`')).stdout.chomp @@ -355,19 +308,12 @@ def puppet_conf_for(host, conf_opts) def bounce_service(host, service, curl_retries = nil, port = nil) curl_retries = 120 if curl_retries.nil? port = options[:puppetserver_port] if port.nil? - if host.graceful_restarts? - service = host.check_for_command('apache2ctl') ? 'apache2ctl' : 'apachectl' - apachectl_path = host.is_pe? ? "#{host['puppetsbindir']}/#{service}" : service - host.exec(Command.new("#{apachectl_path} graceful")) - else - result = host.exec(Command.new("service #{service} reload"), - acceptable_exit_codes: [0, 1, 3]) - return result if result.exit_code == 0 + result = host.exec(Command.new("service #{service} reload"), acceptable_exit_codes: [0, 1, 3]) + return result if result.exit_code == 0 - host.exec puppet_resource('service', service, 'ensure=stopped') - host.exec puppet_resource('service', service, 'ensure=running') + host.exec puppet_resource('service', service, 'ensure=stopped') + host.exec puppet_resource('service', service, 'ensure=running') - end curl_with_retries(" #{service} ", host, "https://localhost:#{port}", [35, 60], curl_retries) end diff --git a/setup/common/040_ValidateSignCert.rb b/setup/common/040_ValidateSignCert.rb index a45b1be..39388ad 100644 --- a/setup/common/040_ValidateSignCert.rb +++ b/setup/common/040_ValidateSignCert.rb @@ -9,13 +9,8 @@ fqdn = on(master, 'facter fqdn').stdout.strip puppet_version = on(master, puppet('--version')).stdout.chomp - if master.use_service_scripts? - step 'Ensure puppet is stopped' - # Passenger, in particular, must be shutdown for the cert setup steps to work, - # but any running puppet master will interfere with webrick starting up and - # potentially ignore the puppet.conf changes. - on(master, puppet('resource', 'service', master['puppetservice'], 'ensure=stopped')) - end + step 'Ensure puppet is stopped' + on(master, puppet('resource', 'service', master['puppetservice'], 'ensure=stopped')) step 'Clear SSL on all hosts' hosts.each do |host| diff --git a/spec/beaker-puppet/helpers/puppet_helpers_spec.rb b/spec/beaker-puppet/helpers/puppet_helpers_spec.rb index f477d33..95049c8 100644 --- a/spec/beaker-puppet/helpers/puppet_helpers_spec.rb +++ b/spec/beaker-puppet/helpers/puppet_helpers_spec.rb @@ -760,7 +760,6 @@ def stub_host_and_subject_to_allow_the_default_testdir_argument_to_be_created end it 'raises the early_exception if backup_the_file fails' do - allow(host).to receive(:use_service_scripts?) allow(subject).to receive(:restore_puppet_conf_from_backup) expect(subject).to receive(:backup_the_file).and_raise(RuntimeError.new('puppet conf backup failed')) expect do @@ -772,7 +771,6 @@ def stub_host_and_subject_to_allow_the_default_testdir_argument_to_be_created allow(subject).to receive(:backup_the_file).and_raise(Minitest::Assertion.new('assertion failed!')) allow(host).to receive(:puppet).and_return({}) allow(subject).to receive(:restore_puppet_conf_from_backup) - allow(host).to receive(:use_service_scripts?) expect(subject).to receive(:fail_test) subject.with_puppet_running_on(host, {}) end @@ -847,7 +845,6 @@ def stub_post_setup allow(subject).to receive(:dump_puppet_log) allow(subject).to receive(:restore_puppet_conf_from_backup) allow(subject).to receive(:puppet_master_started) - allow(subject).to receive(:start_puppet_from_source_on!) allow(subject).to receive(:lay_down_new_puppet_conf) allow(subject).to receive(:logger).and_return(logger) allow(logger).to receive(:error) @@ -953,160 +950,6 @@ def stub_post_setup end end - context 'for foss packaged hosts using passenger' do - before(:each) do - host.uses_passenger! - end - it 'bounces puppet twice' do - allow(subject).to receive(:curl_with_retries) - subject.with_puppet_running_on(host, {}) - expect(host).to execute_commands_matching(/apachectl graceful/).exactly(2).times - end - - it 'gracefully restarts using apache2ctl' do - allow(host).to receive(:check_for_command).and_return(true) - allow(subject).to receive(:curl_with_retries) - subject.with_puppet_running_on(host, {}) - expect(host).to execute_commands_matching(/apache2ctl graceful/).exactly(2).times - end - - it 'gracefully restarts using apachectl' do - allow(host).to receive(:check_for_command).and_return(false) - allow(subject).to receive(:curl_with_retries) - subject.with_puppet_running_on(host, {}) - expect(host).to execute_commands_matching(/apachectl graceful/).exactly(2).times - end - - it 'yields to a block after bouncing service' do - execution = 0 - allow(subject).to receive(:curl_with_retries) - expect do - subject.with_puppet_running_on(host, {}) do - expect(host).to execute_commands_matching(/apachectl graceful/).once - execution += 1 - end - end.to change { execution }.by(1) - expect(host).to execute_commands_matching(/apachectl graceful/).exactly(2).times - end - - context ':restart_when_done flag set false' do - it 'bounces puppet once' do - allow(subject).to receive(:curl_with_retries) - subject.with_puppet_running_on(host, { restart_when_done: false }) - expect(host).to execute_commands_matching(/apachectl graceful/).once - end - - it 'yields to a block after bouncing service' do - execution = 0 - allow(subject).to receive(:curl_with_retries) - expect do - subject.with_puppet_running_on(host, { restart_when_done: false }) do - expect(host).to execute_commands_matching(/apachectl graceful/).once - execution += 1 - end - end.to change { execution }.by(1) - end - end - end - - context 'for foss packaged hosts using webrick' do - let(:use_service) { true } - - it 'stops and starts master using service scripts twice' do - allow(subject).to receive(:curl_with_retries) - subject.with_puppet_running_on(host, {}) - expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(2).times - expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times - end - - it 'yields to a block in between bounce calls for the service' do - execution = 0 - expect do - subject.with_puppet_running_on(host, {}) do - expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once - expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).once - execution += 1 - end - end.to change { execution }.by(1) - expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(2).times - expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times - end - - context ':restart_when_done flag set false' do - it 'stops (twice) and starts (once) master using service scripts' do - allow(subject).to receive(:curl_with_retries) - subject.with_puppet_running_on(host, { restart_when_done: false }) - expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once - expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times - end - - it 'yields to a block after stopping and starting service' do - execution = 0 - expect do - subject.with_puppet_running_on(host, { restart_when_done: false }) do - expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once - expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).once - execution += 1 - end - end.to change { execution }.by(1) - end - end - end - - context 'running from source' do - it 'does not try to stop if not started' do - expect(subject).to receive(:start_puppet_from_source_on!).and_return false - expect(subject).to_not receive(:stop_puppet_from_source_on) - - subject.with_puppet_running_on(host, {}) - end - - context 'successfully' do - before do - expect(host).to receive(:port_open?).with(8140).and_return(true) - end - - it 'starts puppet from source' do - subject.with_puppet_running_on(host, {}) - end - - it 'stops puppet from source' do - subject.with_puppet_running_on(host, {}) - expect(host).to execute_commands_matching(/^kill [^-]/).once - expect(host).to execute_commands_matching(/^kill -0/).once - end - - it 'yields between starting and stopping' do - execution = 0 - expect do - subject.with_puppet_running_on(host, {}) do - expect(host).to execute_commands_matching(/^puppet master/).once - execution += 1 - end - end.to change { execution }.by(1) - expect(host).to execute_commands_matching(/^kill [^-]/).once - expect(host).to execute_commands_matching(/^kill -0/).once - end - - it 'passes on commandline args' do - subject.with_puppet_running_on(host, { __commandline_args__: '--with arg' }) - expect(host).to execute_commands_matching(/^puppet master --with arg/).once - end - - it 'is not affected by the :restart_when_done flag' do - execution = 0 - expect do - subject.with_puppet_running_on(host, { restart_when_done: true }) do - expect(host).to execute_commands_matching(/^puppet master/).once - execution += 1 - end - end.to change { execution }.by(1) - expect(host).to execute_commands_matching(/^kill [^-]/).once - expect(host).to execute_commands_matching(/^kill -0/).once - end - end - end - describe 'backup and restore of puppet.conf' do before :each do allow(subject).to receive(:puppet_config).with(host, 'confdir', anything).and_return('/root/mock') @@ -1139,70 +982,6 @@ def stub_post_setup /ensure=running/) end end - - context 'when a puppetservice is not used' do - before do - expect(host).to receive(:port_open?).with(8140).and_return(true) - end - - it 'backs up puppet.conf' do - subject.with_puppet_running_on(host, {}) - expect(host).to execute_commands_matching(/cp #{original_location} #{backup_location}/).once - expect(host).to execute_commands_matching(/cat #{new_location} > #{original_location}/).once - end - - it 'restores puppet.conf after restarting when a puppetservice is not used' do - subject.with_puppet_running_on(host, {}) - expect(host).to execute_commands_matching_in_order(/kill [^-]/, - /cat '#{backup_location}' > '#{original_location}'/m) - end - - it "doesn't restore a non-existent file" do - allow(subject).to receive(:backup_the_file) - subject.with_puppet_running_on(host, {}) - expect(host).to execute_commands_matching(/rm -f '#{original_location}'/) - end - end - end - - let(:logger) { double.as_null_object } - describe 'handling failures' do - before do - allow(subject).to receive(:logger).and_return(logger) - expect(subject).to receive(:stop_puppet_from_source_on).and_raise(RuntimeError.new('Also failed in teardown.')) - expect(host).to receive(:port_open?).with(8140).and_return(true) - end - - it 'does not swallow an exception raised from within test block if ensure block also fails' do - expect(subject.logger).to receive(:error).with(/Raised during attempt to teardown.*Also failed in teardown/) - - expect do - subject.with_puppet_running_on(host, {}) { raise 'Failed while yielding.' } - end.to raise_error(RuntimeError, /failed.*because.*Failed while yielding./) - end - - it 'dumps the puppet logs if there is an error in the teardown' do - expect(subject.logger).to receive(:notify).with(/Dumping master log/) - - expect do - subject.with_puppet_running_on(host, {}) - end.to raise_error(RuntimeError, /Also failed in teardown/) - end - - it 'does not mask the teardown error with an error from dumping the logs' do - expect(subject.logger).to receive(:notify).with(/Dumping master log/).and_raise('Error from dumping logs') - - expect do - subject.with_puppet_running_on(host, {}) - end.to raise_error(RuntimeError, /Also failed in teardown/) - end - - it 'does not swallow a teardown exception if no earlier exception was raised' do - expect(subject.logger).to_not receive(:error) - expect do - subject.with_puppet_running_on(host, {}) - end.to raise_error(RuntimeError, 'Also failed in teardown.') - end end end end @@ -1229,7 +1008,6 @@ def stub_post_setup host = FakeHost.create allow(result).to receive(:exit_code).and_return(0) allow(host).to receive(:any_exec_result).and_return(result) - allow(host).to receive(:graceful_restarts?).and_return(false) expect(Beaker::Command).to receive(:new).with( /service not_real_service reload/, @@ -1251,7 +1029,6 @@ def stub_post_setup it 'uses the default port argument if none given' do host = FakeHost.create - expect(host).to receive(:graceful_restarts?).and_return(false) allow(result).to receive(:exit_code).and_return(1) expect(subject).to receive(:curl_with_retries).with( anything, anything, /8140/, anything, anything @@ -1261,7 +1038,6 @@ def stub_post_setup it 'takes the port argument' do host = FakeHost.create - expect(host).to receive(:graceful_restarts?).and_return(false) allow(result).to receive(:exit_code).and_return(1) expect(subject).to receive(:curl_with_retries).with( anything, anything, /8000/, anything, anything From 94b8e0bf3799510d53704657e2936e4dbea3d3e7 Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Wed, 7 Feb 2024 09:19:27 -0800 Subject: [PATCH 3/7] Remove logic for end-of-life Puppet versions --- lib/beaker-puppet/helpers/puppet_helpers.rb | 37 ++++--------------- setup/common/040_ValidateSignCert.rb | 6 +-- .../helpers/puppet_helpers_spec.rb | 28 +------------- 3 files changed, 11 insertions(+), 60 deletions(-) diff --git a/lib/beaker-puppet/helpers/puppet_helpers.rb b/lib/beaker-puppet/helpers/puppet_helpers.rb index 4621e69..71448e2 100644 --- a/lib/beaker-puppet/helpers/puppet_helpers.rb +++ b/lib/beaker-puppet/helpers/puppet_helpers.rb @@ -765,28 +765,17 @@ def wait_for_host_in_dashboard(host) def sign_certificate_for(host = []) hostnames = [] hosts = host.is_a?(Array) ? host : [host] - puppet_version = on(master, puppet('--version')).stdout.chomp hosts.each do |current_host| if [master, dashboard, database].include? current_host - on current_host, puppet('agent -t'), acceptable_exit_codes: [0, 1, 2] - - if version_is_less(puppet_version, '5.99') - on master, puppet("cert --allow-dns-alt-names sign #{current_host}"), acceptable_exit_codes: [0, 24] - else - on master, "puppetserver ca sign --certname #{current_host}" - end + on(current_host, puppet('agent -t'), acceptable_exit_codes: [0, 1, 2]) + on(master, "puppetserver ca sign --certname #{current_host}") else hostnames << Regexp.escape(current_host.node_name) end end if hostnames.size < 1 - if version_is_less(puppet_version, '5.99') - on master, puppet('cert --sign --all --allow-dns-alt-names'), - acceptable_exit_codes: [0, 24] - else - on master, 'puppetserver ca sign --all', acceptable_exit_codes: [0, 24] - end + on(master, 'puppetserver ca sign --all', acceptable_exit_codes: [0, 24]) return end @@ -798,21 +787,11 @@ def sign_certificate_for(host = []) fail_test("Failed to sign cert for #{hostnames}") hostnames.clear end - - if version_is_less(puppet_version, '5.99') - on master, puppet('cert --sign --all --allow-dns-alt-names'), acceptable_exit_codes: [0, 24] - out = on(master, puppet('cert --list --all')).stdout - if hostnames.all? { |hostname| out =~ /\+ "?#{hostname}"?/ } - hostnames.clear - break - end - else - on master, 'puppetserver ca sign --all', acceptable_exit_codes: [0, 24] - out = on(master, 'puppetserver ca list --all').stdout - if out !~ /.*Requested.*/ && hostnames.all? { |hostname| out =~ /\b#{hostname}\b/ } - hostnames.clear - break - end + on(master, 'puppetserver ca sign --all', acceptable_exit_codes: [0, 24]) + out = on(master, 'puppetserver ca list --all').stdout + if out !~ /.*Requested.*/ && hostnames.all? { |hostname| out =~ /\b#{hostname}\b/ } + hostnames.clear + break end sleep next_sleep diff --git a/setup/common/040_ValidateSignCert.rb b/setup/common/040_ValidateSignCert.rb index 39388ad..8c9ba98 100644 --- a/setup/common/040_ValidateSignCert.rb +++ b/setup/common/040_ValidateSignCert.rb @@ -7,7 +7,6 @@ skip_test 'not testing with puppetserver' unless @options['is_puppetserver'] hostname = on(master, 'facter hostname').stdout.strip fqdn = on(master, 'facter fqdn').stdout.strip - puppet_version = on(master, puppet('--version')).stdout.chomp step 'Ensure puppet is stopped' on(master, puppet('resource', 'service', master['puppetservice'], 'ensure=stopped')) @@ -33,11 +32,10 @@ }, } - # In Puppet 6, we want to be using an intermediate CA - on master, 'puppetserver ca setup' if !version_is_less(puppet_version, '5.99') && !master['use_existing_container'] + on(master, 'puppetserver ca setup') with_puppet_running_on(master, master_opts) do step 'Agents: Run agent --test with autosigning enabled to get cert' - on agents, puppet('agent --test'), acceptable_exit_codes: [0, 2] + on(agents, puppet('agent --test'), acceptable_exit_codes: [0, 2]) end end end diff --git a/spec/beaker-puppet/helpers/puppet_helpers_spec.rb b/spec/beaker-puppet/helpers/puppet_helpers_spec.rb index 95049c8..2868742 100644 --- a/spec/beaker-puppet/helpers/puppet_helpers_spec.rb +++ b/spec/beaker-puppet/helpers/puppet_helpers_spec.rb @@ -638,7 +638,7 @@ def logger end end - it 'signs certs with `puppetserver ca` in Puppet 6' do + it 'signs certs with `puppetserver ca`' do allow(subject).to receive(:sleep).and_return(true) result.stdout = "+ \"#{agent}\"" @@ -647,34 +647,12 @@ def logger arg end - version_result = double('version', stdout: '6.0.0') - expect(subject).to receive(:on).with(master, '--version').and_return(version_result) - expect(subject).to receive(:version_is_less).and_return(false) expect(subject).to receive(:on).with(master, 'puppetserver ca sign --all', acceptable_exit_codes: [0, 24]).once expect(subject).to receive(:on).with(master, 'puppetserver ca list --all').once.and_return(result) subject.sign_certificate_for(agent) end - it 'signs certs with `puppet cert` in Puppet 5' do - allow(subject).to receive(:sleep).and_return(true) - - result.stdout = "+ \"#{agent}\"" - - allow(subject).to receive(:puppet) do |arg| - arg - end - - version_result = double('version', stdout: '5.0.0') - expect(subject).to receive(:on).with(master, '--version').and_return(version_result) - expect(subject).to receive(:version_is_less).and_return(true) - expect(subject).to receive(:on).with(master, 'cert --sign --all --allow-dns-alt-names', - acceptable_exit_codes: [0, 24]).once - expect(subject).to receive(:on).with(master, 'cert --list --all').once.and_return(result) - - subject.sign_certificate_for(agent) - end - it 'retries 11 times before quitting' do allow(subject).to receive(:sleep).and_return(true) @@ -685,8 +663,6 @@ def logger arg end - version_result = double('version', stdout: '6.0.0') - expect(subject).to receive(:on).with(master, '--version').and_return(version_result) expect(subject).to receive(:on).with(master, 'puppetserver ca sign --all', acceptable_exit_codes: [0, 24]).exactly(11).times expect(subject).to receive(:on).with(master, @@ -706,8 +682,6 @@ def logger arg end expect(subject).to receive(:on).with(master, 'agent -t', acceptable_exit_codes: [0, 1, 2]).once - version_result = double('version', stdout: '6.0.0') - expect(subject).to receive(:on).with(master, '--version').and_return(version_result) expect(subject).to receive(:on).with(master, 'puppetserver ca sign --certname master').once expect(subject).to receive(:on).with(master, 'puppetserver ca sign --all', acceptable_exit_codes: [0, 24]).once From 22a38c8480ebfe2dfef7cf7f50c88dfa29b4dca2 Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Wed, 7 Feb 2024 09:54:43 -0800 Subject: [PATCH 4/7] Remove methods dependent on removed Beaker methods Beaker removed all install_puppet_agent_* method in voxpupuli/beaker@cdaedad. This commit removes beaker-puppet methods that relied on those install_puppet_agent_* methods. Co-authored-by: Tim Meusel --- lib/beaker-puppet/install_utils/foss_utils.rb | 187 -------- .../install_utils/foss_utils_spec.rb | 429 ------------------ .../install_utils/puppet_utils_spec.rb | 23 - 3 files changed, 639 deletions(-) diff --git a/lib/beaker-puppet/install_utils/foss_utils.rb b/lib/beaker-puppet/install_utils/foss_utils.rb index 663b827..49ef8b9 100644 --- a/lib/beaker-puppet/install_utils/foss_utils.rb +++ b/lib/beaker-puppet/install_utils/foss_utils.rb @@ -1195,193 +1195,6 @@ def install_packages_from_local_dev_repo(host, package_name) configure_type_defaults_on(host) end - # Install development repo of the puppet-agent on the given host(s). Downloaded from - # location of the form DEV_BUILDS_URL/puppet-agent/AGENT_VERSION/repos - # - # @param [Host, Array, String, Symbol] hosts One or more hosts to act upon, - # or a role (String or Symbol) that identifies one or more hosts. - # @param [Hash{Symbol=>String}] opts An options hash - # @option opts [String] :puppet_agent_version The version of puppet-agent to install. This - # parameter is used by puppet with the +SUITE_VERSION+ environment - # variable to provide a `git describe` value to beaker to create a - # build server URL. Note that +puppet_agent_sha+ will still be used - # instead of this if a value is provided for that option - # @option opts [String] :puppet_agent_sha The sha of puppet-agent to install, defaults to provided - # puppet_agent_version - # @option opts [String] :copy_base_local Directory where puppet-agent artifact - # will be stored locally - # (default: 'tmp/repo_configs') - # @option opts [String] :copy_dir_external Directory where puppet-agent - # artifact will be pushed to on the external machine - # (default: '/root') - # @option opts [String] :puppet_collection Defaults to 'PC1' - # @option opts [String] :dev_builds_url Base URL to pull artifacts from - # @option opts [String] :copy_base_local Directory where puppet-agent artifact - # will be stored locally - # (default: 'tmp/repo_configs') - # @option opts [String] :copy_dir_external Directory where puppet-agent - # artifact will be pushed to on the external machine - # (default: '/root') - # - # @note on windows, the +:ruby_arch+ host parameter can determine in addition - # to other settings whether the 32 or 64bit install is used - # - # @example - # install_puppet_agent_dev_repo_on(host, { :puppet_agent_sha => 'd3377feaeac173aada3a2c2cedd141eb610960a7', :puppet_agent_version => '1.1.1.225.gd3377fe' }) - # - # @return nil - def install_puppet_agent_dev_repo_on(hosts, global_opts) - global_opts[:puppet_agent_version] ||= global_opts[:version] # backward compatability - unless global_opts[:puppet_agent_version] - raise 'must provide :puppet_agent_version (puppet-agent version) for install_puppet_agent_dev_repo_on' - end - - block_on hosts do |host| - opts = global_opts.dup - - # TODO: consolidate these values as they serve no purpose from beaker's side - # you could provide any values you could to one to the other - puppet_agent_version = opts[:puppet_agent_sha] || opts[:puppet_agent_version] - - opts = sanitize_opts(opts) - opts[:download_url] = "#{opts[:dev_builds_url]}/puppet-agent/#{puppet_agent_version}/repos/" - opts[:copy_base_local] ||= File.join('tmp', 'repo_configs') - opts[:puppet_collection] ||= 'PC1' - - release_path = opts[:download_url] - - variant, version, arch, codename = host['platform'].to_array - add_role(host, 'aio') # we are installing agent, so we want aio role - copy_dir_local = File.join(opts[:copy_base_local], variant) - onhost_copy_base = opts[:copy_dir_external] || host.external_copy_base - - case variant - when /^(fedora|el|redhat|centos|debian|ubuntu|huaweios|cisco_nexus|cisco_ios_xr)$/ - if arch == 's390x' || host['hypervisor'] == 'ec2' - logger.trace("#install_puppet_agent_dev_repo_on: unsupported host #{host} for repo detected. using dev package") - else - install_puppetlabs_dev_repo(host, 'puppet-agent', puppet_agent_version, nil, opts) - host.install_package('puppet-agent') - logger.trace('#install_puppet_agent_dev_repo_on: install_puppetlabs_dev_repo finished') - next - end - when /^(eos|osx|windows|solaris|sles|aix)$/ - # Download installer package file & run install manually. - # Done below, so that el hosts with s390x arch or on ec2 can use this - # workflow as well - else - raise "No repository installation step for #{variant} yet..." - end - - release_path_end, release_file = host.puppet_agent_dev_package_info( - opts[:puppet_collection], opts[:puppet_agent_version], opts - ) - release_path << release_path_end - logger.trace('#install_puppet_agent_dev_repo_on: dev_package_info, continuing...') - - if variant =~ /eos/ - host.get_remote_file("#{release_path}/#{release_file}") - else - onhost_copied_file = File.join(onhost_copy_base, release_file) - fetch_http_file(release_path, release_file, copy_dir_local) - scp_to host, File.join(copy_dir_local, release_file), onhost_copy_base - end - - case variant - when /^eos/ - host.install_from_file(release_file) - when /^(sles|aix|fedora|el|redhat|centos)$/ - # NOTE: AIX does not support repo management. This block assumes - # that the desired rpm has been mirrored to the 'repos' location. - # NOTE: the AIX 7.1 package will only install on 7.2 with - # --ignoreos. This is a bug in package building on AIX 7.1's RPM - aix_72_ignoreos_hack = '--ignoreos' if variant == 'aix' && version == '7.2' - on host, "rpm -ivh #{aix_72_ignoreos_hack} #{onhost_copied_file}" - when /^windows$/ - result = on host, "echo #{onhost_copied_file}" - onhost_copied_file = result.raw_output.chomp - msi_opts = { debug: host[:pe_debug] || opts[:pe_debug] } - install_msi_on(host, onhost_copied_file, {}, msi_opts) - when /^osx$/ - host.install_package("puppet-agent-#{opts[:puppet_agent_version]}*") - when /^solaris$/ - host.solaris_install_local_package(release_file, onhost_copy_base) - end - configure_type_defaults_on(host) - end - end - alias install_puppetagent_dev_repo install_puppet_agent_dev_repo_on - - # Install shared repo of the puppet-agent on the given host(s). Downloaded from - # location of the form PE_PROMOTED_BUILDS_URL/PE_VER/puppet-agent/AGENT_VERSION/repo - # - # @param [Host, Array, String, Symbol] hosts One or more hosts to act upon, - # or a role (String or Symbol) that identifies one or more hosts. - # @param [Hash{Symbol=>String}] opts An options hash - # @option opts [String] :puppet_agent_version The version of puppet-agent to install, defaults to 'latest' - # @option opts [String] :pe_ver The version of PE (will also use host['pe_ver']), defaults to '4.0' - # @option opts [String] :copy_base_local Directory where puppet-agent artifact - # will be stored locally - # (default: 'tmp/repo_configs') - # @option opts [String] :copy_dir_external Directory where puppet-agent - # artifact will be pushed to on the external machine - # (default: '/root') - # @option opts [String] :puppet_collection Defaults to 'PC1' - # @option opts [String] :pe_promoted_builds_url Base URL to pull artifacts from - # - # @note on windows, the +:ruby_arch+ host parameter can determine in addition - # to other settings whether the 32 or 64bit install is used - # - # @example - # install_puppet_agent_pe_promoted_repo_on(host, { :puppet_agent_version => '1.1.0.227', :pe_ver => '4.0.0-rc1'}) - # - # @return nil - def install_puppet_agent_pe_promoted_repo_on(hosts, opts) - opts[:puppet_agent_version] ||= 'latest' - - block_on hosts do |host| - pe_ver = host[:pe_ver] || opts[:pe_ver] || '4.0.0-rc1' - opts = sanitize_opts(opts) - opts[:download_url] = - "#{opts[:pe_promoted_builds_url]}/puppet-agent/#{pe_ver}/#{opts[:puppet_agent_version]}/repos" - opts[:copy_base_local] ||= File.join('tmp', 'repo_configs') - opts[:copy_dir_external] ||= host.external_copy_base - opts[:puppet_collection] ||= puppet_collection_for(:puppet_agent, opts[:puppet_agent_version]) - add_role(host, 'aio') # we are installing agent, so we want aio role - release_path = opts[:download_url] - variant, version, arch, codename = host['platform'].to_array - copy_dir_local = File.join(opts[:copy_base_local], variant) - onhost_copy_base = opts[:copy_dir_external] - - release_path_end, release_file, download_file = - host.pe_puppet_agent_promoted_package_info( - opts[:puppet_collection], opts - ) - release_path << release_path_end - - onhost_copied_download = File.join(onhost_copy_base, download_file) - onhost_copied_file = File.join(onhost_copy_base, release_file) - fetch_http_file(release_path, download_file, copy_dir_local) - scp_to host, File.join(copy_dir_local, download_file), onhost_copy_base - - if variant == 'windows' - result = on host, "echo #{onhost_copied_file}" - onhost_copied_file = result.raw_output.chomp - opts = { debug: host[:pe_debug] || opts[:pe_debug] } - # couldn't pull this out, because it's relying on - # {Beaker::DSL::InstallUtils::WindowsUtils} methods, - # which I didn't want to attack right now. TODO - install_msi_on(host, onhost_copied_file, {}, opts) - else - host.pe_puppet_agent_promoted_package_install( - onhost_copy_base, onhost_copied_download, - onhost_copied_file, download_file, opts - ) - end - configure_type_defaults_on(host) - end - end - # This method will install a pem file certificate on a windows host # # @param [Host] host A host object diff --git a/spec/beaker-puppet/install_utils/foss_utils_spec.rb b/spec/beaker-puppet/install_utils/foss_utils_spec.rb index dc7bd19..d3e1f8e 100644 --- a/spec/beaker-puppet/install_utils/foss_utils_spec.rb +++ b/spec/beaker-puppet/install_utils/foss_utils_spec.rb @@ -1092,435 +1092,6 @@ def stub_uninteresting_portions_of_install_puppetlabs_dev_repo! end end - describe '#install_puppet_agent_dev_repo_on' do - let(:package_name) { 'puppet-agent' } - let(:platform) { @platform || 'other' } - let(:host) do - FakeHost.create('fakvm', platform, opts) - end - - before :each do - allow(subject).to receive(:configure_foss_defaults_on).and_return(true) - end - - it 'raises an exception when host platform is unsupported' do - host = basic_hosts.first - host['platform'] = Beaker::Platform.new('f5-5-x4') - opts = { version: '0.1.0' } - allow(subject).to receive(:options).and_return({}) - - expect do - subject.install_puppet_agent_dev_repo_on(host, opts) - end.to raise_error(RuntimeError, /No repository installation step for/) - end - - it 'runs the correct install for el-based platforms' do - host = basic_hosts.first - host['platform'] = Beaker::Platform.new('el-5-x86_64') - sha_value = 'ereiuwoiur' - opts = { version: '0.1.0', puppet_agent_sha: sha_value } - allow(subject).to receive(:options).and_return({}) - - expect(subject).to receive(:install_puppetlabs_dev_repo).with( - host, 'puppet-agent', sha_value, nil, anything - ) - expect(host).to receive(:install_package).with('puppet-agent') - - subject.install_puppet_agent_dev_repo_on(host, opts) - end - - it 'runs the correct install for el-based platforms on s390x architectures' do - host = basic_hosts.first - host['platform'] = Beaker::Platform.new('el-5-s390x') - sha_value = 'ereiuwoiur' - opts = { version: '0.1.0', puppet_agent_sha: sha_value } - allow(subject).to receive(:options).and_return({}) - - release_path_end = 'fake_release_path_end' - release_file = 'fake_29835_release_file' - expect(host).to receive(:puppet_agent_dev_package_info).and_return( - [release_path_end, release_file], - ) - - expect(subject).not_to receive(:install_puppetlabs_dev_repo) - expect(host).not_to receive(:install_package) - - expect(subject).to receive(:fetch_http_file).once.with(/#{release_path_end}$/, release_file, %r{/el$}) - expect(subject).to receive(:scp_to).once.with(host, /#{release_file}$/, anything) - expect(subject).to receive(:on).ordered.with(host, /rpm -ivh.*#{release_file}$/) - - subject.install_puppet_agent_dev_repo_on(host, opts) - end - - it 'runs the correct agent install for el-based platforms on ec2 hypervisor' do - host = basic_hosts.first - host['platform'] = Beaker::Platform.new('el-5-x86_64') - host['hypervisor'] = 'ec2' - sha_value = 'ereiuwoiur' - opts = { version: '0.1.0', puppet_agent_sha: sha_value } - allow(subject).to receive(:options).and_return({}) - - release_path_end = 'fake_release_path_end' - release_file = 'fake_29835_release_file' - expect(host).to receive(:puppet_agent_dev_package_info).and_return( - [release_path_end, release_file], - ) - - expect(subject).not_to receive(:install_puppetlabs_dev_repo) - expect(host).not_to receive(:install_package) - - expect(subject).to receive(:fetch_http_file).once.with(/#{release_path_end}$/, release_file, %r{/el$}) - expect(subject).to receive(:scp_to).once.with(host, /#{release_file}$/, anything) - expect(subject).to receive(:on).ordered.with(host, /rpm -ivh.*#{release_file}$/) - - subject.install_puppet_agent_dev_repo_on(host, opts) - end - - it 'runs the correct install for debian-based platforms' do - platform = Beaker::Platform.new('debian-5-x86_64') - host = basic_hosts.first - host['platform'] = platform - sha_value = 'ereigregerge' - opts = { version: '0.1.0', puppet_agent_sha: sha_value } - allow(subject).to receive(:options).and_return({}) - - expect(subject).to receive(:install_puppetlabs_dev_repo).with( - host, 'puppet-agent', sha_value, nil, anything - ) - expect(host).to receive(:install_package).with('puppet-agent') - - subject.install_puppet_agent_dev_repo_on(host, opts) - end - - it 'runs the correct install for windows platforms' do - host = winhost - external_copy_base = 'tmp_install_windows_copy_base_1325' - allow(host).to receive(:external_copy_base).and_return(external_copy_base) - opts = { version: '0.1.0' } - allow(subject).to receive(:options).and_return({}) - copied_path = "#{win_temp}\\puppet-agent-0.1.0-x64.msi" - mock_echo = Object.new - allow(mock_echo).to receive(:raw_output).and_return(copied_path) - - expect(subject).to receive(:fetch_http_file).once.with(%r{/windows$}, 'puppet-agent-0.1.0-x64.msi', %r{/windows$}) - expect(subject).to receive(:scp_to).once.with(host, %r{/puppet-agent-0.1.0-x64.msi$}, /#{external_copy_base}/) - expect(subject).to receive(:install_msi_on).with(host, copied_path, {}, { debug: nil }).once - expect(subject).to receive(:on).ordered.with(host, /echo/).and_return(mock_echo) - - subject.install_puppet_agent_dev_repo_on(host, opts) - end - - it 'runs the correct install for osx platforms' do - host = machost - host['platform'] = Beaker::Platform.new('osx-109-x86_64') - sha_value = 'runs the correct install for osx platforms' - copy_dir_external = 'fake_15_copy_dir_external' - opts = { - version: '0.1.0', - puppet_agent_sha: sha_value, - copy_dir_external: copy_dir_external, - } - - release_path_end = 'fake_release_path_end' - release_file = 'fake_29835_release_file' - expect(host).to receive(:puppet_agent_dev_package_info).and_return( - [release_path_end, release_file], - ) - - expect(subject).to receive(:fetch_http_file).once.with(/#{release_path_end}$/, release_file, %r{/osx$}) - expect(subject).to receive(:scp_to).once.with(host, /#{release_file}$/, copy_dir_external) - # the star is necessary, as that's not the entire filename, & we rely on - # the globbing to get this right on OSX SUTs - expect(host).to receive(:install_package).with(/^puppet-agent-0.1.0\*$/) - - subject.install_puppet_agent_dev_repo_on(host, opts) - end - - it 'runs the correct install for solaris platforms' do - @platform = 'solaris-10-x86_64' - opts = { version: '0.1.0' } - allow(subject).to receive(:options).and_return({}) - - release_path_end = 'fake_release_path_end' - release_file = 'fake_sol10_8495_release_file' - expect(host).to receive(:puppet_agent_dev_package_info).and_return( - [release_path_end, release_file], - ) - - expect(subject).to receive(:fetch_http_file).once.with( - /#{release_path_end}$/, release_file, anything - ) - expect(subject).to receive(:scp_to).once.with( - host, /#{release_file}$/, anything - ) - - expect(host).to receive(:solaris_install_local_package) - - allow(subject).to receive(:configure_type_defaults_on) - subject.install_puppet_agent_dev_repo_on(host, opts) - end - - it 'allows you to override the local copy directory' do - # only applies to hosts that don't go down the - # install_puppetlabs_dev_repo route - host = eoshost - host['platform'] = Beaker::Platform.new('eos-5-x86_64') - sha_value = 'dahdahdahdah' - copy_base_local_override = 'face' - opts = { - version: '0.1.0', - copy_base_local: copy_base_local_override, - puppet_agent_sha: sha_value, - } - allow(subject).to receive(:options).and_return({}) - - allow(host).to receive(:puppet_agent_dev_package_info).and_return(['', '']) - - allow(host).to receive(:get_remote_file).once.with(anything) - allow(host).to receive(:install_from_file) - - subject.install_puppet_agent_dev_repo_on(host, opts) - end - - it 'allows you to override the external copy directory' do - host = basic_hosts.first - host['platform'] = Beaker::Platform.new('osx-5-x86_64') - copy_dir_custom = 'muppetsBB8-1435' - opts = { version: '0.1.0', copy_dir_external: copy_dir_custom } - allow(subject).to receive(:options).and_return({}) - - allow(host).to receive(:puppet_agent_dev_package_info).and_return(['', '']) - - allow(subject).to receive(:fetch_http_file).once - expect(subject).to receive(:scp_to).once.with( - host, anything, /#{copy_dir_custom}/ - ) - allow(host).to receive(:install_package) - - subject.install_puppet_agent_dev_repo_on(host, opts) - end - - it 'copies package to the cygwin root directory and installs it' do - @platform = 'windows-7-x86_64' - expect(subject).to receive(:install_msi_on).with(any_args) - copy_base = 'copy_base_cygwin' - allow(host).to receive(:external_copy_base).and_return(copy_base) - expect(subject).to receive(:scp_to).with(host, /puppet-agent-1\.0\.0-x64\.msi/, /#{copy_base}/) - expect(subject).to receive(:configure_type_defaults_on).with(host) - expect(subject).to receive(:fetch_http_file).with(%r{[^/]\z}, anything, anything) - subject.install_puppet_agent_dev_repo_on(host, opts.merge({ puppet_agent_version: '1.0.0' })) - end - - it 'installs on different hosts without erroring' do - mhosts = hosts - mhosts[3] = eoshost - - mhosts.each_with_index do |host, index| - if index == 0 - host['platform'] = Beaker::Platform.new('solaris-5-x4') - allow(host).to receive(:external_copy_base) { '/host0' } - elsif index == 1 - host['platform'] = Beaker::Platform.new('windows-5-x4') - allow(host).to receive(:external_copy_base) { '/host1' } - elsif index == 2 - host['platform'] = Beaker::Platform.new('osx-5-x4') - allow(host).to receive(:external_copy_base) { '/host2' } - elsif index == 3 - host['platform'] = Beaker::Platform.new('eos-5-x4') - allow(host).to receive(:external_copy_base) { '/host3' } - end - allow(host).to receive(:puppet_agent_dev_package_info).with(any_args).and_return(%w[test blah]) - end - - expect(subject).to receive(:add_role).with(any_args).exactly(mhosts.length).times - - expect(subject).to receive(:fetch_http_file).with(any_args).exactly(3).times - expect(subject).to receive(:scp_to).with(any_args).exactly(3).times - - expect(subject).to receive(:install_msi_on).with(mhosts[1], 'xyz', {}, anything).exactly(1).times - expect(mhosts[0]).to receive(:solaris_install_local_package).with('blah', '/host0').exactly(1).times - expect(mhosts[2]).to receive(:install_package).with(any_args).exactly(1).times - expect(mhosts[3]).to receive(:install_from_file).with('blah').exactly(1).times - - result = object_double(Beaker::Result.new({}, 'foo'), raw_output: 'xyz') - allow(subject).to receive(:on).with(mhosts[1], anything).and_return(result) - - expect(subject).to receive(:configure_type_defaults_on).with(any_args).exactly(mhosts.length).times - - subject.install_puppet_agent_dev_repo_on(mhosts, opts.merge({ puppet_agent_version: '1.0.0' })) - end - - it 'installs on different hosts with options specifying :copy_dir_external' do - mhosts = hosts - mhosts[3] = eoshost - - mhosts.each_with_index do |host, index| - if index == 0 - host['platform'] = Beaker::Platform.new('solaris-5-x4') - allow(host).to receive(:external_copy_base) { '/host0' } - elsif index == 1 - host['platform'] = Beaker::Platform.new('windows-5-x4') - allow(host).to receive(:external_copy_base) { '/host1' } - elsif index == 2 - host['platform'] = Beaker::Platform.new('osx-5-x4') - allow(host).to receive(:external_copy_base) { '/host2' } - elsif index == 3 - host['platform'] = Beaker::Platform.new('eos-5-x4') - allow(host).to receive(:external_copy_base) { '/host3' } - end - allow(host).to receive(:puppet_agent_dev_package_info).with(any_args).and_return(['test', '/blah']) - end - - expect(subject).to receive(:add_role).with(any_args).exactly(mhosts.length).times - - expect(subject).to receive(:fetch_http_file).with(any_args).exactly(3).times - expect(subject).to receive(:scp_to).with(any_args).exactly(3).times - - expect(subject).to receive(:install_msi_on).with(mhosts[1], 'xyz', {}, anything).exactly(1).times - expect(mhosts[0]).to receive(:solaris_install_local_package).with('/blah', '/tmp').exactly(1).times - expect(mhosts[2]).to receive(:install_package).with(any_args).exactly(1).times - expect(mhosts[3]).to receive(:install_from_file).with('/blah').exactly(1).times - expect(mhosts[0]).to receive(:external_copy_base).with(no_args).exactly(0).times - expect(mhosts[1]).to receive(:external_copy_base).with(no_args).exactly(0).times - expect(mhosts[2]).to receive(:external_copy_base).with(no_args).exactly(0).times - expect(mhosts[3]).to receive(:external_copy_base).with(no_args).exactly(0).times - - result = object_double(Beaker::Result.new({}, 'foo'), raw_output: 'xyz') - allow(subject).to receive(:on).with(mhosts[1], anything).and_return(result) - - expect(subject).to receive(:configure_type_defaults_on).with(any_args).exactly(mhosts.length).times - - subject.install_puppet_agent_dev_repo_on(mhosts, - opts.merge({ puppet_agent_version: '1.0.0', copy_dir_external: '/tmp' })) - end - end - - describe '#install_puppet_agent_pe_promoted_repo_on' do - let(:package_name) { 'puppet-agent' } - let(:platform) { @platform || 'other' } - let(:host) do - FakeHost.create('fakvm', platform, opts) - end - - before :each do - allow(subject).to receive(:configure_foss_defaults_on).and_return(true) - allow(subject).to receive(:install_msi_on).with(any_args) - end - - def test_fetch_http_file_no_ending_slash(platform) - @platform = platform - allow(subject).to receive(:scp_to) - allow(subject).to receive(:configure_type_defaults_on).with(host) - - expect(subject).to receive(:fetch_http_file).with(%r{[^/]\z}, anything, anything) - subject.install_puppet_agent_pe_promoted_repo_on(host, opts) - end - - context 'on windows' do - it 'calls fetch_http_file with no ending slash' do - test_fetch_http_file_no_ending_slash('windows-7-x86_64') - end - end - - it 'calls fetch_http_file with no ending slash' do - test_fetch_http_file_no_ending_slash('debian-5-x86_64') - end - - context 'when setting different agent versions' do - let(:host) { basic_hosts.first } - let(:platform) { Beaker::Platform.new('el-6-x86_64') } - let(:downloadurl) { 'http://pm.puppet.com' } - before :each do - allow(subject).to receive(:options).and_return(opts) - allow(subject).to receive(:scp_to) - allow(subject).to receive(:configure_type_defaults_on).with(host) - end - - it 'sets correct file paths when agent version is set to latest' do - host['platform'] = platform - agentversion = 'latest' - collection = 'puppet' - opts = { puppet_agent_version: "#{agentversion}", pe_promoted_builds_url: "#{downloadurl}" } - - expect(subject).to receive(:fetch_http_file).once.with( - %r{pm\.puppet\.com/puppet-agent/.*/#{agentversion}/repos}, - /puppet-agent-el-6*/, - %r{/el$}, - ) - expect(host).to receive(:pe_puppet_agent_promoted_package_install).with( - anything, - /puppet-agent-el-6*/, - %r{.*/el/6/#{collection}/.*rpm}, - /puppet-agent-el-6/, - anything, - ) - subject.install_puppet_agent_pe_promoted_repo_on(host, opts) - end - - it 'sets correct file paths for agent version 1.x.x' do - host['platform'] = platform - agentversion = '1.x.x' - collection = 'pc1' - opts = { puppet_agent_version: "#{agentversion}", pe_promoted_builds_url: "#{downloadurl}" } - - expect(subject).to receive(:fetch_http_file).once.with( - %r{pm\.puppet\.com/puppet-agent/.*/#{agentversion}/repos}, - /puppet-agent-el-6*/, %r{/el$} - ) - expect(host).to receive(:pe_puppet_agent_promoted_package_install).with( - anything, - /puppet-agent-el-6*/, - %r{.*/el/6/#{collection}/.*rpm}, - /puppet-agent-el-6/, - anything, - ) - subject.install_puppet_agent_pe_promoted_repo_on(host, opts) - end - - it 'sets correct file paths for agent version >= 5.5.4' do - host['platform'] = platform - agentversion = '5.5.4' - collection = 'puppet5' - opts = { puppet_agent_version: "#{agentversion}", pe_promoted_builds_url: "#{downloadurl}" } - - expect(subject).to receive(:fetch_http_file).once.with( - %r{pm\.puppet\.com/puppet-agent/.*/#{agentversion}/repos}, - /puppet-agent-el-6*/, - %r{/el$}, - ) - expect(host).to receive(:pe_puppet_agent_promoted_package_install).with( - anything, - /puppet-agent-el-6*/, - %r{.*/el/6/#{collection}/.*rpm}, - /puppet-agent-el-6/, - anything, - ) - subject.install_puppet_agent_pe_promoted_repo_on(host, opts) - end - - it 'sets correct file paths for agent version > 5.99' do - host['platform'] = platform - agentversion = '6.0.0' - collection = 'puppet6' - opts = { puppet_agent_version: "#{agentversion}", pe_promoted_builds_url: "#{downloadurl}" } - - expect(subject).to receive(:fetch_http_file).once.with( - %r{pm\.puppet\.com/puppet-agent/.*/#{agentversion}/repos}, - /puppet-agent-el-6*/, - %r{/el$}, - ) - expect(host).to receive(:pe_puppet_agent_promoted_package_install).with( - anything, - /puppet-agent-el-6*/, - %r{.*/el/6/#{collection}/.*rpm}, - /puppet-agent-el-6/, - anything, - ) - subject.install_puppet_agent_pe_promoted_repo_on(host, opts) - end - end - end - describe '#install_puppetserver_on' do let(:host) { make_host('master', platform: 'el-7-x86_64') } diff --git a/spec/beaker-puppet/install_utils/puppet_utils_spec.rb b/spec/beaker-puppet/install_utils/puppet_utils_spec.rb index 0f5ddb3..e7316db 100644 --- a/spec/beaker-puppet/install_utils/puppet_utils_spec.rb +++ b/spec/beaker-puppet/install_utils/puppet_utils_spec.rb @@ -71,11 +71,6 @@ def logger subject.configure_defaults_on(hosts, 'aio') end - it 'can set pe defaults' do - expect(subject).to receive(:add_pe_defaults_on).exactly(hosts.length).times - subject.configure_defaults_on(hosts, 'pe') - end - it 'can remove old defaults ands replace with new' do # fake the results of calling configure_pe_defaults_on hosts.each do |host| @@ -128,24 +123,6 @@ def logger expect(subject).to receive(:add_aio_defaults_on).exactly(hosts.length).times subject.configure_type_defaults_on(hosts) end - - it 'can set pe defaults for pe type' do - hosts.each do |host| - host['type'] = 'pe' - end - expect(subject).to receive(:add_pe_defaults_on).exactly(hosts.length).times - subject.configure_type_defaults_on(hosts) - end - - it 'adds aio defaults to pe hosts when they an aio pe version' do - hosts.each do |host| - host['type'] = 'pe' - host['pe_ver'] = '4.0' - end - expect(subject).to receive(:add_pe_defaults_on).exactly(hosts.length).times - expect(subject).to receive(:add_aio_defaults_on).exactly(hosts.length).times - subject.configure_type_defaults_on(hosts) - end end describe '#puppetserver_version_on' do From 3419307ba6097c2c337fa555e7ae540adee8dd8e Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Wed, 7 Feb 2024 09:59:57 -0800 Subject: [PATCH 5/7] Require Beaker 5.0 Beaker 5.0.0 was released in March 2023 and all development effort is now focused on that stream. This commit updates beaker-puppet to require at least Beaker 5.0. --- beaker-puppet.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beaker-puppet.gemspec b/beaker-puppet.gemspec index 9e3f68e..5169e39 100644 --- a/beaker-puppet.gemspec +++ b/beaker-puppet.gemspec @@ -29,6 +29,6 @@ Gem::Specification.new do |s| s.add_development_dependency 'beaker-vmpooler', '~> 1.4' # Run time dependencies - s.add_runtime_dependency 'beaker', '~> 4.1' + s.add_runtime_dependency 'beaker', '~> 5.0' s.add_runtime_dependency 'oga', '~> 3.4' end From 366bbec79194800a22234e59d8b5f5e02651507e Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Wed, 7 Feb 2024 10:03:30 -0800 Subject: [PATCH 6/7] Require Ruby < 3.2 Ruby 3.2 removed Object#taint and #tainted?. One of beaker-puppet's depenencies, inifile, uses those methods. This commit updates the gemspec to limit usage on Ruby 3.2 and above. Also see: https://github.com/puppetlabs/beaker-puppet/issues/206 --- beaker-puppet.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beaker-puppet.gemspec b/beaker-puppet.gemspec index 5169e39..c51d04e 100644 --- a/beaker-puppet.gemspec +++ b/beaker-puppet.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.description = 'For use for the Beaker acceptance testing tool' s.license = 'Apache-2.0' - s.required_ruby_version = '>= 2.7' + s.required_ruby_version = '>= 2.7', '< 3.2' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") From 56133a86c37748c167e89959e2a8588dd3f3dd24 Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Wed, 7 Feb 2024 15:50:04 -0800 Subject: [PATCH 7/7] Remove deprecated method This commit removes the deprecated get_puppet_collection method. --- lib/beaker-puppet/install_utils/puppet_utils.rb | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/lib/beaker-puppet/install_utils/puppet_utils.rb b/lib/beaker-puppet/install_utils/puppet_utils.rb index 37b754f..96d6e45 100644 --- a/lib/beaker-puppet/install_utils/puppet_utils.rb +++ b/lib/beaker-puppet/install_utils/puppet_utils.rb @@ -65,23 +65,6 @@ def remove_puppet_paths_on(hosts) end end - # Given an agent_version, return the puppet collection associated with that agent version - # - # @param [String] agent_version version string or 'latest' - # @deprecated This method returns 'PC1' as the latest puppet collection; - # this is incorrect. Use {#puppet_collection_for} instead. - def get_puppet_collection(agent_version = 'latest') - collection = 'PC1' - if agent_version != 'latest' - if !version_is_less(agent_version, '5.5.4') and version_is_less(agent_version, '5.99') - collection = 'puppet5' - elsif !version_is_less(agent_version, '5.99') - collection = 'puppet6' - end - end - collection - end - # Determine the puppet collection that matches a given package version. The package # must be one of # * :puppet_agent (you can get this version from the `aio_agent_version_fact`)