Merge pull request #28 from enovance/bug/25/spredzy
[loadbalancer] Feature: Implement proper failover
This commit is contained in:
commit
7c2aa68b8b
12
files/logrotate/haproxy
Normal file
12
files/logrotate/haproxy
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Managed by Puppet
|
||||||
|
# Module cloud::loadbalancer
|
||||||
|
/var/log/haproxy.log {
|
||||||
|
rotate 7
|
||||||
|
daily
|
||||||
|
missingok
|
||||||
|
notifempty
|
||||||
|
delaycompress
|
||||||
|
compress
|
||||||
|
postrotate
|
||||||
|
endscript
|
||||||
|
}
|
@ -15,7 +15,6 @@
|
|||||||
#
|
#
|
||||||
# HAproxy nodes
|
# HAproxy nodes
|
||||||
#
|
#
|
||||||
|
|
||||||
class cloud::loadbalancer(
|
class cloud::loadbalancer(
|
||||||
$ceilometer_api = true,
|
$ceilometer_api = true,
|
||||||
$cinder_api = true,
|
$cinder_api = true,
|
||||||
@ -33,6 +32,8 @@ class cloud::loadbalancer(
|
|||||||
$horizon = true,
|
$horizon = true,
|
||||||
$spice = true,
|
$spice = true,
|
||||||
$haproxy_auth = $os_params::haproxy_auth,
|
$haproxy_auth = $os_params::haproxy_auth,
|
||||||
|
$keepalived_state = 'BACKUP',
|
||||||
|
$keepalived_priority = 50,
|
||||||
$keepalived_interface = $os_params::keepalived_interface,
|
$keepalived_interface = $os_params::keepalived_interface,
|
||||||
$keepalived_ipvs = [$os_params::openstack_vip,$os_params::mysql_vip],
|
$keepalived_ipvs = [$os_params::openstack_vip,$os_params::mysql_vip],
|
||||||
$keepalived_localhost_ip = $os_params::keepalived_localhost_ip,
|
$keepalived_localhost_ip = $os_params::keepalived_localhost_ip,
|
||||||
@ -55,7 +56,9 @@ class cloud::loadbalancer(
|
|||||||
$mysql_vip = $os_params::mysql_vip
|
$mysql_vip = $os_params::mysql_vip
|
||||||
){
|
){
|
||||||
|
|
||||||
class { 'haproxy': }
|
class { 'haproxy':
|
||||||
|
manage_service => false,
|
||||||
|
}
|
||||||
|
|
||||||
class { 'keepalived': }
|
class { 'keepalived': }
|
||||||
|
|
||||||
@ -66,88 +69,19 @@ class cloud::loadbalancer(
|
|||||||
keepalived::instance { '1':
|
keepalived::instance { '1':
|
||||||
interface => $keepalived_interface,
|
interface => $keepalived_interface,
|
||||||
virtual_ips => split(join(flatten([$keepalived_ipvs, ['']]), " dev ${keepalived_interface},"), ','),
|
virtual_ips => split(join(flatten([$keepalived_ipvs, ['']]), " dev ${keepalived_interface},"), ','),
|
||||||
state => 'MASTER',
|
state => $keepalived_state,
|
||||||
track_script => ['haproxy'],
|
track_script => ['haproxy'],
|
||||||
priority => 50,
|
priority => $keepalived_priority,
|
||||||
|
notify_master => '"/etc/init.d/haproxy start"',
|
||||||
|
notify_backup => '"/etc/init.d/haproxy stop"',
|
||||||
}
|
}
|
||||||
|
|
||||||
$monitors_data = inline_template('
|
|
||||||
<%- if @swift_api -%>
|
|
||||||
acl swift_api_dead nbsrv(swift_api_cluster) lt 1
|
|
||||||
monitor fail if swift_api_dead
|
|
||||||
<%- end -%>
|
|
||||||
<%- if @keystone_api -%>
|
|
||||||
acl keystone_api_dead nbsrv(keystone_api_cluster) lt 1
|
|
||||||
monitor fail if keystone_api_dead
|
|
||||||
<% end -%>
|
|
||||||
<%- if @galera -%>
|
|
||||||
acl galera_dead nbsrv(galera_cluster) lt 1
|
|
||||||
monitor fail if galera_dead
|
|
||||||
<%- end -%>
|
|
||||||
<%- if @neutron_api -%>
|
|
||||||
acl neutron_api_dead nbsrv(neutron_api_cluster) lt 1
|
|
||||||
monitor fail if neutron_api_dead
|
|
||||||
<%- end -%>
|
|
||||||
<%- if @cinder_api -%>
|
|
||||||
acl cinder_api_dead nbsrv(cinder_api_cluster) lt 1
|
|
||||||
monitor fail if cinder_api_dead
|
|
||||||
<%- end -%>
|
|
||||||
<%- if @nova_api -%>
|
|
||||||
acl nova_api_dead nbsrv(nova_api_cluster) lt 1
|
|
||||||
monitor fail if nova_api_dead
|
|
||||||
<%- end -%>
|
|
||||||
<%- if @nova_ec2 -%>
|
|
||||||
acl nova_ec2_dead nbsrv(nova_ec2_cluster) lt 1
|
|
||||||
monitor fail if nova_ec2_dead
|
|
||||||
<%- end -%>
|
|
||||||
<%- if @nova_metadata -%>
|
|
||||||
acl nova_metadata_dead nbsrv(nova_metadata_cluster) lt 1
|
|
||||||
monitor fail if nova_metadata_dead
|
|
||||||
<%- end -%>
|
|
||||||
<%- if @spice -%>
|
|
||||||
acl spice_dead nbsrv(spice_cluster) lt 1
|
|
||||||
monitor fail if spice_dead
|
|
||||||
<%- end -%>
|
|
||||||
<%- if @glance_api -%>
|
|
||||||
acl nova_api_dead nbsrv(glance_api_cluster) lt 1
|
|
||||||
monitor fail if nova_api_dead
|
|
||||||
<%- end -%>
|
|
||||||
<%- if @ceilometer_api -%>
|
|
||||||
acl ceilometer_api_dead nbsrv(ceilometer_api_cluster) lt 1
|
|
||||||
monitor fail if ceilometer_api_dead
|
|
||||||
<%- end -%>
|
|
||||||
<%- if @heat_api -%>
|
|
||||||
acl heat_api_dead nbsrv(heat_api_cluster) lt 1
|
|
||||||
monitor fail if heat_api_dead
|
|
||||||
<%- end -%>
|
|
||||||
<%- if @heat_cfn_api -%>
|
|
||||||
acl heat_api_cfn_dead nbsrv(heat_api_cfn_cluster) lt 1
|
|
||||||
monitor fail if heat_api_cfn_dead
|
|
||||||
<%- end -%>
|
|
||||||
<%- if @heat_cloudwatch_api -%>
|
|
||||||
acl heat_api_cloudwatch_dead nbsrv(heat_api_cloudwatch_cluster) lt 1
|
|
||||||
monitor fail if heat_api_cloudwatch_dead
|
|
||||||
<%- end -%>
|
|
||||||
<%- if @horizon -%>
|
|
||||||
acl horizon_dead nbsrv(horizon_cluster) lt 1
|
|
||||||
monitor fail if horizon_dead
|
|
||||||
<%- end -%>
|
|
||||||
')
|
|
||||||
|
|
||||||
file { '/etc/logrotate.d/haproxy':
|
file { '/etc/logrotate.d/haproxy':
|
||||||
content => "
|
ensure => file,
|
||||||
/var/log/haproxy.log
|
source => 'puppet:///cloud/logrotate/haproxy',
|
||||||
{
|
owner => root,
|
||||||
rotate 7
|
group => root,
|
||||||
daily
|
mode => '0644';
|
||||||
missingok
|
|
||||||
notifempty
|
|
||||||
delaycompress
|
|
||||||
compress
|
|
||||||
postrotate
|
|
||||||
endscript
|
|
||||||
}
|
|
||||||
"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
haproxy::listen { 'monitor':
|
haproxy::listen { 'monitor':
|
||||||
@ -157,7 +91,7 @@ monitor fail if horizon_dead
|
|||||||
'mode' => 'http',
|
'mode' => 'http',
|
||||||
'monitor-uri' => '/status',
|
'monitor-uri' => '/status',
|
||||||
'stats' => ['enable','uri /admin','realm Haproxy\ Statistics',"auth ${haproxy_auth}", 'refresh 5s' ],
|
'stats' => ['enable','uri /admin','realm Haproxy\ Statistics',"auth ${haproxy_auth}", 'refresh 5s' ],
|
||||||
'' => $monitors_data,
|
'' => template('cloud/loadbalancer/monitor.erb'),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ describe 'cloud::loadbalancer' do
|
|||||||
:horizon => true,
|
:horizon => true,
|
||||||
:spice => true,
|
:spice => true,
|
||||||
:haproxy_auth => 'root:secrete',
|
:haproxy_auth => 'root:secrete',
|
||||||
|
:keepalived_priority => 50,
|
||||||
:keepalived_interface => 'eth0',
|
:keepalived_interface => 'eth0',
|
||||||
:keepalived_ipvs => ['10.0.0.1', '10.0.0.2'],
|
:keepalived_ipvs => ['10.0.0.1', '10.0.0.2'],
|
||||||
:keepalived_localhost_ip => '127.0.0.1',
|
:keepalived_localhost_ip => '127.0.0.1',
|
||||||
@ -62,13 +63,44 @@ describe 'cloud::loadbalancer' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'configure haproxy server' do
|
it 'configure haproxy server' do
|
||||||
should contain_class('haproxy')
|
should contain_class('haproxy').with({
|
||||||
|
'manage_service' => 'false',
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'configure keepalived server' do
|
it 'configure keepalived server' do
|
||||||
should contain_class('keepalived')
|
should contain_class('keepalived')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'configure keepalived in backup' do
|
||||||
|
it 'configure vrrp_instance with BACKUP state' do
|
||||||
|
should contain_keepalived__instance('1').with({
|
||||||
|
'interface' => 'eth0',
|
||||||
|
'track_script' => ['haproxy'],
|
||||||
|
'state' => 'BACKUP',
|
||||||
|
'priority' => 50,
|
||||||
|
'notify_master' => '"/etc/init.d/haproxy start"',
|
||||||
|
'notify_backup' => '"/etc/init.d/haproxy stop"',
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'configure keepalived in master' do
|
||||||
|
before :each do
|
||||||
|
params.merge!( :keepalived_state => 'MASTER' )
|
||||||
|
end
|
||||||
|
it 'configure vrrp_instance with MASTER state' do
|
||||||
|
should contain_keepalived__instance('1').with({
|
||||||
|
'interface' => 'eth0',
|
||||||
|
'track_script' => ['haproxy'],
|
||||||
|
'state' => 'MASTER',
|
||||||
|
'priority' => 50,
|
||||||
|
'notify_master' => '"/etc/init.d/haproxy start"',
|
||||||
|
'notify_backup' => '"/etc/init.d/haproxy stop"',
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'on Debian platforms' do
|
context 'on Debian platforms' do
|
||||||
|
60
templates/loadbalancer/monitor.erb
Normal file
60
templates/loadbalancer/monitor.erb
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<%- if @swift_api -%>
|
||||||
|
acl swift_api_dead nbsrv(swift_api_cluster) lt 1
|
||||||
|
monitor fail if swift_api_dead
|
||||||
|
<%- end -%>
|
||||||
|
<%- if @keystone_api -%>
|
||||||
|
acl keystone_api_dead nbsrv(keystone_api_cluster) lt 1
|
||||||
|
monitor fail if keystone_api_dead
|
||||||
|
<% end -%>
|
||||||
|
<%- if @galera -%>
|
||||||
|
acl galera_dead nbsrv(galera_cluster) lt 1
|
||||||
|
monitor fail if galera_dead
|
||||||
|
<%- end -%>
|
||||||
|
<%- if @neutron_api -%>
|
||||||
|
acl neutron_api_dead nbsrv(neutron_api_cluster) lt 1
|
||||||
|
monitor fail if neutron_api_dead
|
||||||
|
<%- end -%>
|
||||||
|
<%- if @cinder_api -%>
|
||||||
|
acl cinder_api_dead nbsrv(cinder_api_cluster) lt 1
|
||||||
|
monitor fail if cinder_api_dead
|
||||||
|
<%- end -%>
|
||||||
|
<%- if @nova_api -%>
|
||||||
|
acl nova_api_dead nbsrv(nova_api_cluster) lt 1
|
||||||
|
monitor fail if nova_api_dead
|
||||||
|
<%- end -%>
|
||||||
|
<%- if @nova_ec2 -%>
|
||||||
|
acl nova_ec2_dead nbsrv(nova_ec2_cluster) lt 1
|
||||||
|
monitor fail if nova_ec2_dead
|
||||||
|
<%- end -%>
|
||||||
|
<%- if @nova_metadata -%>
|
||||||
|
acl nova_metadata_dead nbsrv(nova_metadata_cluster) lt 1
|
||||||
|
monitor fail if nova_metadata_dead
|
||||||
|
<%- end -%>
|
||||||
|
<%- if @spice -%>
|
||||||
|
acl spice_dead nbsrv(spice_cluster) lt 1
|
||||||
|
monitor fail if spice_dead
|
||||||
|
<%- end -%>
|
||||||
|
<%- if @glance_api -%>
|
||||||
|
acl nova_api_dead nbsrv(glance_api_cluster) lt 1
|
||||||
|
monitor fail if nova_api_dead
|
||||||
|
<%- end -%>
|
||||||
|
<%- if @ceilometer_api -%>
|
||||||
|
acl ceilometer_api_dead nbsrv(ceilometer_api_cluster) lt 1
|
||||||
|
monitor fail if ceilometer_api_dead
|
||||||
|
<%- end -%>
|
||||||
|
<%- if @heat_api -%>
|
||||||
|
acl heat_api_dead nbsrv(heat_api_cluster) lt 1
|
||||||
|
monitor fail if heat_api_dead
|
||||||
|
<%- end -%>
|
||||||
|
<%- if @heat_cfn_api -%>
|
||||||
|
acl heat_api_cfn_dead nbsrv(heat_api_cfn_cluster) lt 1
|
||||||
|
monitor fail if heat_api_cfn_dead
|
||||||
|
<%- end -%>
|
||||||
|
<%- if @heat_cloudwatch_api -%>
|
||||||
|
acl heat_api_cloudwatch_dead nbsrv(heat_api_cloudwatch_cluster) lt 1
|
||||||
|
monitor fail if heat_api_cloudwatch_dead
|
||||||
|
<%- end -%>
|
||||||
|
<%- if @horizon -%>
|
||||||
|
acl horizon_dead nbsrv(horizon_cluster) lt 1
|
||||||
|
monitor fail if horizon_dead
|
||||||
|
<%- end -%>
|
Loading…
x
Reference in New Issue
Block a user