Remove update['always'] = true
support
We don't really need both of `update['always'] = true` and `update['frequency'] = 'always'`.
This commit is contained in:
parent
4fa28203b9
commit
df47ca7ff4
5 changed files with 84 additions and 128 deletions
|
@ -14,9 +14,6 @@ class apt(
|
||||||
if $update['frequency'] {
|
if $update['frequency'] {
|
||||||
validate_re($update['frequency'], $frequency_options)
|
validate_re($update['frequency'], $frequency_options)
|
||||||
}
|
}
|
||||||
if $update['always'] {
|
|
||||||
validate_bool($update['always'])
|
|
||||||
}
|
|
||||||
if $update['timeout'] {
|
if $update['timeout'] {
|
||||||
unless is_integer($update['timeout']) {
|
unless is_integer($update['timeout']) {
|
||||||
fail('timeout value for update must be an integer')
|
fail('timeout value for update must be an integer')
|
||||||
|
@ -84,7 +81,7 @@ class apt(
|
||||||
true => absent,
|
true => absent,
|
||||||
}
|
}
|
||||||
|
|
||||||
if $_update['always'] {
|
if $_update['frequency'] == 'always' {
|
||||||
Exec <| title=='apt_update' |> {
|
Exec <| title=='apt_update' |> {
|
||||||
refreshonly => false,
|
refreshonly => false,
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,6 @@ class apt::params {
|
||||||
}
|
}
|
||||||
|
|
||||||
$update_defaults = {
|
$update_defaults = {
|
||||||
'always' => false,
|
|
||||||
'frequency' => 'reluctantly',
|
'frequency' => 'reluctantly',
|
||||||
'timeout' => undef,
|
'timeout' => undef,
|
||||||
'tries' => undef,
|
'tries' => undef,
|
||||||
|
|
|
@ -4,51 +4,45 @@ class apt::update {
|
||||||
#on the first run, but if it's not run in awhile something is likely borked
|
#on the first run, but if it's not run in awhile something is likely borked
|
||||||
#with apt and we'd want to know about it.
|
#with apt and we'd want to know about it.
|
||||||
|
|
||||||
if $::apt::_update['always'] == false {
|
case $::apt::_update['frequency'] {
|
||||||
#if always_apt_update is true there's no point in parsing this logic.
|
'always': {
|
||||||
|
$_kick_apt = true
|
||||||
case $::apt::_update['frequency'] {
|
}
|
||||||
'always': {
|
'daily': {
|
||||||
|
#compare current date with the apt_update_last_success fact to determine
|
||||||
|
#if we should kick apt_update.
|
||||||
|
$daily_threshold = (strftime('%s') - 86400)
|
||||||
|
if $::apt_update_last_success {
|
||||||
|
if $::apt_update_last_success < $daily_threshold {
|
||||||
|
$_kick_apt = true
|
||||||
|
} else {
|
||||||
|
$_kick_apt = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#if apt-get update has not successfully run, we should kick apt_update
|
||||||
$_kick_apt = true
|
$_kick_apt = true
|
||||||
}
|
}
|
||||||
'daily': {
|
}
|
||||||
#compare current date with the apt_update_last_success fact to determine
|
'weekly':{
|
||||||
#if we should kick apt_update.
|
#compare current date with the apt_update_last_success fact to determine
|
||||||
$daily_threshold = (strftime('%s') - 86400)
|
#if we should kick apt_update.
|
||||||
if $::apt_update_last_success {
|
$weekly_threshold = (strftime('%s') - 604800)
|
||||||
if $::apt_update_last_success < $daily_threshold {
|
if $::apt_update_last_success {
|
||||||
$_kick_apt = true
|
if ( $::apt_update_last_success < $weekly_threshold ) {
|
||||||
} else {
|
|
||||||
$_kick_apt = false
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
#if apt-get update has not successfully run, we should kick apt_update
|
|
||||||
$_kick_apt = true
|
$_kick_apt = true
|
||||||
}
|
|
||||||
}
|
|
||||||
'weekly':{
|
|
||||||
#compare current date with the apt_update_last_success fact to determine
|
|
||||||
#if we should kick apt_update.
|
|
||||||
$weekly_threshold = (strftime('%s') - 604800)
|
|
||||||
if $::apt_update_last_success {
|
|
||||||
if ( $::apt_update_last_success < $weekly_threshold ) {
|
|
||||||
$_kick_apt = true
|
|
||||||
} else {
|
|
||||||
$_kick_apt = false
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
#if apt-get update has not successfully run, we should kick apt_update
|
$_kick_apt = false
|
||||||
$_kick_apt = true
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
default: {
|
#if apt-get update has not successfully run, we should kick apt_update
|
||||||
#catches 'recluctantly', and any other value (which should not occur).
|
$_kick_apt = true
|
||||||
#do nothing.
|
|
||||||
$_kick_apt = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
default: {
|
||||||
$_kick_apt = false
|
#catches 'recluctantly', and any other value (which should not occur).
|
||||||
|
#do nothing.
|
||||||
|
$_kick_apt = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if $_kick_apt {
|
if $_kick_apt {
|
||||||
|
|
|
@ -96,7 +96,7 @@ describe 'apt' do
|
||||||
context 'lots of non-defaults' do
|
context 'lots of non-defaults' do
|
||||||
let :params do
|
let :params do
|
||||||
{
|
{
|
||||||
:update => { 'always' => true, 'timeout' => 1, 'tries' => 3 },
|
:update => { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
|
||||||
:purge => { 'sources.list' => false, 'sources.list.d' => false,
|
:purge => { 'sources.list' => false, 'sources.list.d' => false,
|
||||||
'preferences' => false, 'preferences.d' => false, },
|
'preferences' => false, 'preferences.d' => false, },
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,108 +2,74 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe 'apt::update', :type => :class do
|
describe 'apt::update', :type => :class do
|
||||||
context "when update['always']=true" do
|
context "and apt::update['frequency']='always'" do
|
||||||
#This should completely disable all of this logic. These tests are to guarantee that we don't somehow magically change the behavior.
|
{ 'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
|
||||||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
|
context "and $::apt_update_last_success indicates #{desc}" do
|
||||||
let (:pre_condition) { "class{'::apt': update => {'always' => true},}" }
|
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } }
|
||||||
it 'should trigger an apt-get update run' do
|
let (:pre_condition) { "class{'::apt': update => {'frequency' => 'always' },}" }
|
||||||
#set the apt_update exec's refreshonly attribute to false
|
|
||||||
is_expected.to contain_exec('apt_update').with({'refreshonly' => false })
|
|
||||||
end
|
|
||||||
['always','daily','weekly','reluctantly'].each do |update_frequency|
|
|
||||||
context "when apt::update['frequency'] has the value of #{update_frequency}" do
|
|
||||||
{ 'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
|
|
||||||
context "and $::apt_update_last_success indicates #{desc}" do
|
|
||||||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } }
|
|
||||||
let (:pre_condition) { "class{'::apt': update => {'always' => true, 'frequency' => '#{update_frequency}'}, }" }
|
|
||||||
it 'should trigger an apt-get update run' do
|
|
||||||
# set the apt_update exec's refreshonly attribute to false
|
|
||||||
is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
context 'when $::apt_update_last_success is nil' do
|
|
||||||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
|
|
||||||
let (:pre_condition) { "class{'::apt': update => {'always' => true, 'frequency' => '#{update_frequency}'}, }" }
|
|
||||||
it 'should trigger an apt-get update run' do
|
|
||||||
#set the apt_update exec\'s refreshonly attribute to false
|
|
||||||
is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when apt::update['always']=false" do
|
|
||||||
context "and apt::update['frequency']='always'" do
|
|
||||||
{ 'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
|
|
||||||
context "and $::apt_update_last_success indicates #{desc}" do
|
|
||||||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } }
|
|
||||||
let (:pre_condition) { "class{'::apt': update => {'always' => false, 'frequency' => 'always' },}" }
|
|
||||||
it 'should trigger an apt-get update run' do
|
|
||||||
#set the apt_update exec's refreshonly attribute to false
|
|
||||||
is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
context 'when $::apt_update_last_success is nil' do
|
|
||||||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
|
|
||||||
let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => 'always' },}" }
|
|
||||||
it 'should trigger an apt-get update run' do
|
it 'should trigger an apt-get update run' do
|
||||||
#set the apt_update exec\'s refreshonly attribute to false
|
#set the apt_update exec's refreshonly attribute to false
|
||||||
is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
|
is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context "and apt::update['frequency']='reluctantly'" do
|
context 'when $::apt_update_last_success is nil' do
|
||||||
{'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
|
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
|
||||||
context "and $::apt_update_last_success indicates #{desc}" do
|
let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'always' },}" }
|
||||||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy'} }
|
it 'should trigger an apt-get update run' do
|
||||||
let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => 'reluctantly' },}" }
|
#set the apt_update exec\'s refreshonly attribute to false
|
||||||
it 'should not trigger an apt-get update run' do
|
is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
|
||||||
#don't change the apt_update exec's refreshonly attribute. (it should be true)
|
|
||||||
is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
context 'when $::apt_update_last_success is nil' do
|
end
|
||||||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
|
end
|
||||||
let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => 'reluctantly' },}" }
|
context "and apt::update['frequency']='reluctantly'" do
|
||||||
|
{'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
|
||||||
|
context "and $::apt_update_last_success indicates #{desc}" do
|
||||||
|
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy'} }
|
||||||
|
let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
|
||||||
it 'should not trigger an apt-get update run' do
|
it 'should not trigger an apt-get update run' do
|
||||||
#don't change the apt_update exec's refreshonly attribute. (it should be true)
|
#don't change the apt_update exec's refreshonly attribute. (it should be true)
|
||||||
is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
|
is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
['daily','weekly'].each do |update_frequency|
|
context 'when $::apt_update_last_success is nil' do
|
||||||
context "and apt::update['frequency'] has the value of #{update_frequency}" do
|
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
|
||||||
{ 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
|
let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
|
||||||
context "and $::apt_update_last_success indicates #{desc}" do
|
it 'should not trigger an apt-get update run' do
|
||||||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } }
|
#don't change the apt_update exec's refreshonly attribute. (it should be true)
|
||||||
let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => '#{update_frequency}',} }" }
|
is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
|
||||||
it 'should trigger an apt-get update run' do
|
end
|
||||||
#set the apt_update exec\'s refreshonly attribute to false
|
end
|
||||||
is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
|
end
|
||||||
end
|
['daily','weekly'].each do |update_frequency|
|
||||||
end
|
context "and apt::update['frequency'] has the value of #{update_frequency}" do
|
||||||
end
|
{ 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
|
||||||
context 'when the $::apt_update_last_success fact has a recent value' do
|
context "and $::apt_update_last_success indicates #{desc}" do
|
||||||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => Time.now.to_i } }
|
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } }
|
||||||
let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => '#{update_frequency}',} }" }
|
let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
|
||||||
it 'should not trigger an apt-get update run' do
|
|
||||||
#don't change the apt_update exec\'s refreshonly attribute. (it should be true)
|
|
||||||
is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
context 'when $::apt_update_last_success is nil' do
|
|
||||||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => nil } }
|
|
||||||
let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => '#{update_frequency}',} }" }
|
|
||||||
it 'should trigger an apt-get update run' do
|
it 'should trigger an apt-get update run' do
|
||||||
#set the apt_update exec\'s refreshonly attribute to false
|
#set the apt_update exec\'s refreshonly attribute to false
|
||||||
is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
|
is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
context 'when the $::apt_update_last_success fact has a recent value' do
|
||||||
|
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => Time.now.to_i } }
|
||||||
|
let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
|
||||||
|
it 'should not trigger an apt-get update run' do
|
||||||
|
#don't change the apt_update exec\'s refreshonly attribute. (it should be true)
|
||||||
|
is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
context 'when $::apt_update_last_success is nil' do
|
||||||
|
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => nil } }
|
||||||
|
let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
|
||||||
|
it 'should trigger an apt-get update run' do
|
||||||
|
#set the apt_update exec\'s refreshonly attribute to false
|
||||||
|
is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue