Does not update Geo node if running on a primary site

Changelog: changed
EE: true
parent 5ca5f2a4
......@@ -22,14 +22,17 @@ module Gitlab
primary_node = GeoNode.primary_node
current_node = GeoNode.current_node
abort 'The primary is not set' unless primary_node
abort 'The primary Geo site is not set' unless primary_node
abort 'Current node is not identified' unless current_node
abort 'This is not a secondary node' unless current_node.secondary?
if current_node.primary?
$stdout.puts "#{current_node.url} is already the primary Geo site".color(:green)
else
primary_node.destroy
current_node.update!(primary: true, enabled: true)
$stdout.puts "#{current_node.url} is now the primary Geo node".color(:green)
$stdout.puts "#{current_node.url} is now the primary Geo site".color(:green)
end
end
end
......
......@@ -35,7 +35,7 @@ RSpec.describe Gitlab::Geo::GeoTasks do
it 'aborts if the primary node is not set' do
primary.update_column(:primary, false)
expect(subject).to receive(:abort).with('The primary is not set').and_raise('aborted')
expect(subject).to receive(:abort).with('The primary Geo site is not set').and_raise('aborted')
expect { subject.set_secondary_as_primary }.to raise_error('aborted')
end
......@@ -48,19 +48,21 @@ RSpec.describe Gitlab::Geo::GeoTasks do
expect { subject.set_secondary_as_primary }.to raise_error('aborted')
end
it 'aborts if run on a node that is not a secondary' do
it 'does nothing if run on a node that is not a secondary' do
primary.update_column(:primary, false)
secondary.update!(primary: true)
expect(subject).to receive(:abort).with('This is not a secondary node').and_raise('aborted')
expect(subject).not_to receive(:abort)
expect { subject.set_secondary_as_primary }.to raise_error('aborted')
expect { subject.set_secondary_as_primary }.to output(/#{secondary.url} is already the primary Geo site/).to_stdout
expect(secondary.reload).to be_primary
expect(primary.reload).to be_secondary
end
it 'sets the secondary as the primary node' do
expect(subject).not_to receive(:abort)
expect { subject.set_secondary_as_primary }.to output(/#{secondary.url} is now the primary Geo node/).to_stdout
expect { subject.set_secondary_as_primary }.to output(/#{secondary.url} is now the primary Geo site/).to_stdout
expect(secondary.reload).to be_primary
end
......@@ -69,7 +71,7 @@ RSpec.describe Gitlab::Geo::GeoTasks do
expect(subject).not_to receive(:abort)
expect { subject.set_secondary_as_primary }.to output(/#{secondary.url} is now the primary Geo node/).to_stdout
expect { subject.set_secondary_as_primary }.to output(/#{secondary.url} is now the primary Geo site/).to_stdout
expect(secondary.reload).to be_primary
expect(secondary.reload).to be_enabled
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