Commit 749590ed authored by Gabriel Mazetto's avatar Gabriel Mazetto Committed by Alex Kalderimis

Added a rake task to print current Geo Site role

parent 53e2348c
...@@ -170,12 +170,12 @@ namespace :geo do ...@@ -170,12 +170,12 @@ namespace :geo do
current_max_id = [from_project_id + batch_size, to_project_id + 1].min current_max_id = [from_project_id + batch_size, to_project_id + 1].min
project_ids = Project project_ids = Project
.where('id >= ? AND id < ?', from_project_id, current_max_id) .where('id >= ? AND id < ?', from_project_id, current_max_id)
.pluck_primary_key .pluck_primary_key
orphaned_registries = Geo::ProjectRegistry orphaned_registries = Geo::ProjectRegistry
.where('project_id NOT IN(?)', project_ids) .where('project_id NOT IN(?)', project_ids)
.where('project_id >= ? AND project_id < ?', from_project_id, current_max_id) .where('project_id >= ? AND project_id < ?', from_project_id, current_max_id)
count = orphaned_registries.delete_all count = orphaned_registries.delete_all
total_count += count total_count += count
...@@ -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