summaryrefslogtreecommitdiff
path: root/lib/puppet/parser/functions
diff options
context:
space:
mode:
authorDavid Schmitt <david.schmitt@puppet.com>2016-10-12 10:04:54 +0100
committerDavid Schmitt <david.schmitt@puppet.com>2016-10-12 10:40:54 +0100
commitb92fad2b7667df836f8ca4eb92d8c8be84bd0538 (patch)
tree912de02b06abd718f737b1a891d2a38ecc57f04c /lib/puppet/parser/functions
parentf3978b87a498959b271c487944b1ce3903c359d4 (diff)
(MODULES-3961) emit more deprecation warnings
This now emits one deprecation warning for each function used (but not for each call-site). Prior to this, only a single deprecation warning would have been triggered, potentially misleading users. Additionally this adds v4 deprecation stubs for the functions that were missed.
Diffstat (limited to 'lib/puppet/parser/functions')
-rw-r--r--lib/puppet/parser/functions/is_absolute_path.rb2
-rw-r--r--lib/puppet/parser/functions/is_array.rb2
-rw-r--r--lib/puppet/parser/functions/is_bool.rb2
-rw-r--r--lib/puppet/parser/functions/is_float.rb2
-rw-r--r--lib/puppet/parser/functions/is_ip_address.rb2
-rw-r--r--lib/puppet/parser/functions/is_ipv4_address.rb2
-rw-r--r--lib/puppet/parser/functions/is_ipv6_address.rb2
-rw-r--r--lib/puppet/parser/functions/is_numeric.rb2
-rw-r--r--lib/puppet/parser/functions/is_string.rb5
-rw-r--r--lib/puppet/parser/functions/validate_absolute_path.rb2
-rw-r--r--lib/puppet/parser/functions/validate_array.rb2
-rw-r--r--lib/puppet/parser/functions/validate_bool.rb2
-rw-r--r--lib/puppet/parser/functions/validate_hash.rb2
-rw-r--r--lib/puppet/parser/functions/validate_integer.rb4
-rw-r--r--lib/puppet/parser/functions/validate_ip_address.rb6
-rw-r--r--lib/puppet/parser/functions/validate_ipv4_address.rb2
-rw-r--r--lib/puppet/parser/functions/validate_ipv6_address.rb2
-rw-r--r--lib/puppet/parser/functions/validate_numeric.rb4
-rw-r--r--lib/puppet/parser/functions/validate_re.rb2
-rw-r--r--lib/puppet/parser/functions/validate_slength.rb2
-rw-r--r--lib/puppet/parser/functions/validate_string.rb9
21 files changed, 31 insertions, 29 deletions
diff --git a/lib/puppet/parser/functions/is_absolute_path.rb b/lib/puppet/parser/functions/is_absolute_path.rb
index 2e37414..e64777f 100644
--- a/lib/puppet/parser/functions/is_absolute_path.rb
+++ b/lib/puppet/parser/functions/is_absolute_path.rb
@@ -23,7 +23,7 @@ module Puppet::Parser::Functions
is_absolute_path($undefined)
ENDHEREDOC
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Absolute_path. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:is_absolute_path, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Absolute_path. There is further documentation for validate_legacy function in the README.'])
require 'puppet/util'
path = args[0]
diff --git a/lib/puppet/parser/functions/is_array.rb b/lib/puppet/parser/functions/is_array.rb
index d1bb58a..1d2c0fa 100644
--- a/lib/puppet/parser/functions/is_array.rb
+++ b/lib/puppet/parser/functions/is_array.rb
@@ -8,7 +8,7 @@ Returns true if the variable passed to this function is an array.
EOS
) do |arguments|
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Array. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:is_array, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Array. There is further documentation for validate_legacy function in the README.'])
raise(Puppet::ParseError, "is_array(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1
diff --git a/lib/puppet/parser/functions/is_bool.rb b/lib/puppet/parser/functions/is_bool.rb
index 48aaa08..83d2ebe 100644
--- a/lib/puppet/parser/functions/is_bool.rb
+++ b/lib/puppet/parser/functions/is_bool.rb
@@ -8,7 +8,7 @@ Returns true if the variable passed to this function is a boolean.
EOS
) do |arguments|
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Bool. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:is_bool, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Bool. There is further documentation for validate_legacy function in the README.'])
raise(Puppet::ParseError, "is_bool(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size != 1
diff --git a/lib/puppet/parser/functions/is_float.rb b/lib/puppet/parser/functions/is_float.rb
index 5233e40..1186458 100644
--- a/lib/puppet/parser/functions/is_float.rb
+++ b/lib/puppet/parser/functions/is_float.rb
@@ -8,7 +8,7 @@ Returns true if the variable passed to this function is a float.
EOS
) do |arguments|
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Float. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:is_float, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Float. There is further documentation for validate_legacy function in the README.'])
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_float(): Wrong number of arguments "+
diff --git a/lib/puppet/parser/functions/is_ip_address.rb b/lib/puppet/parser/functions/is_ip_address.rb
index 1901b2c..5f1d765 100644
--- a/lib/puppet/parser/functions/is_ip_address.rb
+++ b/lib/puppet/parser/functions/is_ip_address.rb
@@ -10,7 +10,7 @@ Returns true if the string passed to this function is a valid IP address.
require 'ipaddr'
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ip_address. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:is_ip_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ip_address. There is further documentation for validate_legacy function in the README.'])
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments "+
diff --git a/lib/puppet/parser/functions/is_ipv4_address.rb b/lib/puppet/parser/functions/is_ipv4_address.rb
index c90fa64..1764e61 100644
--- a/lib/puppet/parser/functions/is_ipv4_address.rb
+++ b/lib/puppet/parser/functions/is_ipv4_address.rb
@@ -10,7 +10,7 @@ Returns true if the string passed to this function is a valid IPv4 address.
require 'ipaddr'
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv4. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:is_ipv4_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv4. There is further documentation for validate_legacy function in the README.'])
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_ipv4_address(): Wrong number of arguments "+
diff --git a/lib/puppet/parser/functions/is_ipv6_address.rb b/lib/puppet/parser/functions/is_ipv6_address.rb
index aec3483..7ca4997 100644
--- a/lib/puppet/parser/functions/is_ipv6_address.rb
+++ b/lib/puppet/parser/functions/is_ipv6_address.rb
@@ -8,7 +8,7 @@ Returns true if the string passed to this function is a valid IPv6 address.
EOS
) do |arguments|
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv6. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:is_ipv6_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv6. There is further documentation for validate_legacy function in the README.'])
require 'ipaddr'
diff --git a/lib/puppet/parser/functions/is_numeric.rb b/lib/puppet/parser/functions/is_numeric.rb
index 2bdd353..4a55225 100644
--- a/lib/puppet/parser/functions/is_numeric.rb
+++ b/lib/puppet/parser/functions/is_numeric.rb
@@ -24,7 +24,7 @@ Valid examples:
EOS
) do |arguments|
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Numeric. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:is_numeric, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Numeric. There is further documentation for validate_legacy function in the README.'])
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_numeric(): Wrong number of arguments "+
diff --git a/lib/puppet/parser/functions/is_string.rb b/lib/puppet/parser/functions/is_string.rb
index 144cf51..31ee91e 100644
--- a/lib/puppet/parser/functions/is_string.rb
+++ b/lib/puppet/parser/functions/is_string.rb
@@ -8,14 +8,15 @@ Returns true if the variable passed to this function is a string.
EOS
) do |arguments|
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:is_string, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.'])
raise(Puppet::ParseError, "is_string(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1
type = arguments[0]
- result = type.is_a?(String)
+ # when called through the v4 API shim, undef gets translated to nil
+ result = type.is_a?(String) || type.nil?
if result and (type == type.to_f.to_s or type == type.to_i.to_s) then
return false
diff --git a/lib/puppet/parser/functions/validate_absolute_path.rb b/lib/puppet/parser/functions/validate_absolute_path.rb
index 15b5c57..c73f3df 100644
--- a/lib/puppet/parser/functions/validate_absolute_path.rb
+++ b/lib/puppet/parser/functions/validate_absolute_path.rb
@@ -27,7 +27,7 @@ module Puppet::Parser::Functions
ENDHEREDOC
# The deprecation function was being called twice, as validate_absolute_path calls is_absolute_path. I have removed it from here so it only calls deprecation once within is_absolute_path.
- # function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Absolute_path. There is further documentation for validate_legacy function in the README.'])
+ # function_deprecation([:validate_absolute_path, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Absolute_path. There is further documentation for validate_legacy function in the README.'])
require 'puppet/util'
diff --git a/lib/puppet/parser/functions/validate_array.rb b/lib/puppet/parser/functions/validate_array.rb
index 97bd41d..3bf3983 100644
--- a/lib/puppet/parser/functions/validate_array.rb
+++ b/lib/puppet/parser/functions/validate_array.rb
@@ -18,7 +18,7 @@ module Puppet::Parser::Functions
ENDHEREDOC
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Array. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:validate_array, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Array. There is further documentation for validate_legacy function in the README.'])
unless args.length > 0 then
raise Puppet::ParseError, ("validate_array(): wrong number of arguments (#{args.length}; must be > 0)")
diff --git a/lib/puppet/parser/functions/validate_bool.rb b/lib/puppet/parser/functions/validate_bool.rb
index e4345eb..49075b8 100644
--- a/lib/puppet/parser/functions/validate_bool.rb
+++ b/lib/puppet/parser/functions/validate_bool.rb
@@ -20,7 +20,7 @@ module Puppet::Parser::Functions
ENDHEREDOC
# The deprecation function was being called twice, as validate_bool calls is_bool. I have removed it from here so it only calls deprecation once within is_bool.
- # function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Bool. There is further documentation for validate_legacy function in the README.'])
+ # function_deprecation([:validate_bool, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Bool. There is further documentation for validate_legacy function in the README.'])
unless args.length > 0 then
raise Puppet::ParseError, ("validate_bool(): wrong number of arguments (#{args.length}; must be > 0)")
diff --git a/lib/puppet/parser/functions/validate_hash.rb b/lib/puppet/parser/functions/validate_hash.rb
index 800a758..fcdc7e1 100644
--- a/lib/puppet/parser/functions/validate_hash.rb
+++ b/lib/puppet/parser/functions/validate_hash.rb
@@ -18,7 +18,7 @@ module Puppet::Parser::Functions
ENDHEREDOC
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Hash. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:validate_hash, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Hash. There is further documentation for validate_legacy function in the README.'])
unless args.length > 0 then
raise Puppet::ParseError, ("validate_hash(): wrong number of arguments (#{args.length}; must be > 0)")
diff --git a/lib/puppet/parser/functions/validate_integer.rb b/lib/puppet/parser/functions/validate_integer.rb
index f52e053..2ae0293 100644
--- a/lib/puppet/parser/functions/validate_integer.rb
+++ b/lib/puppet/parser/functions/validate_integer.rb
@@ -2,7 +2,7 @@ module Puppet::Parser::Functions
newfunction(:validate_integer, :doc => <<-'ENDHEREDOC') do |args|
Validate that the first argument is an integer (or an array of integers). Abort catalog compilation if any of the checks fail.
-
+
The second argument is optional and passes a maximum. (All elements of) the first argument has to be less or equal to this max.
The third argument is optional and passes a minimum. (All elements of) the first argument has to be greater or equal to this min.
@@ -53,7 +53,7 @@ module Puppet::Parser::Functions
ENDHEREDOC
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Integer. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:validate_integer, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Integer. There is further documentation for validate_legacy function in the README.'])
# tell the user we need at least one, and optionally up to two other parameters
raise Puppet::ParseError, "validate_integer(): Wrong number of arguments; must be 1, 2 or 3, got #{args.length}" unless args.length > 0 and args.length < 4
diff --git a/lib/puppet/parser/functions/validate_ip_address.rb b/lib/puppet/parser/functions/validate_ip_address.rb
index 3377c76..5d80cfb 100644
--- a/lib/puppet/parser/functions/validate_ip_address.rb
+++ b/lib/puppet/parser/functions/validate_ip_address.rb
@@ -8,12 +8,12 @@ module Puppet::Parser::Functions
$my_ip = "1.2.3.4"
validate_ip_address($my_ip)
validate_ip_address("8.8.8.8", "172.16.0.1", $my_ip)
-
+
$my_ip = "3ffe:505:2"
validate_ip_address(1)
validate_ip_address($my_ip)
validate_ip_address("fe80::baf6:b1ff:fe19:7507", $my_ip)
-
+
The following values will fail, causing compilation to abort:
$some_array = [ 1, true, false, "garbage string", "3ffe:505:2" ]
validate_ip_address($some_array)
@@ -23,7 +23,7 @@ module Puppet::Parser::Functions
require "ipaddr"
rescuable_exceptions = [ ArgumentError ]
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ip_address. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:validate_ip_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ip_address. There is further documentation for validate_legacy function in the README.'])
if defined?(IPAddr::InvalidAddressError)
rescuable_exceptions << IPAddr::InvalidAddressError
diff --git a/lib/puppet/parser/functions/validate_ipv4_address.rb b/lib/puppet/parser/functions/validate_ipv4_address.rb
index fb2260c..0660abd 100644
--- a/lib/puppet/parser/functions/validate_ipv4_address.rb
+++ b/lib/puppet/parser/functions/validate_ipv4_address.rb
@@ -18,7 +18,7 @@ module Puppet::Parser::Functions
ENDHEREDOC
) do |args|
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv4. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:validate_ipv4_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv4. There is further documentation for validate_legacy function in the README.'])
require "ipaddr"
rescuable_exceptions = [ ArgumentError ]
diff --git a/lib/puppet/parser/functions/validate_ipv6_address.rb b/lib/puppet/parser/functions/validate_ipv6_address.rb
index 4dedcd6..f5dd9e5 100644
--- a/lib/puppet/parser/functions/validate_ipv6_address.rb
+++ b/lib/puppet/parser/functions/validate_ipv6_address.rb
@@ -19,7 +19,7 @@ module Puppet::Parser::Functions
ENDHEREDOC
) do |args|
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv6. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:validate_ipv6_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv6. There is further documentation for validate_legacy function in the README.'])
require "ipaddr"
rescuable_exceptions = [ ArgumentError ]
diff --git a/lib/puppet/parser/functions/validate_numeric.rb b/lib/puppet/parser/functions/validate_numeric.rb
index 6b55f49..4205b30 100644
--- a/lib/puppet/parser/functions/validate_numeric.rb
+++ b/lib/puppet/parser/functions/validate_numeric.rb
@@ -2,7 +2,7 @@ module Puppet::Parser::Functions
newfunction(:validate_numeric, :doc => <<-'ENDHEREDOC') do |args|
Validate that the first argument is a numeric value (or an array of numeric values). Abort catalog compilation if any of the checks fail.
-
+
The second argument is optional and passes a maximum. (All elements of) the first argument has to be less or equal to this max.
The third argument is optional and passes a minimum. (All elements of) the first argument has to be greater or equal to this min.
@@ -15,7 +15,7 @@ module Puppet::Parser::Functions
ENDHEREDOC
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Numeric. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:validate_numeric, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Numeric. There is further documentation for validate_legacy function in the README.'])
# tell the user we need at least one, and optionally up to two other parameters
raise Puppet::ParseError, "validate_numeric(): Wrong number of arguments; must be 1, 2 or 3, got #{args.length}" unless args.length > 0 and args.length < 4
diff --git a/lib/puppet/parser/functions/validate_re.rb b/lib/puppet/parser/functions/validate_re.rb
index 6bdc858..0ac83dd 100644
--- a/lib/puppet/parser/functions/validate_re.rb
+++ b/lib/puppet/parser/functions/validate_re.rb
@@ -30,7 +30,7 @@ module Puppet::Parser::Functions
ENDHEREDOC
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Re. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:validate_re, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Re. There is further documentation for validate_legacy function in the README.'])
if (args.length < 2) or (args.length > 3) then
raise Puppet::ParseError, "validate_re(): wrong number of arguments (#{args.length}; must be 2 or 3)"
diff --git a/lib/puppet/parser/functions/validate_slength.rb b/lib/puppet/parser/functions/validate_slength.rb
index 1828f49..383855c 100644
--- a/lib/puppet/parser/functions/validate_slength.rb
+++ b/lib/puppet/parser/functions/validate_slength.rb
@@ -21,7 +21,7 @@ module Puppet::Parser::Functions
ENDHEREDOC
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with String[]. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:validate_slength, 'This method is deprecated, please use the stdlib validate_legacy function, with String[]. There is further documentation for validate_legacy function in the README.'])
raise Puppet::ParseError, "validate_slength(): Wrong number of arguments (#{args.length}; must be 2 or 3)" unless args.length == 2 or args.length == 3
diff --git a/lib/puppet/parser/functions/validate_string.rb b/lib/puppet/parser/functions/validate_string.rb
index 0057fc1..6675d86 100644
--- a/lib/puppet/parser/functions/validate_string.rb
+++ b/lib/puppet/parser/functions/validate_string.rb
@@ -13,23 +13,24 @@ module Puppet::Parser::Functions
validate_string(true)
validate_string([ 'some', 'array' ])
-
+
Note: validate_string(undef) will not fail in this version of the
functions API (incl. current and future parser). Instead, use:
-
+
if $var == undef {
fail('...')
}
-
+
ENDHEREDOC
- function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.'])
+ function_deprecation([:validate_string, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.'])
unless args.length > 0 then
raise Puppet::ParseError, ("validate_string(): wrong number of arguments (#{args.length}; must be > 0)")
end
args.each do |arg|
+ # when called through the v4 API shim, undef gets translated to nil
unless arg.is_a?(String) || arg.nil?
raise Puppet::ParseError, ("#{arg.inspect} is not a string. It looks to be a #{arg.class}")
end