forked from glarizza/puppet-haproxy
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
option to use multiple defaults sections
- Loading branch information
Showing
10 changed files
with
302 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# == Define Resource Type: haproxy::defaults | ||
# | ||
# This type will setup a additional defaults configuration block inside the | ||
# haproxy.cfg file on an haproxy load balancer. A new default configuration | ||
# block resets all defaults of prior defaults configuration blocks. Listener, | ||
# Backends, Frontends and Balancermember can be configured behind a default | ||
# configuration block by setting the defaults parameter to the corresponding | ||
# defaults name. | ||
# | ||
# === Parameters: | ||
# | ||
# [*options*] | ||
# A hash of options that are inserted into the defaults configuration block. | ||
# | ||
# [*sort_options_alphabetic*] | ||
# Sort options either alphabetic or custom like haproxy internal sorts them. | ||
# Defaults to true. | ||
|
||
define haproxy::defaults ( | ||
$options = {}, | ||
$sort_options_alphabetic = undef, | ||
$instance = 'haproxy', | ||
) { | ||
|
||
if $instance == 'haproxy' { | ||
include haproxy | ||
$instance_name = 'haproxy' | ||
$config_file = $haproxy::config_file | ||
} else { | ||
include haproxy::params | ||
$instance_name = "haproxy-${instance}" | ||
$config_file = inline_template($haproxy::params::config_file_tmpl) | ||
} | ||
include haproxy::globals | ||
$_sort_options_alphabetic = pick($sort_options_alphabetic, $haproxy::globals::sort_options_alphabetic) | ||
|
||
concat::fragment { "${instance_name}-${name}_defaults_block": | ||
order => "25-${name}", | ||
target => $config_file, | ||
content => template('haproxy/haproxy_defaults_block.erb'), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
require 'spec_helper_acceptance' | ||
|
||
describe "frontend backend defines with defaults", :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do | ||
it 'should be able to configure defaults with puppet' do | ||
pp = <<-EOS | ||
class { 'haproxy::globals': | ||
sort_options_alphabetic => false, | ||
} | ||
class { 'haproxy': } | ||
haproxy::defaults { 'http': | ||
options => { | ||
option => [ | ||
'redispatch', | ||
], | ||
'stats' => 'enable', | ||
'log' => 'global', | ||
retries => 3, | ||
'timeout client' => '3s', | ||
'timeout server' => '3s', | ||
'timeout connect' => '1s', | ||
'timeout queue' => '10s', | ||
'timeout check' => '1s', | ||
'timeout http-request' => '2s', | ||
balance => 'roundrobin', | ||
'maxconn' => '8000', | ||
'default-server' => 'weight 100 inter 6s fastinter 1s downinter 3s fall 2 rise 4', | ||
} | ||
} | ||
haproxy::frontend { 'app00': | ||
ipaddress => $::ipaddress_lo, | ||
mode => 'http', | ||
ports => '5555', | ||
defaults => 'http', | ||
options => { 'default_backend' => 'app00' }, | ||
} | ||
haproxy::backend { 'app00': | ||
defaults => 'http', | ||
collect_exported => false, | ||
options => { 'mode' => 'http' }, | ||
} | ||
haproxy::balancermember { 'port 5556': | ||
listening_service => 'app00', | ||
defaults => 'http', | ||
ports => '5556', | ||
} | ||
haproxy::balancermember { 'port 5557': | ||
listening_service => 'app00', | ||
defaults => 'http', | ||
ports => '5557', | ||
} | ||
EOS | ||
apply_manifest(pp, :catch_failures => true) | ||
end | ||
|
||
it "should do a curl against the LB to make sure it gets a response from each port" do | ||
#shell('cat /etc/haproxy/haproxy.cfg').stdout.should match(/^$/) | ||
shell('curl localhost:5555').stdout.chomp.should match(/Response on 555(6|7)/) | ||
shell('curl localhost:5555').stdout.chomp.should match(/Response on 555(6|7)/) | ||
end | ||
|
||
it 'should be able to configure defaults and old style with puppet' do | ||
pp = <<-EOS | ||
class { 'haproxy::globals': | ||
sort_options_alphabetic => false, | ||
} | ||
class { 'haproxy': } | ||
haproxy::defaults { 'http': | ||
options => { | ||
option => [ | ||
'redispatch', | ||
], | ||
'stats' => 'enable', | ||
'log' => 'global', | ||
retries => 3, | ||
'timeout client' => '3s', | ||
'timeout server' => '3s', | ||
'timeout connect' => '1s', | ||
'timeout queue' => '10s', | ||
'timeout check' => '1s', | ||
'timeout http-request' => '2s', | ||
balance => 'roundrobin', | ||
'maxconn' => '8000', | ||
'default-server' => 'weight 100 inter 6s fastinter 1s downinter 3s fall 2 rise 4', | ||
} | ||
} | ||
haproxy::frontend { 'app00': | ||
ipaddress => $::ipaddress_lo, | ||
mode => 'http', | ||
ports => '5555', | ||
defaults => 'http', | ||
options => { 'default_backend' => 'app00' }, | ||
} | ||
haproxy::backend { 'app00': | ||
defaults => 'http', | ||
collect_exported => false, | ||
options => { 'mode' => 'http' }, | ||
} | ||
haproxy::balancermember { 'port 5556': | ||
listening_service => 'app00', | ||
defaults => 'http', | ||
ports => '5556', | ||
} | ||
haproxy::frontend { 'app01': | ||
ipaddress => $::ipaddress_lo, | ||
mode => 'http', | ||
ports => '6666', | ||
options => { 'default_backend' => 'app01' }, | ||
} | ||
haproxy::backend { 'app01': | ||
collect_exported => false, | ||
options => { 'mode' => 'http' }, | ||
} | ||
haproxy::balancermember { 'port 5557': | ||
listening_service => 'app01', | ||
ports => '5557', | ||
} | ||
EOS | ||
apply_manifest(pp, :catch_failures => true) | ||
end | ||
|
||
it "should do a curl against the LB to make sure it gets a response from each port" do | ||
#shell('cat /etc/haproxy/haproxy.cfg').stdout.should match(/^$/) | ||
shell('curl localhost:5555').stdout.chomp.should match(/Response on 5556/) | ||
shell('curl localhost:6666').stdout.chomp.should match(/Response on 5557/) | ||
end | ||
end |
Oops, something went wrong.