Set haproxy state to up when got 401 error

Haproxy state should be set to up, when got 401 code from client
side - Unauthorized - that means that backend is ready and up.

Change-Id: I65b6e6789ac376a2ba0c95f03f6963fed804ba2d
Closes-bug: #1597416
(cherry picked from commit 7e4afb7a6f)
This commit is contained in:
Denis Egorenko 2016-06-29 19:06:02 +03:00
parent e283b62750
commit 6d782f6c0a
2 changed files with 10 additions and 1 deletions

View File

@ -20,7 +20,7 @@ Puppet::Type.type(:haproxy_backend_status).provide(:http) do
status = get_url
return :absent unless status
return :present if [:present, :absent].include? @resource[:ensure]
return :up if status.kind_of? Net::HTTPSuccess or status.kind_of? Net::HTTPRedirection
return :up if status.kind_of? Net::HTTPSuccess or status.kind_of? Net::HTTPRedirection or status.kind_of? Net::HTTPUnauthorized
return :down if status.kind_of? Net::HTTPServerError or status.kind_of? Net::HTTPClientError
:present
end

View File

@ -29,6 +29,10 @@ describe Puppet::Type.type(:haproxy_backend_status).provider(:http) do
Net::HTTPFound.new('1.1', '302', 'Found')
end
let (:http_401) do
Net::HTTPFound.new('1.1', '401', 'Unauthorized')
end
let (:http_503) do
Net::HTTPServiceUnavailable.new('1.1', '503', 'Service Unavailable')
end
@ -81,4 +85,9 @@ describe Puppet::Type.type(:haproxy_backend_status).provider(:http) do
expect(provider.ensure).to eq(:absent)
end
it 'should return :up for running backend (HTTP 401)' do
resource[:name] = 'test-up'
provider.stubs(:get_url).returns(http_401)
expect(provider.ensure).to eq(:up)
end
end