diff --git a/manifests/pool.pp b/manifests/pool.pp index 46f29024..269b3df4 100644 --- a/manifests/pool.pp +++ b/manifests/pool.pp @@ -3,7 +3,7 @@ String $mask, Optional[String] $gateway = undef, Variant[Array[String], Optional[String]] $pool_parameters = undef, - Variant[Array[String], Optional[String], Boolean] $range = undef, + Variant[Array[Dhcp::Range], Optional[Dhcp::Range], Boolean] $range = undef, Optional[String] $failover = undef, Variant[Array[String], Optional[String]] $options = undef, Variant[Array[String], Optional[String]] $parameters = undef, diff --git a/spec/aliases/range_spec.rb b/spec/aliases/range_spec.rb new file mode 100644 index 00000000..ca18210c --- /dev/null +++ b/spec/aliases/range_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe 'test_module::range', type: :class do + describe 'valid handling' do + [ + '192.0.2.100', + '192.0.2.100 192.0.2.200', + '1.1.1.1 255.255.255.255', + 'dynamic-bootp 192.0.2.100 192.0.2.200', + ].each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile } + end + end + end + + describe 'invalid value handling' do + context 'garbage inputs' do + [ + nil, + "all", + "all all", + "1 192.0.2.183", + "192.0.2.100 1", + ].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 Dhcp::Range/) } + end + end + end + + end +end diff --git a/spec/static_fixtures/test_module/manifests/range.pp b/spec/static_fixtures/test_module/manifests/range.pp new file mode 100644 index 00000000..09edf8df --- /dev/null +++ b/spec/static_fixtures/test_module/manifests/range.pp @@ -0,0 +1,6 @@ +# Class to test the dhcp::Range type +class test_module::range( + Dhcp::Range $value, +) { + notice('Success') +} diff --git a/types/range.pp b/types/range.pp new file mode 100644 index 00000000..fb6611d8 --- /dev/null +++ b/types/range.pp @@ -0,0 +1 @@ +type Dhcp::Range= Pattern[/^(dynamic-bootp )?((([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]){3}([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d)))(\/((([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]){3}([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))|[0-9]+))?( ((([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]){3}([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d)))(\/((([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]){3}([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))|[0-9]+))?)?$/]