Merge pull request #795 from eimlav/modules3307
[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 require 'beaker/i18n_helper'
8 require 'beaker-task_helper'
9
10 run_puppet_install_helper
11 configure_type_defaults_on(hosts)
12 install_bolt_on(hosts) unless pe_install?
13 install_module_on(hosts)
14 install_module_dependencies_on(hosts)
15
16 UNSUPPORTED_PLATFORMS = ['RedHat', 'Suse', 'windows', 'AIX', 'Solaris'].freeze
17 MAX_RETRY_COUNT       = 12
18 RETRY_WAIT            = 10
19 ERROR_MATCHER         = %r{(no valid OpenPGP data found|keyserver timed out|keyserver receive failed)}
20
21 # This method allows a block to be passed in and if an exception is raised
22 # that matches the 'error_matcher' matcher, the block will wait a set number
23 # of seconds before retrying.
24 # Params:
25 # - max_retry_count - Max number of retries
26 # - retry_wait_interval_secs - Number of seconds to wait before retry
27 # - error_matcher - Matcher which the exception raised must match to allow retry
28 # Example Usage:
29 # retry_on_error_matching(3, 5, /OpenGPG Error/) do
30 #   apply_manifest(pp, :catch_failures => true)
31 # end
32 def retry_on_error_matching(max_retry_count = MAX_RETRY_COUNT, retry_wait_interval_secs = RETRY_WAIT, error_matcher = ERROR_MATCHER)
33   try = 0
34   begin
35     puts "retry_on_error_matching: try #{try}" unless try.zero?
36     try += 1
37     yield
38   rescue StandardError => e
39     raise unless try < max_retry_count && (error_matcher.nil? || e.message =~ error_matcher)
40     sleep retry_wait_interval_secs
41     retry
42   end
43 end
44
45 RSpec.configure do |c|
46   File.expand_path(File.join(File.dirname(__FILE__), '..'))
47
48   # Readable test descriptions
49   c.formatter = :documentation
50
51   # Configure all nodes in nodeset
52   c.before :suite do
53     run_puppet_access_login(user: 'admin') if pe_install? && (Gem::Version.new(puppet_version) >= Gem::Version.new('5.0.0'))
54
55     hosts.each do |host|
56       # This will be removed, this is temporary to test localisation.
57       if (fact('osfamily') == 'Debian' || fact('osfamily') == 'RedHat') &&
58          (Gem::Version.new(puppet_version) >= Gem::Version.new('4.10.5') &&
59           Gem::Version.new(puppet_version) < Gem::Version.new('5.2.0'))
60         on(host, 'mkdir /opt/puppetlabs/puppet/share/locale/ja')
61         on(host, 'touch /opt/puppetlabs/puppet/share/locale/ja/puppet.po')
62       end
63       if fact('osfamily') == 'Debian'
64         # install language on debian systems
65         install_language_on(host, 'ja_JP.utf-8') if not_controller(host)
66         # This will be removed, this is temporary to test localisation.
67       end
68       # Required for binding tests.
69       if fact('osfamily') == 'RedHat'
70         if fact('operatingsystemmajrelease') =~ %r{7} || fact('operatingsystem') =~ %r{Fedora}
71           shell('yum install -y bzip2')
72         end
73       end
74       on host, puppet('module', 'install', 'stahnma/epel')
75     end
76   end
77 end