Skip to content

Commit

Permalink
Merge branch 'ticket/3.0.x/15717-puppet-kick' into 3.0.x
Browse files Browse the repository at this point in the history
* ticket/3.0.x/15717-puppet-kick:
  (#15717) Acceptance tests for puppet kick
  (#15717) Allow pluginsync as an option to Puppet::Run
  (#15717) Require puppet/run in the agent
  • Loading branch information
joshcooper committed Oct 4, 2012
2 parents ffd5657 + 01574c9 commit 3aaa582
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 7 deletions.
84 changes: 84 additions & 0 deletions acceptance/tests/ticket_15717_puppet_kick.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
test_name "#15717: puppet kick"
step "verify puppet kick actually triggers an agent run"

confine :except, :platform => 'windows'

restauth_conf = <<END
path /run
auth yes
allow *
path /
auth any
END

with_master_running_on(master, "--autosign true") do
agents.each do |agent|
if agent == master
Log.warn("This test does not support nodes that are both master and agent")
next
end

step "create rest auth.conf on agent"
testdir = agent.tmpdir('puppet-kick-auth')
create_remote_file(agent, "#{testdir}/auth.conf", restauth_conf)

step "daemonize the agent"
on(agent, puppet_agent("--debug --daemonize --server #{master} --listen --rest_authconfig #{testdir}/auth.conf"))

begin
step "wait for agent to start listening"
timeout = 15
begin
Timeout.timeout(timeout) do
loop do
# 7 is "Could not connect to host", which will happen before it's running
result = on(agent, "curl -k https://#{agent}:8139", :acceptable_exit_codes => [0,7])
break if result.exit_code == 0
sleep 1
end
end
rescue Timeout::Error
fail_test "Puppet agent #{agent} failed to start after #{timeout} seconds"
end

begin
done = false
while not done do
step "kick the agent from the master"
# `puppet kick` exit code 3 may mean:
# 1. the agent we started above is actively connecting to the master
# and applying a catalog, if so, wait for it to become idle
# 2. auth.conf doesn't allow access to /run, which is the bug we're
# trying to verify
# 3. the SSL server's cert verification failed, in which case fail
# early: SSL_connect returned=1 errno=0 state=SSLv3 read server
# certificate B: certificate verify failed
# 4. who knows what else
#
# So make sure `puppet kick` returns with exit code 0 and prints
# 'status is success'. Also make sure we get a deprecation warning
on(master, puppet_kick("--host #{agent} --"), :acceptable_exit_codes => [0, 3]) do
assert_match(/Puppet kick is deprecated/, stderr, "Puppet kick did not issue deprecation warning")

if result.exit_code == 0
assert_match(/status is success/, stdout, "Puppet kick was successful, but agent #{agent} did not report success")
done = true
elsif stdout.include? "status is running"
step "Agent #{agent} is already running, retrying kick"
else
fail_test "Failed to trigger puppet kick on host #{agent}"
end
end
end
rescue Timeout::Error
fail_test "Puppet agent #{agent} failed to kick after #{timeout} seconds"
end
ensure
step "kill agent"
on(agent, puppet_agent("--configprint pidfile #{config}")) do
on(agent, "kill `cat #{stdout.chomp}`")
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_name "#3172: puppet kick with hostnames on the command line"
step "verify that we trigger our host"
step "Verify puppet kick application attempts to connect to the hostname specified on the command line"

target = 'working.example.org'
agents.each do |host|
Expand All @@ -8,6 +8,10 @@
assert_match(/Puppet kick is not supported/, stderr)
}
else
# Error: Host working.example.org failed: getaddrinfo: Name or service not known
# working.example.org finished with exit code 2
# Failed: working.example.org
# Exited: 3
on(host, puppet_kick(target), :acceptable_exit_codes => [3]) {
assert_match(/Triggering #{target}/, stdout, "didn't trigger #{target} on #{host}" )
}
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/application/agent.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'puppet/application'
require 'puppet/run'

class Puppet::Application::Agent < Puppet::Application

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize(options = {})
options.delete(:background)
end

valid_options = [:tags, :ignoreschedules]
valid_options = [:tags, :ignoreschedules, :pluginsync]
options.each do |key, value|
raise ArgumentError, "Run does not accept #{key}" unless valid_options.include?(key)
end
Expand Down
16 changes: 11 additions & 5 deletions spec/unit/run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@
end

it "should accept options at initialization" do
lambda { Puppet::Run.new :background => true }.should_not raise_error
expect do
Puppet::Run.new(
:background => true,
:tags => 'tag',
:ignoreschedules => false,
:pluginsync => true)
end.not_to raise_error
end

it "should not accept arbitrary options" do
lambda { Puppet::Run.new(:foo => true) }.should raise_error(ArgumentError)
end

it "should default to running in the foreground" do
Expand All @@ -47,10 +57,6 @@
Puppet::Run.new(:background => true).options[:background].should be_nil
end

it "should not accept arbitrary options" do
lambda { Puppet::Run.new(:foo => true) }.should raise_error(ArgumentError)
end

describe "when asked to run" do
before do
@agent = stub 'agent', :run => nil, :running? => false
Expand Down

0 comments on commit 3aaa582

Please sign in to comment.