Skip to content

Commit 0acff93

Browse files
authored
Merge pull request #637 from HelenCampbell/ipdeprecation
(MODULES-3534) Deprecation of ip functions
2 parents 88e9045 + 6d185bd commit 0acff93

21 files changed

+182
-0
lines changed

lib/puppet/parser/functions/is_ip_address.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module Puppet::Parser::Functions
1010

1111
require 'ipaddr'
1212

13+
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.'])
14+
1315
if (arguments.size != 1) then
1416
raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments "+
1517
"given #{arguments.size} for 1")

lib/puppet/parser/functions/is_ipv4_address.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module Puppet::Parser::Functions
1010

1111
require 'ipaddr'
1212

13+
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.'])
14+
1315
if (arguments.size != 1) then
1416
raise(Puppet::ParseError, "is_ipv4_address(): Wrong number of arguments "+
1517
"given #{arguments.size} for 1")

lib/puppet/parser/functions/is_ipv6_address.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module Puppet::Parser::Functions
88
EOS
99
) do |arguments|
1010

11+
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.'])
12+
1113
require 'ipaddr'
1214

1315
if (arguments.size != 1) then

lib/puppet/parser/functions/validate_ip_address.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ module Puppet::Parser::Functions
2323
require "ipaddr"
2424
rescuable_exceptions = [ ArgumentError ]
2525

26+
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.'])
27+
2628
if defined?(IPAddr::InvalidAddressError)
2729
rescuable_exceptions << IPAddr::InvalidAddressError
2830
end

lib/puppet/parser/functions/validate_ipv4_address.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ module Puppet::Parser::Functions
1818
ENDHEREDOC
1919
) do |args|
2020

21+
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.'])
22+
2123
require "ipaddr"
2224
rescuable_exceptions = [ ArgumentError ]
2325

lib/puppet/parser/functions/validate_ipv6_address.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module Puppet::Parser::Functions
1919
ENDHEREDOC
2020
) do |args|
2121

22+
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.'])
23+
2224
require "ipaddr"
2325
rescuable_exceptions = [ ArgumentError ]
2426

spec/aliases/ip_address.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'spec_helper'
2+
3+
if Puppet.version.to_f >= 4.0
4+
describe 'test::ip_address', type: :class do
5+
describe 'accepts ipv4 and ipv6 addresses' do
6+
[
7+
'224.0.0.0',
8+
'255.255.255.255',
9+
'0.0.0.0',
10+
'192.88.99.0',
11+
'2001:0db8:85a3:0000:0000:8a2e:0370:7334',
12+
'fa76:8765:34ac:0823:ab76:eee9:0987:1111'
13+
].each do |value|
14+
describe value.inspect do
15+
let(:params) {{ value: value }}
16+
it { is_expected.to compile }
17+
end
18+
end
19+
end
20+
describe 'rejects other values' do
21+
[
22+
'nope',
23+
'77',
24+
'4.4.4',
25+
'2001:0db8:85a3:000000:0000:8a2e:0370:7334'
26+
].each do |value|
27+
describe value.inspect do
28+
let(:params) {{ value: value }}
29+
it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for/) }
30+
end
31+
end
32+
end
33+
end
34+
end

spec/aliases/ipv4_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'spec_helper'
2+
3+
if Puppet.version.to_f >= 4.0
4+
describe 'test::ipv4', type: :class do
5+
describe 'accepts ipv4 addresses' do
6+
[
7+
'224.0.0.0',
8+
'255.255.255.255',
9+
'0.0.0.0',
10+
'192.88.99.0'
11+
].each do |value|
12+
describe value.inspect do
13+
let(:params) {{ value: value }}
14+
it { is_expected.to compile }
15+
end
16+
end
17+
end
18+
describe 'rejects other values' do
19+
[
20+
'nope',
21+
'77',
22+
'4.4.4',
23+
'2001:0db8:85a3:0000:0000:8a2e:0370:73342001:0db8:85a3:0000:0000:8a2e:0370:7334'
24+
].each do |value|
25+
describe value.inspect do
26+
let(:params) {{ value: value }}
27+
it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::Compat::Ipv4/) }
28+
end
29+
end
30+
end
31+
end
32+
end

spec/aliases/ipv6_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'spec_helper'
2+
3+
if Puppet.version.to_f >= 4.0
4+
describe 'test::ipv6', type: :class do
5+
describe 'accepts ipv6 addresses' do
6+
[
7+
'2001:0db8:85a3:0000:0000:8a2e:0370:7334',
8+
'fa76:8765:34ac:0823:ab76:eee9:0987:1111'
9+
].each do |value|
10+
describe value.inspect do
11+
let(:params) {{ value: value }}
12+
it { is_expected.to compile }
13+
end
14+
end
15+
end
16+
describe 'rejects other values' do
17+
[
18+
'nope',
19+
'77',
20+
'4.4.4',
21+
'2000:7334'
22+
].each do |value|
23+
describe value.inspect do
24+
let(:params) {{ value: value }}
25+
it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::Compat::Ipv6/) }
26+
end
27+
end
28+
end
29+
end
30+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Class to test the Stdlib::Compat::Ip_address type alias
2+
class test::ip_address(
3+
Stdlib::Compat::Ip_address $value,
4+
) {
5+
notice("Success")
6+
}

0 commit comments

Comments
 (0)