From 231c79ab4878dc6d3270c0cf8ffa8d87b7e1420c Mon Sep 17 00:00:00 2001 From: Anton Chuchkalov Date: Fri, 4 Mar 2016 17:50:01 +0300 Subject: [PATCH] CID-443: rollbacks servers with failed bootstrap --- devops-service/lib/executors/server_executor.rb | 6 +++--- devops-service/spec/executors/server_executor_spec.rb | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/devops-service/lib/executors/server_executor.rb b/devops-service/lib/executors/server_executor.rb index 7cf84e8..520d4d6 100644 --- a/devops-service/lib/executors/server_executor.rb +++ b/devops-service/lib/executors/server_executor.rb @@ -262,8 +262,8 @@ module Devops return error_code(:server_not_in_chef_nodes) end else - # @out << roll_back - # mongo.server_delete @server.id + roll_back + mongo.server_delete @server.id msg = "Failed while bootstraping server with id '#{@server.id}'\n" msg << "Bootstraping operation result was #{bootstrap_status}" DevopsLogger.logger.error msg @@ -510,7 +510,7 @@ module Devops def schedule_expiration if @deploy_env.expires - @out << "Planning expiration in #{@deploy_env.expires}" + puts_and_flush "Planning expiration in #{@deploy_env.expires}" ExpirationScheduler.new(@deploy_env.expires, @server).schedule_expiration! end end diff --git a/devops-service/spec/executors/server_executor_spec.rb b/devops-service/spec/executors/server_executor_spec.rb index db48152..ca2be93 100644 --- a/devops-service/spec/executors/server_executor_spec.rb +++ b/devops-service/spec/executors/server_executor_spec.rb @@ -366,10 +366,19 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec end context "when bootstrap wasn't successful" do - it 'returns :server_bootstrap_fail error code' do + before do allow(executor).to receive(:bootstrap) { 1 } + allow(executor).to receive(:roll_back) + end + + it 'returns :server_bootstrap_fail error code' do expect(two_phase_bootstrap).to eq 2 end + + it 'rollbacks server' do + allow(executor).to receive(:roll_back) + two_phase_bootstrap + end end context 'when an error occured during bootstrap' do