Commit 843cfce7 authored by Michael Kozono's avatar Michael Kozono

Merge branch 'geo-http-check' into 'master'

Replace Net::HTTP with Gitlab::HTTP in rake gitlab:geo:check

Closes #36878

See merge request gitlab-org/gitlab!23741
parents 99bf6515 1f679685
---
title: Replace Net::HTTP with Gitlab::HTTP in rake gitlab:geo:check
merge_request: 23741
author: Rajendra Kadam
type: added
...@@ -33,11 +33,9 @@ module SystemCheck ...@@ -33,11 +33,9 @@ module SystemCheck
private private
def check_gitlab_geo_node(node) def check_gitlab_geo_node(node)
response = Net::HTTP.start(node.internal_uri.host, node.internal_uri.port, use_ssl: (node.internal_uri.scheme == 'https')) do |http| response = Gitlab::HTTP.get(node.internal_uri, allow_local_requests: true)
http.request(Net::HTTP::Get.new(node.internal_uri))
end
if response.code_type == Net::HTTPFound if response.code_type == Net::HTTPOK
$stdout.puts 'yes'.color(:green) $stdout.puts 'yes'.color(:green)
else else
$stdout.puts 'no'.color(:red) $stdout.puts 'no'.color(:red)
......
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
require 'spec_helper' require 'spec_helper'
describe SystemCheck::Geo::HttpConnectionCheck do describe SystemCheck::Geo::HttpConnectionCheck do
include EE::GeoHelpers
let_it_be(:primary_node) { create(:geo_node, :primary) }
let_it_be(:http_method) { :get }
describe 'skip?' do describe 'skip?' do
it 'skips when Geo is disabled' do it 'skips when Geo is disabled' do
allow(Gitlab::Geo).to receive(:enabled?) { false } allow(Gitlab::Geo).to receive(:enabled?) { false }
...@@ -18,4 +23,70 @@ describe SystemCheck::Geo::HttpConnectionCheck do ...@@ -18,4 +23,70 @@ describe SystemCheck::Geo::HttpConnectionCheck do
expect(subject.skip_reason).to eq('not a secondary node') expect(subject.skip_reason).to eq('not a secondary node')
end end
end end
describe 'multi_check' do
before do
stub_current_geo_node(primary_node)
end
context 'connection success' do
it 'puts yes if check works' do
stub_request(http_method, primary_node.internal_uri).to_return(status: 200, body: "", headers: {})
expect do
subject.multi_check
end.to output("\n* Can connect to the primary node ... yes\n").to_stdout
end
end
context 'connection errored' do
it 'puts no if check errored' do
stub_request(http_method, primary_node.internal_uri).to_return(status: 400, body: "", headers: {})
expect do
subject.multi_check
end.to output("\n* Can connect to the primary node ... no\n").to_stdout
end
end
context 'connection exceptions' do
it 'calls try_fixing_it for econnrefused' do
stub_request(http_method, primary_node.internal_uri).to_raise(Errno::ECONNREFUSED)
expect do
subject.multi_check
end.to output(econnrefused_help_messages).to_stdout
end
it 'calls try_fixing_it for econnrefused' do
stub_request(http_method, primary_node.internal_uri).to_raise(SocketError.new)
expect do
subject.multi_check
end.to output(socketerror_help_messages).to_stdout
end
it 'calls try_fixing_it for openssl errors' do
stub_request(http_method, primary_node.internal_uri).to_raise(OpenSSL::SSL::SSLError.new)
expect do
subject.multi_check
end.to output(openssl_error_help_messages).to_stdout
end
end
end
private
def econnrefused_help_messages
/Can connect to the primary node ... no.*Connection refused/m
end
def socketerror_help_messages
/Can connect to the primary node ... no.*SocketError/m
end
def openssl_error_help_messages
/Can connect to the primary node ... no.*OpenSSL::SSL::SSLError/m
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