summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xlib/puppet/type/exec.rb26
-rwxr-xr-xtest/ral/types/exec.rb30
2 files changed, 52 insertions, 4 deletions
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index 4a5bbd08f..9dfa2b05e 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -37,15 +37,18 @@ module Puppet
obviously different images, so ``exec`` had to be treated specially.
It is recommended to avoid duplicate names whenever possible.
+
+ Note that if an ``exec`` receives an event from another resource,
+ it will get executed again (or execute the command specified in
+ ``refresh``, if there is one).
There is a strong tendency to use ``exec`` to do whatever work Puppet
can't already do; while this is obviously acceptable (and unavoidable)
in the short term, it is highly recommended to migrate work from ``exec``
- to real Puppet element types as quickly as possible. If you find that
+ to native Puppet types as quickly as possible. If you find that
you are doing a lot of work with ``exec``, please at least notify
us at Reductive Labs what you are doing, and hopefully we can work with
- you to get a native element type for the work you are doing. In general,
- it is a Puppet bug if you need ``exec`` to do your work."
+ you to get a native element type for the work you are doing."
require 'open3'
require 'puppet/type/property'
@@ -236,6 +239,17 @@ module Puppet
newvalues(*values)
end
+ newparam(:refresh) do
+ desc "How to refresh this command. By default, the exec is just
+ called again when it receives an event from another resource,
+ but this parameter allows you to define a different command
+ for refreshing."
+
+ validate do |command|
+ @parent.validatecmd(command)
+ end
+ end
+
newparam(:env) do
desc "Any additional environment variables you want to set for a
command. Note that if you use this to set PATH, it will override
@@ -487,7 +501,11 @@ module Puppet
# this might be a very, very bad idea...
def refresh
if self.check
- self.property(:returns).sync
+ if cmd = self[:refresh]
+ self.run(cmd)
+ else
+ self.property(:returns).sync
+ end
end
end
diff --git a/test/ral/types/exec.rb b/test/ral/types/exec.rb
index d16392921..300e26367 100755
--- a/test/ral/types/exec.rb
+++ b/test/ral/types/exec.rb
@@ -700,7 +700,37 @@ and stuff"
exec.refresh
end
assert(! FileTest.exists?(maker), "exec refreshed with failing checks")
+ end
+
+ def test_explicit_refresh
+ refresher = tempfile()
+ maker = tempfile()
+ exec = Puppet::Type.type(:exec).create(
+ :title => "maker",
+ :command => "touch #{maker}",
+ :path => ENV["PATH"]
+ )
+
+ # Call refresh normally
+ assert_nothing_raised do
+ exec.refresh
+ end
+
+ # Make sure it created the normal file
+ assert(FileTest.exists?(maker), "normal refresh did not work")
+ File.unlink(maker)
+
+ # Now reset refresh, and make sure it wins
+ assert_nothing_raised("Could not set refresh parameter") do
+ exec[:refresh] = "touch #{refresher}"
+ end
+ assert_nothing_raised do
+ exec.refresh
+ end
+ # Make sure it created the normal file
+ assert(FileTest.exists?(refresher), "refresh param was ignored")
+ assert(! FileTest.exists?(maker), "refresh param also ran command")
end
end