Skip to content
Snippets Groups Projects
Commit d475f73a authored by Ian Baum's avatar Ian Baum
Browse files

Merge branch '5676-add-restart-and-reload-sub-commands-to-patroni-controller' into 'master'

Add restart and reload sub-commands to Patroni controller

Closes #5676

See merge request gitlab-org/omnibus-gitlab!4601
parents 027b900b a17280c5
No related branches found
No related tags found
No related merge requests found
---
title: Add wrappers for Patroni restart and reload commands
merge_request: 4601
author:
type: added
Loading
Loading
@@ -21,6 +21,8 @@ module Patroni
resume Resume auto failover
failover Failover to a replica
switchover Switchover to a replica
restart Restart Patroni service without triggering failover
reload Reload Patroni configuration
EOS
 
# rubocop:disable Metrics/AbcSize
Loading
Loading
@@ -114,6 +116,16 @@ module Patroni
opts.on('--scheduled [SCHEDULED]', 'Schedule of switchover') do |t|
options[:scheduled] = t
end
end,
'restart' => OptionParser.new do |opts|
opts.on('-h', '--help', 'Prints this help') do
Utils.warn_and_exit opts
end
end,
'reload' => OptionParser.new do |opts|
opts.on('-h', '--help', 'Prints this help') do
Utils.warn_and_exit opts
end
end
}
 
Loading
Loading
@@ -183,6 +195,16 @@ module Patroni
Utils.patronictl(command)
end
 
def self.restart(options)
attributes = GitlabCtl::Util.get_node_attributes
Utils.patronictl("restart --force #{attributes['patroni']['scope']} #{attributes['patroni']['name']}")
end
def self.reload(options)
attributes = GitlabCtl::Util.get_node_attributes
Utils.patronictl("reload --force #{attributes['patroni']['scope']} #{attributes['patroni']['name']}")
end
class Utils
def self.patronictl(cmd, user = 'root')
attributes = GitlabCtl::Util.get_public_node_attributes
Loading
Loading
Loading
Loading
@@ -7,14 +7,16 @@ require_relative('../../../files/gitlab-ctl-commands-ee/lib/patroni')
 
RSpec.describe 'Patroni' do
core_commands = %w(bootstrap check-leader check-replica)
additional_commands = %w(members pause resume failover switchover)
additional_commands = %w(members pause resume failover switchover restart reload)
all_commands = core_commands + additional_commands
command_lines = {
'bootstrap' => %w(--srcdir=SRCDIR --scope=SCOPE --datadir=DATADIR),
'pause' => %w(-w),
'resume' => %w(--wait),
'failover' => %w(--master MASTER --candidate CANDIDATE),
'switchover' => %w(--master MASTER --candidate CANDIDATE --scheduled SCHEDULED)
'switchover' => %w(--master MASTER --candidate CANDIDATE --scheduled SCHEDULED),
'restart' => [],
'reload' => []
}
command_options = {
'bootstrap' => { srcdir: 'SRCDIR', scope: 'SCOPE', datadir: 'DATADIR' },
Loading
Loading
@@ -22,13 +24,17 @@ RSpec.describe 'Patroni' do
'resume' => { wait: true },
'failover' => { master: 'MASTER', candidate: 'CANDIDATE' },
'switchover' => { master: 'MASTER', candidate: 'CANDIDATE', scheduled: 'SCHEDULED' },
'restart' => {},
'reload' => {}
}
patronictl_command = {
'members' => 'list',
'pause' => 'pause -w',
'resume' => 'resume -w',
'failover' => 'failover --master MASTER --candidate CANDIDATE',
'switchover' => 'switchover --master MASTER --candidate CANDIDATE --scheduled SCHEDULED'
'switchover' => 'switchover --master MASTER --candidate CANDIDATE --scheduled SCHEDULED',
'restart' => 'restart --force fake-scope fake-node',
'reload' => 'reload --force fake-scope fake-node'
}
 
describe '#parse_options' do
Loading
Loading
@@ -133,6 +139,7 @@ RSpec.describe 'Patroni' do
describe 'additional commands' do
before do
allow(GitlabCtl::Util).to receive(:get_public_node_attributes).and_return({ 'patroni' => { 'config_dir' => '/fake' } })
allow(GitlabCtl::Util).to receive(:get_node_attributes).and_return({ 'patroni' => { 'scope' => 'fake-scope', 'name' => 'fake-node' } })
allow(GitlabCtl::Util).to receive(:run_command)
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