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 = ['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:
31 '~!@#$%^*-/ aZ', lifetime: '5y')
32 on(master, puppet('access', 'login', '--username', user, '--lifetime', lifetime), stdin: password)
35 def run_task(task_name:, params: nil, password: DEFAULT_PASSWORD)
37 run_puppet_task(task_name: task_name, params: params)
39 run_bolt_task(task_name: task_name, params: params, password: password)
43 def run_bolt_task(task_name:, params: nil, password: DEFAULT_PASSWORD)
44 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
47 def run_puppet_task(task_name:, params: nil)
48 on(master, puppet('task', 'run', task_name, '--nodes', fact_on(master, 'fqdn'), params.to_s), acceptable_exit_codes: [0, 1]).stdout
51 def expect_multiple_regexes(result:, regexes:)
52 regexes.each do |regex|
53 expect(result).to match(regex)
57 # This method allows a block to be passed in and if an exception is raised
58 # that matches the 'error_matcher' matcher, the block will wait a set number
59 # of seconds before retrying.
61 # - max_retry_count - Max number of retries
62 # - retry_wait_interval_secs - Number of seconds to wait before retry
63 # - error_matcher - Matcher which the exception raised must match to allow retry
65 # retry_on_error_matching(3, 5, /OpenGPG Error/) do
66 # apply_manifest(pp, :catch_failures => true)
68 def retry_on_error_matching(max_retry_count = 3, retry_wait_interval_secs = 5, error_matcher = nil)
73 rescue StandardError => e
74 raise unless try < max_retry_count && (error_matcher.nil? || e.message =~ error_matcher)
75 sleep retry_wait_interval_secs
80 RSpec.configure do |c|
81 File.expand_path(File.join(File.dirname(__FILE__), '..'))
83 # Readable test descriptions
84 c.formatter = :documentation
86 # Configure all nodes in nodeset
88 run_puppet_access_login(user: 'admin') if pe_install? && puppet_version =~ %r{(5\.\d\.\d)}