diff options
| author | Paul Berry <paul@puppetlabs.com> | 2011-03-07 16:52:19 -0800 |
|---|---|---|
| committer | Paul Berry <paul@puppetlabs.com> | 2011-03-07 16:52:19 -0800 |
| commit | 8dbdcb057115bb2abdca22230d819303ff18ed6d (patch) | |
| tree | 39b3d4fc5ad5443de66e856d5eaf7f6d5ea09efb /lib | |
| parent | 609ddcf2b1ae0c835973a584ac20796d962334f6 (diff) | |
| parent | 23d1c0346a609369b457da876714c6671fcf3d44 (diff) | |
| download | puppet-8dbdcb057115bb2abdca22230d819303ff18ed6d.tar.gz puppet-8dbdcb057115bb2abdca22230d819303ff18ed6d.tar.xz puppet-8dbdcb057115bb2abdca22230d819303ff18ed6d.zip | |
Merge branch 'maint/2.6.next/make_execute_stubbable' into 2.6.next
* maint/2.6.next/make_execute_stubbable:
Maint: Added the ability to replace the behavior of Puppet::Util.execute with an arbitrary code block for ease in spec testing.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/util.rb | 5 | ||||
| -rw-r--r-- | lib/puppet/util/execution_stub.rb | 26 |
2 files changed, 31 insertions, 0 deletions
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index 850d147e2..d06f44808 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -4,6 +4,7 @@ require 'puppet/util/monkey_patches' require 'sync' require 'puppet/external/lock' require 'monitor' +require 'puppet/util/execution_stub' module Puppet # A command failed to execute. @@ -264,6 +265,10 @@ module Util arguments[:uid] = Puppet::Util::SUIDManager.convert_xid(:uid, arguments[:uid]) if arguments[:uid] arguments[:gid] = Puppet::Util::SUIDManager.convert_xid(:gid, arguments[:gid]) if arguments[:gid] + if execution_stub = Puppet::Util::ExecutionStub.current_value + return execution_stub.call(command, arguments) + end + @@os ||= Facter.value(:operatingsystem) output = nil child_pid, child_status = nil diff --git a/lib/puppet/util/execution_stub.rb b/lib/puppet/util/execution_stub.rb new file mode 100644 index 000000000..af74e0f72 --- /dev/null +++ b/lib/puppet/util/execution_stub.rb @@ -0,0 +1,26 @@ +module Puppet::Util + class ExecutionStub + class << self + # Set a stub block that Puppet::Util.execute() should invoke instead + # of actually executing commands on the target machine. Intended + # for spec testing. + # + # The arguments passed to the block are |command, options|, where + # command is an array of strings and options is an options hash. + def set(&block) + @value = block + end + + # Uninstall any execution stub, so that calls to + # Puppet::Util.execute() behave normally again. + def reset + @value = nil + end + + # Retrieve the current execution stub, or nil if there is no stub. + def current_value + @value + end + end + end +end |
