Skip to content

Commit bd20633

Browse files
authored
update resolver parameters (#526)
* resolver: fix default accepted_payload_size This fixes the error: Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Comparison of: Undef Value < Integer, is not possible. Caused by 'Only Strings, Numbers, Timespans, Timestamps, and Versions are comparable'. (file: /etc/puppetlabs/code/modules/haproxy/manifests/resolver.pp, line: 125, column: 30) HAProxy allows this parameter to be unset, and the code here works with this ok, aside from the bounds check. Replace the bounds check with a parameter type declaration, so that puppet itself will do the check for us. Update tests accordingly. * resolver: support parse-resolv-conf parameter The parse-resolv-conf parameter can be used on its own or in conjunction with the nameservers parameter. Adjust the nameservers parameter default to allow the template to work; an empty hash results in no nameservers specified. Add a new test. * resolver: visually re-align parameter assignments
1 parent 552c5fe commit bd20633

File tree

3 files changed

+67
-19
lines changed

3 files changed

+67
-19
lines changed

manifests/resolver.pp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
# @param nameservers
1616
# Set of id, ip addresses and port options.
1717
# $nameservers = { 'dns1' => '10.0.0.1:53', 'dns2' => '10.0.0.2:53' }
18+
# Either the 'nameservers' or the 'parse_resolv_conf' parameter must be
19+
# specified in order for the resolver to work.
20+
# Default: none specified.
21+
#
22+
# @param parse_resolv_conf
23+
# If true, parse resolv.conf to retrieve an ordered set of nameservers.
24+
# This can be used instead of (or in addition to) the 'nameservers'
25+
# parameter.
26+
# Default: false
1827
#
1928
# @param hold
2029
# Defines <period> during which the last name resolution should be kept
@@ -87,17 +96,19 @@
8796
# Ricardo Rosales <[email protected]>
8897
#
8998
define haproxy::resolver (
90-
$nameservers = undef,
91-
$hold = undef,
92-
$resolve_retries = undef,
93-
$timeout = undef,
94-
$accepted_payload_size = undef,
95-
$instance = 'haproxy',
96-
$section_name = $name,
97-
$sort_options_alphabetic = undef,
98-
$collect_exported = true,
99-
$config_file = undef,
100-
$defaults = undef,
99+
Hash $nameservers = {},
100+
Boolean $parse_resolv_conf = false,
101+
$hold = undef,
102+
$resolve_retries = undef,
103+
$timeout = undef,
104+
# https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#5.3.2-accepted_payload_size
105+
Optional[Integer[512, 8192]] $accepted_payload_size = undef,
106+
$instance = 'haproxy',
107+
$section_name = $name,
108+
$sort_options_alphabetic = undef,
109+
$collect_exported = true,
110+
$config_file = undef,
111+
$defaults = undef,
101112
) {
102113
include haproxy::params
103114

@@ -120,12 +131,6 @@
120131
$order = "25-${defaults}-${section_name}-02"
121132
}
122133

123-
# verify accepted_payload_size is withing the allowed range per HAProxy docs
124-
# https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#5.3.2-accepted_payload_size
125-
if ($accepted_payload_size < 512) or ($accepted_payload_size > 8192) {
126-
fail('$accepted_payload_size must be atleast 512 and not more than 8192')
127-
}
128-
129134
# Template uses: $section_name
130135
concat::fragment { "${instance_name}-${section_name}_resolver_block":
131136
order => $order,

spec/defines/resolver_spec.rb

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,46 @@
1313
end
1414

1515
context 'with two resolvers' do
16+
let(:title) { 'bar' }
17+
let(:params) do
18+
{
19+
nameservers: { 'dns1' => '1.1.1.1:53', 'dns2' => '1.1.1.2:53' },
20+
hold: { 'other' => '30s', 'refused' => '30s', 'nx' => '30s', 'timeout' => '30s', 'valid' => '10s' },
21+
resolve_retries: 3,
22+
timeout: { 'retry' => '1s' },
23+
}
24+
end
25+
26+
it {
27+
is_expected.to contain_concat__fragment('haproxy-bar_resolver_block').with(
28+
'order' => '20-bar-01',
29+
'target' => '/etc/haproxy/haproxy.cfg',
30+
'content' => "\nresolvers bar\n nameserver dns1 1.1.1.1:53\n nameserver dns2 1.1.1.2:53\n resolve_retries 3\n timeout retry 1s\n hold other 30s\n hold refused 30s\n hold nx 30s\n hold timeout 30s\n hold valid 10s\n", # rubocop:disable Layout/LineLength
31+
)
32+
}
33+
end
34+
35+
context 'with parse_resolv_conf' do
36+
let(:title) { 'bar' }
37+
let(:params) do
38+
{
39+
parse_resolv_conf: true,
40+
hold: { 'other' => '30s', 'refused' => '30s', 'nx' => '30s', 'timeout' => '30s', 'valid' => '10s' },
41+
resolve_retries: 3,
42+
timeout: { 'retry' => '1s' },
43+
}
44+
end
45+
46+
it {
47+
is_expected.to contain_concat__fragment('haproxy-bar_resolver_block').with(
48+
'order' => '20-bar-01',
49+
'target' => '/etc/haproxy/haproxy.cfg',
50+
'content' => "\nresolvers bar\n parse-resolv-conf\n resolve_retries 3\n timeout retry 1s\n hold other 30s\n hold refused 30s\n hold nx 30s\n hold timeout 30s\n hold valid 10s\n",
51+
)
52+
}
53+
end
54+
55+
context 'with accepted_payload_size within range' do
1656
let(:title) { 'bar' }
1757
let(:params) do
1858
{
@@ -45,7 +85,7 @@
4585
}
4686
end
4787

48-
it { is_expected.to compile.and_raise_error(%r{accepted_payload_size must be atleast 512 and not more than 8192}) }
88+
it { is_expected.to compile.and_raise_error(%r{expects a value of type Undef or Integer\[512, 8192\]}) }
4989
end
5090

5191
context 'with accepted_payload_size too large' do
@@ -60,6 +100,6 @@
60100
}
61101
end
62102

63-
it { is_expected.to compile.and_raise_error(%r{accepted_payload_size must be atleast 512 and not more than 8192}) }
103+
it { is_expected.to compile.and_raise_error(%r{expects a value of type Undef or Integer\[512, 8192\]}) }
64104
end
65105
end

templates/haproxy_resolver_block.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ resolvers <%= @section_name %>
33
<% @nameservers.each do |id, nameserver| -%>
44
nameserver <%= id %> <%= nameserver %>
55
<% end -%>
6+
<% if @parse_resolv_conf -%>
7+
parse-resolv-conf
8+
<% end -%>
69
<% if @resolve_retries -%>
710
resolve_retries <%= @resolve_retries %>
811
<% end -%>

0 commit comments

Comments
 (0)