From c0068fc6535289f7828ba42ad8610914a57604f1 Mon Sep 17 00:00:00 2001 From: Enis Inan Date: Wed, 9 Jan 2019 10:27:10 -0800 Subject: (MODULES-7789) Don't run new tests on older agents We only want to run these tests on agents that shipped with PUP-9217's changes. These are any agents newer than 5.5.8 in the 5.y release stream, and any agents newer than 6.0.4 in the 6.y release stream. --- ...erwrite_crontab_file_on_file_read_error_spec.rb | 33 +++++++++++++++++----- ...associated_resources_on_file_read_error_spec.rb | 29 ++++++++++++++++--- 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 -- cgit v1.2.3