Skip to content
Snippets Groups Projects
Commit 905045e1 authored by Marin Jankovski's avatar Marin Jankovski
Browse files

Merge branch '2594-increase-mixlib-shellout-timeout-for-repmgr-commands' into 'master'

Resolve "Increase Mixlib::Shellout timeout for repmgr commands"

Closes #2594

See merge request !1757
parents 3b47fd88 af59f107
No related branches found
No related tags found
1 merge request!1757Resolve "Increase Mixlib::Shellout timeout for repmgr commands"
Loading
Loading
@@ -21,19 +21,29 @@ class RepmgrHelper
end
 
def cmd(command, user = 'root')
results = Mixlib::ShellOut.new(command, user: user, cwd: '/tmp')
results = Mixlib::ShellOut.new(
command,
user: user,
cwd: '/tmp',
# Allow a week before timing out.
timeout: 604800
)
begin
results.run_command
results.error!
rescue Mixlib::ShellOut::ShellCommandFailed
puts "Error running command: #{results.command}"
puts "STDOUT: #{results.stdout}" if results.stdout
puts "STDERR: #{results.stderr}" if results.stderr
$stderr.puts "Error running command: #{results.command}"
$stderr.puts "ERROR: #{results.stderr}" unless results.stderr.empty?
raise
rescue Mixlib::ShellOut::CommandTimeout
$stderr.puts "Timeout running command: #{results.command}"
raise
rescue StandardError => se
puts "Unknown Error: #{se}"
end
results.stdout
# repmgr logs most output to stderr by default
return results.stdout unless results.stdout.empty?
results.stderr
end
 
def repmgr_with_args(command, args)
Loading
Loading
Loading
Loading
@@ -7,7 +7,15 @@ require 'repmgr'
describe RepmgrHelper do
let(:repmgr_base_cmd) { '/opt/gitlab/embedded/bin/repmgr -f /var/opt/gitlab/postgresql/repmgr.conf' }
let(:shellout) do
double('shellout', error!: nil, stdout: 'xxxx', run_command: nil)
double('shellout', error!: nil, stdout: 'xxxx', stderr: 'yyyy', run_command: nil)
end
let(:shellout_args) do
{
user: 'gitlab-psql',
cwd: '/tmp',
timeout: 604800
}
end
 
before do
Loading
Loading
@@ -19,8 +27,7 @@ describe RepmgrHelper do
it 'calls repmgr with the correct arguments' do
expect(Mixlib::ShellOut).to receive(:new).with(
"#{repmgr_base_cmd} -h ahost -U auser -d adatabase -D /a/directory standby follow",
user: 'gitlab-psql',
cwd: '/tmp'
shellout_args
)
args = {
primary: 'ahost',
Loading
Loading
@@ -36,8 +43,7 @@ describe RepmgrHelper do
it 'calls clone with the correct arguments' do
expect(Mixlib::ShellOut).to receive(:new).with(
"#{repmgr_base_cmd} -h ahost -U auser -d adatabase -D /a/directory standby clone",
user: 'gitlab-psql',
cwd: '/tmp'
shellout_args
)
args = {
primary: 'ahost',
Loading
Loading
@@ -54,8 +60,7 @@ describe RepmgrHelper do
it 'calls register with the correct arguments' do
expect(Mixlib::ShellOut).to receive(:new).with(
"#{repmgr_base_cmd} standby register",
user: 'gitlab-psql',
cwd: '/tmp'
shellout_args
)
described_class.send(:register, {})
end
Loading
Loading
@@ -65,8 +70,7 @@ describe RepmgrHelper do
it 'unregisters the current host if no node is specified' do
expect(Mixlib::ShellOut).to receive(:new).with(
"#{repmgr_base_cmd} standby unregister",
user: 'gitlab-psql',
cwd: '/tmp'
shellout_args
)
described_class.send(:unregister, {})
end
Loading
Loading
@@ -74,8 +78,7 @@ describe RepmgrHelper do
it 'removes a different host if node is specified' do
expect(Mixlib::ShellOut).to receive(:new).with(
"#{repmgr_base_cmd} standby unregister --node=1234",
user: 'gitlab-psql',
cwd: '/tmp'
shellout_args
)
described_class.send(:unregister, {}, 1234)
end
Loading
Loading
@@ -86,7 +89,8 @@ describe RepmgrHelper do
context '#show' do
it 'should call the correct command' do
expect(Mixlib::ShellOut).to receive(:new).with(
"#{repmgr_base_cmd} cluster show", user: 'gitlab-psql', cwd: '/tmp'
"#{repmgr_base_cmd} cluster show",
shellout_args
)
described_class.send(:show, {})
end
Loading
Loading
@@ -96,7 +100,10 @@ describe RepmgrHelper do
describe RepmgrHelper::Master do
context '#register' do
it 'should register the master node' do
expect(Mixlib::ShellOut).to receive(:new).with("#{repmgr_base_cmd} master register", user: 'gitlab-psql', cwd: '/tmp')
expect(Mixlib::ShellOut).to receive(:new).with(
"#{repmgr_base_cmd} master register",
shellout_args
)
described_class.send(:register, {})
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