Remove puppet status files right before running it

This prevents us from picking up status files from previous run when
current run hasn't written them for some reason, i.e. crash etc.

Change-Id: I83d0b4aa3c42210279b75ed7b575919d2d092ff0
Closes-Bug: #1560026
(cherry picked from commit e5311dd97b)
This commit is contained in:
Georgy Kibardin 2016-09-21 13:58:45 +03:00
parent 67896b9a59
commit ac2703949f
3 changed files with 6 additions and 17 deletions

View File

@ -37,7 +37,6 @@ module Astute
@node = node
@retries = @options[:retries]
@time_observer = TimeObserver.new(@options[:timeout])
@prev_summary = nil
@is_hung = false
@succeed_retries = @options[:succeed_retries]
@summary = {}
@ -47,7 +46,6 @@ module Astute
Astute.logger.debug "Waiting for puppet to finish deployment on " \
"node #{@node['uid']} (timeout = #{@time_observer.time_limit} sec)..."
@time_observer.start
@prev_summary ||= puppet_status
puppetd_runonce
end
@ -147,8 +145,7 @@ module Astute
def succeed?(status)
status[:status] == 'stopped' &&
status[:resources]['failed'].to_i == 0 &&
status[:resources]['failed_to_restart'].to_i == 0 &&
status[:time]['last_run'] != (@prev_summary && @prev_summary[:time]['last_run'])
status[:resources]['failed_to_restart'].to_i == 0
end
# Runs puppetd.runonce only if puppet is stopped on the host at the time
@ -207,8 +204,6 @@ module Astute
Astute.logger.info "Retrying to run puppet for following succeed " \
"node: #{@node['uid']}"
puppetd_runonce
# We need this magic with prev_summary to reflect new puppetd run statuses..
@prev_summary = last_run
node_report_format('status' => 'deploying')
else
Astute.logger.debug "Node #{@node['uid']} has succeed to deploy. " \
@ -225,8 +220,6 @@ module Astute
Astute.logger.info "Retrying to run puppet for following error " \
"nodes: #{@node['uid']}"
puppetd_runonce
# We need this magic with prev_summary to reflect new puppetd run statuses..
@prev_summary = last_run
node_report_format('status' => 'deploying')
else
Astute.logger.debug "Node #{@node['uid']} has failed to deploy. " \

View File

@ -197,6 +197,8 @@ module MCollective
end
def runonce_background
rm_file(@last_report)
rm_file(@last_summary)
cwd = request.fetch(:cwd, '/')
cmd = [
@puppetd,

View File

@ -118,7 +118,7 @@ describe Astute::PuppetTask do
describe "#run" do
it 'run puppet using mcollective' do
puppet_task.expects(:puppet_status).returns(mco_puppet_stopped).times(2)
puppet_task.expects(:puppet_status).returns(mco_puppet_stopped)
puppet_task.expects(:puppet_run)
puppet_task.run
end
@ -131,7 +131,6 @@ describe Astute::PuppetTask do
it 'check puppet using mcollective' do
puppet_task.stubs(:puppet_status).returns(mco_puppet_stopped)
.then.returns(mco_puppet_stopped)
.then.returns(mco_puppet_running)
.then.returns(mco_puppet_finished)
@ -141,7 +140,6 @@ describe Astute::PuppetTask do
it 'return error for node if puppet failed (a cycle w/o any transitional states)' do
puppet_task_wo_retries.stubs(:puppet_status).returns(mco_puppet_stopped)
.then.returns(mco_puppet_stopped)
.then.returns(mco_puppet_failed)
puppet_task_wo_retries.expects(:puppet_run)
@ -151,7 +149,6 @@ describe Astute::PuppetTask do
it 'retries to run puppet if it fails and return middle status' do
puppet_task.stubs(:puppet_status).returns(mco_puppet_stopped)
.then.returns(mco_puppet_stopped)
.then.returns(mco_puppet_failed)
.then.returns(mco_puppet_failed)
.then.returns(mco_puppet_finished)
@ -164,7 +161,6 @@ describe Astute::PuppetTask do
it "return error for node if puppet failed (a cycle with one running state only)" do
puppet_task_wo_retries.stubs(:puppet_status).returns(mco_puppet_stopped)
.then.returns(mco_puppet_stopped)
.then.returns(mco_puppet_running)
.then.returns(mco_puppet_running)
.then.returns(mco_puppet_fail)
@ -181,7 +177,6 @@ describe Astute::PuppetTask do
it "error status for node if puppet failed (a cycle w/o idle and finishing states)" do
puppet_task_wo_retries.stubs(:puppet_status).returns(mco_puppet_stopped)
.then.returns(mco_puppet_stopped)
.then.returns(mco_puppet_running)
.then.returns(mco_puppet_failed)
@ -198,15 +193,14 @@ describe Astute::PuppetTask do
.then.returns(mco_puppet_running)
.then.returns(mco_puppet_finished)
puppet_task.expects(:puppet_run).times(2)
puppet_task.expects(:puppet_run)
puppet_task.run
expect(puppet_task.status).to eql('deploying')
expect(puppet_task.status).to eql('ready')
end
it "error status for node if puppet failed (mcollective retries)" do
puppet_task.stubs(:puppet_status).returns(mco_puppet_stopped)
.then.raises(Astute::MClientTimeout)
puppet_task.stubs(:puppet_status).raises(Astute::MClientTimeout)
puppet_task.stubs(:puppetd_runonce)
puppet_task.run