[Pkg-puppet-devel] [facter] 307/352: (FACT-357) Raise errors when command execution fails
Stig Sandbeck Mathisen
ssm at debian.org
Sun Apr 6 22:21:56 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 ab78e3a6ad290feafb285f5c4fc892065b9198cc
Author: Adrien Thebo <git at somethingsinistral.net>
Date: Tue Mar 4 11:12:20 2014 -0800
(FACT-357) Raise errors when command execution fails
The behavior of returning an empty string when a command cannot be run
is surprising and makes it impossible to determine if a command failed
to run or simply had no output. This commit allows users to determine if
an error should be raised on error, or if a default value should be
returned instead. It also updates calling code to respect this new
behavior.
---
lib/facter/core/execution.rb | 18 ++++++++++--
lib/facter/core/execution/base.rb | 28 +++++++++++-------
lib/facter/util/resolution.rb | 8 ++++--
spec/unit/core/execution/base_spec.rb | 31 ++++++++++++++------
spec/unit/core/execution_spec.rb | 2 +-
spec/unit/hardwareisa_spec.rb | 10 +++----
spec/unit/hardwaremodel_spec.rb | 4 +--
spec/unit/hostname_spec.rb | 2 +-
spec/unit/id_spec.rb | 4 +--
spec/unit/kernelrelease_spec.rb | 54 +++++++++++++++++------------------
spec/unit/kernelversion_spec.rb | 26 ++++++++---------
spec/unit/lsbdistcodename_spec.rb | 12 ++++----
spec/unit/lsbdistid_spec.rb | 12 ++++----
spec/unit/lsbdistrelease_spec.rb | 4 +--
spec/unit/lsbrelease_spec.rb | 12 ++++----
spec/unit/processor_spec.rb | 10 +++----
spec/unit/uniqueid_spec.rb | 6 ++--
spec/unit/util/ip_spec.rb | 4 +++
spec/unit/util/resolution_spec.rb | 2 +-
spec/unit/zonename_spec.rb | 2 +-
20 files changed, 146 insertions(+), 105 deletions(-)
diff --git a/lib/facter/core/execution.rb b/lib/facter/core/execution.rb
index 353d0fa..84a8546 100644
--- a/lib/facter/core/execution.rb
+++ b/lib/facter/core/execution.rb
@@ -89,12 +89,24 @@ module Facter
# executing the code.
#
# @param code [String] the program to run
- # @return [String] the output of the program or the empty string on error
+ # @param options [Hash]
+ #
+ # @option options [Object] :on_fail How to behave when the command could
+ # not be run. Specifying :raise will raise an error, anything else will
+ # return that object on failure. Default is :raise.
+ #
+ # @raise [Facter::Core::Execution::ExecutionFailure] If the command does
+ # not exist or could not be executed.
+ #
+ # @return [String] the output of the program, or the value of :on_fail if
+ # command execution failed and :on_fail was specified.
#
# @api public
- def exec(command)
- @@impl.exec(command)
+ def exec(command, options = {})
+ @@impl.exec(command, options)
end
+
+ class ExecutionFailure < StandardError; end
end
end
end
diff --git a/lib/facter/core/execution/base.rb b/lib/facter/core/execution/base.rb
index cdeda13..95a5b93 100644
--- a/lib/facter/core/execution/base.rb
+++ b/lib/facter/core/execution/base.rb
@@ -27,31 +27,39 @@ class Facter::Core::Execution::Base
rv
end
- def exec(code)
+ def exec(command, options = {})
+
+ on_fail = options.fetch(:on_fail, :raise)
## Set LANG to force i18n to C for the duration of this exec; this ensures that any code that parses the
## output of the command can expect it to be in a consistent / predictable format / locale
with_env "LANG" => "C" do
- if expanded_code = expand_command(code)
- # if we can find the binary, we'll run the command with the expanded path to the binary
- code = expanded_code
- else
- return ''
+ expanded_command = expand_command(command)
+
+ if expanded_command.nil?
+ if on_fail == :raise
+ raise Facter::Core::Execution::ExecutionFailure.new, "Could not execute '#{command}': command not found"
+ else
+ return on_fail
+ end
end
out = ''
begin
wait_for_child = true
- out = %x{#{code}}.chomp
+ out = %x{#{expanded_command}}.chomp
wait_for_child = false
rescue => detail
- Facter.warn(detail.message)
- return ''
+ if on_fail == :raise
+ raise Facter::Core::Execution::ExecutionFailure.new, "Failed while executing '#{expanded_command}': #{detail.message}"
+ else
+ return on_fail
+ end
ensure
if wait_for_child
- # We need to ensure that if this code exits early then any spawned
+ # We need to ensure that if this command exits early then any spawned
# children will be reaped. Process execution is frequently
# terminated using Timeout.timeout but since the timeout isn't in
# this scope we can't rescue the raised exception. The best that
diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb
index 336e7c6..4ac25e4 100644
--- a/lib/facter/util/resolution.rb
+++ b/lib/facter/util/resolution.rb
@@ -128,8 +128,12 @@ class Facter::Util::Resolution
def setcode(string = nil, &block)
if string
@code = Proc.new do
- output = Facter::Core::Execution.exec(string)
- output.empty? ? nil : output
+ output = Facter::Core::Execution.exec(string, :on_fail => nil)
+ if output.nil? or output.empty?
+ nil
+ else
+ output
+ end
end
elsif block_given?
@code = block
diff --git a/spec/unit/core/execution/base_spec.rb b/spec/unit/core/execution/base_spec.rb
index 652f392..00fdbd8 100644
--- a/spec/unit/core/execution/base_spec.rb
+++ b/spec/unit/core/execution/base_spec.rb
@@ -77,18 +77,31 @@ describe Facter::Core::Execution::Base do
subject.exec('foo')
end
- it "returns an empty string when the command could not be expanded" do
- subject.expects(:expand_command).with('foo').returns nil
- expect(subject.exec('foo')).to be_empty
+ describe "and the command is not present" do
+ it "raises an error when the :on_fail behavior is :raise" do
+ subject.expects(:expand_command).with('foo').returns nil
+ expect { subject.exec('foo') }.to raise_error(Facter::Core::Execution::ExecutionFailure)
+ end
+
+ it "returns the given value when :on_fail is set to a value" do
+ subject.expects(:expand_command).with('foo').returns nil
+ expect(subject.exec('foo', :on_fail => nil)).to be_nil
+ end
end
- it "logs a warning and returns an empty string when the command execution fails" do
- subject.expects(:`).with("/bin/foo").raises "kaboom!"
- Facter.expects(:warn).with("kaboom!")
+ describe "when command execution fails" do
+ before do
+ subject.expects(:`).with("/bin/foo").raises "kaboom!"
+ subject.expects(:expand_command).with('foo').returns '/bin/foo'
+ end
- subject.expects(:expand_command).with('foo').returns '/bin/foo'
+ it "raises an error when the :on_fail behavior is :raise" do
+ expect { subject.exec('foo') }.to raise_error(Facter::Core::Execution::ExecutionFailure)
+ end
- expect(subject.exec("foo")).to be_empty
+ it "returns the given value when :on_fail is set to a value" do
+ expect(subject.exec('foo', :on_fail => nil)).to be_nil
+ end
end
it "launches a thread to wait on children if the command was interrupted" do
@@ -99,7 +112,7 @@ describe Facter::Core::Execution::Base do
Thread.expects(:new).yields
Process.expects(:waitall).once
- subject.exec("foo")
+ subject.exec("foo", :on_fail => nil)
end
it "returns the output of the command" do
diff --git a/spec/unit/core/execution_spec.rb b/spec/unit/core/execution_spec.rb
index c36358f..201345f 100644
--- a/spec/unit/core/execution_spec.rb
+++ b/spec/unit/core/execution_spec.rb
@@ -31,7 +31,7 @@ describe Facter::Core::Execution do
end
it "delegates #exec to the implementation" do
- impl.expects(:exec).with('waffles')
+ impl.expects(:exec).with('waffles', {})
subject.exec('waffles')
end
end
diff --git a/spec/unit/hardwareisa_spec.rb b/spec/unit/hardwareisa_spec.rb
index 39bb705..8559ae9 100755
--- a/spec/unit/hardwareisa_spec.rb
+++ b/spec/unit/hardwareisa_spec.rb
@@ -6,35 +6,35 @@ require 'facter'
describe "Hardwareisa fact" do
it "should match uname -p on Linux" do
Facter.fact(:kernel).stubs(:value).returns("Linux")
- Facter::Core::Execution.stubs(:exec).with("uname -p").returns("Inky")
+ Facter::Core::Execution.stubs(:exec).with("uname -p", anything).returns("Inky")
Facter.fact(:hardwareisa).value.should == "Inky"
end
it "should match uname -p on Darwin" do
Facter.fact(:kernel).stubs(:value).returns("Darwin")
- Facter::Core::Execution.stubs(:exec).with("uname -p").returns("Blinky")
+ Facter::Core::Execution.stubs(:exec).with("uname -p", anything).returns("Blinky")
Facter.fact(:hardwareisa).value.should == "Blinky"
end
it "should match uname -p on SunOS" do
Facter.fact(:kernel).stubs(:value).returns("SunOS")
- Facter::Core::Execution.stubs(:exec).with("uname -p").returns("Pinky")
+ Facter::Core::Execution.stubs(:exec).with("uname -p", anything).returns("Pinky")
Facter.fact(:hardwareisa).value.should == "Pinky"
end
it "should match uname -p on FreeBSD" do
Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
- Facter::Core::Execution.stubs(:exec).with("uname -p").returns("Clyde")
+ Facter::Core::Execution.stubs(:exec).with("uname -p", anything).returns("Clyde")
Facter.fact(:hardwareisa).value.should == "Clyde"
end
it "should match uname -m on HP-UX" do
Facter.fact(:kernel).stubs(:value).returns("HP-UX")
- Facter::Core::Execution.stubs(:exec).with("uname -m").returns("Pac-Man")
+ Facter::Core::Execution.stubs(:exec).with("uname -m", anything).returns("Pac-Man")
Facter.fact(:hardwareisa).value.should == "Pac-Man"
end
diff --git a/spec/unit/hardwaremodel_spec.rb b/spec/unit/hardwaremodel_spec.rb
index 0a8e9ee..b4c65ec 100644
--- a/spec/unit/hardwaremodel_spec.rb
+++ b/spec/unit/hardwaremodel_spec.rb
@@ -6,7 +6,7 @@ require 'facter'
describe "Hardwaremodel fact" do
it "should match uname -m by default" do
Facter.fact(:kernel).stubs(:value).returns("Darwin")
- Facter::Core::Execution.stubs(:exec).with("uname -m").returns("Inky")
+ Facter::Core::Execution.stubs(:exec).with("uname -m", anything).returns("Inky")
Facter.fact(:hardwaremodel).value.should == "Inky"
end
@@ -23,7 +23,7 @@ describe "Hardwaremodel fact" do
Facter::Util::WMI.expects(:execquery).returns([cpu])
Facter.fact(:hardwaremodel).value.should == "i486"
- end
+ end
it "should detect i686" do
cpu = mock('cpu', :Architecture => 0, :Level => 6)
diff --git a/spec/unit/hostname_spec.rb b/spec/unit/hostname_spec.rb
index a787031..9350c4f 100755
--- a/spec/unit/hostname_spec.rb
+++ b/spec/unit/hostname_spec.rb
@@ -33,7 +33,7 @@ describe "Hostname facts" do
end
it "should use scutil to get the hostname" do
- Facter::Core::Execution.expects(:exec).with('/usr/sbin/scutil --get LocalHostName').returns("host1")
+ Facter::Core::Execution.expects(:exec).with('/usr/sbin/scutil --get LocalHostName', anything).returns("host1")
Facter.fact(:hostname).value.should == "host1"
end
end
diff --git a/spec/unit/id_spec.rb b/spec/unit/id_spec.rb
index b2eff37..f5f4ad4 100755
--- a/spec/unit/id_spec.rb
+++ b/spec/unit/id_spec.rb
@@ -12,7 +12,7 @@ describe "id fact" do
it "should return the current user" do
given_a_configuration_of(:is_windows => k == 'windows')
Facter.fact(:kernel).stubs(:value).returns(k)
- Facter::Core::Execution.expects(:exec).once.with('whoami').returns 'bar'
+ Facter::Core::Execution.expects(:exec).once.with('whoami', anything).returns 'bar'
Facter.fact(:id).value.should == 'bar'
end
@@ -22,7 +22,7 @@ describe "id fact" do
it "should return the current user on Solaris" do
given_a_configuration_of(:is_windows => false)
Facter::Core::Execution.stubs(:exec).with('uname -s').returns('SunOS')
- Facter::Core::Execution.expects(:exec).once.with('/usr/xpg4/bin/id -un').returns 'bar'
+ Facter::Core::Execution.expects(:exec).once.with('/usr/xpg4/bin/id -un', anything).returns 'bar'
Facter.fact(:id).value.should == 'bar'
end
diff --git a/spec/unit/kernelrelease_spec.rb b/spec/unit/kernelrelease_spec.rb
index 94eec12..12c4d05 100644
--- a/spec/unit/kernelrelease_spec.rb
+++ b/spec/unit/kernelrelease_spec.rb
@@ -2,52 +2,52 @@
require 'spec_helper'
-describe "Kernel release fact" do
+describe "Kernel release fact" do
- describe "on Windows" do
- before do
+ describe "on Windows" do
+ before do
Facter.fact(:kernel).stubs(:value).returns("windows")
require 'facter/util/wmi'
version = stubs 'version'
version.stubs(:Version).returns("test_kernel")
Facter::Util::WMI.stubs(:execquery).with("SELECT Version from Win32_OperatingSystem").returns([version])
end
-
- it "should return the kernel release" do
+
+ it "should return the kernel release" do
Facter.fact(:kernelrelease).value.should == "test_kernel"
- end
- end
+ end
+ end
- describe "on AIX" do
- before do
+ describe "on AIX" do
+ before do
Facter.fact(:kernel).stubs(:value).returns("aix")
- Facter::Core::Execution.stubs(:exec).with('oslevel -s').returns("test_kernel")
- end
-
- it "should return the kernel release" do
+ Facter::Core::Execution.stubs(:exec).with('oslevel -s', anything).returns("test_kernel")
+ end
+
+ it "should return the kernel release" do
Facter.fact(:kernelrelease).value.should == "test_kernel"
- end
- end
+ end
+ end
describe "on HP-UX" do
before do
- Facter.fact(:kernel).stubs(:value).returns("hp-ux")
+ Facter.fact(:kernel).stubs(:value).returns("hp-ux")
Facter::Core::Execution.stubs(:exec).with('uname -r').returns("B.11.31")
- end
-
+ end
+
it "should remove preceding letters" do
Facter.fact(:kernelrelease).value.should == "11.31"
- end
- end
+ end
+ end
- describe "on everything else" do
+ describe "on everything else" do
before do
Facter.fact(:kernel).stubs(:value).returns("linux")
- Facter::Core::Execution.stubs(:exec).with('uname -r').returns("test_kernel")
- end
-
+ Facter::Core::Execution.stubs(:exec).with('uname -r', anything).returns("test_kernel")
+ end
+
it "should return the kernel release" do
Facter.fact(:kernelrelease).value.should == "test_kernel"
- end
- end
-end
+ end
+ end
+end
diff --git a/spec/unit/kernelversion_spec.rb b/spec/unit/kernelversion_spec.rb
index 93ee061..6d20665 100644
--- a/spec/unit/kernelversion_spec.rb
+++ b/spec/unit/kernelversion_spec.rb
@@ -3,29 +3,29 @@
require 'spec_helper'
describe "Kernel version fact" do
-
+
describe "on Solaris/Sun OS" do
before do
Facter.fact(:kernel).stubs(:value).returns('sunos')
- Facter::Core::Execution.stubs(:exec).with('uname -v').returns("1.234.5")
- end
-
- it "should return the kernel version using 'uname -v'" do
+ Facter::Core::Execution.stubs(:exec).with('uname -v', anything).returns("1.234.5")
+ end
+
+ it "should return the kernel version using 'uname -v'" do
Facter.fact(:kernelversion).value.should == "1.234.5"
- end
+ end
end
-
+
describe "on everything else" do
- before do
+ before do
Facter.fact(:kernel).stubs(:value).returns('linux')
Facter.fact(:kernelrelease).stubs(:value).returns('1.23.4-56')
- end
-
- it "should return the kernel version using kernel release" do
+ end
+
+ it "should return the kernel version using kernel release" do
Facter.fact(:kernelversion).value.should == "1.23.4"
- end
+ end
end
-end
+end
diff --git a/spec/unit/lsbdistcodename_spec.rb b/spec/unit/lsbdistcodename_spec.rb
index 6516c4c..ab0a4cb 100755
--- a/spec/unit/lsbdistcodename_spec.rb
+++ b/spec/unit/lsbdistcodename_spec.rb
@@ -10,14 +10,14 @@ describe "lsbdistcodename fact" do
Facter.fact(:kernel).stubs(:value).returns kernel
end
- it "should return the codename through lsb_release -c -s 2>/dev/null" do
- Facter::Core::Execution.stubs(:exec).with('lsb_release -c -s 2>/dev/null').returns 'n/a'
- Facter.fact(:lsbdistcodename).value.should == 'n/a'
+ it "returns the codename through lsb_release -c -s 2>/dev/null" do
+ Facter::Core::Execution.impl.stubs(:exec).with('lsb_release -c -s 2>/dev/null', anything).returns 'n/a'
+ expect(Facter.fact(:lsbdistcodename).value).to eq 'n/a'
end
- it "should return nil if lsb_release is not installed" do
- Facter::Core::Execution.stubs(:exec).with('lsb_release -c -s 2>/dev/null').returns nil
- Facter.fact(:lsbdistcodename).value.should be_nil
+ it "returns nil if lsb_release is not installed" do
+ Facter::Core::Execution.impl.stubs(:expand_command).with('lsb_release -c -s 2>/dev/null').returns nil
+ expect(Facter.fact(:lsbdistcodename).value).to be_nil
end
end
end
diff --git a/spec/unit/lsbdistid_spec.rb b/spec/unit/lsbdistid_spec.rb
index bec2fc5..53cc961 100755
--- a/spec/unit/lsbdistid_spec.rb
+++ b/spec/unit/lsbdistid_spec.rb
@@ -10,14 +10,14 @@ describe "lsbdistid fact" do
Facter.fact(:kernel).stubs(:value).returns kernel
end
- it "should return the id through lsb_release -i -s 2>/dev/null" do
- Facter::Core::Execution.stubs(:exec).with('lsb_release -i -s 2>/dev/null').returns 'Gentoo'
- Facter.fact(:lsbdistid).value.should == 'Gentoo'
+ it "returns the id through lsb_release -i -s 2>/dev/null" do
+ Facter::Core::Execution.impl.stubs(:exec).with('lsb_release -i -s 2>/dev/null', anything).returns 'Gentoo'
+ expect(Facter.fact(:lsbdistid).value).to eq 'Gentoo'
end
- it "should return nil if lsb_release is not installed 2>/dev/null" do
- Facter::Core::Execution.stubs(:exec).with('lsb_release -i -s 2>/dev/null').returns nil
- Facter.fact(:lsbdistid).value.should be_nil
+ it "returns nil if lsb_release is not installed" do
+ Facter::Core::Execution.impl.stubs(:expand_command).with('lsb_release -i -s 2>/dev/null').returns nil
+ expect(Facter.fact(:lsbdistid).value).to be_nil
end
end
end
diff --git a/spec/unit/lsbdistrelease_spec.rb b/spec/unit/lsbdistrelease_spec.rb
index 1d9476d..9e8d5d2 100755
--- a/spec/unit/lsbdistrelease_spec.rb
+++ b/spec/unit/lsbdistrelease_spec.rb
@@ -11,12 +11,12 @@ describe "lsbdistrelease fact" do
end
it "should return the release through lsb_release -r -s 2>/dev/null" do
- Facter::Core::Execution.stubs(:exec).with('lsb_release -r -s 2>/dev/null').returns '2.1'
+ Facter::Core::Execution.stubs(:exec).with('lsb_release -r -s 2>/dev/null', anything).returns '2.1'
Facter.fact(:lsbdistrelease).value.should == '2.1'
end
it "should return nil if lsb_release is not installed" do
- Facter::Core::Execution.stubs(:exec).with('lsb_release -r -s 2>/dev/null').returns nil
+ Facter::Core::Execution.stubs(:exec).with('lsb_release -r -s 2>/dev/null', anything).returns nil
Facter.fact(:lsbdistrelease).value.should be_nil
end
end
diff --git a/spec/unit/lsbrelease_spec.rb b/spec/unit/lsbrelease_spec.rb
index 18bf751..eaddedd 100755
--- a/spec/unit/lsbrelease_spec.rb
+++ b/spec/unit/lsbrelease_spec.rb
@@ -10,14 +10,14 @@ describe "lsbrelease fact" do
Facter.fact(:kernel).stubs(:value).returns kernel
end
- it "should return the release through lsb_release -v -s 2>/dev/null" do
- Facter::Core::Execution.stubs(:exec).with('lsb_release -v -s 2>/dev/null').returns 'n/a'
- Facter.fact(:lsbrelease).value.should == 'n/a'
+ it "returns the release through lsb_release -v -s 2>/dev/null" do
+ Facter::Core::Execution.impl.stubs(:exec).with('lsb_release -v -s 2>/dev/null', anything).returns 'n/a'
+ expect(Facter.fact(:lsbrelease).value).to eq 'n/a'
end
- it "should return nil if lsb_release is not installed" do
- Facter::Core::Execution.stubs(:exec).with('lsb_release -v -s 2>/dev/null').returns nil
- Facter.fact(:lsbrelease).value.should be_nil
+ it "returns nil if lsb_release is not installed" do
+ Facter::Core::Execution.impl.stubs(:expand_command).with('lsb_release -v -s 2>/dev/null').returns nil
+ expect(Facter.fact(:lsbrelease).value).to be_nil
end
end
end
diff --git a/spec/unit/processor_spec.rb b/spec/unit/processor_spec.rb
index 717f942..d9d5c67 100755
--- a/spec/unit/processor_spec.rb
+++ b/spec/unit/processor_spec.rb
@@ -185,35 +185,35 @@ describe "Processor facts" do
it "should be 2 on dual-processor Darwin box" do
Facter.fact(:kernel).stubs(:value).returns("Darwin")
- Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu", anything).returns('2')
Facter.fact(:processorcount).value.should == "2"
end
it "should be 2 on dual-processor OpenBSD box" do
Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
- Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu", anything).returns('2')
Facter.fact(:processorcount).value.should == "2"
end
it "should be 2 on dual-processor FreeBSD box" do
Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
- Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu", anything).returns('2')
Facter.fact(:processorcount).value.should == "2"
end
it "should print the correct CPU Model on FreeBSD" do
Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
- Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.model").returns('SomeVendor CPU 3GHz')
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.model", anything).returns('SomeVendor CPU 3GHz')
Facter.fact(:processor).value.should == "SomeVendor CPU 3GHz"
end
it "should be 2 on dual-processor DragonFly box" do
Facter.fact(:kernel).stubs(:value).returns("DragonFly")
- Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu", anything).returns('2')
Facter.fact(:processorcount).value.should == "2"
end
diff --git a/spec/unit/uniqueid_spec.rb b/spec/unit/uniqueid_spec.rb
index 93adb79..261dee3 100755
--- a/spec/unit/uniqueid_spec.rb
+++ b/spec/unit/uniqueid_spec.rb
@@ -6,21 +6,21 @@ require 'facter'
describe "Uniqueid fact" do
it "should match hostid on Solaris" do
Facter.fact(:kernel).stubs(:value).returns("SunOS")
- Facter::Core::Execution.stubs(:exec).with("hostid").returns("Larry")
+ Facter::Core::Execution.stubs(:exec).with("hostid", anything).returns("Larry")
Facter.fact(:uniqueid).value.should == "Larry"
end
it "should match hostid on Linux" do
Facter.fact(:kernel).stubs(:value).returns("Linux")
- Facter::Core::Execution.stubs(:exec).with("hostid").returns("Curly")
+ Facter::Core::Execution.stubs(:exec).with("hostid", anything).returns("Curly")
Facter.fact(:uniqueid).value.should == "Curly"
end
it "should match hostid on AIX" do
Facter.fact(:kernel).stubs(:value).returns("AIX")
- Facter::Core::Execution.stubs(:exec).with("hostid").returns("Moe")
+ Facter::Core::Execution.stubs(:exec).with("hostid", anything).returns("Moe")
Facter.fact(:uniqueid).value.should == "Moe"
end
diff --git a/spec/unit/util/ip_spec.rb b/spec/unit/util/ip_spec.rb
index ace30e0..22922f3 100755
--- a/spec/unit/util/ip_spec.rb
+++ b/spec/unit/util/ip_spec.rb
@@ -401,10 +401,13 @@ describe Facter::Util::IP do
describe "exec_ifconfig" do
it "uses get_ifconfig" do
+ Facter::Core::Execution.stubs(:exec)
+
Facter::Util::IP.stubs(:get_ifconfig).returns("/sbin/ifconfig").once
Facter::Util::IP.exec_ifconfig
end
+
it "support additional arguments" do
Facter::Util::IP.stubs(:get_ifconfig).returns("/sbin/ifconfig")
@@ -412,6 +415,7 @@ describe Facter::Util::IP do
Facter::Util::IP.exec_ifconfig(["-a"])
end
+
it "joins multiple arguments correctly" do
Facter::Util::IP.stubs(:get_ifconfig).returns("/sbin/ifconfig")
diff --git a/spec/unit/util/resolution_spec.rb b/spec/unit/util/resolution_spec.rb
index fbfdaec..3a0b028 100755
--- a/spec/unit/util/resolution_spec.rb
+++ b/spec/unit/util/resolution_spec.rb
@@ -74,7 +74,7 @@ describe Facter::Util::Resolution do
describe "and the code is a string" do
it "returns the result of executing the code" do
resolution.setcode "/bin/foo"
- Facter::Core::Execution.expects(:exec).once.with("/bin/foo").returns "yup"
+ Facter::Core::Execution.expects(:exec).once.with("/bin/foo", anything).returns "yup"
expect(resolution.value).to eq "yup"
end
diff --git a/spec/unit/zonename_spec.rb b/spec/unit/zonename_spec.rb
index 23a2f98..eeb522f 100644
--- a/spec/unit/zonename_spec.rb
+++ b/spec/unit/zonename_spec.rb
@@ -7,7 +7,7 @@ describe "zonename fact" do
it "should return global zone" do
Facter.fact(:kernel).stubs(:value).returns("SunOS")
- Facter::Core::Execution.stubs(:exec).with("zonename").returns('global')
+ Facter::Core::Execution.stubs(:exec).with("zonename", anything).returns('global')
Facter.fact(:zonename).value.should == "global"
end
--
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