2 require 'beaker/puppet_install_helper'
3 require 'beaker/module_install_helper'
5 def install_bolt_on(hosts)
6 on(hosts, "/opt/puppetlabs/puppet/bin/gem install --source http://rubygems.delivery.puppetlabs.net bolt -v '> 0.0.1'", acceptable_exit_codes: [0, 1]).stdout
10 ENV['PUPPET_INSTALL_TYPE'] =~ %r{pe}i
13 run_puppet_install_helper
14 install_bolt_on(hosts) unless pe_install?
15 install_module_on(hosts)
16 install_module_dependencies_on(hosts)
18 UNSUPPORTED_PLATFORMS = %w[RedHat Suse windows AIX Solaris].freeze
20 DEFAULT_PASSWORD = if default[:hypervisor] == 'vagrant'
22 elsif default[:hypervisor] == 'vcloud'
27 (on default, puppet('--version')).output.chomp
30 def run_puppet_access_login(user:, password: '~!@#$%^*-/ aZ', lifetime: '5y')
31 on(master, puppet('access', 'login', '--username', user, '--lifetime', lifetime), stdin: password)
34 def run_task(task_name:, params: nil, password: DEFAULT_PASSWORD)
36 run_puppet_task(task_name: task_name, params: params)
38 run_bolt_task(task_name: task_name, params: params, password: password)
42 def run_bolt_task(task_name:, params: nil, password: DEFAULT_PASSWORD)
43 on(master, "/opt/puppetlabs/puppet/bin/bolt task run #{task_name} --modules /etc/puppetlabs/code/modules/service --nodes localhost --password #{password} #{params}", acceptable_exit_codes: [0, 1]).stdout # rubocop:disable Metrics/LineLength
46 def run_puppet_task(task_name:, params: nil)
47 on(master, puppet('task', 'run', task_name, '--nodes', fact_on(master, 'fqdn'), params.to_s), acceptable_exit_codes: [0, 1]).stdout
50 def expect_multiple_regexes(result:, regexes:)
51 regexes.each do |regex|
52 expect(result).to match(regex)
56 # This method allows a block to be passed in and if an exception is raised
57 # that matches the 'error_matcher' matcher, the block will wait a set number
58 # of seconds before retrying.
60 # - max_retry_count - Max number of retries
61 # - retry_wait_interval_secs - Number of seconds to wait before retry
62 # - error_matcher - Matcher which the exception raised must match to allow retry
64 # retry_on_error_matching(3, 5, /OpenGPG Error/) do
65 # apply_manifest(pp, :catch_failures => true)
67 def retry_on_error_matching(max_retry_count = 3, retry_wait_interval_secs = 5, error_matcher = nil)
73 if try < max_retry_count && (error_matcher.nil? || e.message =~ error_matcher)
74 sleep retry_wait_interval_secs
82 RSpec.configure do |c|
84 proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
86 # Readable test descriptions
87 c.formatter = :documentation
89 # Configure all nodes in nodeset
91 run_puppet_access_login(user: 'admin') if pe_install?