From 809473b7b0d6cd4de4c84d1172d9db55bdc5e968 Mon Sep 17 00:00:00 2001 From: Dimitri Savineau Date: Fri, 13 Feb 2015 17:19:29 -0500 Subject: [PATCH] loadbalancer: Adapt number of process of Haproxy Currently we only use one process for Haproxy. This patch allow to adapt the number of process of Haproxy to the number of processor. Change-Id: Id5a211b72c397bb6cef0f81f7759702f65f9e828 --- manifests/loadbalancer.pp | 21 ++++++++++++++++++++- spec/classes/cloud_loadbalancer_spec.rb | 25 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/manifests/loadbalancer.pp b/manifests/loadbalancer.pp index 0a922e57..874098df 100644 --- a/manifests/loadbalancer.pp +++ b/manifests/loadbalancer.pp @@ -241,6 +241,10 @@ # (optional) The HTTP sytle basic credentials (using login:password form) # Defaults to 'admin:changeme' # +# [*haproxy_options*] +# (optional) The haproxy global options +# Defaults to {} +# # [*keepalived_state*] # (optional) TODO # Defaults to 'BACKUP' @@ -543,6 +547,7 @@ class cloud::loadbalancer( $sensu_api = true, $redis = true, $haproxy_auth = 'admin:changeme', + $haproxy_options = {}, $keepalived_state = 'BACKUP', $keepalived_priority = '50', $keepalived_vrrp_interface = false, @@ -642,10 +647,24 @@ class cloud::loadbalancer( fail('galera_ip should be part of keepalived_public_ipvs or keepalived_internal_ipvs.') } + # TODO : Use global_options in puppetlabs-haproxy as merge in params.pp + $haproxy_default_options = { + 'log' => "${::ipaddress} local0", + 'chroot' => '/var/lib/haproxy', + 'pidfile' => '/var/run/haproxy.pid', + 'maxconn' => '4000', + 'user' => 'haproxy', + 'group' => 'haproxy', + 'daemon' => '', + 'stats' => 'socket /var/lib/haproxy/stats', + 'nbproc' => $::processorcount + } + $haproxy_global_options = merge($haproxy_default_options,$haproxy_options) # Ensure Keepalived is started before HAproxy to avoid binding errors. class { 'keepalived': } -> class { 'haproxy': - service_manage => true + service_manage => true, + global_options => $haproxy_global_options } keepalived::vrrp_script { 'haproxy': diff --git a/spec/classes/cloud_loadbalancer_spec.rb b/spec/classes/cloud_loadbalancer_spec.rb index 2ccbc287..1159732a 100644 --- a/spec/classes/cloud_loadbalancer_spec.rb +++ b/spec/classes/cloud_loadbalancer_spec.rb @@ -110,6 +110,31 @@ describe 'cloud::loadbalancer' do is_expected.not_to contain_keepalived__instance('2') end + context 'with 4 processors' do + before :each do + facts.merge!( + :processorcount => '4', + :ipaddress => '10.10.0.1' + ) + end + it 'configure haproxy server' do + is_expected.to contain_class('haproxy').with( + :service_manage => true, + :global_options => { + 'log' => '10.10.0.1 local0', + 'chroot' => '/var/lib/haproxy', + 'pidfile' => '/var/run/haproxy.pid', + 'maxconn' => '4000', + 'user' => 'haproxy', + 'group' => 'haproxy', + 'daemon' => '', + 'stats' => 'socket /var/lib/haproxy/stats', + 'nbproc' => '4' + } + ) + end + end # configure haproxy server + context 'configure an internal VIP with the same VIP as public network' do before do params.merge!(:keepalived_internal_ipvs => ['10.0.0.1', '10.0.0.2'])