summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-02-18 17:36:30 -0600
committerLuke Kanies <luke@madstop.com>2008-02-18 17:36:30 -0600
commite830f286ee1e657c775871d18340499badc6ef1f (patch)
tree2b82f28d57fa02221bd7c8c2a54b4df951baf2b0
parent60dd5692715bf38226db2d46eb6b93e18a72eb00 (diff)
downloadpuppet-e830f286ee1e657c775871d18340499badc6ef1f.tar.gz
puppet-e830f286ee1e657c775871d18340499badc6ef1f.tar.xz
puppet-e830f286ee1e657c775871d18340499badc6ef1f.zip
Fixed #1018 -- resources now have their namevars added as
aliases in the resource catalog, just like they were added in the resource classes.
-rw-r--r--CHANGELOG4
-rw-r--r--lib/puppet/node/catalog.rb9
-rwxr-xr-xspec/unit/node/catalog.rb13
3 files changed, 25 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 3d08f305a..1fc69c0a7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,7 @@
+ Fixed #1018 -- resources now have their namevars added as
+ aliases in the resource catalog, just like they were added
+ in the resource classes.
+
Fixed #1037 -- remote unreadable files no longer have the
permission denied exceptions caught, thus forbidding them
from being replaced with 'nil'.
diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb
index b74947107..ee4cedd4b 100644
--- a/lib/puppet/node/catalog.rb
+++ b/lib/puppet/node/catalog.rb
@@ -68,7 +68,11 @@ class Puppet::Node::Catalog < Puppet::PGraph
@resource_table[ref] = resource
+ # If the name and title differ, set up an alias
+ self.alias(resource, resource.name) if resource.respond_to?(:name) and resource.respond_to?(:title) and resource.name != resource.title
+
resource.catalog = self if resource.respond_to?(:catalog=) and ! is_relationship_graph
+
add_vertex(resource)
end
end
@@ -78,7 +82,10 @@ class Puppet::Node::Catalog < Puppet::PGraph
resource.ref =~ /^(.+)\[/
newref = "%s[%s]" % [$1 || resource.class.name, name]
- raise(ArgumentError, "Cannot alias %s to %s; resource %s already exists" % [resource.ref, name, newref]) if @resource_table[newref]
+ if existing = @resource_table[newref]
+ return if existing == resource
+ raise(ArgumentError, "Cannot alias %s to %s; resource %s already exists" % [resource.ref, name, newref])
+ end
@resource_table[newref] = resource
@aliases[resource.ref] << newref
end
diff --git a/spec/unit/node/catalog.rb b/spec/unit/node/catalog.rb
index aa49909e2..be4edb65d 100755
--- a/spec/unit/node/catalog.rb
+++ b/spec/unit/node/catalog.rb
@@ -455,6 +455,11 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do
proc { @catalog.alias @two, "one" }.should raise_error(ArgumentError)
end
+ it "should not fail when a resource has duplicate aliases created" do
+ @catalog.add_resource @one
+ proc { @catalog.alias @one, "one" }.should_not raise_error
+ end
+
it "should remove resource aliases when the target resource is removed" do
@catalog.add_resource @one
@catalog.alias(@one, "other")
@@ -463,6 +468,14 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do
@catalog.resource("me", "other").should be_nil
end
+ it "should add an alias for the namevar when the title and name differ" do
+ @one.stubs(:name).returns "other"
+ resource = Puppet::Type.type(:file).create :path => "/something", :title => "other", :content => "blah"
+ @catalog.add_resource(resource)
+ @catalog.resource(:file, "other").should equal(resource)
+ @catalog.resource(:file, "/something").should equal(resource)
+ end
+
after do
Puppet::Type.allclear
end