Skip to content

Commit 81837ec

Browse files
authored
Merge pull request voxpupuli#1031 from bastelfreak/puppet4
replace validate_* with datatypes
2 parents 12cef18 + 4482b6e commit 81837ec

File tree

9 files changed

+165
-349
lines changed

9 files changed

+165
-349
lines changed

manifests/config.pp

-3
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,6 @@
178178
owner => $daemon_user,
179179
}
180180

181-
if ($daemon) {
182-
validate_re($daemon, '^(on|off)$')
183-
}
184181

185182
file {$proxy_temp_path:
186183
ensure => directory,

manifests/init.pp

+115-180
Large diffs are not rendered by default.

manifests/resource/geo.pp

+8-18
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,16 @@
5353

5454

5555
define nginx::resource::geo (
56-
$networks,
57-
$default = undef,
58-
$ensure = 'present',
59-
$ranges = false,
60-
$address = undef,
61-
$delete = undef,
62-
$proxies = undef,
63-
$proxy_recursive = undef
56+
Hash $networks,
57+
Optional[String] $default = undef,
58+
Enum['present', 'absent'] $ensure = 'present',
59+
Boolean $ranges = false,
60+
Optional[String] $address = undef,
61+
Optional[String] $delete = undef,
62+
Optional[Array] $proxies = undef,
63+
Optional[Boolean] $proxy_recursive = undef
6464
) {
6565

66-
validate_hash($networks)
67-
validate_bool($ranges)
68-
validate_re($ensure, '^(present|absent)$',
69-
"Invalid ensure value '${ensure}'. Expected 'present' or 'absent'")
70-
if ($default != undef) { validate_string($default) }
71-
if ($address != undef) { validate_string($address) }
72-
if ($delete != undef) { validate_string($delete) }
73-
if ($proxies != undef) { validate_array($proxies) }
74-
if ($proxy_recursive != undef) { validate_bool($proxy_recursive) }
75-
7666
$root_group = $::nginx::root_group
7767
$conf_dir = "${::nginx::conf_dir}/conf.d"
7868

manifests/resource/map.pp

+5-13
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,14 @@
6363

6464

6565
define nginx::resource::map (
66-
$string,
67-
$mappings,
68-
$default = undef,
69-
$ensure = 'present',
70-
$hostnames = false
66+
String $string,
67+
Variant[Array, Hash] $mappings,
68+
Optional[String] $default = undef,
69+
Enum['absent', 'present'] $ensure = 'present',
70+
Boolean $hostnames = false
7171
) {
72-
validate_string($string)
7372
validate_re($string, '^.{2,}$',
7473
"Invalid string value [${string}]. Expected a minimum of 2 characters.")
75-
if ! ( is_array($mappings) or is_hash($mappings) ) {
76-
fail("\$mappings must be a hash of the form { 'foo' => 'pool_b' } or array of hashes of form [{ 'key' => 'foo', 'value' => 'pool_b' }, ...]")
77-
}
78-
validate_bool($hostnames)
79-
validate_re($ensure, '^(present|absent)$',
80-
"Invalid ensure value '${ensure}'. Expected 'present' or 'absent'")
81-
if ($default != undef) { validate_string($default) }
8274

8375
$root_group = $::nginx::root_group
8476
$conf_dir = "${::nginx::conf_dir}/conf.d"

manifests/resource/streamhost.pp

+17-52
Original file line numberDiff line numberDiff line change
@@ -47,60 +47,25 @@
4747
# ensure => present,
4848
# }
4949
define nginx::resource::streamhost (
50-
$ensure = 'present',
51-
$listen_ip = '*',
52-
$listen_port = 80,
53-
$listen_options = undef,
54-
$ipv6_enable = false,
55-
$ipv6_listen_ip = '::',
56-
$ipv6_listen_port = 80,
57-
$ipv6_listen_options = 'default ipv6only=on',
58-
$proxy = undef,
59-
$proxy_read_timeout = $::nginx::proxy_read_timeout,
60-
$proxy_connect_timeout = $::nginx::proxy_connect_timeout,
61-
$resolver = [],
62-
$raw_prepend = undef,
63-
$raw_append = undef,
64-
$owner = $::nginx::global_owner,
65-
$group = $::nginx::global_group,
66-
$mode = $::nginx::global_mode,
50+
Enum['absent', 'present'] $ensure = 'present',
51+
Variant[Array, String] $listen_ip = '*',
52+
Integer $listen_port = 80,
53+
Optional[String] $listen_options = undef,
54+
Boolean $ipv6_enable = false,
55+
Variant[Array, String] $ipv6_listen_ip = '::',
56+
Integer $ipv6_listen_port = 80,
57+
String $ipv6_listen_options = 'default ipv6only=on',
58+
$proxy = undef,
59+
String $proxy_read_timeout = $::nginx::proxy_read_timeout,
60+
$proxy_connect_timeout = $::nginx::proxy_connect_timeout,
61+
Array $resolver = [],
62+
$raw_prepend = undef,
63+
$raw_append = undef,
64+
String $owner = $::nginx::global_owner,
65+
String $group = $::nginx::global_group,
66+
String $mode = $::nginx::global_mode,
6767
) {
6868

69-
validate_re($ensure, '^(present|absent)$',
70-
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
71-
if !(is_array($listen_ip) or is_string($listen_ip)) {
72-
fail('$listen_ip must be a string or array.')
73-
}
74-
if is_string($listen_port) {
75-
warning('DEPRECATION: String $listen_port must be converted to an integer. Integer string support will be removed in a future release.')
76-
}
77-
elsif !is_integer($listen_port) {
78-
fail('$listen_port must be an integer.')
79-
}
80-
if ($listen_options != undef) {
81-
validate_string($listen_options)
82-
}
83-
validate_bool($ipv6_enable)
84-
if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) {
85-
fail('$ipv6_listen_ip must be a string or array.')
86-
}
87-
if is_string($ipv6_listen_port) {
88-
warning('DEPRECATION: String $ipv6_listen_port must be converted to an integer. Integer string support will be removed in a future release.')
89-
}
90-
elsif !is_integer($ipv6_listen_port) {
91-
fail('$ipv6_listen_port must be an integer.')
92-
}
93-
validate_string($ipv6_listen_options)
94-
95-
validate_string($proxy_read_timeout)
96-
97-
validate_array($resolver)
98-
99-
validate_string($owner)
100-
validate_string($group)
101-
validate_re($mode, '^\d{4}$',
102-
"${mode} is not valid. It should be 4 digits (0644 by default).")
103-
10469
# Variables
10570
if $::nginx::confd_only {
10671
$streamhost_dir = "${::nginx::conf_dir}/conf.stream.d"

manifests/resource/upstream.pp

+8-22
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,16 @@
4141
# upstream_cfg_prepend => $my_config,
4242
# }
4343
define nginx::resource::upstream (
44-
$members = undef,
45-
$members_tag = undef,
46-
$ensure = 'present',
47-
$upstream_cfg_append = undef,
48-
$upstream_cfg_prepend = undef,
49-
$upstream_fail_timeout = '10s',
50-
$upstream_max_fails = undef,
51-
$upstream_context = 'http',
44+
Optional[Array] $members = undef,
45+
$members_tag = undef,
46+
Enum['present', 'absent'] $ensure = 'present',
47+
Optional[Hash] $upstream_cfg_append = undef,
48+
Optional[Hash] $upstream_cfg_prepend = undef,
49+
$upstream_fail_timeout = '10s',
50+
$upstream_max_fails = undef,
51+
Enum['http', 'stream'] $upstream_context = 'http',
5252
) {
5353

54-
if $members != undef {
55-
validate_array($members)
56-
}
57-
validate_re($ensure, '^(present|absent)$',
58-
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
59-
validate_re($upstream_context, '^(http|stream)$',
60-
"${upstream_context} is not supported for upstream_context. Allowed values are 'http' and 'stream'.")
61-
if ($upstream_cfg_append != undef) {
62-
validate_hash($upstream_cfg_append)
63-
}
64-
if ($upstream_cfg_prepend != undef) {
65-
validate_hash($upstream_cfg_prepend)
66-
}
67-
6854
$root_group = $::nginx::root_group
6955

7056
$ensure_real = $ensure ? {

manifests/resource/upstream/member.pp

+2-17
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,11 @@
3737
define nginx::resource::upstream::member (
3838
$upstream,
3939
$server,
40-
$ensure = 'present',
41-
$port = 80,
40+
Enum['present', 'absent'] $ensure = 'present',
41+
Integer $port = 80,
4242
$upstream_fail_timeout = '10s',
4343
) {
4444

45-
validate_re($ensure, '^(present|absent)$',
46-
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
47-
48-
if is_string($port) {
49-
warning('DEPRECATION: String $port must be converted to an integer. Integer string support will be removed in a future release.')
50-
}
51-
elsif !is_integer($port) {
52-
fail('$port must be an integer.')
53-
}
54-
55-
$ensure_real = $ensure ? {
56-
'absent' => absent,
57-
default => present,
58-
}
59-
6045
# Uses: $server, $port, $upstream_fail_timeout
6146
concat::fragment { "${upstream}_upstream_member_${name}":
6247
target => "${::nginx::conf_dir}/conf.d/${upstream}-upstream.conf",

spec/classes/nginx_spec.rb

+10-34
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@
395395
{
396396
title: 'should set worker_processes',
397397
attr: 'worker_processes',
398-
value: '4',
398+
value: 4,
399399
match: 'worker_processes 4;'
400400
},
401401
{
@@ -407,7 +407,7 @@
407407
{
408408
title: 'should set worker_rlimit_nofile',
409409
attr: 'worker_rlimit_nofile',
410-
value: '10000',
410+
value: 10_000,
411411
match: 'worker_rlimit_nofile 10000;'
412412
},
413413
{
@@ -464,7 +464,7 @@
464464
{
465465
title: 'should set worker_connections',
466466
attr: 'worker_connections',
467-
value: '100',
467+
value: 100,
468468
match: ' worker_connections 100;'
469469
},
470470
{
@@ -503,12 +503,6 @@
503503
value: 'eventport',
504504
match: %r{\s*use\s+eventport;}
505505
},
506-
{
507-
title: 'should not set events_use',
508-
attr: 'events_use',
509-
value: false,
510-
notmatch: %r{use }
511-
},
512506
{
513507
title: 'should set access_log',
514508
attr: 'http_access_log',
@@ -686,36 +680,18 @@
686680
value: '/path/to/proxy.cache',
687681
match: %r{\s+proxy_cache_path\s+/path/to/proxy.cache levels=1 keys_zone=d2:100m max_size=500m inactive=20m;}
688682
},
689-
{
690-
title: 'should not set proxy_cache_path',
691-
attr: 'proxy_cache_path',
692-
value: false,
693-
notmatch: %r{proxy_cache_path}
694-
},
695683
{
696684
title: 'should set fastcgi_cache_path',
697685
attr: 'fastcgi_cache_path',
698686
value: '/path/to/proxy.cache',
699687
match: %r{\s*fastcgi_cache_path\s+/path/to/proxy.cache levels=1 keys_zone=d3:100m max_size=500m inactive=20m;}
700688
},
701-
{
702-
title: 'should not set fastcgi_cache_path',
703-
attr: 'fastcgi_cache_path',
704-
value: false,
705-
notmatch: %r{fastcgi_cache_path}
706-
},
707689
{
708690
title: 'should set fastcgi_cache_use_stale',
709691
attr: 'fastcgi_cache_use_stale',
710692
value: 'invalid_header',
711693
match: ' fastcgi_cache_use_stale invalid_header;'
712694
},
713-
{
714-
title: 'should not set fastcgi_cache_use_stale',
715-
attr: 'fastcgi_cache_use_stale',
716-
value: false,
717-
notmatch: %r{fastcgi_cache_use_stale}
718-
},
719695
{
720696
title: 'should contain ordered appended directives from hash',
721697
attr: 'http_cfg_prepend',
@@ -906,7 +882,13 @@
906882
end
907883

908884
context 'when proxy_cache_path is /path/to/proxy.cache and loader_files is 1000' do
909-
let(:params) { { conf_dir: '/path/to/nginx', proxy_cache_path: '/path/to/proxy.cache', proxy_cache_loader_files: '1000' } }
885+
let(:params) do
886+
{
887+
conf_dir: '/path/to/nginx',
888+
proxy_cache_path: '/path/to/proxy.cache',
889+
proxy_cache_loader_files: 1000
890+
}
891+
end
910892
it { is_expected.to contain_file('/path/to/nginx/nginx.conf').with_content(%r{\s+proxy_cache_path\s+/path/to/proxy.cache levels=1 keys_zone=d2:100m max_size=500m inactive=20m loader_files=1000;}) }
911893
end
912894

@@ -1085,12 +1067,6 @@
10851067
it { is_expected.to contain_file('/etc/nginx/nginx.conf').with_content %r{^user www-data;} }
10861068
end
10871069

1088-
context 'when nginx_error_log_severity = invalid' do
1089-
let(:params) { { nginx_error_log_severity: 'invalid' } }
1090-
1091-
it { expect { is_expected.to contain_class('nginx::config') }.to raise_error(Puppet::Error, %r{\$nginx_error_log_severity must be debug, info, notice, warn, error, crit, alert or emerg}) }
1092-
end
1093-
10941070
context 'when log_dir is non-default' do
10951071
let(:params) { { log_dir: '/foo/bar' } }
10961072

spec/defines/resource_map_spec.rb

-10
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,6 @@
104104

105105
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").with_ensure('absent') }
106106
end
107-
108-
context 'when mappings is a string' do
109-
let :params do
110-
default_params.merge(
111-
mappings: 'foo pool_b'
112-
)
113-
end
114-
115-
it { is_expected.to raise_error(Puppet::Error, %r[mappings must be a hash of the form { 'foo' => 'pool_b' }]) }
116-
end
117107
end
118108
end
119109
end

0 commit comments

Comments
 (0)