Skip to content

Commit 0e262ad

Browse files
Merge branch '396474-geo-add-silent-mode-option-to-promotion-command' into 'master'
Add Silent mode option to Geo promotion command See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/7102 Merged-by: Balasankar 'Balu' C <[email protected]> Approved-by: Andrew Patterson <[email protected]> Approved-by: Balasankar 'Balu' C <[email protected]> Reviewed-by: Balasankar 'Balu' C <[email protected]> Co-authored-by: Douglas Barbosa Alexandre <[email protected]>
2 parents dbadfa8 + 863e617 commit 0e262ad

File tree

5 files changed

+56
-17
lines changed

5 files changed

+56
-17
lines changed

files/gitlab-ctl-commands-ee/lib/geo.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def self.parse_options(args)
4545
Utils.warn_and_exit opts
4646
end
4747

48+
opts.on('--enable-silent-mode', 'Enable GitLab Silent Mode') do |e|
49+
options[:enable_silent_mode] = e
50+
end
51+
4852
opts.on('-f', '--force', 'Proceed with no confirmation') do |f|
4953
options[:force] = f
5054
end

files/gitlab-ctl-commands-ee/lib/geo/promote.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def promote_to_primary
164164
log('Detected an application node.')
165165

166166
unless progress_message('Promoting secondary site to primary site') do
167-
!run_task('geo:set_secondary_as_primary').error?
167+
!run_task('geo:set_secondary_as_primary', env: { ENABLE_SILENT_MODE: options[:enable_silent_mode].to_s }).error?
168168
end
169169
die("Unable to promote secondary site to primary site.")
170170
end
@@ -305,16 +305,16 @@ def attributes
305305
@attributes ||= GitlabCtl::Util.get_node_attributes(base_path)
306306
end
307307

308-
def run_command(cmd, live: true)
309-
GitlabCtl::Util.run_command(cmd, live: live)
308+
def run_command(cmd, live: true, env: {})
309+
GitlabCtl::Util.run_command(cmd, live: live, env: env)
310310
end
311311

312-
def run_query(query, live: false)
313-
run_command("#{base_path}/bin/gitlab-psql -c \"#{query}\" -q -t", live: live)
312+
def run_query(query, live: false, env: {})
313+
run_command("#{base_path}/bin/gitlab-psql -c \"#{query}\" -q -t", live: live, env: env)
314314
end
315315

316-
def run_task(task, live: true)
317-
run_command("#{base_path}/bin/gitlab-rake #{task}", live: live)
316+
def run_task(task, live: true, env: {})
317+
run_command("#{base_path}/bin/gitlab-rake #{task}", live: live, env: env)
318318
end
319319

320320
def sv_progress(action, service)

files/gitlab-ctl-commands/lib/gitlab_ctl/util.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def get_command_output(command, user = nil, timeout = nil)
2323
shell_out.stdout
2424
end
2525

26-
def run_command(command, live: false, user: nil, timeout: nil)
26+
def run_command(command, live: false, user: nil, timeout: nil, env: {})
2727
timeout = Mixlib::ShellOut::DEFAULT_READ_TIMEOUT if timeout.nil?
28-
shell_out = Mixlib::ShellOut.new(command, timeout: timeout)
28+
shell_out = Mixlib::ShellOut.new(command, timeout: timeout, environment: env)
2929
shell_out.user = user unless user.nil?
3030
shell_out.live_stdout = $stdout if live
3131
shell_out.live_stderr = $stderr if live

spec/chef/gitlab-ctl-commands-ee/geo_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
commands = %w(promote)
1212

1313
command_lines = {
14-
'promote' => []
14+
'promote' => ['--enable-silent-mode']
1515
}
1616

1717
command_options = {
18-
'promote' => {}
18+
'promote' => { enable_silent_mode: true }
1919
}
2020

2121
describe '.parse_options' do

spec/chef/gitlab-ctl-commands-ee/lib/geo/promote_spec.rb

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@
8181
allow(command).to receive(:run_reconfigure)
8282
allow(command).to receive(:restart_services)
8383

84-
expect(command).not_to receive(:run_command).with("#{base_path}/bin/gitlab-rake geo:set_secondary_as_primary", live: true)
84+
expect(command)
85+
.not_to receive(:run_command)
86+
.with("#{base_path}/bin/gitlab-rake geo:set_secondary_as_primary", live: true, env: {})
8587

8688
command.execute
8789
end
@@ -96,15 +98,39 @@
9698
it 'promotes the secondary site to primary site' do
9799
allow(command).to receive(:restart_services)
98100

99-
expect(command).to receive(:run_command).with("#{base_path}/bin/gitlab-rake geo:set_secondary_as_primary", live: true).once.and_return(double(error?: false))
101+
expect(command)
102+
.to receive(:run_command)
103+
.with("#{base_path}/bin/gitlab-rake geo:set_secondary_as_primary", { live: true, env: an_instance_of(Hash) })
104+
.once
105+
.and_return(double(error?: false))
100106

101107
command.execute
102108
end
103109

110+
context 'with enable_silent_mode option set' do
111+
let(:options) { { enable_silent_mode: 'true', force: false } }
112+
113+
it 'calls the underlying rake task with ENABLE_SILENT_MODE env var set' do
114+
allow(command).to receive(:restart_services)
115+
116+
expect(command)
117+
.to receive(:run_command)
118+
.with("#{base_path}/bin/gitlab-rake geo:set_secondary_as_primary", { live: true, env: a_hash_including(ENABLE_SILENT_MODE: 'true') })
119+
.once
120+
.and_return(double(error?: false))
121+
122+
command.execute
123+
end
124+
end
125+
104126
it 'restarts the puma service' do
105127
allow(command).to receive(:promote_to_primary)
106128

107-
expect(ctl).to receive(:run_sv_command_for_service).with('restart', 'puma').once.and_return(double(zero?: true))
129+
expect(ctl)
130+
.to receive(:run_sv_command_for_service)
131+
.with('restart', 'puma')
132+
.once
133+
.and_return(double(zero?: true))
108134

109135
command.execute
110136
end
@@ -465,15 +491,24 @@ def stub_service_enabled(service)
465491
end
466492

467493
def stub_primary_node
468-
allow(command).to receive(:run_command).with("#{base_path}/bin/gitlab-rake geo:site:role", live: true).and_return(double(error?: false, stdout: 'primary'))
494+
allow(command)
495+
.to receive(:run_command)
496+
.with("#{base_path}/bin/gitlab-rake geo:site:role", live: true, env: {})
497+
.and_return(double(error?: false, stdout: 'primary'))
469498
end
470499

471500
def stub_secondary_node
472-
allow(command).to receive(:run_command).with("#{base_path}/bin/gitlab-rake geo:site:role", live: true).and_return(double(error?: false, stdout: 'secondary'))
501+
allow(command)
502+
.to receive(:run_command)
503+
.with("#{base_path}/bin/gitlab-rake geo:site:role", live: true, env: {})
504+
.and_return(double(error?: false, stdout: 'secondary'))
473505
end
474506

475507
def stub_misconfigured_node
476-
allow(command).to receive(:run_command).with("#{base_path}/bin/gitlab-rake geo:site:role", live: true).and_return(double(error?: true, stdout: 'misconfigured'))
508+
allow(command)
509+
.to receive(:run_command)
510+
.with("#{base_path}/bin/gitlab-rake geo:site:role", live: true, env: {})
511+
.and_return(double(error?: true, stdout: 'misconfigured'))
477512
end
478513

479514
def stub_single_server_secondary_site

0 commit comments

Comments
 (0)