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