From 888afbecad18a65c5b6405e370eae4e6a0c3a94f Mon Sep 17 00:00:00 2001 From: "Bryan M. Schlief" Date: Mon, 13 Oct 2014 11:44:56 -0700 Subject: [PATCH] Add support for RandomSleep to 10periodic --- manifests/unattended_upgrades.pp | 7 +++++++ spec/classes/unattended_upgrades_spec.rb | 11 +++++++++++ templates/10periodic.erb | 3 +++ 3 files changed, 21 insertions(+) diff --git a/manifests/unattended_upgrades.pp b/manifests/unattended_upgrades.pp index 2f75d5dd19..069c3593dd 100644 --- a/manifests/unattended_upgrades.pp +++ b/manifests/unattended_upgrades.pp @@ -28,6 +28,7 @@ $remove_unused = true, $auto_reboot = false, $dl_limit = 'NONE', + $randomsleep = undef, $enable = '1', $backup_interval = '0', $backup_level = '3', @@ -48,6 +49,12 @@ ) validate_array($origins) + if $randomsleep { + unless is_numeric($randomsleep) { + fail('randomsleep must be numeric') + } + } + package { 'unattended-upgrades': ensure => present, } diff --git a/spec/classes/unattended_upgrades_spec.rb b/spec/classes/unattended_upgrades_spec.rb index 291719b009..57df21cbdf 100644 --- a/spec/classes/unattended_upgrades_spec.rb +++ b/spec/classes/unattended_upgrades_spec.rb @@ -94,6 +94,14 @@ it { expect { should raise_error(Puppet::Error) } } end + context 'bad randomsleep' do + let :params do + { + 'randomsleep' => '4ever' + } + end + it { expect { should raise_error(Puppet::Error) } } + end end context 'defaults' do @@ -123,6 +131,7 @@ it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Unattended-Upgrade "1";}} it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::AutocleanInterval "7";}} it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Verbose "0";}} + it { is_expected.to_not contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::RandomSleep}} end context 'anything but defaults' do @@ -157,6 +166,7 @@ 'remove_unused' => false, 'auto_reboot' => true, 'dl_limit' => '70', + 'randomsleep' => '1799', } end @@ -183,6 +193,7 @@ it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Unattended-Upgrade "0";}} it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::AutocleanInterval "0";}} it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Verbose "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::RandomSleep "1799";}} end end diff --git a/templates/10periodic.erb b/templates/10periodic.erb index 5737c9ac29..43caed9ea1 100644 --- a/templates/10periodic.erb +++ b/templates/10periodic.erb @@ -10,3 +10,6 @@ APT::Periodic::Download-Upgradeable-Packages-Debdelta "<%= @download_delta %>"; APT::Periodic::Unattended-Upgrade "<%= @upgrade %>"; APT::Periodic::AutocleanInterval "<%= @autoclean %>"; APT::Periodic::Verbose "<%= @verbose %>"; +<%- unless @randomsleep.nil? -%> +APT::Periodic::RandomSleep "<%= @randomsleep %>"; +<%- end -%>