summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-15 01:01:08 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-15 01:01:08 +0000
commit3b8c9ff8235e1a2cfc7e17dae9933979e10264b3 (patch)
treefa1a111a1455b5a25902312623f8b3d84c209f88
parentbf5d0bc3cd4fd688aae2c0b1b93c32ddcbf3983c (diff)
downloadpuppet-3b8c9ff8235e1a2cfc7e17dae9933979e10264b3.tar.gz
puppet-3b8c9ff8235e1a2cfc7e17dae9933979e10264b3.tar.xz
puppet-3b8c9ff8235e1a2cfc7e17dae9933979e10264b3.zip
Fixing #269. I was aliasing every case where the title and name were different, where I should only have been aliasing isomorphic types, which does not include exec
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1595 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/type.rb16
-rw-r--r--test/types/type.rb45
2 files changed, 58 insertions, 3 deletions
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index ad38cbeec..f422940fe 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -1392,8 +1392,10 @@ class Type < Puppet::Element
begin
obj = new(hash)
rescue => detail
- if Puppet[:debug]
- puts detail.backtrace
+ unless detail.is_a? Puppet::Error
+ if Puppet[:debug]
+ puts detail.backtrace
+ end
end
Puppet.err "Could not create %s: %s" % [title, detail.to_s]
if obj
@@ -1596,8 +1598,16 @@ class Type < Puppet::Element
self.devfail "I was not passed a namevar"
end
+ # If the name and title differ, set up an alias
if self.name != self.title
- self.class.alias(self.name, self)
+ if obj = self.class[self.name]
+ if self.class.isomorphic?
+ raise Puppet::Error, "%s already exists with name %s" %
+ [obj.title, self.name]
+ end
+ else
+ self.class.alias(self.name, self)
+ end
end
# The information to cache to disk. We have to do this after
diff --git a/test/types/type.rb b/test/types/type.rb
index a98ab26ae..420024fb3 100644
--- a/test/types/type.rb
+++ b/test/types/type.rb
@@ -706,6 +706,51 @@ end
assert_equal(greater, type.defaultprovider)
end
+
+ # Make sure that we can have multiple isomorphic objects with the same name,
+ # but not with non-isomorphic objects.
+ def test_isomorphic_names
+ # First do execs, since they're not isomorphic.
+ echo = Puppet::Util.binary "echo"
+ exec1 = exec2 = nil
+ assert_nothing_raised do
+ exec1 = Puppet::Type.type(:exec).create(
+ :title => "exec1",
+ :command => "#{echo} funtest"
+ )
+ end
+ assert_nothing_raised do
+ exec2 = Puppet::Type.type(:exec).create(
+ :title => "exec2",
+ :command => "#{echo} funtest"
+ )
+ end
+
+ assert_apply(exec1, exec2)
+
+ # Now do files, since they are. This should fail.
+ file1 = file2 = nil
+ path = tempfile()
+ assert_nothing_raised do
+ file1 = Puppet::Type.type(:file).create(
+ :title => "file1",
+ :path => path,
+ :content => "yayness"
+ )
+ end
+
+ # This will fail, but earlier systems will catch it.
+ assert_nothing_raised do
+ file2 = Puppet::Type.type(:file).create(
+ :title => "file2",
+ :path => path,
+ :content => "rahness"
+ )
+ end
+
+ assert(file1, "Did not create first file")
+ assert_nil(file2, "Incorrectly created second file")
+ end
end
# $Id$