Last active
May 17, 2018 11:53
-
-
Save hunner/fc630550d0cd8f2fe24a to your computer and use it in GitHub Desktop.
Example code for beaker-rspec on master & agent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is what a test would look like. | |
require 'spec_helper_acceptance' | |
describe 'some class' do | |
it 'does stuff' do | |
pp=<<-EOS | |
notify { 'done stuff spec': | |
message => 'This message should appear', | |
} | |
EOS | |
make_site_pp(pp) | |
# First run for successful changes | |
run_agent({:acceptable_exit_codes => [0,2]}) | |
# Second run for idempotency | |
run_agent({:acceptable_exit_codes => [0]}) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This is some code that can be placed in the spec/spec_helper_acceptance.rb | |
def make_sitepp(pp, path = File.join(master['puppetpath'], 'manifests')) | |
on master, "mkdir -p #{path}" | |
on master, create_remote_file(master, File.join(path, "site.pp"), pp) | |
on master, "chown -R #{master['user']}:#{master['group']} #{path}" | |
end | |
def run_agent(opts = {}) | |
run_agent_on(default, opts) | |
end | |
def run_agent_on(hosts, opts = {}) | |
exit_codes = Array(opts[:acceptable_exit_codes]) | |
exit_codes |= [0] | |
shell(puppet('agent', '-t'), {:acceptable_exit_codes => exit_codes}) | |
end | |
# And then the usual stuff... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment