diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-01-12 01:58:19 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-01-12 01:58:19 +0000 |
| commit | 411ab22588da2cbe76d186fbd4b59f6194766c4d (patch) | |
| tree | 149909b773377b9a11bf5f68e7d104b1f975047c | |
| parent | 97fb6c91d60cfe20f0521a7148d202ed25434b7d (diff) | |
| download | puppet-411ab22588da2cbe76d186fbd4b59f6194766c4d.tar.gz puppet-411ab22588da2cbe76d186fbd4b59f6194766c4d.tar.xz puppet-411ab22588da2cbe76d186fbd4b59f6194766c4d.zip | |
Adding autorequire to files, and added the cwd to the list of files to be required for exec. Also, exec catches inline files and autorequires them.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@805 980ebf18-57e1-0310-9a29-db15c13687c0
| -rw-r--r-- | lib/puppet/type.rb | 3 | ||||
| -rwxr-xr-x | lib/puppet/type/exec.rb | 19 | ||||
| -rw-r--r-- | lib/puppet/type/pfile.rb | 10 | ||||
| -rw-r--r-- | test/puppettest.rb | 2 | ||||
| -rwxr-xr-x | test/server/fileserver.rb | 2 | ||||
| -rwxr-xr-x | test/types/exec.rb | 24 | ||||
| -rw-r--r-- | test/types/file.rb | 20 | ||||
| -rwxr-xr-x | test/types/filebucket.rb | 5 | ||||
| -rw-r--r-- | test/types/fileignoresource.rb | 5 | ||||
| -rwxr-xr-x | test/types/filesources.rb | 5 |
10 files changed, 75 insertions, 20 deletions
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index af74e76c1..fa87de641 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -1046,6 +1046,9 @@ class Type < Puppet::Element # Retrieve the list of names from the block. next unless list = self.instance_eval(&block) + unless list.is_a?(Array) + list = [list] + end list.each { |dep| if obj = typeobj[dep] unless self.requires?(obj) diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 5d96dabd7..9570c86b8 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -265,9 +265,24 @@ module Puppet end autorequire(:file) do - if self[:command] =~ /^#{File::SEPARATOR}/ - self[:command].sub(/\s.+/,'') + reqs = [] + + # Stick the cwd in there if we have it + if self[:cwd] + reqs << self[:cwd] end + + tmp = self[:command].dup + + # And search the command line for files, adding any we find. This + # will also catch the command itself if it's fully qualified. It might + # not be a bad idea to add unqualified files, but, well, that's a + # bit more annoying to do. + while tmp.sub!(%r{(#{File::SEPARATOR}\S+)}, '') + reqs << $1 + end + + reqs end def output diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index dfe76b401..c13e7038d 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -75,6 +75,16 @@ module Puppet end end + autorequire(:file) do + cur = [] + # Skip the nil in the beginning and don't add ourselves as a prereq + # either. + self.name.split(File::SEPARATOR)[1..-2].collect { |dir| + cur << dir + "/" + cur.join(File::SEPARATOR) + } + end + @depthfirst = false diff --git a/test/puppettest.rb b/test/puppettest.rb index 202d57478..d489cd5e8 100644 --- a/test/puppettest.rb +++ b/test/puppettest.rb @@ -122,7 +122,7 @@ module TestPuppet return f end - def testdir + def tstdir if defined? @testdirnum @testdirnum += 1 else diff --git a/test/server/fileserver.rb b/test/server/fileserver.rb index d1cdd696b..bc610f65b 100755 --- a/test/server/fileserver.rb +++ b/test/server/fileserver.rb @@ -631,7 +631,7 @@ class TestFileServer < Test::Unit::TestCase def test_filereread server = nil - dir = testdir() + dir = tstdir() files = mktestfiles(dir) diff --git a/test/types/exec.rb b/test/types/exec.rb index 02bb5e9eb..446865774 100755 --- a/test/types/exec.rb +++ b/test/types/exec.rb @@ -229,17 +229,39 @@ class TestExec < Test::Unit::TestCase :mode => 755 ) + basedir = File.dirname(oexe) + baseobj = Puppet.type(:file).create( + :name => basedir, + :source => exe, + :mode => 755 + ) + ofile = Puppet.type(:file).create( :name => exe, :mode => 755 ) exec = Puppet.type(:exec).create( - :name => oexe + :name => oexe, + :cwd => basedir ) + cat = Puppet.type(:exec).create( + :name => "cat %s" % oexe, + :path => ENV["PATH"] + ) + + # Verify we get the script itself assert(exec.requires?(file), "Exec did not autorequire file") + + # Verify we catch the cwd + assert(exec.requires?(baseobj), "Exec did not autorequire cwd") + + # Verify we don't require ourselves assert(!exec.requires?(ofile), "Exec incorrectly required file") + + # Verify that we catch inline files + assert(cat.requires?(file), "Exec did not catch inline file") end if Process.uid == 0 diff --git a/test/types/file.rb b/test/types/file.rb index 1e70b725f..93332e06a 100644 --- a/test/types/file.rb +++ b/test/types/file.rb @@ -566,6 +566,26 @@ class TestFile < Test::Unit::TestCase assert_equal("file=%s" % file.name, file.path) end + + def test_autorequire + basedir = tempfile() + subfile = File.join(basedir, "subfile") + + baseobj = Puppet.type(:file).create( + :name => basedir, + :create => "directory" + ) + + subobj = Puppet.type(:file).create( + :name => subfile, + :create => "file" + ) + + assert(subobj.requires?(baseobj), "File did not require basedir") + assert(!subobj.requires?(subobj), "File required itself") + comp = newcomp(subobj, baseobj) + assert_events([:directory_created, :file_created], comp) + end end # $Id$ diff --git a/test/types/filebucket.rb b/test/types/filebucket.rb index 909170f77..5220eea98 100755 --- a/test/types/filebucket.rb +++ b/test/types/filebucket.rb @@ -56,11 +56,6 @@ class TestFileBucket < Test::Unit::TestCase end end - def teardown - super - clearstorage - end - def initstorage Puppet::Storage.init Puppet::Storage.load diff --git a/test/types/fileignoresource.rb b/test/types/fileignoresource.rb index 688b57845..ce8352384 100644 --- a/test/types/fileignoresource.rb +++ b/test/types/fileignoresource.rb @@ -24,11 +24,6 @@ class TestFileIgnoreSources < Test::Unit::TestCase end end - def teardown - super - clearstorage - end - #This is not needed unless using md5 (correct me if I'm wrong) def initstorage Puppet::Storage.init diff --git a/test/types/filesources.rb b/test/types/filesources.rb index 8dd0ca6b5..5ae728c81 100755 --- a/test/types/filesources.rb +++ b/test/types/filesources.rb @@ -27,11 +27,6 @@ class TestFileSources < Test::Unit::TestCase end end - def teardown - super - clearstorage - end - def initstorage Puppet::Storage.init Puppet::Storage.load |
