Skip to content
Snippets Groups Projects
Commit e09b50f5 authored by Aakriti Gupta's avatar Aakriti Gupta
Browse files

List manual checks with link to documentation

parent 758ff2a3
No related branches found
No related tags found
No related merge requests found
---
title: Add (optional) list of manual checks to promote_to_primary script.
merge_request: 4231
author:
type: other
Loading
Loading
@@ -9,6 +9,8 @@ module Geo
end
 
def execute
run_preflight_checks
make_sure_primary_is_down
 
promote_postgresql_to_primary
Loading
Loading
@@ -22,6 +24,31 @@ module Geo
 
private
 
def run_preflight_checks
return true if @options[:skip_preflight_checks]
puts
puts 'Ensure you have completed the following manual '\
'preflight checks:'
puts '- Check if you need to migrate to Object Storage'
puts '- Review configuration of each secondary node'
puts '- Run system checks'
puts '- Check that secrets match between nodes'
puts '- Ensure Geo replication is up-to-date'
puts '- Verify the integrity of replicated data'
puts '- Notify users of scheduled maintenance'
puts 'Please read https://docs.gitlab.com/ee/administration/geo/'\
'disaster_recovery/planned_failover.html#preflight-checks'
puts
puts 'Did you perform all manual preflight checks (y/n)?'.color(:green)
return if STDIN.gets.chomp.casecmp('y').zero?
raise 'ERROR: Manual preflight checks were not performed! '\
'Please read https://docs.gitlab.com/ee/administration/geo/'\
'disaster_recovery/planned_failover.html#preflight-checks'.color(:red)
end
def make_sure_primary_is_down
return true if @options[:confirm_primary_is_down]
 
Loading
Loading
Loading
Loading
@@ -26,13 +26,17 @@ def get_ctl_options
OptionParser.new do |opts|
opts.banner = "Usage: gitlab-ctl promote-to-primary-node [options]"
 
opts.on('-p', '--[no-]confirm-primary-is-down', 'Do not ask a confirmation that primary is down') do |p|
opts.on('-p', '--[no-]confirm-primary-is-down', 'Do not ask for confirmation that primary is down') do |p|
options[:confirm_primary_is_down] = p
end
 
opts.on('-c', '--[no-]confirm-removing-keys', 'Do not ask a confirmation about removing keys') do |c|
opts.on('-c', '--[no-]confirm-removing-keys', 'Do not ask for confirmation about removing keys') do |c|
options[:confirm_removing_keys] = c
end
opts.on('-m', '--skip-preflight-checks', 'Do not ask for confirmation if manual checks ran') do |c|
options[:skip_preflight_checks] = m
end
end.parse!(ARGV.dup)
 
options
Loading
Loading
Loading
Loading
@@ -5,11 +5,10 @@ $LOAD_PATH << './files/gitlab-ctl-commands/lib'
 
require 'fileutils'
require 'geo/promote_to_primary'
require 'fileutils'
require 'gitlab_ctl/util'
 
describe Geo::PromoteToPrimary, '#execute' do
subject(:command) { described_class.new(nil, {}) }
subject(:command) { described_class.new(nil, { skip_preflight_checks: true }) }
 
let(:temp_directory) { Dir.mktmpdir }
let(:gitlab_config_path) { File.join(temp_directory, 'gitlab.rb') }
Loading
Loading
@@ -23,6 +22,54 @@ describe Geo::PromoteToPrimary, '#execute' do
FileUtils.rm_rf(temp_directory)
end
 
describe '#run_preflight_checks' do
subject(:run_preflight_checks) do
described_class.new(nil, options).send(:run_preflight_checks)
end
let(:confirmation) { 'y' }
before do
allow(STDIN).to receive(:gets).and_return(confirmation)
end
context 'when `--skip-preflight-checks` is passed' do
let(:options) { { skip_preflight_checks: true } }
let(:confirmation) { 'n' }
it 'does not raise error' do
expect { run_preflight_checks }.not_to raise_error
end
end
context 'when `--skip-preflight-checks` is not passed' do
let(:options) { {} }
it 'prints preflight check instructions' do
expect { run_preflight_checks }.to output(
/Ensure you have completed the following manual preflight checks/)
.to_stdout
end
context 'when confirmation is accepted' do
it 'does not raise an error' do
expect { run_preflight_checks }.to_not raise_error
end
end
context 'when confirmation is not accepted' do
let(:confirmation) { 'n' }
it 'raises error' do
expect { run_preflight_checks }.to raise_error(
RuntimeError,
/ERROR: Manual preflight checks were not performed/
)
end
end
end
end
context 'when confirmation is accepted' do
before do
allow(STDIN).to receive(:gets).and_return('y')
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