[Pkg-puppet-devel] [facter] 322/352: (maint) Return nil on uptime command fail
Stig Sandbeck Mathisen
ssm at debian.org
Sun Apr 6 22:21:57 UTC 2014
This is an automated email from the git hooks/post-receive script.
ssm pushed a commit to branch master
in repository facter.
commit e6f453be70b9afd43b127de9ce22bcadd13adf08
Author: Adrien Thebo <git at somethingsinistral.net>
Date: Mon Mar 10 17:20:14 2014 -0700
(maint) Return nil on uptime command fail
---
lib/facter/util/uptime.rb | 6 +++---
spec/unit/util/uptime_spec.rb | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/facter/util/uptime.rb b/lib/facter/util/uptime.rb
index 7f74c2f..4ec592e 100644
--- a/lib/facter/util/uptime.rb
+++ b/lib/facter/util/uptime.rb
@@ -29,15 +29,15 @@ module Facter::Util::Uptime
def self.uptime_sysctl
output = Facter::Core::Execution.exec("#{uptime_sysctl_cmd} 2>/dev/null", :on_fail => nil)
- if not output.empty?
+ if output
compute_uptime(Time.at(output.match(/\d+/)[0].to_i))
end
end
def self.uptime_executable
- output = Facter::Core::Execution.exec("#{uptime_executable_cmd} 2>/dev/null")
+ output = Facter::Core::Execution.exec("#{uptime_executable_cmd} 2>/dev/null", :on_fail => nil)
- if not output.empty?
+ if output
up=0
if output =~ /(\d+) day(?:s|\(s\))?,\s+(\d+):(\d+)/
# Regexp handles Solaris, AIX, HP-UX, and Tru64.
diff --git a/spec/unit/util/uptime_spec.rb b/spec/unit/util/uptime_spec.rb
index 06472a0..a6940ed 100755
--- a/spec/unit/util/uptime_spec.rb
+++ b/spec/unit/util/uptime_spec.rb
@@ -99,14 +99,14 @@ describe Facter::Util::Uptime do
test_cases.each do |uptime, expected|
it "should return #{expected} for #{uptime}" do
- Facter::Core::Execution.stubs(:exec).with('uptime 2>/dev/null').returns(uptime)
+ Facter::Core::Execution.stubs(:exec).with('uptime 2>/dev/null', {:on_fail => nil}).returns(uptime)
Facter.fact(:uptime_seconds).value.should == expected
end
end
describe "nor is 'uptime' command" do
before :each do
- Facter::Util::Uptime.stubs(:uptime_executable_cmd).returns("cat \"#{@nonexistent_file}\"")
+ Facter::Core::Execution.stubs(:exec).with('uptime 2>/dev/null', {:on_fail => nil}).returns(nil)
end
it "should return nil" do
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git
More information about the Pkg-puppet-devel
mailing list