summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Thebo <adrien.thebo@gmail.com>2012-10-12 11:58:14 -0700
committerAdrien Thebo <adrien.thebo@gmail.com>2012-10-12 11:58:14 -0700
commit362d0ebf99b9dbfde8027646a84bf35f809be64f (patch)
tree4c07f89af518c81c4d76ec905e38547ada6af0bc
parent5d92b84d02befd48e1392bdd9ee21c7cb5a0b321 (diff)
parentde367852d14c8c205c06cb6bfa9555fe01165a41 (diff)
Merge pull request #14 from hunner/ports_string
Update ports to also accept a ,-separated string
-rw-r--r--manifests/listen.pp5
-rw-r--r--spec/defines/listen_spec.rb21
-rw-r--r--templates/haproxy_listen_block.erb2
3 files changed, 23 insertions, 5 deletions
diff --git a/manifests/listen.pp b/manifests/listen.pp
index d4ddd60..40e2cf1 100644
--- a/manifests/listen.pp
+++ b/manifests/listen.pp
@@ -22,8 +22,9 @@
#
# [*ports*]
# Ports on which the proxy will listen for connections on the ip address
-# specified in the virtual_ip parameter. Accepts either a single string or
-# an array of strings which may be a unique port or a hyphenated port range.
+# specified in the virtual_ip parameter. Accepts either a single
+# comma-separated string or an array of strings which may be ports or
+# hyphenated port ranges.
#
# [*order*]
# The order, or numerical weight, of the fragment created by this defined
diff --git a/spec/defines/listen_spec.rb b/spec/defines/listen_spec.rb
index c4539b8..16a0cfa 100644
--- a/spec/defines/listen_spec.rb
+++ b/spec/defines/listen_spec.rb
@@ -5,7 +5,8 @@ describe 'haproxy::listen' do
let(:facts) {{ :ipaddress => '1.1.1.1' }}
context "when only one port is provided" do
let(:params) do
- { :name => 'croy',
+ {
+ :name => 'croy',
:ports => '18140'
}
end
@@ -18,7 +19,8 @@ describe 'haproxy::listen' do
end
context "when an array of ports is provided" do
let(:params) do
- { :name => 'apache',
+ {
+ :name => 'apache',
:ipaddress => '23.23.23.23',
:ports => [
'80',
@@ -33,4 +35,19 @@ describe 'haproxy::listen' do
'content' => "\nlisten apache 23.23.23.23:80,23.23.23.23:443\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
) }
end
+ context "when a comma-separated list of ports is provided" do
+ let(:params) do
+ {
+ :name => 'apache',
+ :ipaddress => '23.23.23.23',
+ :ports => '80,443'
+ }
+ end
+
+ it { should contain_concat__fragment('apache_listen_block').with(
+ 'order' => '20',
+ 'target' => '/etc/haproxy/haproxy.cfg',
+ 'content' => "\nlisten apache 23.23.23.23:80,23.23.23.23:443\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
+ ) }
+ end
end
diff --git a/templates/haproxy_listen_block.erb b/templates/haproxy_listen_block.erb
index 66abf1f..12f55f6 100644
--- a/templates/haproxy_listen_block.erb
+++ b/templates/haproxy_listen_block.erb
@@ -1,5 +1,5 @@
-listen <%= name %> <%= ipaddress %>:<%= Array(ports).join(",#{ipaddress}:") %>
+listen <%= name %> <%= ipaddress %>:<%= Array(ports).collect { |x| x.split(',')}.flatten.join(",#{ipaddress}:") %>
<% options.sort.each do |key, val| -%>
<% if val.is_a?(Array) -%>
<% val.each do |item| -%>