Skip to content

Commit

Permalink
Deprecation of ip functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Helen Campbell committed Aug 17, 2016
1 parent 1d9d2c0 commit 6d185bd
Show file tree
Hide file tree
Showing 21 changed files with 182 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/puppet/parser/functions/is_ip_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module Puppet::Parser::Functions

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")
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/parser/functions/is_ipv4_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module Puppet::Parser::Functions

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")
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/parser/functions/is_ipv6_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Puppet::Parser::Functions
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
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/parser/functions/validate_ip_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/parser/functions/validate_ipv4_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]

Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/parser/functions/validate_ipv6_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]

Expand Down
34 changes: 34 additions & 0 deletions spec/aliases/ip_address.rb
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions spec/aliases/ipv4_spec.rb
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions spec/aliases/ipv6_spec.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions spec/fixtures/test/manifests/ip_address.pp
Original file line number Diff line number Diff line change
@@ -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")
}
6 changes: 6 additions & 0 deletions spec/fixtures/test/manifests/ipv4.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Class to test the Stdlib::Compat::Ipv4 type alias
class test::ipv4(
Stdlib::Compat::Ipv4 $value,
) {
notice("Success")
}
6 changes: 6 additions & 0 deletions spec/fixtures/test/manifests/ipv6.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Class to test the Stdlib::Compat::Ipv6 type alias
class test::ipv6(
Stdlib::Compat::Ipv6 $value,
) {
notice("Success")
}
5 changes: 5 additions & 0 deletions spec/functions/is_ip_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
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
17 changes: 17 additions & 0 deletions spec/functions/is_ipv4_address_spec.rb
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions spec/functions/is_ipv6_address_spec.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions spec/functions/validate_ip_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
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') }
Expand Down
5 changes: 5 additions & 0 deletions spec/functions/validate_ipv4_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
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') }
Expand Down
4 changes: 4 additions & 0 deletions spec/functions/validate_ipv6_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
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
Expand Down
1 change: 1 addition & 0 deletions types/compat/ip_address.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Stdlib::Compat::Ip_address = Variant[Stdlib::Compat::Ipv4, Stdlib::Compat::Ipv6]
2 changes: 2 additions & 0 deletions types/compat/ipv4.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Emulate the validate_ipv4_address and is_ipv4_address functions
type Stdlib::Compat::Ipv4 = Pattern[/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/]
1 change: 1 addition & 0 deletions types/compat/ipv6.pp
Original file line number Diff line number Diff line change
@@ -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+))$/]

0 comments on commit 6d185bd

Please sign in to comment.