Implement retry on tests which pull key from a key server which sometimes times out...
[puppet-modules/puppetlabs-apt.git] / spec / spec_helper_acceptance.rb
1 require 'beaker-rspec'
2 require 'beaker/puppet_install_helper'
3
4 run_puppet_install_helper
5
6 UNSUPPORTED_PLATFORMS = ['RedHat','Suse','windows','AIX','Solaris']
7
8 # This method allows a block to be passed in and if an exception is raised
9 # that matches the 'error_matcher' matcher, the block will wait a set number
10 # of seconds before retrying.
11 # Params:
12 # - max_retry_count - Max number of retries
13 # - retry_wait_interval_secs - Number of seconds to wait before retry
14 # - error_matcher - Matcher which the exception raised must match to allow retry
15 # Example Usage:
16 # retry_on_error_matching(3, 5, /OpenGPG Error/) do
17 #   apply_manifest(pp, :catch_failures => true)
18 # end
19 def retry_on_error_matching(max_retry_count = 3, retry_wait_interval_secs = 5, error_matcher = nil)
20   try = 0
21   begin
22     try += 1
23     yield
24   rescue Exception => e
25     if try < max_retry_count && (error_matcher == nil || e.message =~ error_matcher)
26       sleep retry_wait_interval_secs
27       retry
28     else
29       raise
30     end
31   end
32 end
33
34 RSpec.configure do |c|
35   # Project root
36   proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
37
38   # Readable test descriptions
39   c.formatter = :documentation
40
41   # Configure all nodes in nodeset
42   c.before :suite do
43     # Install module and dependencies
44     hosts.each do |host|
45       copy_module_to(host, :source => proj_root, :module_name => 'apt')
46       shell("/bin/touch #{default['puppetpath']}/hiera.yaml")
47       on host, puppet('module install puppetlabs-stdlib --version 4.5.0'), { :acceptable_exit_codes => [0,1] }
48     end
49   end
50 end