diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2005-09-13 02:20:24 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2005-09-13 02:20:24 +0000 |
| commit | 58ca9d1241eac3fb982aa673195d5e49ab0a1889 (patch) | |
| tree | 8515f03f1c1e466ce9d7cee179bc4f4f89e46470 | |
| parent | f9df5236aa75aa2978c7d9ce826aa6b9bf06a711 (diff) | |
| download | puppet-58ca9d1241eac3fb982aa673195d5e49ab0a1889.tar.gz puppet-58ca9d1241eac3fb982aa673195d5e49ab0a1889.tar.xz puppet-58ca9d1241eac3fb982aa673195d5e49ab0a1889.zip | |
adding snippet test to verify correct behaviour with missing exec path; also, adding "creates" parameter to exec
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@649 980ebf18-57e1-0310-9a29-db15c13687c0
| -rw-r--r-- | examples/code/snippets/missingexecpath.pp | 13 | ||||
| -rwxr-xr-x | lib/puppet/type/exec.rb | 25 | ||||
| -rwxr-xr-x | test/language/tc_snippets.rb | 11 | ||||
| -rwxr-xr-x | test/types/tc_exec.rb | 35 |
4 files changed, 65 insertions, 19 deletions
diff --git a/examples/code/snippets/missingexecpath.pp b/examples/code/snippets/missingexecpath.pp new file mode 100644 index 000000000..3f43be325 --- /dev/null +++ b/examples/code/snippets/missingexecpath.pp @@ -0,0 +1,13 @@ +define distloc(path) { + file { "/tmp/exectesting1": + create => file + } + exec { "touch $path": + subscribe => file["/tmp/exectesting1"], + refreshonly => true + } +} + +distloc { + path => "/tmp/execdisttesting", +} diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index e58c25f24..a86e0207c 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -20,6 +20,14 @@ module Puppet # we're just using retrieve to verify that the command # exists and such def retrieve + if file = @parent[:creates] + if FileTest.exists?(file) + @is = true + @should = true + return + end + end + cmd = self.parent[:command] if cmd =~ /^\// exe = cmd.split(/ /)[0] @@ -124,6 +132,7 @@ module Puppet @parameters = [ :path, :user, + :creates, :cwd, :refreshonly, :command @@ -138,10 +147,14 @@ module Puppet @paramdoc[:refreshonly] = "The command should only be run as a refresh mechanism for when a dependent object is changed." @paramdoc[:command] = "The actual command to execute." + @paramdoc[:creates] = "A file that this command creates. If this + parameter is provided, then the command will only be run + if the specified file does not exist." @doc = "Executes external commands. It is critical that all commands executed using this mechanism can be run multiple times without - harm, i.e., they are *idempotent*." + harm, i.e., they are *idempotent*. One useful way to create idempotent + commands is to use the *creates* parameter." @name = :exec @namevar = :command @@ -169,7 +182,6 @@ module Puppet # if we're not fully qualified, require a path if self[:command] !~ /^\// if self[:path].nil? - puts caller raise TypeError, "'%s' is both unqualifed and specified no search path" % self[:command] @@ -185,6 +197,15 @@ module Puppet end end + # FIXME if they try to set this and fail, then we should probably + # fail the entire exec, right? + def paramcreates=(file) + unless file =~ %r{^#{File::SEPARATOR}} + raise Puppet::Error, "'creates' files must be fully qualified." + end + @parameters[:creates] = file + end + # this might be a very, very bad idea... def refresh self.state(:returns).sync diff --git a/test/language/tc_snippets.rb b/test/language/tc_snippets.rb index a02b9fa4d..6623affd6 100755 --- a/test/language/tc_snippets.rb +++ b/test/language/tc_snippets.rb @@ -341,6 +341,14 @@ class TestSnippets < Test::Unit::TestCase "File %s is not 755" % file) end + def snippet_missingexecpath(trans) + file = "/tmp/exectesting1" + execfile = "/tmp/execdisttesting" + @@tmpfiles << file + @@tmpfiles << execfile + assert(!FileTest.exists?(execfile), "File %s exists" % execfile) + end + def disabled_snippet_dirchmod(trans) dirs = %w{a b}.collect { |letter| "/tmp/dirchmodtest%s" % letter @@ -364,7 +372,8 @@ class TestSnippets < Test::Unit::TestCase Dir.entries($snippetbase).sort.each { |file| next if file =~ /^\./ - mname = "snippet_" + file + + mname = "snippet_" + file.sub(/\.pp$/, '') if self.method_defined?(mname) #eval("alias %s %s" % [testname, mname]) testname = ("test_" + mname).intern diff --git a/test/types/tc_exec.rb b/test/types/tc_exec.rb index bdfebc267..f2a8775b8 100755 --- a/test/types/tc_exec.rb +++ b/test/types/tc_exec.rb @@ -1,30 +1,17 @@ if __FILE__ == $0 $:.unshift '..' $:.unshift '../../lib' - $puppetbase = "../../../../language/trunk" + $puppetbase = "../.." end require 'puppet' +require 'puppettest' require 'test/unit' require 'facter' # $Id$ -class TestExec < Test::Unit::TestCase - def setup - Puppet[:loglevel] = :debug if __FILE__ == $0 - @@tmpfiles = [] - end - - def teardown - Puppet::Type.allclear - @@tmpfiles.each { |f| - if FileTest.exists?(f) - system("rm -rf %s" % f) - end - } - end - +class TestExec < TestPuppet def test_execution command = nil output = nil @@ -205,4 +192,20 @@ class TestExec < Test::Unit::TestCase events ) end + + def test_creates + file = tempfile() + exec = nil + assert_nothing_raised { + exec = Puppet::Type::Exec.new( + :command => "touch %s" % file, + :path => "/usr/bin:/bin:/usr/sbin:/sbin", + :creates => file + ) + } + + comp = newcomp("createstest", exec) + assert_events(comp, [:executed_command], "creates") + assert_events(comp, [], "creates") + end end |
