Skip to content

Commit f617912

Browse files
Merge pull request #5 from Phil-Friderici/cron-arrays
Use new data type for cron periodic values
2 parents 8e1a73f + e5f6db9 commit f617912

File tree

8 files changed

+260
-17
lines changed

8 files changed

+260
-17
lines changed

.pdkignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
/.fixtures.yml
3030
/Gemfile
3131
/.gitattributes
32+
/.github/
3233
/.gitignore
3334
/.pdkignore
3435
/.puppet-lint.rc

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ group :development do
3434
gem "rubocop", '= 1.48.1', require: false
3535
gem "rubocop-performance", '= 1.16.0', require: false
3636
gem "rubocop-rspec", '= 2.19.0', require: false
37+
gem "puppet-strings", '~> 4.0', require: false
3738
gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw]
3839
end
3940
group :system_tests do
4041
gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw]
4142
gem "serverspec", '~> 2.41', require: false
4243
end
44+
group :release_prep do
45+
gem "puppet-strings", '~> 4.0', require: false
46+
gem "puppetlabs_spec_helper", '~> 6.0', require: false
47+
end
4348

4449
puppet_version = ENV['PUPPET_GEM_VERSION']
4550
facter_version = ENV['FACTER_GEM_VERSION']

manifests/cron.pp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@
5151
#
5252
define types::cron (
5353
String[1] $command,
54-
Enum['present', 'absent'] $ensure = 'present',
55-
Optional[String[1]] $environment = undef,
56-
Optional[String[1]] $hour = undef,
57-
Optional[String[1]] $minute = undef,
58-
Optional[String[1]] $month = undef,
59-
Optional[String[1]] $monthday = undef,
60-
Optional[String[1]] $provider = undef,
61-
Optional[String[1]] $special = undef,
62-
Optional[String[1]] $target = undef,
63-
Optional[String[1]] $user = undef,
64-
Optional[String[1]] $weekday = undef,
54+
Enum['present', 'absent'] $ensure = 'present',
55+
Optional[String[1]] $environment = undef,
56+
Optional[Types::Cron::Periodic] $hour = undef,
57+
Optional[Types::Cron::Periodic] $minute = undef,
58+
Optional[Types::Cron::Periodic] $month = undef,
59+
Optional[Types::Cron::Periodic] $monthday = undef,
60+
Optional[Types::Cron::Periodic] $weekday = undef,
61+
Optional[Types::Cron::Periodic] $special = undef,
62+
Optional[String[1]] $provider = undef,
63+
Optional[String[1]] $target = undef,
64+
Optional[String[1]] $user = undef,
6565
) {
6666
cron { $name:
6767
ensure => $ensure,

metadata.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
}
6969
],
7070
"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.",
71-
"pdk-version": "3.0.0",
72-
"template-url": "pdk-default#3.0.0",
73-
"template-ref": "tags/3.0.0-0-g056e50d"
71+
"pdk-version": "3.0.1",
72+
"template-url": "pdk-default#3.0.1",
73+
"template-ref": "tags/3.0.1-0-gd13288a"
7474
}

spec/classes/init_spec.rb

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,116 @@
451451
it { is_expected.to contain_types__cron('cronjob-2') } # only needed for 100% resource coverage
452452
end
453453

454+
context 'with cron periodic attributs specified as valid types' do
455+
let(:params) do
456+
{
457+
crons: {
458+
'array_with_integers' => {
459+
'command' => '/usr/local/bin/array_with_integers.sh',
460+
'hour' => [6, 9],
461+
'minute' => [2, 42],
462+
'month' => [2, 3],
463+
'monthday' => [3, 6],
464+
'weekday' => [0, 3],
465+
'special' => [1, 42],
466+
},
467+
'array_with_strings' => {
468+
'command' => '/usr/local/bin/array_with_strings.sh',
469+
'hour' => ['6, 9'],
470+
'minute' => ['*/2', '*/42'],
471+
'month' => ['*/2'],
472+
'monthday' => ['3', '6'],
473+
'weekday' => ['0'],
474+
'special' => ['1', '42'],
475+
},
476+
'strings' => {
477+
'command' => '/usr/local/bin/strings.sh',
478+
'hour' => '3',
479+
'minute' => '*/42',
480+
'month' => '*/2',
481+
'monthday' => '3',
482+
'weekday' => '0',
483+
'special' => '1',
484+
},
485+
'integers' => {
486+
'command' => '/usr/local/bin/integers.sh',
487+
'hour' => 3,
488+
'minute' => 42,
489+
'month' => 2,
490+
'monthday' => 3,
491+
'weekday' => 0,
492+
'special' => 1,
493+
},
494+
}
495+
}
496+
end
497+
498+
it do
499+
is_expected.to contain_cron('array_with_integers').with(
500+
{
501+
'ensure' => 'present',
502+
'command' => '/usr/local/bin/array_with_integers.sh',
503+
'hour' => [6, 9],
504+
'minute' => [2, 42],
505+
'month' => [2, 3],
506+
'monthday' => [3, 6],
507+
'weekday' => [0, 3],
508+
'special' => [1, 42],
509+
},
510+
)
511+
end
512+
513+
it do
514+
is_expected.to contain_cron('array_with_strings').with(
515+
{
516+
'ensure' => 'present',
517+
'command' => '/usr/local/bin/array_with_strings.sh',
518+
'hour' => ['6, 9'],
519+
'minute' => ['*/2', '*/42'],
520+
'month' => ['*/2'],
521+
'monthday' => ['3', '6'],
522+
'weekday' => ['0'],
523+
'special' => ['1', '42'],
524+
},
525+
)
526+
end
527+
528+
it do
529+
is_expected.to contain_cron('strings').with(
530+
{
531+
'ensure' => 'present',
532+
'command' => '/usr/local/bin/strings.sh',
533+
'hour' => '3',
534+
'minute' => '*/42',
535+
'month' => '*/2',
536+
'monthday' => '3',
537+
'weekday' => '0',
538+
'special' => '1',
539+
},
540+
)
541+
end
542+
543+
it do
544+
is_expected.to contain_cron('integers').with(
545+
{
546+
'ensure' => 'present',
547+
'command' => '/usr/local/bin/integers.sh',
548+
'hour' => 3,
549+
'minute' => 42,
550+
'month' => 2,
551+
'monthday' => 3,
552+
'weekday' => 0,
553+
'special' => 1,
554+
},
555+
)
556+
end
557+
558+
it { is_expected.to contain_types__cron('array_with_integers') } # only needed for 100% resource coverage
559+
it { is_expected.to contain_types__cron('array_with_strings') } # only needed for 100% resource coverage
560+
it { is_expected.to contain_types__cron('strings') } # only needed for 100% resource coverage
561+
it { is_expected.to contain_types__cron('integers') } # only needed for 100% resource coverage
562+
end
563+
454564
context 'with cron specified as an invalid type' do
455565
let(:params) { { crons: ['not', 'a', 'hash'] } }
456566

spec/default_facts.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#
33
# Facts specified here will override the values provided by rspec-puppet-facts.
44
---
5-
ipaddress: "172.16.254.254"
6-
ipaddress6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA"
5+
networking:
6+
ip: "172.16.254.254"
7+
ip6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA"
8+
mac: "AA:AA:AA:AA:AA:AA"
79
is_pe: false
8-
macaddress: "AA:AA:AA:AA:AA:AA"

spec/defines/cron_spec.rb

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,126 @@
5555
end
5656
end
5757

58+
context 'with periodic attributs specified as valid array containing integers' do
59+
let(:title) { 'array_with_integers' }
60+
let(:params) do
61+
{
62+
command: '/usr/local/bin/array_with_integers.sh',
63+
hour: [6, 9],
64+
minute: [2, 42],
65+
month: [2, 3],
66+
monthday: [3, 6],
67+
weekday: [0, 3],
68+
special: [1, 42],
69+
}
70+
end
71+
72+
it do
73+
is_expected.to contain_cron('array_with_integers').with(
74+
{
75+
'ensure' => 'present',
76+
'command' => '/usr/local/bin/array_with_integers.sh',
77+
'hour' => [6, 9],
78+
'minute' => [2, 42],
79+
'month' => [2, 3],
80+
'monthday' => [3, 6],
81+
'weekday' => [0, 3],
82+
'special' => [1, 42],
83+
},
84+
)
85+
end
86+
end
87+
88+
context 'with periodic attributs specified as valid array containing strings' do
89+
let(:title) { 'array_with_integers' }
90+
let(:params) do
91+
{
92+
command: '/usr/local/bin/array_with_strings.sh',
93+
hour: ['6, 9'],
94+
minute: ['*/2', '*/42'],
95+
month: ['*/2'],
96+
monthday: ['3', '6'],
97+
weekday: ['0'],
98+
special: ['1', '42'],
99+
}
100+
end
101+
102+
it do
103+
is_expected.to contain_cron('array_with_integers').with(
104+
{
105+
'ensure' => 'present',
106+
'command' => '/usr/local/bin/array_with_strings.sh',
107+
'hour' => ['6, 9'],
108+
'minute' => ['*/2', '*/42'],
109+
'month' => ['*/2'],
110+
'monthday' => ['3', '6'],
111+
'weekday' => ['0'],
112+
'special' => ['1', '42'],
113+
},
114+
)
115+
end
116+
end
117+
118+
context 'with periodic attributs specified as valid strings' do
119+
let(:title) { 'strings' }
120+
let(:params) do
121+
{
122+
command: '/usr/local/bin/strings.sh',
123+
hour: '3',
124+
minute: '*/42',
125+
month: '*/2',
126+
monthday: '3',
127+
weekday: '0',
128+
special: '1',
129+
}
130+
end
131+
132+
it do
133+
is_expected.to contain_cron('strings').with(
134+
{
135+
'ensure' => 'present',
136+
'command' => '/usr/local/bin/strings.sh',
137+
'hour' => '3',
138+
'minute' => '*/42',
139+
'month' => '*/2',
140+
'monthday' => '3',
141+
'weekday' => '0',
142+
'special' => '1',
143+
},
144+
)
145+
end
146+
end
147+
148+
context 'with periodic attributs specified as valid integers' do
149+
let(:title) { 'integers' }
150+
let(:params) do
151+
{
152+
command: '/usr/local/bin/integers.sh',
153+
hour: 3,
154+
minute: 42,
155+
month: 2,
156+
monthday: 3,
157+
weekday: 0,
158+
special: 1,
159+
}
160+
end
161+
162+
it do
163+
is_expected.to contain_cron('integers').with(
164+
{
165+
'ensure' => 'present',
166+
'command' => '/usr/local/bin/integers.sh',
167+
'hour' => 3,
168+
'minute' => 42,
169+
'month' => 2,
170+
'monthday' => 3,
171+
'weekday' => 0,
172+
'special' => 1,
173+
},
174+
)
175+
end
176+
end
177+
58178
context 'cron with invalid ensure' do
59179
let(:title) { 'invalid' }
60180
let(:params) do

types/cron/periodic.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Data type for cron periodic values (hour, minute, month, monthday, weekday, or special)
2+
type Types::Cron::Periodic = Variant[
3+
Array,
4+
Integer,
5+
String[1],
6+
]

0 commit comments

Comments
 (0)