Skip to content

Commit

Permalink
Merge 0129bf1 into caff5e8
Browse files Browse the repository at this point in the history
  • Loading branch information
traylenator committed Dec 2, 2018
2 parents caff5e8 + 0129bf1 commit 309ded7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
fixtures:
repositories:
stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib.git'
yumrepo_core:
repo: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git
puppet_version: ">= 6.0.0"
augeas_core:
repo: https://github.com/puppetlabs/puppetlabs-augeas_core.git
puppet_version: ">= 6.0.0"
15 changes: 15 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$http_proxy = $fetchcrl::http_proxy,
$httptimeout = $fetchcrl::httptimeout,
$parallelism = $fetchcrl::parallelism,
$randomcron = $fetchcrl::randomcron,
$logmode = $fetchcrl::logmode,
$pkgname = $fetchcrl::pkgname,
$cache_control_request = $fetchcrl::cache_control_request,
Expand Down Expand Up @@ -46,4 +47,18 @@
recurse => true,
}

# Set 6 hour interval cron to have a random offset.
if $randomcron {
$_hour = "${fqdn_rand(6,'fetchcrl')}-23/6"
$_minute = fqdn_rand(60,'fetchcrl')
augeas{'randomise_cron':
incl => '/etc/cron.d/fetch-crl',
lens => 'Cron.lns',
context => '/files/etc/cron.d/fetch-crl/entry/time',
changes => [
"set minute ${_minute}",
"set hour ${_hour}",
],
}
}
}
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
# @param runcron
# Should fetch-crl be run as a cron job.
#
# @param randomcron
# Should the every 6 hour cron set to have a random offset.
#
# @param cache_control_request
# sends a cache-control max-age hint in seconds towards the server in the HTTP request.
#
Expand All @@ -72,6 +75,7 @@
Boolean $nosymlinks = true,
Boolean $nowarnings = true,
Boolean $noerrors = false,
Boolean $randomcron = true,
Optional[Stdlib::Httpurl] $http_proxy = undef,
Integer $httptimeout = 30,
Integer $parallelism = 4,
Expand Down
25 changes: 14 additions & 11 deletions spec/acceptance/fetchcrl_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
require 'spec_helper_acceptance'

describe 'fetchcrl' do
it 'configures and work with no errors' do
pp = <<-EOS
class{'fetchcrl':
}
EOS
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
# We accept 1 as a return code also since there will be some failing CAs
# out there in the wild.
shell('fetch-crl', acceptable_exit_codes: [0, 1])
shell('ls /etc/grid-security/certificates/*.r0', acceptable_exit_codes: 0)
context 'with fetchcrl' do
let(:pp) { 'class{"fetchcrl": }' }

it 'configures and work with no errors' do
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
# We accept 1 as a return code also since there will be some failing CAs
# out there in the wild.
shell('fetch-crl', acceptable_exit_codes: [0, 1])
shell('ls /etc/grid-security/certificates/*.r0', acceptable_exit_codes: 0)
end
describe file('/etc/cron.d/fetch-crl') do
its(:content) { is_expected.to match %r{^([0-9]|[1-5][0-9]) [0-5]-23/6 \* \* \*.*$} }
end
end
end
20 changes: 18 additions & 2 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
it { is_expected.to contain_package('fetch-crl') }
it { is_expected.to contain_file('/etc/fetch-crl.conf').without_content(%r{cache_control_request}) }
it { is_expected.to contain_file('/etc/fetch-crl.conf').without_content(%r{noerrors}) }
it { is_expected.to contain_augeas('randomise_cron').with_incl('/etc/cron.d/fetch-crl') }
it { is_expected.to contain_augeas('randomise_cron').with_changes([%r{set minute ([0-9]|[1-5][0-9])}, %r{set hour [0-5]-23/6}]) }
end
context 'with all parameters set' do
let(:params) do
Expand All @@ -27,14 +29,28 @@
it { is_expected.to contain_package('abc').with_ensure('present') }
it { is_expected.to contain_package('def').with_ensure('present') }
end
context 'with noerrors parameters set' do
context 'with boolean params parameters set true' do
let(:params) do
{
noerrors: true
noerrors: true,
randomcron: true
}
end

it { is_expected.to contain_file('/etc/fetch-crl.conf').with_content(%r{^noerrors$}) }
it { is_expected.to contain_augeas('randomise_cron').with_incl('/etc/cron.d/fetch-crl') }
it { is_expected.to contain_augeas('randomise_cron').with_changes([%r{set minute ([0-9]|[1-5][0-9])}, %r{set hour [0-5]-23/6}]) }
end
context 'with boolean params parameters set false' do
let(:params) do
{
noerrors: false,
randomcron: false
}
end

it { is_expected.to contain_file('/etc/fetch-crl.conf').without_content(%r{^noerrors$}) }
it { is_expected.not_to contain_augeas('randomise_cron') }
end
end
end
Expand Down

0 comments on commit 309ded7

Please sign in to comment.