forked from evolvingweb/puppet-apt
-
Notifications
You must be signed in to change notification settings - Fork 460
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 #375 from raphink/dev/facts_perfs
Refactor facts to improve performance.
- Loading branch information
Showing
7 changed files
with
109 additions
and
65 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,9 +1,37 @@ | ||
Facter.add("apt_updates") do | ||
apt_package_updates = nil | ||
Facter.add("apt_has_updates") do | ||
confine :osfamily => 'Debian' | ||
if File.executable?("/usr/lib/update-notifier/apt-check") | ||
apt_package_updates = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check 2>&1').split(';') | ||
end | ||
|
||
setcode do | ||
apt_package_updates != ['0', '0'] unless apt_package_updates.nil? | ||
end | ||
end | ||
|
||
Facter.add("apt_package_updates") do | ||
confine :apt_has_updates => true | ||
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]) | ||
packages = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check -p 2>&1').split("\n") | ||
if Facter.version < '2.0.0' | ||
packages.join(',') | ||
else | ||
packages | ||
end | ||
end | ||
end | ||
|
||
Facter.add("apt_updates") do | ||
confine :apt_has_updates => true | ||
setcode do | ||
Integer(apt_package_updates[0]) | ||
end | ||
end | ||
|
||
Facter.add("apt_security_updates") do | ||
confine :apt_has_updates => true | ||
setcode do | ||
Integer(apt_package_updates[1]) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'spec_helper' | ||
|
||
describe 'apt_has_updates fact' do | ||
subject { Facter.fact(:apt_has_updates).value } | ||
after(:each) { Facter.clear } | ||
|
||
describe 'on non-Debian distro' do | ||
before { | ||
Facter.fact(:osfamily).expects(:value).returns 'RedHat' | ||
} | ||
it { should be_nil } | ||
end | ||
|
||
describe 'on Debian based distro missing update-notifier-common' do | ||
before { | ||
Facter.fact(:osfamily).expects(:value).returns 'Debian' | ||
File.stubs(:executable?) # Stub all other calls | ||
File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns false | ||
} | ||
it { should be_nil } | ||
end | ||
|
||
describe 'on Debian based distro' do | ||
before { | ||
Facter.fact(:osfamily).expects(:value).returns 'Debian' | ||
File.stubs(:executable?) # Stub all other calls | ||
Facter::Util::Resolution.stubs(:exec) # Catch all other calls | ||
File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true | ||
Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "4;3" | ||
} | ||
it { should be true } | ||
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