Merge pull request #28 from enovance/bug/25/spredzy

[loadbalancer] Feature: Implement proper failover
This commit is contained in:
Yanis Guenane 2014-01-22 08:08:03 -08:00
commit 7c2aa68b8b
4 changed files with 126 additions and 88 deletions

12
files/logrotate/haproxy Normal file
View File

@ -0,0 +1,12 @@
# Managed by Puppet
# Module cloud::loadbalancer
/var/log/haproxy.log {
rotate 7
daily
missingok
notifempty
delaycompress
compress
postrotate
endscript
}

View File

@ -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,8 +32,10 @@ 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,
$ks_cinder_public_port = $os_params::ks_cinder_public_port, $ks_cinder_public_port = $os_params::ks_cinder_public_port,
$ks_ceilometer_public_port = $os_params::ks_ceilometer_public_port, $ks_ceilometer_public_port = $os_params::ks_ceilometer_public_port,
@ -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': }
@ -64,90 +67,21 @@ 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(' file { '/etc/logrotate.d/haproxy':
<%- if @swift_api -%> ensure => file,
acl swift_api_dead nbsrv(swift_api_cluster) lt 1 source => 'puppet:///cloud/logrotate/haproxy',
monitor fail if swift_api_dead owner => root,
<%- end -%> group => root,
<%- if @keystone_api -%> mode => '0644';
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':
content => "
/var/log/haproxy.log
{
rotate 7
daily
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'),
} }
} }

View File

@ -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',
@ -57,18 +58,49 @@ describe 'cloud::loadbalancer' do
:ks_cinder_public_port => '8776', :ks_cinder_public_port => '8776',
:ks_neutron_public_port => '9696', :ks_neutron_public_port => '9696',
:ks_heat_public_port => '8004', :ks_heat_public_port => '8004',
:ks_heat_cfn_public_port => '8000', :ks_heat_cfn_public_port => '8000',
:ks_heat_cloudwatch_public_port => '8003' } :ks_heat_cloudwatch_public_port => '8003' }
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

View 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 -%>