Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for RandomSleep to 10periodic #374

Merged
merged 1 commit into from
Oct 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions manifests/unattended_upgrades.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
$remove_unused = true,
$auto_reboot = false,
$dl_limit = 'NONE',
$randomsleep = undef,
$enable = '1',
$backup_interval = '0',
$backup_level = '3',
Expand All @@ -48,6 +49,12 @@
)
validate_array($origins)

if $randomsleep {
unless is_numeric($randomsleep) {
fail('randomsleep must be numeric')
}
}

package { 'unattended-upgrades':
ensure => present,
}
Expand Down
11 changes: 11 additions & 0 deletions spec/classes/unattended_upgrades_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -157,6 +166,7 @@
'remove_unused' => false,
'auto_reboot' => true,
'dl_limit' => '70',
'randomsleep' => '1799',
}
end

Expand All @@ -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
3 changes: 3 additions & 0 deletions templates/10periodic.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>