summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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/validate_ip_address.rb2
-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--spec/aliases/ip_address.rb34
-rw-r--r--spec/aliases/ipv4_spec.rb32
-rw-r--r--spec/aliases/ipv6_spec.rb30
-rw-r--r--spec/fixtures/test/manifests/ip_address.pp6
-rw-r--r--spec/fixtures/test/manifests/ipv4.pp6
-rw-r--r--spec/fixtures/test/manifests/ipv6.pp6
-rwxr-xr-xspec/functions/is_ip_address_spec.rb5
-rw-r--r--spec/functions/is_ipv4_address_spec.rb17
-rw-r--r--spec/functions/is_ipv6_address_spec.rb17
-rw-r--r--spec/functions/validate_ip_address_spec.rb4
-rwxr-xr-xspec/functions/validate_ipv4_address_spec.rb5
-rwxr-xr-xspec/functions/validate_ipv6_address_spec.rb4
-rw-r--r--types/compat/ip_address.pp1
-rw-r--r--types/compat/ipv4.pp2
-rw-r--r--types/compat/ipv6.pp1
21 files changed, 182 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/is_ip_address.rb b/lib/puppet/parser/functions/is_ip_address.rb
index a90adab..1901b2c 100644
--- a/lib/puppet/parser/functions/is_ip_address.rb
+++ b/lib/puppet/parser/functions/is_ip_address.rb
@@ -10,6 +10,8 @@ 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.'])
+
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments "+
"given #{arguments.size} for 1")
diff --git a/lib/puppet/parser/functions/is_ipv4_address.rb b/lib/puppet/parser/functions/is_ipv4_address.rb
index b4861d5..c90fa64 100644
--- a/lib/puppet/parser/functions/is_ipv4_address.rb
+++ b/lib/puppet/parser/functions/is_ipv4_address.rb
@@ -10,6 +10,8 @@ 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.'])
+
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_ipv4_address(): Wrong number of arguments "+
"given #{arguments.size} for 1")
diff --git a/lib/puppet/parser/functions/is_ipv6_address.rb b/lib/puppet/parser/functions/is_ipv6_address.rb
index 475ad50..aec3483 100644
--- a/lib/puppet/parser/functions/is_ipv6_address.rb
+++ b/lib/puppet/parser/functions/is_ipv6_address.rb
@@ -8,6 +8,8 @@ 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.'])
+
require 'ipaddr'
if (arguments.size != 1) then
diff --git a/lib/puppet/parser/functions/validate_ip_address.rb b/lib/puppet/parser/functions/validate_ip_address.rb
index 64fbd75..3377c76 100644
--- a/lib/puppet/parser/functions/validate_ip_address.rb
+++ b/lib/puppet/parser/functions/validate_ip_address.rb
@@ -23,6 +23,8 @@ 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.'])
+
if defined?(IPAddr::InvalidAddressError)
rescuable_exceptions << IPAddr::InvalidAddressError
end
diff --git a/lib/puppet/parser/functions/validate_ipv4_address.rb b/lib/puppet/parser/functions/validate_ipv4_address.rb
index 97faa57..fb2260c 100644
--- a/lib/puppet/parser/functions/validate_ipv4_address.rb
+++ b/lib/puppet/parser/functions/validate_ipv4_address.rb
@@ -18,6 +18,8 @@ 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.'])
+
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 b0f2558..4dedcd6 100644
--- a/lib/puppet/parser/functions/validate_ipv6_address.rb
+++ b/lib/puppet/parser/functions/validate_ipv6_address.rb
@@ -19,6 +19,8 @@ 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.'])
+
require "ipaddr"
rescuable_exceptions = [ ArgumentError ]
diff --git a/spec/aliases/ip_address.rb b/spec/aliases/ip_address.rb
new file mode 100644
index 0000000..036bfe5
--- /dev/null
+++ b/spec/aliases/ip_address.rb
@@ -0,0 +1,34 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'test::ip_address', type: :class do
+ describe 'accepts ipv4 and ipv6 addresses' do
+ [
+ '224.0.0.0',
+ '255.255.255.255',
+ '0.0.0.0',
+ '192.88.99.0',
+ '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
+ 'fa76:8765:34ac:0823:ab76:eee9:0987:1111'
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+ describe 'rejects other values' do
+ [
+ 'nope',
+ '77',
+ '4.4.4',
+ '2001:0db8:85a3:000000:0000:8a2e:0370:7334'
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/ipv4_spec.rb b/spec/aliases/ipv4_spec.rb
new file mode 100644
index 0000000..640618c
--- /dev/null
+++ b/spec/aliases/ipv4_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'test::ipv4', type: :class do
+ describe 'accepts ipv4 addresses' do
+ [
+ '224.0.0.0',
+ '255.255.255.255',
+ '0.0.0.0',
+ '192.88.99.0'
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+ describe 'rejects other values' do
+ [
+ 'nope',
+ '77',
+ '4.4.4',
+ '2001:0db8:85a3:0000:0000:8a2e:0370:73342001:0db8:85a3:0000:0000:8a2e:0370:7334'
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::Compat::Ipv4/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/ipv6_spec.rb b/spec/aliases/ipv6_spec.rb
new file mode 100644
index 0000000..688eb16
--- /dev/null
+++ b/spec/aliases/ipv6_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'test::ipv6', type: :class do
+ describe 'accepts ipv6 addresses' do
+ [
+ '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
+ 'fa76:8765:34ac:0823:ab76:eee9:0987:1111'
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+ describe 'rejects other values' do
+ [
+ 'nope',
+ '77',
+ '4.4.4',
+ '2000:7334'
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::Compat::Ipv6/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/fixtures/test/manifests/ip_address.pp b/spec/fixtures/test/manifests/ip_address.pp
new file mode 100644
index 0000000..bbbd804
--- /dev/null
+++ b/spec/fixtures/test/manifests/ip_address.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Compat::Ip_address type alias
+class test::ip_address(
+ Stdlib::Compat::Ip_address $value,
+ ) {
+ notice("Success")
+ }
diff --git a/spec/fixtures/test/manifests/ipv4.pp b/spec/fixtures/test/manifests/ipv4.pp
new file mode 100644
index 0000000..2e8022d
--- /dev/null
+++ b/spec/fixtures/test/manifests/ipv4.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Compat::Ipv4 type alias
+class test::ipv4(
+ Stdlib::Compat::Ipv4 $value,
+ ) {
+ notice("Success")
+ }
diff --git a/spec/fixtures/test/manifests/ipv6.pp b/spec/fixtures/test/manifests/ipv6.pp
new file mode 100644
index 0000000..7912fd6
--- /dev/null
+++ b/spec/fixtures/test/manifests/ipv6.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Compat::Ipv6 type alias
+class test::ipv6(
+ Stdlib::Compat::Ipv6 $value,
+ ) {
+ notice("Success")
+}
diff --git a/spec/functions/is_ip_address_spec.rb b/spec/functions/is_ip_address_spec.rb
index a7a383a..9386ca9 100755
--- a/spec/functions/is_ip_address_spec.rb
+++ b/spec/functions/is_ip_address_spec.rb
@@ -20,4 +20,9 @@ describe 'is_ip_address' do
it { is_expected.to run.with_params(1).and_return(false) }
it { is_expected.to run.with_params({}).and_return(false) }
it { is_expected.to run.with_params([]).and_return(false) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('1.1.1.1')
+ end
end
diff --git a/spec/functions/is_ipv4_address_spec.rb b/spec/functions/is_ipv4_address_spec.rb
new file mode 100644
index 0000000..2b9fc49
--- /dev/null
+++ b/spec/functions/is_ipv4_address_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe 'is_ipv4_address' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ it { is_expected.to run.with_params('1.2.3.4').and_return(true) }
+ it { is_expected.to run.with_params('1.2.3.255').and_return(true) }
+ it { is_expected.to run.with_params('1.2.3').and_return(false) }
+ it { is_expected.to run.with_params('1.2.3.4.5').and_return(false) }
+ it { is_expected.to run.with_params('').and_return(false) }
+ it { is_expected.to run.with_params('one').and_return(false) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('1.1.1.1')
+ end
+end
diff --git a/spec/functions/is_ipv6_address_spec.rb b/spec/functions/is_ipv6_address_spec.rb
new file mode 100644
index 0000000..e3e4734
--- /dev/null
+++ b/spec/functions/is_ipv6_address_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe 'is_ipv6_address' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ it { is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334').and_return(true) }
+ it { is_expected.to run.with_params('85a3:0000:0000:8a2e:0370:7334:100.100.100.100').and_return(true) }
+ it { is_expected.to run.with_params('1.2.3').and_return(false) }
+ it { is_expected.to run.with_params('1.2.3.4.5').and_return(false) }
+ it { is_expected.to run.with_params('').and_return(false) }
+ it { is_expected.to run.with_params('one').and_return(false) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334')
+ end
+end
diff --git a/spec/functions/validate_ip_address_spec.rb b/spec/functions/validate_ip_address_spec.rb
index b56ce51..10f6c37 100644
--- a/spec/functions/validate_ip_address_spec.rb
+++ b/spec/functions/validate_ip_address_spec.rb
@@ -19,6 +19,10 @@ describe 'validate_ip_address' do
it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') }
it { is_expected.to run.with_params('::1/64') }
it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
+ it 'should display a single deprecation' do
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('1.1.1.1')
+ end
context 'with netmasks' do
it { is_expected.to run.with_params('8.8.8.8/0') }
it { is_expected.to run.with_params('8.8.8.8/16') }
diff --git a/spec/functions/validate_ipv4_address_spec.rb b/spec/functions/validate_ipv4_address_spec.rb
index b6170d4..b67bf6f 100755
--- a/spec/functions/validate_ipv4_address_spec.rb
+++ b/spec/functions/validate_ipv4_address_spec.rb
@@ -5,6 +5,11 @@ describe 'validate_ipv4_address' do
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ it 'should display a single deprecation' do
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('1.1.1.1')
+ end
+
describe 'valid inputs' do
it { is_expected.to run.with_params('0.0.0.0') }
it { is_expected.to run.with_params('8.8.8.8') }
diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb
index 7aaf006..3afab56 100755
--- a/spec/functions/validate_ipv6_address_spec.rb
+++ b/spec/functions/validate_ipv6_address_spec.rb
@@ -10,6 +10,10 @@ describe 'validate_ipv6_address' do
it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') }
it { is_expected.to run.with_params('::1/64') }
it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
+ it 'should display a single deprecation' do
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('3ffe:0505:0002::')
+ end
end
describe 'invalid inputs' do
diff --git a/types/compat/ip_address.pp b/types/compat/ip_address.pp
new file mode 100644
index 0000000..bf4c4b4
--- /dev/null
+++ b/types/compat/ip_address.pp
@@ -0,0 +1 @@
+type Stdlib::Compat::Ip_address = Variant[Stdlib::Compat::Ipv4, Stdlib::Compat::Ipv6]
diff --git a/types/compat/ipv4.pp b/types/compat/ipv4.pp
new file mode 100644
index 0000000..1d72ebd
--- /dev/null
+++ b/types/compat/ipv4.pp
@@ -0,0 +1,2 @@
+# Emulate the validate_ipv4_address and is_ipv4_address functions
+type Stdlib::Compat::Ipv4 = Pattern[/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/]
diff --git a/types/compat/ipv6.pp b/types/compat/ipv6.pp
new file mode 100644
index 0000000..18b148d
--- /dev/null
+++ b/types/compat/ipv6.pp
@@ -0,0 +1 @@
+type Stdlib::Compat::Ipv6 = Pattern[/^(?:(?:[\da-f]{1,4}:){7}[\da-f]{1,4}|((?:[\da-f]{1,4}:){6})(\d+)\.(\d+)\.(\d+)\.(\d+))$/]