Skip to content

Commit 001ad69

Browse files
author
Phil Friderici
committed
Remove support for stringified booleans
1 parent 865b5de commit 001ad69

File tree

4 files changed

+59
-63
lines changed

4 files changed

+59
-63
lines changed

manifests/init.pp

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,38 +55,20 @@
5555
# The name of the puppet server.
5656
#
5757
class puppet (
58-
String $certname = $facts['networking']['fqdn'],
59-
Variant[Enum['true', 'false'], Boolean] $run_every_thirty = true, #lint:ignore:quoted_booleans
60-
Variant[Enum['true', 'false'], Boolean] $run_in_noop = true, #lint:ignore:quoted_booleans
61-
String $cron_command = '/opt/puppetlabs/bin/puppet agent --onetime --no-daemonize --no-usecacheonfailure --detailed-exitcodes --no-splay', #lint:ignore:140chars
62-
Variant[Enum['true', 'false'], Boolean] $run_at_boot = true, #lint:ignore:quoted_booleans
63-
Stdlib::Absolutepath $config_path = '/etc/puppetlabs/puppet/puppet.conf',
64-
String $server = 'puppet',
65-
String $ca_server = 'puppet',
66-
String $env = $environment,
67-
Variant[Enum['true', 'false'], Boolean] $graph = false, #lint:ignore:quoted_booleans
68-
Stdlib::Absolutepath $agent_sysconfig_path = '/etc/sysconfig/puppet',
69-
Hash $custom_settings = {},
58+
String $certname = $facts['networking']['fqdn'],
59+
Boolean $run_every_thirty = true,
60+
Boolean $run_in_noop = true,
61+
String $cron_command = '/opt/puppetlabs/bin/puppet agent --onetime --no-daemonize --no-usecacheonfailure --detailed-exitcodes --no-splay', #lint:ignore:140chars
62+
Boolean $run_at_boot = true,
63+
Stdlib::Absolutepath $config_path = '/etc/puppetlabs/puppet/puppet.conf',
64+
String $server = 'puppet',
65+
String $ca_server = 'puppet',
66+
String $env = $environment,
67+
Boolean $graph = false,
68+
Stdlib::Absolutepath $agent_sysconfig_path = '/etc/sysconfig/puppet',
69+
Hash $custom_settings = {},
7070
) {
71-
if is_string($run_every_thirty) == true {
72-
$run_every_thirty_bool = str2bool($run_every_thirty)
73-
} else {
74-
$run_every_thirty_bool = $run_every_thirty
75-
}
76-
77-
if is_string($run_in_noop) == true {
78-
$run_in_noop_bool = str2bool($run_in_noop)
79-
} else {
80-
$run_in_noop_bool = $run_in_noop
81-
}
82-
83-
if is_string($run_at_boot) == true {
84-
$run_at_boot_bool = str2bool($run_at_boot)
85-
} else {
86-
$run_at_boot_bool = $run_at_boot
87-
}
88-
89-
if $run_every_thirty_bool == true {
71+
if $run_every_thirty == true {
9072
$cron_run_one = fqdn_rand(30)
9173
$cron_run_two = fqdn_rand(30) + 30
9274
$cron_minute = [$cron_run_one, $cron_run_two]
@@ -96,7 +78,7 @@
9678
$cron_minute = undef
9779
}
9880

99-
if $run_in_noop_bool == true {
81+
if $run_in_noop == true {
10082
$cron_command_real = "${cron_command} --noop"
10183
} else {
10284
$cron_command_real = $cron_command
@@ -110,7 +92,7 @@
11092
minute => $cron_minute,
11193
}
11294

113-
if $run_at_boot_bool == true {
95+
if $run_at_boot == true {
11496
$at_boot_ensure = 'present'
11597
} else {
11698
$at_boot_ensure = 'absent'

manifests/server.pp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
# The absolute path to the puppetserver sysconfig file.
2727
#
2828
class puppet::server (
29-
Variant[Enum['true', 'false'], Boolean] $ca = false, #lint:ignore:quoted_booleans
30-
Variant[Array[String, 1], Undef] $autosign_entries = undef,
31-
Stdlib::Absolutepath $sysconfig_path = '/etc/sysconfig/puppetserver',
32-
Pattern[/^\d+(m|g)$/] $memory_size = '2g', # only m and g are appropriate for unit
33-
Optional[Stdlib::Absolutepath] $enc = undef,
34-
Optional[String] $dns_alt_names = undef,
29+
Boolean $ca = false,
30+
Variant[Array[String, 1], Undef] $autosign_entries = undef,
31+
Stdlib::Absolutepath $sysconfig_path = '/etc/sysconfig/puppetserver',
32+
Pattern[/^\d+(m|g)$/] $memory_size = '2g', # only m and g are appropriate for unit
33+
Optional[Stdlib::Absolutepath] $enc = undef,
34+
Optional[String] $dns_alt_names = undef,
3535
) {
3636
include puppet
3737

spec/classes/init_spec.rb

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@
106106
end
107107

108108
describe 'with run_every_thirty' do
109-
[true, 'true', false, 'false'].each do |value|
110-
[true, 'true', false, 'false'].each do |noop_value|
109+
[true, false].each do |value|
110+
[true, false].each do |noop_value|
111111
context "set to #{value} (as #{value.class}) and run_in_noop set to #{noop_value} (as #{noop_value.class})" do
112112
let(:params) do
113113
{
@@ -116,15 +116,15 @@
116116
}
117117
end
118118

119-
if [true, 'true'].include?(value)
119+
if value == true
120120
cron_ensure = 'present'
121121
cron_minute = minute
122122
else
123123
cron_ensure = 'absent'
124124
cron_minute = nil
125125
end
126126

127-
cron_command = if [true, 'true'].include?(noop_value)
127+
cron_command = if noop_value == true
128128
'/opt/puppetlabs/bin/puppet agent --onetime --no-daemonize --no-usecacheonfailure --detailed-exitcodes --no-splay --noop'
129129
else
130130
'/opt/puppetlabs/bin/puppet agent --onetime --no-daemonize --no-usecacheonfailure --detailed-exitcodes --no-splay'
@@ -173,11 +173,11 @@
173173
end
174174

175175
describe 'with run_at_boot' do
176-
[true, 'true', false, 'false'].each do |value|
176+
[true, false].each do |value|
177177
context "set to #{value} (as #{value.class})" do
178178
let(:params) { { run_at_boot: value } }
179179

180-
foo = if [true, 'true'].include?(value)
180+
foo = if value == true
181181
'present'
182182
else
183183
'absent'
@@ -201,20 +201,17 @@
201201
end
202202

203203
describe 'with puppet.conf ini setting' do
204-
['server', 'ca_server', 'certname', 'graph'].each do |setting|
204+
['server', 'ca_server', 'certname'].each do |setting|
205205
context "#{setting} set to a valid entry" do
206-
# 'true' is used because it is acceptable to all of the above
207-
# parameters. Some of the settings are strings and some are boolean and
208-
# stringified booleans.
209-
let(:params) { { setting => 'true' } }
206+
let(:params) { { setting => 'testing' } }
210207

211208
it do
212209
is_expected.to contain_ini_setting(setting).with(
213210
{
214-
ensure: 'present',
211+
ensure: 'present',
215212
setting: setting,
216-
value: 'true',
217-
path: '/etc/puppetlabs/puppet/puppet.conf',
213+
value: 'testing',
214+
path: '/etc/puppetlabs/puppet/puppet.conf',
218215
section: 'main',
219216
require: 'File[puppet_config]',
220217
},
@@ -224,6 +221,23 @@
224221
end
225222
end
226223

224+
context 'with graph set to a valid entry' do
225+
let(:params) { { graph: true } }
226+
227+
it do
228+
is_expected.to contain_ini_setting('graph').with(
229+
{
230+
ensure: 'present',
231+
setting: 'graph',
232+
value: 'true',
233+
path: '/etc/puppetlabs/puppet/puppet.conf',
234+
section: 'main',
235+
require: 'File[puppet_config]',
236+
},
237+
)
238+
end
239+
end
240+
227241
describe 'with env specified' do
228242
let(:params) { { env: 'myenv' } }
229243

@@ -315,25 +329,25 @@
315329
'Stdlib::Absolutepath' => {
316330
name: ['config_path', 'agent_sysconfig_path'],
317331
valid: ['/absolute/path'],
318-
invalid: ['not/an/absolute/path'],
332+
invalid: ['not/an/absolute/path', ['array'], { 'ha' => 'sh' }, 3, 2.42, false],
319333
message: 'expects a Stdlib::Absolutepath',
320334
},
321-
'booleans' => {
335+
'Boolean' => {
322336
name: ['run_every_thirty', 'run_in_noop', 'run_at_boot', 'graph'],
323-
valid: [true, 'true', false, 'false'],
337+
valid: [true, false],
324338
invalid: ['string', ['array'], { 'ha' => 'sh' }, 3, 2.42],
325-
message: 'Error while evaluating a Resource Statement',
339+
message: 'expects a Boolean',
326340
},
327341
'hash' => {
328342
name: ['custom_settings'],
329343
valid: [], # valid hashes are to complex to block test them here
330-
invalid: ['string', ['array'], 3, 2.42, true, nil],
344+
invalid: ['string', ['array'], 3, 2.42, false, nil],
331345
message: 'expects a Hash value',
332346
},
333347
'strings' => {
334348
name: ['certname', 'cron_command', 'server', 'ca_server', 'env'],
335349
valid: ['string'],
336-
invalid: [true, ['array'], { 'ha' => 'sh' }, 3, 2.42],
350+
invalid: [true, ['array'], { 'ha' => 'sh' }, 3, 2.42, false],
337351
message: 'Error while evaluating a Resource Statement',
338352
},
339353
}

spec/classes/server_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
end
9292

9393
describe 'with ca' do
94-
[true, 'true', false, 'false'].each do |value|
94+
[true, false].each do |value|
9595
context "set to #{value} (as #{value.class})" do
9696
let(:params) { { ca: value } }
9797

@@ -189,11 +189,11 @@
189189
invalid: ['not/an/absolute/path'],
190190
message: 'expects a Stdlib::Absolutepath',
191191
},
192-
'booleans' => {
192+
'Boolean' => {
193193
name: ['ca'],
194-
valid: [true, 'true', false, 'false'],
194+
valid: [true, false],
195195
invalid: ['string', ['array'], { 'ha' => 'sh' }, 3, 2.42],
196-
message: 'Error while evaluating a Resource Statement',
196+
message: 'expects a Boolean',
197197
},
198198
'strings' => {
199199
name: ['dns_alt_names'],

0 commit comments

Comments
 (0)