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 facts showing available updates #319

Merged
merged 1 commit into from
Jun 27, 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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ If you would like to configure your system so the source is the Puppet Labs APT
key_server => 'pgp.mit.edu',
}

### Facts

There are a few facts included within the apt module describing the state of the apt system:

* `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. On Facter 2.0 and newer this will be a list type, in earlier versions it is a comma delimitered string.

#### Hiera example
<pre>
Expand Down
13 changes: 13 additions & 0 deletions lib/facter/apt_package_updates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Facter.add("apt_package_updates") do
confine :osfamily => 'Debian'
setcode do
if File.executable?("/usr/lib/update-notifier/apt-check")
packages = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check -p 2>&1')
packages = packages.split("\n")
if Facter.version < '2.0.0'
packages = packages.join(',')
end
packages
end
end
end
9 changes: 9 additions & 0 deletions lib/facter/apt_security_updates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Facter.add("apt_security_updates") do
confine :osfamily => 'Debian'
setcode do
if File.executable?("/usr/lib/update-notifier/apt-check")
updates = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check 2>&1')
Integer(updates.strip.split(';')[1])
end
end
end
9 changes: 9 additions & 0 deletions lib/facter/apt_updates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Facter.add("apt_updates") do
confine :osfamily => 'Debian'
setcode do
if File.executable?("/usr/lib/update-notifier/apt-check")
updates = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check 2>&1')
Integer(updates.strip.split(';')[0])
end
end
end
29 changes: 29 additions & 0 deletions spec/unit/facter/apt_package_updates_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

describe 'apt_package_updates fact' do
subject { Facter.fact(:apt_package_updates).value }
after(:each) { Facter.clear }

describe 'on Debian based distro missing update-notifier-common' do
before {
Facter.fact(:osfamily).stubs(:value).returns 'Debian'
File.stubs(:executable?).returns false
}
it { should == nil }
end

describe 'on Debian based distro' do
before {
Facter.fact(:osfamily).stubs(:value).returns 'Debian'
File.stubs(:executable?).returns true
Facter::Util::Resolution.stubs(:exec).returns "puppet-common\nlinux-generic\nlinux-image-generic"
}
it {
if Facter.version < '2.0.0'
should == 'puppet-common,linux-generic,linux-image-generic'
else
should == ['puppet-common', 'linux-generic', 'linux-image-generic']
end
}
end
end
24 changes: 24 additions & 0 deletions spec/unit/facter/apt_security_updates_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper'

describe 'apt_security_updates fact' do
subject { Facter.fact(:apt_security_updates).value }
after(:each) { Facter.clear }

describe 'on Debian based distro missing update-notifier-common' do
before {
Facter.fact(:osfamily).stubs(:value).returns 'Debian'
File.stubs(:executable?).returns false
}
it { should == nil }
end

describe 'on Debian based distro' do
before {
Facter.fact(:osfamily).stubs(:value).returns 'Debian'
File.stubs(:executable?).returns true
Facter::Util::Resolution.stubs(:exec).returns '14;7'
}
it { should == 7 }
end

end
24 changes: 24 additions & 0 deletions spec/unit/facter/apt_updates_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper'

describe 'apt_updates fact' do
subject { Facter.fact(:apt_updates).value }
after(:each) { Facter.clear }

describe 'on Debian based distro missing update-notifier-common' do
before {
Facter.fact(:osfamily).stubs(:value).returns 'Debian'
File.stubs(:executable?).returns false
}
it { should == nil }
end

describe 'on Debian based distro' do
before {
Facter.fact(:osfamily).stubs(:value).returns 'Debian'
File.stubs(:executable?).returns true
Facter::Util::Resolution.stubs(:exec).returns '14;7'
}
it { should == 14 }
end

end