forked from evolvingweb/puppet-apt
-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #349 from wolfspyre/apt_update_tooling
Apt update tooling
- Loading branch information
Showing
10 changed files
with
260 additions
and
8 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ The parameters for `apt` are not generally required and are predominantly for de | |
|
||
class { 'apt': | ||
always_apt_update => false, | ||
apt_update_frequency => undef, | ||
disable_keys => undef, | ||
proxy_host => false, | ||
proxy_port => '8080', | ||
|
@@ -153,9 +154,9 @@ Moreover, when Puppet is told to hold a package, it holds it at the current vers | |
|
||
At first glance, it seems this issue could also be solved by passing the version required to the ensure attribute---but that only means that Puppet will install that | ||
version after it processes the package. It does not inform apt that we want | ||
this package to be held; that is, should another package want to upgrade this one (because of a version requirement in a dependency, for example), we want apt to refuse. | ||
this package to be held; that is, should another package want to upgrade this one (because of a version requirement in a dependency, for example), we want apt to refuse. | ||
|
||
To solve this issue, use apt::hold. Implement this by creating a preferences file with a priority of 1001. Under normal circumstances, this preference will always win. Because the priority is > 1000, apt will maintain the required version, downgrading the current package if necessary. | ||
To solve this issue, use apt::hold. Implement this by creating a preferences file with a priority of 1001. Under normal circumstances, this preference will always win. Because the priority is > 1000, apt will maintain the required version, downgrading the current package if necessary. | ||
|
||
With this, you can now set a package's ensure attribute to 'latest' but get the version specified by apt::hold: | ||
|
||
|
@@ -211,7 +212,7 @@ If you would like to configure your system so the source is the Puppet Labs APT | |
|
||
### apt::update | ||
|
||
Runs `apt-get update`, updating the list of available packages and their versions without installing or upgrading any packages. | ||
Runs `apt-get update`, updating the list of available packages and their versions without installing or upgrading any packages. | ||
|
||
The update runs on the first Puppet run after you include the class, then whenever `notify => Exec['apt_update']` occurs---this should happen when config files get updated or other relevant changes occur. If you set the `always_apt_update` parameter, the update will run on every Puppet run. | ||
|
||
|
@@ -222,6 +223,7 @@ There are a few facts included in the apt module describing the state of the apt | |
* `apt_updates` --- the number of updates available on the system | ||
* `apt_security_updates` --- the number of updates which are security updates | ||
* `apt_package_updates` --- the package names that are available for update. In Facter 2.0 and later, this will be a list type; in earlier versions, it is a comma-delimited string. | ||
* `apt_update_last_success` --- The date in epochtime that `apt-get update` last ran successfully. This is determined by reading the mtime of the file `/var/lib/apt/periodic/update-success-stamp`. That file is generated by the `/etc/apt/apt.conf.d/15update-stamp` file. | ||
|
||
#### Hiera example | ||
<pre> | ||
|
@@ -332,3 +334,4 @@ A lot of great people have contributed to this module. A somewhat current list f | |
* Zach Leslie <[email protected]> | ||
* Daniele Sluijters <[email protected]> | ||
* Daniel Paulus <[email protected]> | ||
* Wolf Noble <[email protected]> |
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.