Commit 2b742827 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Move task geo:check_replication_verification_status to gitlab namespace

We intend to consolidate all geo tasks inside the `gitlab:` namespace
parent 59b0dcc4
......@@ -238,38 +238,6 @@ namespace :geo do
Gitlab::Geo::GeoTasks.update_primary_geo_node_url
end
desc "Gitlab | Geo | Check replication/verification status"
task check_replication_verification_status: :environment do
abort GEO_LICENSE_ERROR_TEXT unless Gitlab::Geo.license_allows?
current_node_status = GeoNodeStatus.current_node_status
geo_node = current_node_status.geo_node
unless geo_node.secondary?
puts 'This command is only available on a secondary node'.color(:red)
exit
end
puts
status_check = Gitlab::Geo::GeoNodeStatusCheck.new(current_node_status, geo_node)
status_check.print_replication_verification_status
complete = status_check.replication_verification_complete?
if complete
puts 'SUCCESS - Replication is up-to-date.'.color(:green)
exit 0
else
puts "ERROR - Replication is not up-to-date. \n"\
"Please see documentation to complete replication: "\
"https://docs.gitlab.com/ee/administration/geo/disaster_recovery"\
"/planned_failover.html#ensure-geo-replication-is-up-to-date"
.color(:red)
exit 1
end
end
desc 'GitLab | Geo | Print Geo node status'
task status: :environment do
abort GEO_LICENSE_ERROR_TEXT unless Gitlab::Geo.license_allows?
......
namespace :gitlab do
namespace :geo do
desc "Gitlab | Geo | Check replication/verification status"
task check_replication_verification_status: :environment 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
geo_node = current_node_status.geo_node
unless geo_node.secondary?
puts 'This command is only available on a secondary node'.color(:red)
exit
end
puts
status_check = Gitlab::Geo::GeoNodeStatusCheck.new(current_node_status, geo_node)
status_check.print_replication_verification_status
complete = status_check.replication_verification_complete?
if complete
puts 'SUCCESS - Replication is up-to-date.'.color(:green)
exit 0
else
puts "ERROR - Replication is not up-to-date. \n"\
"Please see documentation to complete replication: "\
"https://docs.gitlab.com/ee/administration/geo/disaster_recovery"\
"/planned_failover.html#ensure-geo-replication-is-up-to-date"
.color(:red)
exit 1
end
end
end
end
......@@ -321,47 +321,6 @@ RSpec.describe 'geo rake tasks', :geo do
end
end
describe 'geo:check_replication_verification_status' do
let(:run_task) { run_rake_task('geo:check_replication_verification_status') }
let!(:current_node) { create(:geo_node) }
let!(:geo_node_status) { build(:geo_node_status, :healthy, geo_node: current_node) }
around do |example|
example.run
rescue SystemExit
end
before do
allow(GeoNodeStatus).to receive(:current_node_status).and_return(geo_node_status)
allow(Gitlab.config.geo.registry_replication).to receive(:enabled).and_return(true)
allow(Gitlab::Geo::GeoNodeStatusCheck).to receive(:replication_verification_complete?)
.and_return(complete)
end
context 'when replication is up-to-date' do
let(:complete) { true }
it 'prints a success message' do
expect { run_task }.to output(/SUCCESS - Replication is up-to-date/).to_stdout
end
end
context 'when replication is not up-to-date' do
let(:complete) { false }
it 'prints an error message' do
expect { run_task }.to output(/ERROR - Replication is not up-to-date/).to_stdout
end
it 'exits with a 1' do
expect { run_task }.to raise_error(SystemExit) do |error|
expect(error.status).to eq(1)
end
end
end
end
describe 'geo:status', :geo_fdw do
context 'without a valid license' do
before do
......
# frozen_string_literal: true
require 'rake_helper'
RSpec.describe 'gitlab:geo rake tasks', :geo do
include ::EE::GeoHelpers
before do
Rake.application.rake_require 'tasks/gitlab/geo'
stub_licensed_features(geo: true)
end
describe 'gitlab:geo:check_replication_verification_status' do
let(:run_task) { run_rake_task('gitlab:geo:check_replication_verification_status') }
let!(:current_node) { create(:geo_node) }
let!(:geo_node_status) { build(:geo_node_status, :healthy, geo_node: current_node) }
around do |example|
example.run
rescue SystemExit
end
before do
allow(GeoNodeStatus).to receive(:current_node_status).and_return(geo_node_status)
allow(Gitlab.config.geo.registry_replication).to receive(:enabled).and_return(true)
allow(Gitlab::Geo::GeoNodeStatusCheck).to receive(:replication_verification_complete?)
.and_return(complete)
end
context 'when replication is up-to-date' do
let(:complete) { true }
it 'prints a success message' do
expect { run_task }.to output(/SUCCESS - Replication is up-to-date/).to_stdout
end
end
context 'when replication is not up-to-date' do
let(:complete) { false }
it 'prints an error message' do
expect { run_task }.to output(/ERROR - Replication is not up-to-date/).to_stdout
end
it 'exits with a 1' do
expect { run_task }.to raise_error(SystemExit) do |error|
expect(error.status).to eq(1)
end
end
end
end
end
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