Merge pull request #374 from bschlief/random_sleep
authorDaniele Sluijters <daenney@users.noreply.github.com>
Tue, 14 Oct 2014 07:12:18 +0000 (09:12 +0200)
committerDaniele Sluijters <daenney@users.noreply.github.com>
Tue, 14 Oct 2014 07:12:18 +0000 (09:12 +0200)
Add support for RandomSleep to 10periodic

README.md
manifests/unattended_upgrades.pp
spec/classes/unattended_upgrades_spec.rb
templates/10periodic.erb

index d07c7a2fbc974f1906deb7b3f0cae8a665309293..99481a374436951b4c9008a6a57d8ee5bd818f5d 100644 (file)
--- a/README.md
+++ b/README.md
@@ -283,6 +283,7 @@ apt::sources:
 * `download`: How often, in days, to run `apt-get upgrade --download-only`.
 * `upgrade`: How often, in days, to upgrade packages included in the origins list.
 * `autoclean`: How often, in days, to run `apt-get autoclean`.
+* `randomsleep`: How long, in seconds, to randomly wait before applying upgrades.
 
 ### Testing
 
index 2f75d5dd19aef4eba17a96bfbf80cd6ba3b163a1..069c3593dd627ebd6207f595e5633540b248f021 100644 (file)
@@ -28,6 +28,7 @@ class apt::unattended_upgrades (
   $remove_unused       = true,
   $auto_reboot         = false,
   $dl_limit            = 'NONE',
+  $randomsleep         = undef,
   $enable              = '1',
   $backup_interval     = '0',
   $backup_level        = '3',
@@ -48,6 +49,12 @@ class apt::unattended_upgrades (
   )
   validate_array($origins)
 
+  if $randomsleep {
+    unless is_numeric($randomsleep) {
+      fail('randomsleep must be numeric')
+    }
+  }
+
   package { 'unattended-upgrades':
     ensure => present,
   }
index 291719b0098b66e986bfeb4cfee5b61cc6ff47bd..57df21cbdfa3a2750ab38d167cf20393fd919d08 100644 (file)
@@ -94,6 +94,14 @@ describe 'apt::unattended_upgrades', :type => :class do
       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 @@ describe 'apt::unattended_upgrades', :type => :class do
     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 @@ describe 'apt::unattended_upgrades', :type => :class do
         'remove_unused'       => false,
         'auto_reboot'         => true,
         'dl_limit'            => '70',
+        'randomsleep'         => '1799',
       }
     end
 
@@ -183,6 +193,7 @@ describe 'apt::unattended_upgrades', :type => :class do
     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
index 5737c9ac29fc8b25405a7e618ce150532e8d453e..43caed9ea149841dbdbe8fd1cee051b770966dab 100644 (file)
@@ -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 -%>