From 8ce43deaf56b905f9698c848292f7c1116261fb2 Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Sun, 8 Jul 2012 21:11:02 -0700 Subject: [PATCH 1/3] Add puppet-lint to the Rakefile --- deployment/puppet/haproxy/Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/puppet/haproxy/Rakefile b/deployment/puppet/haproxy/Rakefile index c5e9594f15..aa737b9b33 100644 --- a/deployment/puppet/haproxy/Rakefile +++ b/deployment/puppet/haproxy/Rakefile @@ -1,5 +1,5 @@ require 'rake' - +require 'puppet-lint/tasks/puppet-lint' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |t| From 672cd9ecb855edbd85f1685b6cc28ebfb8b7dacf Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Sun, 8 Jul 2012 21:33:13 -0700 Subject: [PATCH 2/3] Properly handle both Arrays and Strings passed as balancer member options The template cannot rely on deprecated functionality of the String class (`#each` which disappears in 1.9) Fixes #9 --- .../spec/defines/balancermember_spec.rb | 43 +++++++++++++------ .../templates/haproxy_balancermember.erb | 5 ++- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/deployment/puppet/haproxy/spec/defines/balancermember_spec.rb b/deployment/puppet/haproxy/spec/defines/balancermember_spec.rb index 75b761e478..4566ca4906 100644 --- a/deployment/puppet/haproxy/spec/defines/balancermember_spec.rb +++ b/deployment/puppet/haproxy/spec/defines/balancermember_spec.rb @@ -7,17 +7,36 @@ describe 'haproxy::balancermember' do :hostname => 'dero' } end - let(:params) do - { :name => 'tyler', - :listening_service => 'croy', - :balancer_port => '18140', - :balancermember_options => 'check' - } + + context 'with a single balancermember option' do + let(:params) do + { :name => 'tyler', + :listening_service => 'croy', + :balancer_port => '18140', + :balancermember_options => 'check' + } + end + + it { should contain_concat__fragment('croy_balancermember_tyler').with( + 'order' => '20', + 'target' => '/etc/haproxy/haproxy.cfg', + 'content' => " server dero 1.1.1.1:18140 check\n" + ) } end - it { should contain_concat__fragment('croy_balancermember_tyler').with( - 'order' => '20', - 'target' => '/etc/haproxy/haproxy.cfg', - 'content' => " server dero 1.1.1.1:18140 check \n" - ) } -end \ No newline at end of file + context 'with multiple balancermember options' do + let(:params) do + { :name => 'tyler', + :listening_service => 'croy', + :balancer_port => '18140', + :balancermember_options => ['check', 'close'] + } + end + + it { should contain_concat__fragment('croy_balancermember_tyler').with( + 'order' => '20', + 'target' => '/etc/haproxy/haproxy.cfg', + 'content' => " server dero 1.1.1.1:18140 check close\n" + ) } + end +end diff --git a/deployment/puppet/haproxy/templates/haproxy_balancermember.erb b/deployment/puppet/haproxy/templates/haproxy_balancermember.erb index b739e11af1..f85137dfac 100644 --- a/deployment/puppet/haproxy/templates/haproxy_balancermember.erb +++ b/deployment/puppet/haproxy/templates/haproxy_balancermember.erb @@ -1 +1,4 @@ - server <%= server_name %> <%= balancer_ip %>:<%= balancer_port %> <% balancermember_options.each do |item| %> <%= item %> <% end %> + server <%= server_name %> <%= balancer_ip %>:<%= balancer_port %> <% + items = balancermember_options + items = [items] unless balancermember_options.instance_of? Array + items.each do |item| %> <%= item %><% end %> From 535b1bf91aa8e4c268c71fc26a0c9d8ef12f40f9 Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Sun, 8 Jul 2012 21:38:34 -0700 Subject: [PATCH 3/3] Fix some, but by no means all, of puppet-lint's complaining --- .../haproxy/manifests/balancermember.pp | 2 +- deployment/puppet/haproxy/manifests/config.pp | 7 ++-- deployment/puppet/haproxy/manifests/init.pp | 17 ++++++---- deployment/puppet/haproxy/tests/init.pp | 32 +++++++++++-------- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/deployment/puppet/haproxy/manifests/balancermember.pp b/deployment/puppet/haproxy/manifests/balancermember.pp index 50e90c080b..29fb38246c 100644 --- a/deployment/puppet/haproxy/manifests/balancermember.pp +++ b/deployment/puppet/haproxy/manifests/balancermember.pp @@ -21,7 +21,7 @@ # fragment name. # # [*listening_service*] -# The haproxy service's instance name (or, the title of the +# The haproxy service's instance name (or, the title of the # haproxy::config resource). This must match up with a declared # haproxy::config resource. # diff --git a/deployment/puppet/haproxy/manifests/config.pp b/deployment/puppet/haproxy/manifests/config.pp index fba4f336f3..5825dd0ef8 100644 --- a/deployment/puppet/haproxy/manifests/config.pp +++ b/deployment/puppet/haproxy/manifests/config.pp @@ -51,7 +51,8 @@ # virtual_ip => $::ipaddress, # virtual_ip_port => '18140', # mode => 'tcp', -# haproxy_config_options => {'option' => ['tcplog', 'ssl-hello-chk'], 'balance' => 'roundrobin'}, +# haproxy_config_options => {'option' => ['tcplog', 'ssl-hello-chk'], +# 'balance' => 'roundrobin'}, # } # # === Authors @@ -63,7 +64,9 @@ define haproxy::config ( $order = '20', $virtual_ip = $::ipaddress, $mode = 'tcp', - $haproxy_config_options = {'option' => ['tcplog', 'ssl-hello-chk'], 'balance' => 'roundrobin'}, + $haproxy_config_options = {'option' => ['tcplog', + 'ssl-hello-chk'], + 'balance' => 'roundrobin'}, ) { concat::fragment { "${name}_config_block": order => $order, diff --git a/deployment/puppet/haproxy/manifests/init.pp b/deployment/puppet/haproxy/manifests/init.pp index a0f5265d18..8005aec0d6 100644 --- a/deployment/puppet/haproxy/manifests/init.pp +++ b/deployment/puppet/haproxy/manifests/init.pp @@ -45,7 +45,12 @@ # 'stats' => 'enable', # 'option' => 'redispatch', # 'retries' => '3', -# 'timeout' => ['http-request 10s', 'queue 1m', 'connect 10s', 'client 1m', 'server 1m', 'check 10s'], +# 'timeout' => ['http-request 10s', +# 'queue 1m', +# 'connect 10s', +# 'client 1m', +# 'server 1m', +# 'check 10s'], # 'maxconn' => '8000' # }, # @@ -63,13 +68,13 @@ class haproxy ( include concat::setup package { 'haproxy': - ensure => $enable ? { + ensure => $enable ? { true => present, false => absent, }, - name => 'haproxy', + name => 'haproxy', } - + if $enable { concat { '/etc/haproxy/haproxy.cfg': owner => '0', @@ -95,11 +100,11 @@ class haproxy ( } service { 'haproxy': - ensure => $enable ? { + ensure => $enable ? { true => running, false => stopped, }, - enable => $enable ? { + enable => $enable ? { true => true, false => false, }, diff --git a/deployment/puppet/haproxy/tests/init.pp b/deployment/puppet/haproxy/tests/init.pp index 32c32c7f94..f27f809bf5 100644 --- a/deployment/puppet/haproxy/tests/init.pp +++ b/deployment/puppet/haproxy/tests/init.pp @@ -1,7 +1,7 @@ # Declare haproxy base class with configuration options class { 'haproxy': - enable => true, - haproxy_global_options => { 'log' => "${::ipaddress} local0", + enable => true, + haproxy_global_options => {'log' => "${::ipaddress} local0", 'chroot' => '/var/lib/haproxy', 'pidfile' => '/var/run/haproxy.pid', 'maxconn' => '4000', @@ -10,14 +10,18 @@ class { 'haproxy': 'daemon' => '', 'stats' => 'socket /var/lib/haproxy/stats' }, - haproxy_defaults_options => { 'log' => 'global', - 'stats' => 'enable', - 'option' => 'redispatch', - 'retries' => '3', - 'timeout' => ['http-request 10s', 'queue 1m', 'connect 10s', 'client 1m', 'server 1m', 'check 10s'], - 'maxconn' => '8000' - }, - + haproxy_defaults_options => {'log' => 'global', + 'stats' => 'enable', + 'option' => 'redispatch', + 'retries' => '3', + 'timeout' => ['http-request 10s', + 'queue 1m', + 'connect 10s', + 'client 1m', + 'server 1m', + 'check 10s'], + 'maxconn' => '8000' + }, } # Export a balancermember server, note that the listening_service parameter @@ -39,12 +43,14 @@ haproxy::config { 'puppet00': order => '20', virtual_ip => $::ipaddress, virtual_ip_port => '18140', - haproxy_config_options => { 'option' => ['tcplog', 'ssl-hello-chk'], 'balance' => 'roundrobin' }, + haproxy_config_options => { + 'option' => ['tcplog', 'ssl-hello-chk'], 'balance' => 'roundrobin' }, } haproxy::config { 'stats': order => '30', virtual_ip => '', virtual_ip_port => '9090', - haproxy_config_options => { 'mode' => 'http', 'stats' => ['uri /', 'auth puppet:puppet'] }, + haproxy_config_options => { 'mode' => 'http', + 'stats' => ['uri /', 'auth puppet:puppet'] + }, } -