Support detailed puppet run report
Without this change Astute send only combined summary: part data from last_run_summary and part data from last_run_report. With this change user can setup Astute send detailed report in summary by setup 'puppet_raw_report' in Astute config. In this case Astute will also send raw_report field with full puppet run report. Change-Id: I52bd709fc3fdd44d5477f75bdb36d063a2754555
This commit is contained in:
parent
9484ebf70d
commit
065bc28c80
|
@ -103,6 +103,7 @@ module Astute
|
|||
conf[:bootstrap_profile] = 'ubuntu_bootstrap' # use the Ubuntu based bootstrap by default
|
||||
conf[:graph_dot_dir] = "/var/lib/astute/graphs" # default dir patch for debug graph file
|
||||
conf[:enable_graph_file] = true # enable debug graph records to file
|
||||
conf[:puppet_raw_report] = false # enable puppet detailed report
|
||||
|
||||
# Server settings
|
||||
conf[:broker_host] = 'localhost'
|
||||
|
|
|
@ -65,12 +65,14 @@ class Astute::DeploymentEngine::GranularDeployment < Astute::DeploymentEngine
|
|||
Astute::PuppetTask.new(
|
||||
@hook_context,
|
||||
@nodes_by_uid[node_id], # Use single node uid instead of task['uids']
|
||||
task['parameters']['retries'] || Astute.config.puppet_retries,
|
||||
task['parameters']['puppet_manifest'],
|
||||
task['parameters']['puppet_modules'],
|
||||
task['parameters']['cwd'],
|
||||
task['parameters']['timeout'],
|
||||
@puppet_debug
|
||||
{
|
||||
:retries => task['parameters']['retries'],
|
||||
:puppet_manifest => task['parameters']['puppet_manifest'],
|
||||
:puppet_modules => task['parameters']['puppet_modules'],
|
||||
:cwd => task['parameters']['cwd'],
|
||||
:timeout => task['parameters']['timeout'],
|
||||
:debug => @puppet_debug
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -18,18 +18,27 @@ module Astute
|
|||
|
||||
class PuppetTask
|
||||
|
||||
def initialize(ctx, node, retries=1, puppet_manifest=nil, puppet_modules=nil, cwd=nil, timeout=nil, puppet_debug=false, succeed_retries=nil)
|
||||
def initialize(ctx, node, options={})
|
||||
default_options = {
|
||||
:retries => Astute.config.puppet_retries,
|
||||
:puppet_manifest => '/etc/puppet/manifests/site.pp',
|
||||
:puppet_modules => Astute.config.puppet_module_path,
|
||||
:cwd => Astute.config.shell_cwd,
|
||||
:timeout => Astute.config.puppet_timeout,
|
||||
:puppet_debug => false,
|
||||
:succeed_retries => Astute.config.puppet_succeed_retries,
|
||||
:raw_report => Astute.config.puppet_raw_report
|
||||
}
|
||||
@options = options.compact.reverse_merge(default_options)
|
||||
@options.freeze
|
||||
|
||||
@ctx = ctx
|
||||
@node = node
|
||||
@retries = retries
|
||||
@puppet_manifest = puppet_manifest || '/etc/puppet/manifests/site.pp'
|
||||
@puppet_modules = puppet_modules || '/etc/puppet/modules'
|
||||
@cwd = cwd || '/'
|
||||
@time_observer = TimeObserver.new(timeout || Astute.config.puppet_timeout)
|
||||
@retries = @options[:retries]
|
||||
@time_observer = TimeObserver.new(@options[:timeout])
|
||||
@prev_summary = nil
|
||||
@is_hung = false
|
||||
@puppet_debug = puppet_debug
|
||||
@succeed_retries = succeed_retries || Astute.config.puppet_succeed_retries
|
||||
@succeed_retries = @options[:succeed_retries]
|
||||
@summary = {}
|
||||
end
|
||||
|
||||
|
@ -93,15 +102,17 @@ module Astute
|
|||
end
|
||||
|
||||
def puppet_status
|
||||
puppetd.last_run_summary.first[:data]
|
||||
puppetd.last_run_summary(
|
||||
:raw_report => @options[:raw_report]
|
||||
).first[:data]
|
||||
end
|
||||
|
||||
def puppet_run
|
||||
puppetd.runonce(
|
||||
:puppet_debug => @puppet_debug,
|
||||
:manifest => @puppet_manifest,
|
||||
:modules => @puppet_modules,
|
||||
:cwd => @cwd
|
||||
:puppet_debug => @options[:puppet_debug],
|
||||
:manifest => @options[:puppet_manifest],
|
||||
:modules => @options[:puppet_modules],
|
||||
:cwd => @options[:cwd]
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -55,12 +55,14 @@ module Astute
|
|||
PuppetTask.new(
|
||||
@ctx,
|
||||
n,
|
||||
@retries,
|
||||
@puppet_manifest,
|
||||
@puppet_modules,
|
||||
@cwd,
|
||||
timeout=Astute.config.puppet_timeout,
|
||||
@puppet_debug)
|
||||
{
|
||||
:retries => @retries,
|
||||
:puppet_manifest => @puppet_manifest,
|
||||
:puppet_modules => @puppet_modules,
|
||||
:cwd => @cwd,
|
||||
:timeout => Astute.config.puppet_timeout,
|
||||
:puppet_debug => @puppet_debug
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -58,12 +58,14 @@ module Astute
|
|||
LogParser::NoParsing.new
|
||||
),
|
||||
{'uid' => @task['node_id'].to_s, 'role' => task_name},
|
||||
@task['parameters']['retries'],
|
||||
@task['parameters']['puppet_manifest'],
|
||||
@task['parameters']['puppet_modules'],
|
||||
@task['parameters']['cwd'],
|
||||
@task['parameters']['timeout'],
|
||||
@task['parameters']['debug']
|
||||
{
|
||||
:retries => @task['parameters']['retries'],
|
||||
:puppet_manifest => @task['parameters']['puppet_manifest'],
|
||||
:puppet_modules => @task['parameters']['puppet_modules'],
|
||||
:cwd => @task['parameters']['cwd'],
|
||||
:timeout => @task['parameters']['timeout'],
|
||||
:debug => @task['parameters']['debug']
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -9,9 +9,18 @@ metadata :name => "puppetd",
|
|||
action "last_run_summary", :description => "Get a summary of the last puppet run" do
|
||||
display :always
|
||||
|
||||
input :raw_report,
|
||||
:prompt => "Enable puppet raw report",
|
||||
:description => "Get raw las run report",
|
||||
:type => :boolean,
|
||||
:validation => :typecheck,
|
||||
:default => false,
|
||||
:optional => true
|
||||
|
||||
output :time,
|
||||
:description => "Time per resource type",
|
||||
:display_as => "Times"
|
||||
|
||||
output :resources,
|
||||
:description => "Overall resource counts",
|
||||
:display_as => "Resources"
|
||||
|
@ -27,6 +36,10 @@ action "last_run_summary", :description => "Get a summary of the last puppet run
|
|||
output :version,
|
||||
:description => "Puppet and Catalog versions",
|
||||
:display_as => "Versions"
|
||||
|
||||
output :raw_report,
|
||||
:description => "Full last run report",
|
||||
:display_as => "Raw report"
|
||||
end
|
||||
|
||||
action "stop_and_disable", :description => "Stop and disable puppet" do
|
||||
|
|
|
@ -92,7 +92,13 @@ module MCollective
|
|||
summary["time"] ||= {}
|
||||
summary["time"]["last_run"] ||= 0
|
||||
# if 'failed' is not provided, it means something is wrong. So default value is 1.
|
||||
reply[:resources] = {"failed"=>1, "changed"=>0, "total"=>0, "restarted"=>0, "out_of_sync"=>0}.merge(summary["resources"])
|
||||
reply[:resources] = {
|
||||
"failed"=>1,
|
||||
"changed"=>0,
|
||||
"total"=>0,
|
||||
"restarted"=>0,
|
||||
"out_of_sync"=>0
|
||||
}.merge(summary["resources"])
|
||||
|
||||
["time", "events", "changes", "version"].each do |dat|
|
||||
reply[dat.to_sym] = summary[dat]
|
||||
|
@ -108,16 +114,21 @@ module MCollective
|
|||
|
||||
changed = []
|
||||
failed = []
|
||||
# only generate list of changes and failures if we could parse the
|
||||
# puppet report
|
||||
if report.is_a?(Puppet::Transaction::Report) && report.resource_statuses
|
||||
if valid_report?(report)
|
||||
report.resource_statuses.each do |name, resource|
|
||||
changed << name if resource.changed
|
||||
failed << name if resource.failed
|
||||
end
|
||||
end
|
||||
# add list of resources into the reply
|
||||
reply[:resources] = {"changed_resources" => changed.join(','), "failed_resources" => failed.join(',')}.merge(reply[:resources])
|
||||
reply[:resources] = {
|
||||
"changed_resources" => changed.join(','),
|
||||
"failed_resources" => failed.join(',')
|
||||
}.merge(reply[:resources])
|
||||
|
||||
if valid_report?(report) && request.fetch(:raw_report, false)
|
||||
reply[:raw_report] = File.read(@last_report)
|
||||
end
|
||||
end
|
||||
|
||||
def set_status
|
||||
|
@ -259,6 +270,10 @@ module MCollective
|
|||
|
||||
private
|
||||
|
||||
def valid_report?(report)
|
||||
report.is_a?(Puppet::Transaction::Report) && report.resource_statuses
|
||||
end
|
||||
|
||||
def kill_process
|
||||
return if ['stopped', 'disabled'].include? puppet_daemon_status
|
||||
|
||||
|
|
|
@ -50,8 +50,17 @@ describe Astute::PuppetTask do
|
|||
}
|
||||
|
||||
let(:puppet_task) { Astute::PuppetTask.new(ctx, node)}
|
||||
let(:puppet_task_wo_retries) { Astute::PuppetTask.new(ctx, node, retries=0)}
|
||||
let(:puppet_task_success_retries) { Astute::PuppetTask.new(ctx, node, retries=1, puppet_manifest=nil, puppet_modules=nil, cwd=nil, timeout=nil, puppet_debug=false, succeed_retries=1) }
|
||||
let(:puppet_task_wo_retries) { Astute::PuppetTask.new(ctx, node, {:retries=>0})}
|
||||
let(:puppet_task_success_retries) { Astute::PuppetTask.new(ctx, node, {
|
||||
:retries=>1,
|
||||
:puppet_manifest=>nil,
|
||||
:puppet_modules=>nil,
|
||||
:cwd=>nil,
|
||||
:timeout=>nil,
|
||||
:puppet_debug=>false,
|
||||
:succeed_retries=>1
|
||||
})
|
||||
}
|
||||
|
||||
let(:mco_puppet_stopped) do
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue