diff --git a/.pdkignore b/.pdkignore index 584438f..862847a 100644 --- a/.pdkignore +++ b/.pdkignore @@ -29,6 +29,7 @@ /.fixtures.yml /Gemfile /.gitattributes +/.github/ /.gitignore /.pdkignore /.puppet-lint.rc diff --git a/Gemfile b/Gemfile index add1873..ca0e773 100644 --- a/Gemfile +++ b/Gemfile @@ -34,12 +34,17 @@ group :development do gem "rubocop", '= 1.48.1', require: false gem "rubocop-performance", '= 1.16.0', require: false gem "rubocop-rspec", '= 2.19.0', require: false + gem "puppet-strings", '~> 4.0', require: false gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] end group :system_tests do gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] gem "serverspec", '~> 2.41', require: false end +group :release_prep do + gem "puppet-strings", '~> 4.0', require: false + gem "puppetlabs_spec_helper", '~> 6.0', require: false +end puppet_version = ENV['PUPPET_GEM_VERSION'] facter_version = ENV['FACTER_GEM_VERSION'] diff --git a/manifests/cron.pp b/manifests/cron.pp index 4bf7f91..6f1a1f4 100644 --- a/manifests/cron.pp +++ b/manifests/cron.pp @@ -51,17 +51,17 @@ # define types::cron ( String[1] $command, - Enum['present', 'absent'] $ensure = 'present', - Optional[String[1]] $environment = undef, - Optional[String[1]] $hour = undef, - Optional[String[1]] $minute = undef, - Optional[String[1]] $month = undef, - Optional[String[1]] $monthday = undef, - Optional[String[1]] $provider = undef, - Optional[String[1]] $special = undef, - Optional[String[1]] $target = undef, - Optional[String[1]] $user = undef, - Optional[String[1]] $weekday = undef, + Enum['present', 'absent'] $ensure = 'present', + Optional[String[1]] $environment = undef, + Optional[Types::Cron::Periodic] $hour = undef, + Optional[Types::Cron::Periodic] $minute = undef, + Optional[Types::Cron::Periodic] $month = undef, + Optional[Types::Cron::Periodic] $monthday = undef, + Optional[Types::Cron::Periodic] $weekday = undef, + Optional[Types::Cron::Periodic] $special = undef, + Optional[String[1]] $provider = undef, + Optional[String[1]] $target = undef, + Optional[String[1]] $user = undef, ) { cron { $name: ensure => $ensure, diff --git a/metadata.json b/metadata.json index 75d1daa..1c1a668 100644 --- a/metadata.json +++ b/metadata.json @@ -68,7 +68,7 @@ } ], "description": "Puppet module to manage default types through hashes in Hiera with the\ncreate_resources() function. This module adds validation and helper functions,\nsuch as ensuring directories. Without specifying any hashes, this module will take no action.", - "pdk-version": "3.0.0", - "template-url": "pdk-default#3.0.0", - "template-ref": "tags/3.0.0-0-g056e50d" + "pdk-version": "3.0.1", + "template-url": "pdk-default#3.0.1", + "template-ref": "tags/3.0.1-0-gd13288a" } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 365248c..e887bbd 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -451,6 +451,116 @@ it { is_expected.to contain_types__cron('cronjob-2') } # only needed for 100% resource coverage end + context 'with cron periodic attributs specified as valid types' do + let(:params) do + { + crons: { + 'array_with_integers' => { + 'command' => '/usr/local/bin/array_with_integers.sh', + 'hour' => [6, 9], + 'minute' => [2, 42], + 'month' => [2, 3], + 'monthday' => [3, 6], + 'weekday' => [0, 3], + 'special' => [1, 42], + }, + 'array_with_strings' => { + 'command' => '/usr/local/bin/array_with_strings.sh', + 'hour' => ['6, 9'], + 'minute' => ['*/2', '*/42'], + 'month' => ['*/2'], + 'monthday' => ['3', '6'], + 'weekday' => ['0'], + 'special' => ['1', '42'], + }, + 'strings' => { + 'command' => '/usr/local/bin/strings.sh', + 'hour' => '3', + 'minute' => '*/42', + 'month' => '*/2', + 'monthday' => '3', + 'weekday' => '0', + 'special' => '1', + }, + 'integers' => { + 'command' => '/usr/local/bin/integers.sh', + 'hour' => 3, + 'minute' => 42, + 'month' => 2, + 'monthday' => 3, + 'weekday' => 0, + 'special' => 1, + }, + } + } + end + + it do + is_expected.to contain_cron('array_with_integers').with( + { + 'ensure' => 'present', + 'command' => '/usr/local/bin/array_with_integers.sh', + 'hour' => [6, 9], + 'minute' => [2, 42], + 'month' => [2, 3], + 'monthday' => [3, 6], + 'weekday' => [0, 3], + 'special' => [1, 42], + }, + ) + end + + it do + is_expected.to contain_cron('array_with_strings').with( + { + 'ensure' => 'present', + 'command' => '/usr/local/bin/array_with_strings.sh', + 'hour' => ['6, 9'], + 'minute' => ['*/2', '*/42'], + 'month' => ['*/2'], + 'monthday' => ['3', '6'], + 'weekday' => ['0'], + 'special' => ['1', '42'], + }, + ) + end + + it do + is_expected.to contain_cron('strings').with( + { + 'ensure' => 'present', + 'command' => '/usr/local/bin/strings.sh', + 'hour' => '3', + 'minute' => '*/42', + 'month' => '*/2', + 'monthday' => '3', + 'weekday' => '0', + 'special' => '1', + }, + ) + end + + it do + is_expected.to contain_cron('integers').with( + { + 'ensure' => 'present', + 'command' => '/usr/local/bin/integers.sh', + 'hour' => 3, + 'minute' => 42, + 'month' => 2, + 'monthday' => 3, + 'weekday' => 0, + 'special' => 1, + }, + ) + end + + it { is_expected.to contain_types__cron('array_with_integers') } # only needed for 100% resource coverage + it { is_expected.to contain_types__cron('array_with_strings') } # only needed for 100% resource coverage + it { is_expected.to contain_types__cron('strings') } # only needed for 100% resource coverage + it { is_expected.to contain_types__cron('integers') } # only needed for 100% resource coverage + end + context 'with cron specified as an invalid type' do let(:params) { { crons: ['not', 'a', 'hash'] } } diff --git a/spec/default_facts.yml b/spec/default_facts.yml index f777abf..3346c39 100644 --- a/spec/default_facts.yml +++ b/spec/default_facts.yml @@ -2,7 +2,8 @@ # # Facts specified here will override the values provided by rspec-puppet-facts. --- -ipaddress: "172.16.254.254" -ipaddress6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" +networking: + ip: "172.16.254.254" + ip6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" + mac: "AA:AA:AA:AA:AA:AA" is_pe: false -macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/defines/cron_spec.rb b/spec/defines/cron_spec.rb index 82f9fd6..ed7d4a8 100644 --- a/spec/defines/cron_spec.rb +++ b/spec/defines/cron_spec.rb @@ -55,6 +55,126 @@ end end + context 'with periodic attributs specified as valid array containing integers' do + let(:title) { 'array_with_integers' } + let(:params) do + { + command: '/usr/local/bin/array_with_integers.sh', + hour: [6, 9], + minute: [2, 42], + month: [2, 3], + monthday: [3, 6], + weekday: [0, 3], + special: [1, 42], + } + end + + it do + is_expected.to contain_cron('array_with_integers').with( + { + 'ensure' => 'present', + 'command' => '/usr/local/bin/array_with_integers.sh', + 'hour' => [6, 9], + 'minute' => [2, 42], + 'month' => [2, 3], + 'monthday' => [3, 6], + 'weekday' => [0, 3], + 'special' => [1, 42], + }, + ) + end + end + + context 'with periodic attributs specified as valid array containing strings' do + let(:title) { 'array_with_integers' } + let(:params) do + { + command: '/usr/local/bin/array_with_strings.sh', + hour: ['6, 9'], + minute: ['*/2', '*/42'], + month: ['*/2'], + monthday: ['3', '6'], + weekday: ['0'], + special: ['1', '42'], + } + end + + it do + is_expected.to contain_cron('array_with_integers').with( + { + 'ensure' => 'present', + 'command' => '/usr/local/bin/array_with_strings.sh', + 'hour' => ['6, 9'], + 'minute' => ['*/2', '*/42'], + 'month' => ['*/2'], + 'monthday' => ['3', '6'], + 'weekday' => ['0'], + 'special' => ['1', '42'], + }, + ) + end + end + + context 'with periodic attributs specified as valid strings' do + let(:title) { 'strings' } + let(:params) do + { + command: '/usr/local/bin/strings.sh', + hour: '3', + minute: '*/42', + month: '*/2', + monthday: '3', + weekday: '0', + special: '1', + } + end + + it do + is_expected.to contain_cron('strings').with( + { + 'ensure' => 'present', + 'command' => '/usr/local/bin/strings.sh', + 'hour' => '3', + 'minute' => '*/42', + 'month' => '*/2', + 'monthday' => '3', + 'weekday' => '0', + 'special' => '1', + }, + ) + end + end + + context 'with periodic attributs specified as valid integers' do + let(:title) { 'integers' } + let(:params) do + { + command: '/usr/local/bin/integers.sh', + hour: 3, + minute: 42, + month: 2, + monthday: 3, + weekday: 0, + special: 1, + } + end + + it do + is_expected.to contain_cron('integers').with( + { + 'ensure' => 'present', + 'command' => '/usr/local/bin/integers.sh', + 'hour' => 3, + 'minute' => 42, + 'month' => 2, + 'monthday' => 3, + 'weekday' => 0, + 'special' => 1, + }, + ) + end + end + context 'cron with invalid ensure' do let(:title) { 'invalid' } let(:params) do diff --git a/types/cron/periodic.pp b/types/cron/periodic.pp new file mode 100644 index 0000000..014f3d6 --- /dev/null +++ b/types/cron/periodic.pp @@ -0,0 +1,6 @@ +# Data type for cron periodic values (hour, minute, month, monthday, weekday, or special) +type Types::Cron::Periodic = Variant[ + Array, + Integer, + String[1], +]