summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-22 12:56:32 -0500
committerLuke Kanies <luke@madstop.com>2007-09-22 12:56:32 -0500
commit60cd6a73b2b0cb7b26b091d4214c66eb5ed3b0ad (patch)
tree1199cb338548abd11c3f92dd3bcb056fe69d20ce
parent46d69068fa7b2f3448294c5d3da21c69cef73d2f (diff)
The structure for handling resource generation is now
in place, which means I'm over the hump in developing this branch. I have to fix some design flaws I made in the configurations, particularly that the 'runner' handler needs to be able to specify tags and whether to ignore schedules, but otherwise, I think it's straightforward test- and bug-fixing from here out.
-rw-r--r--lib/puppet/metatype/instances.rb5
-rw-r--r--lib/puppet/node/configuration.rb12
-rw-r--r--lib/puppet/transaction.rb3
-rw-r--r--lib/puppet/type.rb12
-rw-r--r--lib/puppet/type/pfile.rb3
-rwxr-xr-xtest/ral/types/file.rb12
-rwxr-xr-xtest/ral/types/filesources.rb2
7 files changed, 35 insertions, 14 deletions
diff --git a/lib/puppet/metatype/instances.rb b/lib/puppet/metatype/instances.rb
index 4fd72e85c..4af230b28 100644
--- a/lib/puppet/metatype/instances.rb
+++ b/lib/puppet/metatype/instances.rb
@@ -137,9 +137,8 @@ class Puppet::Type
# now pass through and create the new object
elsif implicit
- Puppet.notice "Ignoring implicit %s" % title
-
- return retobj
+ Puppet.debug "Ignoring implicit %s[%s]" % [self.name, title]
+ return nil
else
# If only one of the objects is being managed, then merge them
if retobj.managed?
diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb
index de6e776c5..747ab9ef6 100644
--- a/lib/puppet/node/configuration.rb
+++ b/lib/puppet/node/configuration.rb
@@ -118,11 +118,21 @@ class Puppet::Node::Configuration < Puppet::PGraph
# Create an implicit resource, meaning that it will lose out
# to any explicitly defined resources. This method often returns
# nil.
+ # The quirk of this method is that it's not possible to create
+ # an implicit resource before an explicit resource of the same name,
+ # because all explicit resources are created before any generate()
+ # methods are called on the individual resources. Thus, this
+ # method can safely just check if an explicit resource already exists
+ # and toss this implicit resource if so.
def create_implicit_resource(type, options)
unless options.include?(:implicit)
options[:implicit] = true
end
- # LAK:FIXME catch exceptions here and return nil when problems
+
+ # This will return nil if an equivalent explicit resource already exists.
+ # When resource classes no longer retain references to resource instances,
+ # this will need to be modified to catch that conflict and discard
+ # implicit resources.
if resource = create_resource(type, options)
resource.implicit = true
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 43889927c..bb8918845 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -26,7 +26,8 @@ class Transaction
end
end
- # Check to see if we should actually allow deleition.
+ # Check to see if we should actually allow processing, but this really only
+ # matters when a resource is getting deleted.
def allow_processing?(resource, changes)
# If a resource is going to be deleted but it still has
# dependencies, then don't delete it unless it's implicit or the
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index e55873c2b..19f676ff4 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -316,9 +316,15 @@ class Type
def parent
return nil unless configuration
- # We should never have more than one parent, so let's just ignore
- # it if we happen to.
- if parents = configuration.relationship_graph.adjacent(self, :direction => :in)
+ # This is kinda weird.
+ if implicit?
+ parents = configuration.relationship_graph.adjacent(self, :direction => :in)
+ else
+ parents = configuration.adjacent(self, :direction => :in)
+ end
+ if parents
+ # We should never have more than one parent, so let's just ignore
+ # it if we happen to.
return parents.shift
else
return nil
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index f2fa6a14d..8b5d6e399 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -650,6 +650,9 @@ module Puppet
return nil
end
end
+
+ # LAK:FIXME This shouldn't be necessary, but as long as we're
+ # modeling the relationship graph specifically, it is.
configuration.relationship_graph.add_edge! self, child
unless child.parent
raise "Did not set parent of %s" % child.ref
diff --git a/test/ral/types/file.rb b/test/ral/types/file.rb
index b58814a7f..0c16d6dff 100755
--- a/test/ral/types/file.rb
+++ b/test/ral/types/file.rb
@@ -676,7 +676,7 @@ class TestFile < Test::Unit::TestCase
:check => %w{owner mode group}
)
}
- mk_configuration dir
+ config = mk_configuration dir
children = nil
@@ -687,19 +687,22 @@ class TestFile < Test::Unit::TestCase
assert_equal([subdir], children.collect {|c| c.title },
"Incorrect generated children")
- dir.class[subdir].remove
+ # Remove our subdir resource,
+ subdir_resource = config.resource(:file, subdir)
+ config.remove_resource(subdir_resource)
+ # Create the test file
File.open(tmpfile, "w") { |f| f.puts "yayness" }
assert_nothing_raised {
children = dir.eval_generate
}
+ # And make sure we get both resources back.
assert_equal([subdir, tmpfile].sort, children.collect {|c| c.title }.sort,
- "Incorrect generated children")
+ "Incorrect generated children when recurse == %s" % value.inspect)
File.unlink(tmpfile)
- #system("rm -rf %s" % basedir)
Puppet.type(:file).clear
end
end
@@ -1297,7 +1300,6 @@ class TestFile < Test::Unit::TestCase
assert(FileTest.exists?(purgee), "File got prematurely purged")
assert_nothing_raised { destobj[:purge] = true }
- Puppet.err :yay
config.apply
assert(FileTest.exists?(localfile), "Local file got purged")
diff --git a/test/ral/types/filesources.rb b/test/ral/types/filesources.rb
index 046d46c1e..01d9766db 100755
--- a/test/ral/types/filesources.rb
+++ b/test/ral/types/filesources.rb
@@ -290,7 +290,7 @@ class TestFileSources < Test::Unit::TestCase
assert_equal([dfileobj], result)
# Clean this up so it can be recreated
- dfileobj.remove
+ config.remove_resource(dfileobj)
# Make sure we correctly iterate over the sources
nosource = tempfile()