Skip to content
Snippets Groups Projects
Commit fdc8ca7c authored by Aakriti Gupta's avatar Aakriti Gupta Committed by Ian Baum
Browse files

Geo: Add final confirmation for promotion to primary

parent e01a0548
No related branches found
No related tags found
No related merge requests found
---
title: 'Geo: Add final confirmation for promotion to primary'
merge_request: 4523
author:
type: changed
Loading
Loading
@@ -11,6 +11,8 @@ module Geo
def execute
run_preflight_checks
 
final_confirmation
promote_postgresql_to_primary
 
reconfigure
Loading
Loading
@@ -46,6 +48,18 @@ module Geo
exit 1
end
 
def final_confirmation
return if @options[:force]
puts
puts 'WARNING: Secondary will now be promoted to primary. '\
'Are you sure you want to proceed? (y/n)'.color(:yellow)
return if STDIN.gets.chomp.casecmp('y').zero?
exit 1
end
def promote_postgresql_to_primary
puts
puts 'Promoting the PostgreSQL to primary...'.color(:yellow)
Loading
Loading
Loading
Loading
@@ -13,8 +13,8 @@ RSpec.describe Geo::PromoteToPrimaryNode, '#execute' do
let(:gitlab_config_path) { File.join(temp_directory, 'gitlab.rb') }
 
before do
allow(command).to receive(:puts)
allow(command).to receive(:print)
allow($stdout).to receive(:puts)
allow($stdout).to receive(:print)
 
allow(command).to receive(:run_command).with(any_args)
end
Loading
Loading
@@ -67,16 +67,40 @@ RSpec.describe Geo::PromoteToPrimaryNode, '#execute' do
context 'when preflight checks pass' do
before do
allow(STDIN).to receive(:gets).and_return('y')
allow_any_instance_of(Geo::PromotionPreflightChecks).to receive(
:execute).and_return(true)
allow(command).to receive(:promote_postgresql_to_primary).and_return(true)
allow(command).to receive(:reconfigure).and_return(true)
allow(command).to receive(:promote_to_primary).and_return(true)
allow(command).to receive(:success_message).and_return(true)
end
 
it 'calls all the subcommands' do
is_expected.to receive(:run_command).with('gitlab-ctl reconfigure', live: true).once
is_expected.to receive(:run_command).with('gitlab-rake geo:set_secondary_as_primary', live: true).once
context 'when running in force mode' do
let(:options) { { force: true } }
 
shell_out_object = double.tap { |shell_out_object| expect(shell_out_object).to receive(:error!) }
is_expected.to receive(:run_command).with("/opt/gitlab/embedded/bin/gitlab-pg-ctl promote", live: true).once.and_return(shell_out_object)
it 'does not ask for final confirmation' do
expect { command.execute }.not_to output(
/WARNING\: Secondary will now be promoted to primary./).to_stdout
end
end
 
command.execute
context 'when not running in force mode' do
let(:options) { { force: false } }
it 'asks for confirmation' do
expect { command.execute }.to output(
/WARNING\: Secondary will now be promoted to primary./).to_stdout
end
context 'when final confirmation is given' do
it 'calls the next subcommand' do
expect(command).to receive(:promote_postgresql_to_primary)
command.execute
end
end
end
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment