Skip to content

Instantly share code, notes, and snippets.

@lucywyman
Last active January 31, 2018 18:46
Show Gist options
  • Save lucywyman/3eb9b125aded88a2e4d9905d78ca5604 to your computer and use it in GitHub Desktop.
Save lucywyman/3eb9b125aded88a2e4d9905d78ca5604 to your computer and use it in GitHub Desktop.
plan test::my_unix_plan($nodes) {
$array = $nodes.split(',')
$result = run_task(test::hostname_nix, $array,
'success_nodes' => [$array[0]],
'_catch_errors' =>true)
$retry = run_task(test::hostname_nix, $result.error_set.names,
'success_nodes' => $result.error_set.names)
notice("Result is $result and retry result is $retry")
{ "result" => $result,
"retry" => $retry }
}
require 'bolt_command_helper'
extend Acceptance::BoltCommandHelper
test_name "C100553: \
bolt plan run should execute puppet plan on remote hosts via ssh" do
ssh_nodes = select_hosts(roles: ['ssh'])
user = ENV['SSH_USER']
password = ENV['SSH_PASSWORD']
nodes_csv = ssh_nodes.map(&:hostname).join(',')
skip_test('no applicable nodes to test on') if ssh_nodes.empty?
dir = bolt.tmpdir('C100553')
step 'create task on bolt controller' do
on(bolt, "mkdir -p #{dir}/modules/test/{tasks,plans}")
# TODO will this ever be run on non-vmpooler nodes?
create_remote_file(bolt, "#{dir}/modules/test/tasks/hostname_nix.sh", <<-FILE)
#!/bin/bash
HOSTNAME=$HOSTNAME.delivery.puppetlabs.net
if [ ! -f /tmp/retry.txt ] && [ "$HOSTNAME" = '#{ssh_nodes[0].hostname}' ]; then
touch /tmp/retry.txt;
exit 1
fi
FILE
end
step "create plan on bolt controller" do
create_remote_file(bolt,
"#{dir}/modules/test/plans/my_unix_plan.pp", <<-FILE)
plan test::my_unix_plan($nodes) {
$array = $nodes.split(',')
$result = run_task(test::hostname_nix, $array,
'success_nodes' => [$array[0]],
'_catch_errors' =>true)
$retry = run_task(test::hostname_nix, $result.error_set.names,
'success_nodes' => $result.error_set.names)
notice("Result is $result and retry result is $retry")
{ "result" => $result,
"retry" => $retry }
}
FILE
end
step "execute `bolt plan run` via SSH with json output" do
bolt_command = "bolt plan run test::my_unix_plan nodes=#{nodes_csv}"
flags = {
'-u' => user,
'--modulepath' => "#{dir}/modules",
'-p' => password,
'--no-host-key-check' => nil,
'--format' => 'json'
}
result = bolt_command_on(bolt, bolt_command, flags)
puts "STDERR #{result.stderr}"
puts "STDOUT #{result.stdout}"
ssh_nodes.each do |node|
assert_equal(0, result.exit_code,
"The task on #{node.hostname} did not exit with code 0 as expected")
end
end
step "execute `bolt plan run` via SSH with verbose, human readable output" do
bolt_command = "bolt plan run test::my_unix_plan nodes=#{nodes_csv}"
flags = {
'-u' => user,
'--modulepath' => "#{dir}/modules",
'-p' => password,
'--no-host-key-check' => nil,
'--verbose' => nil
}
result = bolt_command_on(bolt, bolt_command, flags)
puts "STDERR #{result.stderr}"
puts "STDOUT #{result.stdout}"
ssh_nodes.each do |node|
# Verify logging
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment