aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorEnis Inan <enis.inan@puppet.com>2019-01-09 10:27:10 -0800
committerEnis Inan <enis.inan@puppet.com>2019-01-09 13:29:10 -0800
commitc0068fc6535289f7828ba42ad8610914a57604f1 (patch)
treec1cf43c794803ea8e33cae71feaed893d900cf1d /spec
parent071e84c6974d3f783abc8b5a0ded66684f6ac65f (diff)
downloadpuppet-cron_core-c0068fc6535289f7828ba42ad8610914a57604f1.tar.gz
puppet-cron_core-c0068fc6535289f7828ba42ad8610914a57604f1.tar.bz2
(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.
Diffstat (limited to 'spec')
-rw-r--r--spec/acceptance/tests/resource/cron/should_not_overwrite_crontab_file_on_file_read_error_spec.rb33
-rw-r--r--spec/acceptance/tests/resource/cron/should_only_fail_associated_resources_on_file_read_error_spec.rb29
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