Skip to content

Commit

Permalink
Deprecate ports parameter as a string
Browse files Browse the repository at this point in the history
Previously it was possible to set the ports parameter
as:

* `'1234'`
* `'1234,5678'`
* `['1234']`
* `['1234','5678']`

Since #610 the ports parameter could also be specified with `Stdlib::Ports`:

* `1234`
* `[1234]`
* `[1234, 5678]`

With this patch all the previous string values are deprecated and
will fail. The `Stdlib::Port` values must be used.
  • Loading branch information
traylenator committed May 22, 2024
1 parent dcfd35d commit a9d92b3
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 264 deletions.
28 changes: 8 additions & 20 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ file on an haproxy load balancer.
* [`haproxy::sort_bind`](#haproxy--sort_bind)
* [`haproxy::validate_ip_addr`](#haproxy--validate_ip_addr)

### Data types

* [`Haproxy::Ports`](#Haproxy--Ports): Port or list of ports for haproxy. Supports `,` seperated list of ports also.

## Classes

### <a name="haproxy"></a>`haproxy`
Expand Down Expand Up @@ -570,7 +566,7 @@ The haproxy service's instance name (or, the title of the

##### <a name="-haproxy--balancermember--ports"></a>`ports`

Data type: `Optional[Haproxy::Ports]`
Data type: `Optional[Variant[Array[Stdlib::Port,0],Stdlib::Port]]`

An array or commas-separated list of ports for which the balancer member
will accept connections from the load balancer. Note that cookie values
Expand Down Expand Up @@ -825,7 +821,7 @@ Default value: `$name`

##### <a name="-haproxy--frontend--ports"></a>`ports`

Data type: `Optional[Haproxy::Ports]`
Data type: `Optional[Variant[Array[Stdlib::Port,0],Stdlib::Port]]`

Ports on which the proxy will listen for connections on the ip address
specified in the ipaddress parameter. Accepts either a single
Expand Down Expand Up @@ -972,7 +968,7 @@ i.e. emulate Class['haproxy']
instance => 'haproxy',
collect_exported => false,
ipaddress => $::ipaddress,
ports => '8140',
ports => 8140,
}
```

Expand All @@ -988,7 +984,7 @@ Multiple instances of haproxy:
instance => 'group1',
collect_exported => false,
ipaddress => $::ipaddress,
ports => '8800',
ports => 8800,
requires => Package['haproxy'],
}
haproxy::instance { 'group2': }
Expand All @@ -999,7 +995,7 @@ Multiple instances of haproxy:
instance => 'group2',
collect_exported => false,
ipaddress => $::ipaddress,
ports => '9900',
ports => 9900,
requires => Package['haproxy'],
}
```
Expand All @@ -1016,7 +1012,7 @@ Multiple instances of haproxy, one with a custom haproxy package:
instance => 'group1',
collect_exported => false,
ipaddress => $::ipaddress,
ports => '8800',
ports => 8800,
requires => Package['haproxy'],
}
haproxy::instance { 'group2': }
Expand All @@ -1028,7 +1024,7 @@ Multiple instances of haproxy, one with a custom haproxy package:
instance => 'group2',
collect_exported => false,
ipaddress => $::ipaddress,
ports => '9900',
ports => 9900,
requires => Package['haproxy'],
}
```
Expand Down Expand Up @@ -1331,7 +1327,7 @@ Default value: `$name`

##### <a name="-haproxy--listen--ports"></a>`ports`

Data type: `Optional[Haproxy::Ports]`
Data type: `Optional[Variant[Array[Stdlib::Port,0],Stdlib::Port]]`

Ports on which the proxy will listen for connections on the ip address
specified in the ipaddress parameter. Accepts either a single
Expand Down Expand Up @@ -2089,11 +2085,3 @@ Data type: `String`



## Data types

### <a name="Haproxy--Ports"></a>`Haproxy::Ports`

Port or list of ports for haproxy. Supports `,` seperated list of ports also.

Alias of `Variant[Array[Variant[Pattern[/^[0-9]+$/],Stdlib::Port],0], Pattern[/^[0-9,]+$/], Stdlib::Port]`

4 changes: 2 additions & 2 deletions examples/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
haproxy::listen { 'puppet00':
order => '20',
ipaddress => $facts['networking']['ip'],
ports => '18140',
ports => 18140,
options => {
'option' => [
'tcplog',
Expand All @@ -57,7 +57,7 @@
haproxy::listen { 'stats':
order => '30',
ipaddress => '',
ports => '9090',
ports => 9090,
options => {
'mode' => 'http',
'stats' => [
Expand Down
32 changes: 16 additions & 16 deletions manifests/balancermember.pp
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,22 @@
# (this resource can be declared anywhere)
#
define haproxy::balancermember (
String $listening_service,
Enum['server', 'default-server', 'server-template'] $type = 'server',
Optional[Haproxy::Ports] $ports = undef,
Optional[Variant[String, Stdlib::Port]] $port = undef,
Variant[String[1], Array] $server_names = $facts['networking']['hostname'],
Variant[String, Array] $ipaddresses = $facts['networking']['ip'],
String $prefix = 'server',
String $amount = '1',
Optional[String] $fqdn = undef,
Optional[Variant[String, Array]] $options = undef,
Boolean $define_cookies = false,
String $instance = 'haproxy',
Optional[String] $defaults = undef,
Optional[Stdlib::Absolutepath] $config_file = undef,
Boolean $verifyhost = false,
Optional[Variant[String, Integer]] $weight = undef,
String $listening_service,
Enum['server', 'default-server', 'server-template'] $type = 'server',
Optional[Variant[Array[Stdlib::Port,0],Stdlib::Port]] $ports = undef,
Optional[Variant[String, Stdlib::Port]] $port = undef,
Variant[String[1], Array] $server_names = $facts['networking']['hostname'],
Variant[String, Array] $ipaddresses = $facts['networking']['ip'],
String $prefix = 'server',
String $amount = '1',
Optional[String] $fqdn = undef,
Optional[Variant[String, Array]] $options = undef,
Boolean $define_cookies = false,
String $instance = 'haproxy',
Optional[String] $defaults = undef,
Optional[Stdlib::Absolutepath] $config_file = undef,
Boolean $verifyhost = false,
Optional[Variant[String, Integer]] $weight = undef,
) {
include haproxy::params

Expand Down
28 changes: 14 additions & 14 deletions manifests/frontend.pp
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,25 @@
# Gary Larizza <[email protected]>
#
define haproxy::frontend (
Optional[Haproxy::Ports] $ports = undef,
Optional[Variant[String, Array]] $ipaddress = undef,
Optional[Hash] $bind = undef,
Optional[Enum['tcp', 'http', 'health']] $mode = undef,
Boolean $collect_exported = true,
Variant[Hash, Array[Hash]] $options = {
Optional[Variant[Array[Stdlib::Port,0],Stdlib::Port]] $ports = undef,
Optional[Variant[String, Array]] $ipaddress = undef,
Optional[Hash] $bind = undef,
Optional[Enum['tcp', 'http', 'health']] $mode = undef,
Boolean $collect_exported = true,
Variant[Hash, Array[Hash]] $options = {
'option' => [
'tcplog',
],
},
String $instance = 'haproxy',
String[1] $section_name = $name,
Boolean $sort_options_alphabetic = true,
Optional[String] $description = undef,
Optional[String] $defaults = undef,
Boolean $defaults_use_backend = true,
Optional[Stdlib::Absolutepath] $config_file = undef,
String $instance = 'haproxy',
String[1] $section_name = $name,
Boolean $sort_options_alphabetic = true,
Optional[String] $description = undef,
Optional[String] $defaults = undef,
Boolean $defaults_use_backend = true,
Optional[Stdlib::Absolutepath] $config_file = undef,
# Deprecated
Optional[Array] $bind_options = undef,
Optional[Array] $bind_options = undef,
) {
if $ports and $bind {
fail('The use of $ports and $bind is mutually exclusive, please choose either one')
Expand Down
10 changes: 5 additions & 5 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
# instance => 'haproxy',
# collect_exported => false,
# ipaddress => $::ipaddress,
# ports => '8140',
# ports => 8140,
# }
#
# @example
Expand All @@ -106,7 +106,7 @@
# instance => 'group1',
# collect_exported => false,
# ipaddress => $::ipaddress,
# ports => '8800',
# ports => 8800,
# requires => Package['haproxy'],
# }
# haproxy::instance { 'group2': }
Expand All @@ -117,7 +117,7 @@
# instance => 'group2',
# collect_exported => false,
# ipaddress => $::ipaddress,
# ports => '9900',
# ports => 9900,
# requires => Package['haproxy'],
# }
#
Expand All @@ -131,7 +131,7 @@
# instance => 'group1',
# collect_exported => false,
# ipaddress => $::ipaddress,
# ports => '8800',
# ports => 8800,
# requires => Package['haproxy'],
# }
# haproxy::instance { 'group2': }
Expand All @@ -143,7 +143,7 @@
# instance => 'group2',
# collect_exported => false,
# ipaddress => $::ipaddress,
# ports => '9900',
# ports => 9900,
# requires => Package['haproxy'],
# }
#
Expand Down
26 changes: 13 additions & 13 deletions manifests/listen.pp
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,25 @@
# Gary Larizza <[email protected]>
#
define haproxy::listen (
Optional[Haproxy::Ports] $ports = undef,
Optional[Variant[String, Array]] $ipaddress = undef,
Optional[Hash] $bind = undef,
Optional[Enum['tcp', 'http', 'health']] $mode = undef,
Boolean $collect_exported = true,
Variant[Hash, Array[Hash]] $options = {
Optional[Variant[Array[Stdlib::Port,0],Stdlib::Port]] $ports = undef,
Optional[Variant[String, Array]] $ipaddress = undef,
Optional[Hash] $bind = undef,
Optional[Enum['tcp', 'http', 'health']] $mode = undef,
Boolean $collect_exported = true,
Variant[Hash, Array[Hash]] $options = {
'option' => [
'tcplog',
],
'balance' => 'roundrobin',
},
String $instance = 'haproxy',
String[1] $section_name = $name,
Boolean $sort_options_alphabetic = true,
Optional[String] $description = undef,
Optional[String] $defaults = undef,
Optional[Stdlib::Absolutepath] $config_file = undef,
String $instance = 'haproxy',
String[1] $section_name = $name,
Boolean $sort_options_alphabetic = true,
Optional[String] $description = undef,
Optional[String] $defaults = undef,
Optional[Stdlib::Absolutepath] $config_file = undef,
# Deprecated
Optional[Array] $bind_options = undef,
Optional[Array] $bind_options = undef,
) {
if $ports and $bind {
fail('The use of $ports and $bind is mutually exclusive, please choose either one')
Expand Down
30 changes: 2 additions & 28 deletions spec/acceptance/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class { 'haproxy':
}
haproxy::listen { 'stats':
ipaddress => '127.0.0.1',
ports => ['9090','9091'],
ports => [9090, 9091],
options => {
'mode' => 'http',
'stats' => ['uri /','auth puppet:puppet'],
},
}
haproxy::listen { 'test00':
ipaddress => '127.0.0.1',
ports => '80',
ports => 80,
}
PUPPETCODE
it 'does not listen on any ports' do
Expand Down Expand Up @@ -63,32 +63,6 @@ class { 'haproxy': }
end
end

describe 'multiple ports as strings' do
pp_two = <<-PUPPETCODE
class { 'haproxy': }
haproxy::listen { 'stats':
ipaddress => '127.0.0.1',
ports => ['9090','9091'],
mode => 'http',
options => { 'stats' => ['uri /','auth puppet:puppet'], },
}
PUPPETCODE
it 'is able to listen on an array of ports' do
retry_on_error_matching do
apply_manifest(pp_two, catch_failures: true)
end
end

['9090', '9091'].each do |port|
it "port #{port} has stats listening on each port" do
run_shell("/usr/bin/curl -u puppet:puppet localhost:#{port}") do |r|
expect(r.stdout).to contain %r{HAProxy}
expect(r.exit_code).to eq 0
end
end
end
end

describe 'with sort_options_alphabetic false' do
pp_three = <<-PUPPETCODE
class { 'haproxy::globals':
Expand Down
14 changes: 7 additions & 7 deletions spec/acceptance/defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class { 'haproxy': }
haproxy::frontend { 'app00':
ipaddress => '127.0.0.1',
mode => 'http',
ports => '5555',
ports => 5555,
defaults => 'http',
options => { 'default_backend' => 'app00' },
}
Expand All @@ -43,13 +43,13 @@ class { 'haproxy': }
listening_service => 'app00',
server_names => 'test00.example.com',
defaults => 'http',
ports => '5556',
ports => 5556,
}
haproxy::balancermember { 'port 5557':
listening_service => 'app00',
server_names => 'test01.example.com',
defaults => 'http',
ports => '5557',
ports => 5557,
}
PUPPETCODE
it 'is able to configure defaults with puppet' do
Expand Down Expand Up @@ -89,7 +89,7 @@ class { 'haproxy': }
haproxy::frontend { 'app00':
ipaddress => '127.0.0.1',
mode => 'http',
ports => '5555',
ports => 5555,
defaults => 'http',
options => { 'default_backend' => 'app00' },
}
Expand All @@ -102,12 +102,12 @@ class { 'haproxy': }
listening_service => 'app00',
server_names => 'test00.example.com',
defaults => 'http',
ports => '5556',
ports => 5556,
}
haproxy::frontend { 'app01':
ipaddress => '127.0.0.1',
mode => 'http',
ports => '6666',
ports => 6666,
options => { 'default_backend' => 'app01' },
}
haproxy::backend { 'app01':
Expand All @@ -117,7 +117,7 @@ class { 'haproxy': }
haproxy::balancermember { 'port 5557':
listening_service => 'app01',
server_names => 'test01.example.com',
ports => '5557',
ports => 5557,
}
PUPPETCODE
it 'is able to configure defaults and old style with puppet' do
Expand Down
Loading

0 comments on commit a9d92b3

Please sign in to comment.