diff options
Diffstat (limited to 'spec/acceptance/tests')
2 files changed, 51 insertions, 11 deletions
diff --git a/spec/acceptance/tests/resource/cron/should_not_overwrite_crontab_file_on_file_read_error_spec.rb b/spec/acceptance/tests/resource/cron/should_not_overwrite_crontab_file_on_file_read_error_spec.rb index 08e8bb8..6a5b2c6 100644 --- a/spec/acceptance/tests/resource/cron/should_not_overwrite_crontab_file_on_file_read_error_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_not_overwrite_crontab_file_on_file_read_error_spec.rb @@ -1,18 +1,31 @@  require 'spec_helper_acceptance'  RSpec.context 'when Puppet cannot read a crontab file' do +  # This test only makes sense for agents that shipped with PUP-9217's +  # changes, so we do not want to run it on older agents. +  def older_agent?(agent) +    puppet_version = Gem::Version.new(on(agent, puppet('--version')).stdout.chomp) +    minimum_puppet_version = if puppet_version < Gem::Version.new('6.0.0') +                               Gem::Version.new('5.5.9') +                             else +                               Gem::Version.new('6.0.5') +                             end + +    puppet_version < minimum_puppet_version +  end +    let(:username) { "pl#{rand(999_999).to_i}" }    let(:crontab_contents) { '6 6 6 6 6 /usr/bin/true' }    before(:each) do -    step 'Create the user on the agents' do -      compatible_agents.each do |agent| +    compatible_agents.each do |agent| +      next if older_agent?(agent) + +      step "Create the user on #{agent}" do          user_present(agent, username)        end -    end -    step "Set the user's crontab" do -      compatible_agents.each do |agent| +      step "Set the user's crontab on #{agent}" do          run_cron_on(agent, :add, username, crontab_contents)          assert_matching_arrays([crontab_contents], crontab_entries_of(agent, username), "Could not set the user's crontab for testing")        end @@ -20,8 +33,10 @@ RSpec.context 'when Puppet cannot read a crontab file' do    end    after(:each) do -    step 'Teardown -- Erase the user on the agents' do -      compatible_agents.each do |agent| +    compatible_agents.each do |agent| +      next if older_agent?(agent) + +      step "Teardown -- Erase the user on #{agent}" do          run_cron_on(agent, :remove, username)          user_absent(agent, username)        end @@ -30,6 +45,10 @@ RSpec.context 'when Puppet cannot read a crontab file' do    compatible_agents.each do |agent|      it "should not overwrite it on #{agent}" do +      if older_agent?(agent) +        skip('Skipping this test since we are on an older agent that does not have the PUP-9217 changes') +      end +        crontab_exe = nil        step 'Find the crontab executable' do          crontab_exe = on(agent, 'which crontab').stdout.chomp diff --git a/spec/acceptance/tests/resource/cron/should_only_fail_associated_resources_on_file_read_error_spec.rb b/spec/acceptance/tests/resource/cron/should_only_fail_associated_resources_on_file_read_error_spec.rb index 3e06d0c..1846523 100644 --- a/spec/acceptance/tests/resource/cron/should_only_fail_associated_resources_on_file_read_error_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_only_fail_associated_resources_on_file_read_error_spec.rb @@ -1,12 +1,27 @@  require 'spec_helper_acceptance'  RSpec.context 'when Puppet cannot read a crontab file' do +  # This test only makes sense for agents that shipped with PUP-9217's +  # changes, so we do not want to run it on older agents. +  def older_agent?(agent) +    puppet_version = Gem::Version.new(on(agent, puppet('--version')).stdout.chomp) +    minimum_puppet_version = if puppet_version < Gem::Version.new('6.0.0') +                               Gem::Version.new('5.5.9') +                             else +                               Gem::Version.new('6.0.5') +                             end + +    puppet_version < minimum_puppet_version +  end +    let(:username) { "pl#{rand(999_999).to_i}" }    let(:failed_username) { "pl#{rand(999_999).to_i}" }    before(:each) do -    step 'Create the users' do -      compatible_agents.each do |agent| +    compatible_agents.each do |agent| +      next if older_agent?(agent) + +      step "Create the users on #{agent}" do          user_present(agent, username)          user_present(agent, failed_username)        end @@ -14,8 +29,10 @@ RSpec.context 'when Puppet cannot read a crontab file' do    end    after(:each) do -    step 'Teardown -- Erase the users' do -      compatible_agents.each do |agent| +    compatible_agents.each do |agent| +      next if older_agent?(agent) + +      step "Teardown -- Erase the users on #{agent}" do          run_cron_on(agent, :remove, username)          user_absent(agent, username) @@ -26,6 +43,10 @@ RSpec.context 'when Puppet cannot read a crontab file' do    compatible_agents.each do |agent|      it "should only fail the associated resources on #{agent}" do +      if older_agent?(agent) +        skip('Skipping this test since we are on an older agent that does not have the PUP-9217 changes') +      end +        crontab_exe = nil        step 'Find the crontab executable' do          crontab_exe = on(agent, 'which crontab').stdout.chomp  | 
