Commit b79e15b3 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'brodock/geo_site_role' into 'master'

Geo: rake task to print current site role

See merge request gitlab-org/gitlab!73175
parents 593b777e 749590ed
...@@ -214,6 +214,10 @@ namespace :geo do ...@@ -214,6 +214,10 @@ namespace :geo do
abort GEO_LICENSE_ERROR_TEXT unless Gitlab::Geo.license_allows? abort GEO_LICENSE_ERROR_TEXT unless Gitlab::Geo.license_allows?
current_node_status = GeoNodeStatus.current_node_status current_node_status = GeoNodeStatus.current_node_status
unless current_node_status
abort 'Gitlab Geo is not configured for this site'
end
geo_node = current_node_status.geo_node geo_node = current_node_status.geo_node
unless geo_node.secondary? unless geo_node.secondary?
...@@ -223,4 +227,20 @@ namespace :geo do ...@@ -223,4 +227,20 @@ namespace :geo do
Gitlab::Geo::GeoNodeStatusCheck.new(current_node_status, geo_node).print_status Gitlab::Geo::GeoNodeStatusCheck.new(current_node_status, geo_node).print_status
end end
namespace :site do
desc 'GitLab | Geo | Print Geo site role'
task role: :environment do
current_node = GeoNode.current_node
if current_node&.primary?
puts 'primary'
elsif current_node&.secondary?
puts 'secondary'
else
puts 'misconfigured'
exit 1
end
end
end
end end
...@@ -309,6 +309,12 @@ RSpec.describe 'geo rake tasks', :geo, :silence_stdout do ...@@ -309,6 +309,12 @@ RSpec.describe 'geo rake tasks', :geo, :silence_stdout do
end end
describe 'geo:status' do describe 'geo:status' do
context 'when geo is not properly configured' do
it 'returns misconfigured when not a primary nor a secondary site' do
expect { run_rake_task('geo:status') }.to raise_error("Gitlab Geo is not configured for this site")
end
end
context 'without a valid license' do context 'without a valid license' do
before do before do
stub_licensed_features(geo: false) stub_licensed_features(geo: false)
...@@ -398,6 +404,30 @@ RSpec.describe 'geo rake tasks', :geo, :silence_stdout do ...@@ -398,6 +404,30 @@ RSpec.describe 'geo rake tasks', :geo, :silence_stdout do
end end
end end
describe 'geo:site:role' do
context 'when in a primary site' do
it 'returns primary' do
create(:geo_node, :primary, name: 'primary')
allow(GeoNode).to receive(:current_node_name).and_return('primary')
expect { run_rake_task('geo:site:role') }.to output(/primary/).to_stdout
end
end
context 'when in a secondary site' do
it 'returns secondary' do
create(:geo_node, :secondary, name: 'secondary')
allow(GeoNode).to receive(:current_node_name).and_return('secondary')
expect { run_rake_task('geo:site:role') }.to output(/secondary/).to_stdout
end
end
it 'returns misconfigured when not a primary nor a secondary site' do
expect { run_rake_task('geo:site:role') }.to output(/misconfigured/).to_stdout & raise_error(SystemExit)
end
end
describe 'geo:run_orphaned_project_registry_cleaner' do describe 'geo:run_orphaned_project_registry_cleaner' do
let!(:current_node) { create(:geo_node) } let!(:current_node) { create(:geo_node) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment