summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-01-13 22:47:22 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-01-13 22:47:22 +0000
commit1d4638a03df6821c16c00db3084f89889f19ac33 (patch)
tree7fcc1306648893d78090eb04492e108a9347e0d5
parenta6e367e5989d0646c2f53c2de839893be76988cb (diff)
downloadpuppet-1d4638a03df6821c16c00db3084f89889f19ac33.tar.gz
puppet-1d4638a03df6821c16c00db3084f89889f19ac33.tar.xz
puppet-1d4638a03df6821c16c00db3084f89889f19ac33.zip
Added "finish" method, using it in Type.finalize, and moved autorequire and setdefaults to it.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@824 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/type.rb20
-rwxr-xr-xlib/puppet/type/pfile/create.rb26
-rw-r--r--test/puppettest.rb9
-rw-r--r--test/types/file.rb21
4 files changed, 68 insertions, 8 deletions
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 0e4c1425d..74c163338 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -294,6 +294,16 @@ class Type < Puppet::Element
# Perform any operations that need to be done between instance creation
# and instance evaluation.
def self.finalize
+ finished = {}
+ self.eachtype do |type|
+ type.each do |object|
+ unless finished.has_key?(object)
+ Puppet.debug "Finishing %s" % object.name
+ object.finish
+ finished[object] = true
+ end
+ end
+ end
self.mkdepends
@finalized = true
@@ -1103,7 +1113,7 @@ class Type < Puppet::Element
end
}
- self.setdefaults
+ #self.setdefaults
if hash.length > 0
self.debug hash.inspect
@@ -1118,8 +1128,6 @@ class Type < Puppet::Element
if self.respond_to?(:validate)
self.validate
end
-
- self.autorequire
end
# Figure out of there are any objects we can automatically add as
@@ -1152,6 +1160,12 @@ class Type < Puppet::Element
}
end
+ # Set up all of our autorequires.
+ def finish
+ self.setdefaults
+ self.autorequire
+ end
+
# Is the specified parameter set?
def attrset?(type, attr)
case type
diff --git a/lib/puppet/type/pfile/create.rb b/lib/puppet/type/pfile/create.rb
index 449978de7..4b7ee1e15 100755
--- a/lib/puppet/type/pfile/create.rb
+++ b/lib/puppet/type/pfile/create.rb
@@ -10,14 +10,14 @@ module Puppet
# default to just about anything meaning 'true'
case value
when "false", false, nil:
- return false
+ false
when "true", true, "file", "plain", /^f/:
- return "file"
+ "file"
when "directory", /^d/:
- return "directory"
+ "directory"
when :notfound:
# this is where a creation is being rolled back
- return :notfound
+ :notfound
else
raise Puppet::Error, "Cannot create files of type %s" % value
end
@@ -36,6 +36,24 @@ module Puppet
def sync
event = nil
+ basedir = File.dirname(@parent.name)
+
+ if ! FileTest.exists?(basedir)
+ raise Puppet::Error,
+ "Can not create %s; parent directory does not exist" %
+ @parent.name
+ elsif ! FileTest.directory?(basedir)
+ raise Puppet::Error,
+ "Can not create %s; %s is not a directory" %
+ [@parent.name, dirname]
+ end
+
+ self.retrieve
+ if self.insync?
+ self.info "already in sync"
+ return nil
+ end
+
mode = @parent.should(:mode)
# First, determine if a user has been specified and if so if
diff --git a/test/puppettest.rb b/test/puppettest.rb
index 9309a54b9..48dc2d2b5 100644
--- a/test/puppettest.rb
+++ b/test/puppettest.rb
@@ -194,7 +194,14 @@ module TestPuppet
# A simpler method that just applies what we have.
def assert_apply(*objects)
- comp = newcomp(*objects)
+ if objects[0].is_a?(Puppet.type(:component))
+ comp = objects.shift
+ unless objects.empty?
+ objects.each { |o| comp.push o }
+ end
+ else
+ comp = newcomp(*objects)
+ end
trans = nil
assert_nothing_raised("Failed to create transaction") {
diff --git a/test/types/file.rb b/test/types/file.rb
index f0bcf8ed6..9210e712b 100644
--- a/test/types/file.rb
+++ b/test/types/file.rb
@@ -627,6 +627,27 @@ class TestFile < Test::Unit::TestCase
obj.retrieve
assert(obj.insync?, "Object is not in sync")
end
+
+ # Unfortunately, I know this fails
+ def disabled_test_recursivemkdir
+ path = tempfile()
+ subpath = File.join(path, "this", "is", "a", "dir")
+ file = nil
+ assert_nothing_raised {
+ file = Puppet.type(:file).create(
+ :name => subpath,
+ :create => "directory",
+ :recurse => true
+ )
+ }
+
+ comp = newcomp("yay", file)
+ Puppet::Type.finalize
+ assert_apply(comp)
+ #assert_events([:directory_created], comp)
+
+ assert(FileTest.directory?(subpath), "Did not create directory")
+ end
end
# $Id$