Files
puppet-tripleo/spec/classes/tripleo_haproxy_spec.rb
Michele Baldessari 97d501251e Give horizon's stanza in haproxy a per-server cookie
Currently our haproxy.cfg stanza for horizon looks like the following:
server overcloud-controller-0.internalapi.localdomain 172.17.0.22:80 check cookie overcloud-controller-0 fall 5 inter 2000 rise 2
server overcloud-controller-1.internalapi.localdomain 172.17.0.25:80 check cookie overcloud-controller-0 fall 5 inter 2000 rise 2
server overcloud-controller-2.internalapi.localdomain 172.17.0.12:80 check cookie overcloud-controller-0 fall 5 inter 2000 rise 2

We need to make sure that the cookie is set the same as the server:
server overcloud-controller-0.internalapi.localdomain 172.17.0.22:80 check cookie overcloud-controller-0.internalapi.localdomain fall 5 inter 2000 rise 2
server overcloud-controller-1.internalapi.localdomain 172.17.0.25:80 check cookie overcloud-controller-1.internalapi.localdomain fall 5 inter 2000 rise 2
server overcloud-controller-2.internalapi.localdomain 172.17.0.12:80 check cookie overcloud-controller-2.internalapi.localdomain fall 5 inter 2000 rise 2

The problem here is that the cookie is being inserted into the response
by haproxy so that we have session persistence. When logging to horizon
we want the session to be persistent and go to the same backend server.
When haproxy sees a match for the cookie, it does just that. The cookie
value will should match the server name. Prior to this fix
each server was matching on the same cookie ($::hostname) which is not
correct.

Tested by connecting to horizon's VIP and shutting off horizon on each
controller node one at the time. Observed that after each stop, the
correct cookie from the remaining servers was sent to the browser.

Closes-Bug: #1738453
Change-Id: Ieb9cf3c6a8373df288a73ff2dacfc9d0b09e675a
2017-12-22 19:41:55 +00:00

176 lines
4.6 KiB
Ruby

# Copyright 2016 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
require 'spec_helper'
describe 'tripleo::haproxy' do
shared_examples_for 'tripleo::haproxy' do
let :params do {
:controller_virtual_ip => '10.1.0.1',
:public_virtual_ip => '192.168.0.1'
}
end
describe "default settings" do
it 'should configure haproxy' do
is_expected.to contain_haproxy__listen('mysql').with(
:options => {
'timeout client' => "90m",
'timeout server' => "90m",
'maxconn' => :undef
}
)
end
end
describe "set clustercheck" do
before :each do
params.merge!({
:mysql_clustercheck => true,
})
end
it 'should configure haproxy with clustercheck' do
is_expected.to contain_haproxy__listen('mysql').with(
:options => {
'option' => ["tcpka", "httpchk", "tcplog"],
'timeout client' => "90m",
'timeout server' => "90m",
'stick-table' => "type ip size 1000",
'stick' => "on dst",
'maxconn' => :undef
}
)
end
end
describe "override maxconn with clustercheck" do
before :each do
params.merge!({
:mysql_clustercheck => true,
:mysql_max_conn => 6500,
})
end
it 'should configure haproxy' do
is_expected.to contain_haproxy__listen('mysql').with(
:options => {
'option' => ["tcpka", "httpchk", "tcplog"],
'timeout client' => "90m",
'timeout server' => "90m",
'stick-table' => "type ip size 1000",
'stick' => "on dst",
'maxconn' => 6500
}
)
end
end
describe "horizon" do
before :each do
params.merge!({
:horizon => true,
})
end
it 'should configure haproxy horizon endpoint' do
is_expected.to contain_class('tripleo::haproxy::horizon_endpoint')
is_expected.to contain_haproxy__balancermember('horizon_127.0.0.1_controller-1').with(
:options => ['check', 'inter 2000', 'rise 2', 'fall 5', 'cookie controller-1'],
)
end
end
describe "override maxconn without clustercheck" do
before :each do
params.merge!({
:mysql_max_conn => 6500,
})
end
it 'should configure haproxy' do
is_expected.to contain_haproxy__listen('mysql').with(
:options => {
'timeout client' => "90m",
'timeout server' => "90m",
'maxconn' => 6500
}
)
end
end
describe "default Defaults for haproxy" do
it 'should NOT activate httplog' do
is_expected.to contain_class('haproxy').with(
:defaults_options => {
"mode"=>"tcp",
"log"=>"global",
"retries"=>"3",
"timeout"=> [
"http-request 10s",
"queue 2m",
"connect 10s",
"client 2m",
"server 2m",
"check 10s",
],
"maxconn"=>4096,
}
)
end
end
describe "activate httplog" do
before :each do
params.merge!({
:activate_httplog => true,
})
end
it 'should activate httplog' do
is_expected.to contain_class('haproxy').with(
:defaults_options => {
"mode"=>"tcp",
"log"=>"global",
"retries"=>"3",
"timeout"=> [
"http-request 10s",
"queue 2m",
"connect 10s",
"client 2m",
"server 2m",
"check 10s",
],
"maxconn"=>4096,
"option"=>"httplog",
}
)
end
end
end
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge({ })
end
it_behaves_like 'tripleo::haproxy'
end
end
end