Commit 1f679685 authored by Rajendra Kadam's avatar Rajendra Kadam Committed by Michael Kozono

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

parent d6c8dbbb
---
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
private
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|
http.request(Net::HTTP::Get.new(node.internal_uri))
end
response = Gitlab::HTTP.get(node.internal_uri, allow_local_requests: true)
if response.code_type == Net::HTTPFound
if response.code_type == Net::HTTPOK
$stdout.puts 'yes'.color(:green)
else
$stdout.puts 'no'.color(:red)
......
......@@ -2,6 +2,11 @@
require 'spec_helper'
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
it 'skips when Geo is disabled' do
allow(Gitlab::Geo).to receive(:enabled?) { false }
......@@ -18,4 +23,70 @@ describe SystemCheck::Geo::HttpConnectionCheck do
expect(subject.skip_reason).to eq('not a secondary node')
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
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