(maint) make apt testing more stable, cleanup
[puppet-modules/puppetlabs-apt.git] / spec / spec_helper_acceptance.rb
1 require 'beaker-rspec'
2 require 'beaker/puppet_install_helper'
3 require 'beaker/module_install_helper'
4 require 'beaker-task_helper'
5
6 run_puppet_install_helper
7 install_bolt_on(hosts) unless pe_install?
8 install_module_on(hosts)
9 install_module_dependencies_on(hosts)
10
11 UNSUPPORTED_PLATFORMS = ['RedHat', 'Suse', 'windows', 'AIX', 'Solaris'].freeze
12 MAX_RETRY_COUNT       = 12
13 RETRY_WAIT            = 10
14 ERROR_MATCHER         = %r{(no valid OpenPGP data found|keyserver timed out|keyserver receive failed)}
15
16 # This method allows a block to be passed in and if an exception is raised
17 # that matches the 'error_matcher' matcher, the block will wait a set number
18 # of seconds before retrying.
19 # Params:
20 # - max_retry_count - Max number of retries
21 # - retry_wait_interval_secs - Number of seconds to wait before retry
22 # - error_matcher - Matcher which the exception raised must match to allow retry
23 # Example Usage:
24 # retry_on_error_matching(3, 5, /OpenGPG Error/) do
25 #   apply_manifest(pp, :catch_failures => true)
26 # end
27 def retry_on_error_matching(max_retry_count = MAX_RETRY_COUNT, retry_wait_interval_secs = RETRY_WAIT, error_matcher = ERROR_MATCHER)
28   try = 0
29   begin
30     puts "retry_on_error_matching: try #{try}" unless try.zero?
31     try += 1
32     yield
33   rescue StandardError => e
34     raise unless try < max_retry_count && (error_matcher.nil? || e.message =~ error_matcher)
35     sleep retry_wait_interval_secs
36     retry
37   end
38 end
39
40 RSpec.configure do |c|
41   File.expand_path(File.join(File.dirname(__FILE__), '..'))
42
43   # Readable test descriptions
44   c.formatter = :documentation
45
46   # Configure all nodes in nodeset
47   c.before :suite do
48     run_puppet_access_login(user: 'admin') if pe_install? && puppet_version =~ %r{(5\.\d\.\d)}
49   end
50 end