CID-538: reports are not marked failed after stack creation fail

This commit is contained in:
Anton Chuchkalov 2016-06-29 16:48:31 +03:00
parent e2499100cd
commit 13b199d40e
2 changed files with 27 additions and 19 deletions

View File

@ -65,6 +65,15 @@ RSpec.describe StackBootstrapWorker, type: :worker, stubbed_connector: true, ini
expect(perform_with_bootstrap).to eq 1
end
it 'return 1 as a result of a block, not returning from #perform immediately' do
allow(executor).to receive(:wait_till_stack_is_created) { false }
allow(worker).to receive(:call) do |&block|
block.call
'block_return_value'
end
expect(perform_with_bootstrap).to eq 'block_return_value'
end
context 'if without_bootstrap is true' do
it "doesn't bootstrap servers" do
expect(worker).not_to receive(:bootstrap_or_rollback_if_failed)

View File

@ -11,27 +11,12 @@ class StackBootstrapWorker < Worker
save_report(stack_attrs)
@stack = executor.create_stack(stack_attrs)
without_bootstrap = @stack.without_bootstrap?
skip_rollback = @stack.skip_rollback?
if !executor.wait_till_stack_is_created
puts_and_flush "Stack creating error"
return 1
end
begin
executor.persist_new_servers
@stack.unlock_persisting!
if without_bootstrap
puts_and_flush "\n\nBootstrap has been skipped. Stack has been successfully created."
0
else
bootstrap_or_rollback_if_failed(skip_rollback: skip_rollback)
end
rescue StandardError => e
puts_and_flush "\nAn error occured."
rollback_stack! unless skip_rollback
raise e
1
else
persist_and_bootstrap_servers
end
end
end
@ -42,10 +27,24 @@ class StackBootstrapWorker < Worker
@executor ||= Devops::Executor::StackExecutor.new(out: out)
end
def persist_and_bootstrap_servers
executor.persist_new_servers
@stack.unlock_persisting!
if @stack.without_bootstrap?
puts_and_flush "\n\nBootstrap has been skipped. Stack has been successfully created."
0
else
bootstrap_or_rollback_if_failed(skip_rollback: @stack.skip_rollback?)
end
rescue => e
puts_and_flush "\nAn error occured."
rollback_stack! unless @stack.skip_rollback?
raise e
end
def bootstrap_or_rollback_if_failed(options)
bootstrap_result = executor.bootstrap_just_persisted(jid)
puts_and_flush Devops::Messages.t("worker.stack_bootstrap.bootstrap_result.#{bootstrap_result.reason}")
# move try_rollback to stack executor
if bootstrap_result.bootstrap_error?
if options[:skip_rollback]
puts_and_flush "\nSkip rollback because skip_rollback option set to true."