forked from evolvingweb/puppet-apt
-
Notifications
You must be signed in to change notification settings - Fork 461
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
Apt update tooling #349
Merged
Merged
Apt update tooling #349
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'facter' | ||
|
||
#This is derived from the file /var/lib/apt/periodic/update-success-stamp | ||
# This is generated upon a successful apt-get update run natively in ubuntu. | ||
# the Puppetlabs-apt module deploys this same functionality for other debian-ish OSes | ||
Facter.add('apt_update_last_success') do | ||
confine :osfamily => 'Debian' | ||
setcode do | ||
if File.exists?('/var/lib/apt/periodic/update-success-stamp') | ||
#get epoch time | ||
lastsuccess = File.mtime('/var/lib/apt/periodic/update-success-stamp').to_i | ||
lastsuccess | ||
else | ||
lastsuccess = -1 | ||
lastsuccess | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/usr/bin/env rspec | ||
require 'spec_helper' | ||
|
||
describe 'apt::update', :type => :class do | ||
context 'when apt::always_apt_update is true' do | ||
#This should completely disable all of this logic. These tests are to guarantee that we don't somehow magically change the behavior. | ||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } | ||
let (:pre_condition) { "class{'::apt': always_apt_update => true}" } | ||
it 'should trigger an apt-get update run' do | ||
#set the apt_update exec's refreshonly attribute to false | ||
should contain_exec('apt_update').with({'refreshonly' => false }) | ||
end | ||
['always','daily','weekly','reluctantly'].each do |update_frequency| | ||
context "when apt::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 } } | ||
let (:pre_condition) { "class{'::apt': always_apt_update => true, apt_update_frequency => '#{update_frequency}' }" } | ||
it 'should trigger an apt-get update run' do | ||
# set the apt_update exec's refreshonly attribute to false | ||
should contain_exec('apt_update').with({'refreshonly' => false}) | ||
end | ||
end | ||
context 'when $::apt_update_last_success is nil' do | ||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } | ||
let (:pre_condition) { "class{'::apt': always_apt_update => true, apt_update_frequency => '#{update_frequency}' }" } | ||
it 'should trigger an apt-get update run' do | ||
#set the apt_update exec\'s refreshonly attribute to false | ||
should contain_exec('apt_update').with({'refreshonly' => false}) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
context 'when apt::always_apt_update is false' do | ||
context "and apt::apt_update_frequency has the value of 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 } } | ||
let (:pre_condition) { "class{'::apt': always_apt_update => false, apt_update_frequency => 'always' }" } | ||
it 'should trigger an apt-get update run' do | ||
#set the apt_update exec's refreshonly attribute to false | ||
should 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' } } | ||
let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => 'always' }" } | ||
it 'should trigger an apt-get update run' do | ||
#set the apt_update exec\'s refreshonly attribute to false | ||
should contain_exec('apt_update').with({'refreshonly' => false}) | ||
end | ||
end | ||
end | ||
context "and apt::apt_update_frequency has the value of 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} } | ||
let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => 'reluctantly' }" } | ||
it 'should not trigger an apt-get update run' do | ||
#don't change the apt_update exec's refreshonly attribute. (it should be true) | ||
should contain_exec('apt_update').with({'refreshonly' => true}) | ||
end | ||
end | ||
end | ||
context 'when $::apt_update_last_success is nil' do | ||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } | ||
let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => 'reluctantly' }" } | ||
it 'should not trigger an apt-get update run' do | ||
#don't change the apt_update exec's refreshonly attribute. (it should be true) | ||
should contain_exec('apt_update').with({'refreshonly' => true}) | ||
end | ||
end | ||
end | ||
['daily','weekly'].each do |update_frequency| | ||
context "and apt::apt_update_frequency has the value of #{update_frequency}" do | ||
{ '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 } } | ||
let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => '#{update_frequency}' }" } | ||
it 'should trigger an apt-get update run' do | ||
#set the apt_update exec\'s refreshonly attribute to false | ||
should contain_exec('apt_update').with({'refreshonly' => false}) | ||
end | ||
end | ||
end | ||
context 'when the $::apt_update_last_success fact has a recent value' do | ||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => Time.now.to_i } } | ||
let (:pre_condition) { "class{ '::apt': always_apt_update => false, 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) | ||
should contain_exec('apt_update').with({'refreshonly' => true}) | ||
end | ||
end | ||
context 'when $::apt_update_last_success is nil' do | ||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } | ||
let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => '#{update_frequency}' }" } | ||
it 'should trigger an apt-get update run' do | ||
#set the apt_update exec\'s refreshonly attribute to false | ||
should contain_exec('apt_update').with({'refreshonly' => false}) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your comment above makes it sounds like this is intended to only run on Ubuntu, yet you confine to Debian? Is this right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/puppetlabs/facter/blob/stable/lib/facter/operatingsystem/linux.rb#L28-L29
I'm under the impression that osfamily will resolve to debian under operatingsystem 'Debian','Ubuntu', or 'LinuxMint'. Is that incorrect?
What I meant by that is that the /var/lib/apt/periodic/update-success-stamp is natively provided in Ubuntu. I've added the necessary bits to replicate this functionality in Debian-ish systems that are not Ubuntu, so it works the same there as well. (see /etc/apt/apt.conf.d/15update-stamp in init.pp)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok that explains it. I just got confused by the comment :)