From 7ab7d9f9ff378041ab7a2baf159860439bd1c812 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 17 Apr 2009 01:08:53 -0500 Subject: Fixing #2112 - Transactions handle conflicting generated resources This commit rips out all of the 'implicit resource' crap, replacing it with a simple system that just skips resources that the catalog says are in conflict. Removes a bunch of code, and fixes the bug to boot. Signed-off-by: Luke Kanies --- spec/unit/resource.rb | 2 +- spec/unit/resource/catalog.rb | 44 ------------------------------------------- spec/unit/transaction.rb | 34 +++++++++++++++++++++++++++++++++ spec/unit/type.rb | 6 +++--- spec/unit/type/file.rb | 4 ---- 5 files changed, 38 insertions(+), 52 deletions(-) (limited to 'spec/unit') diff --git a/spec/unit/resource.rb b/spec/unit/resource.rb index 0fcf51b8b..141986f90 100755 --- a/spec/unit/resource.rb +++ b/spec/unit/resource.rb @@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../spec_helper' require 'puppet/resource' describe Puppet::Resource do - [:catalog, :file, :line, :implicit].each do |attr| + [:catalog, :file, :line].each do |attr| it "should have an #{attr} attribute" do resource = Puppet::Resource.new("file", "/my/file") resource.should respond_to(attr) diff --git a/spec/unit/resource/catalog.rb b/spec/unit/resource/catalog.rb index f72162b39..6a5922e2e 100755 --- a/spec/unit/resource/catalog.rb +++ b/spec/unit/resource/catalog.rb @@ -350,50 +350,6 @@ describe Puppet::Resource::Catalog, "when compiling" do proc { @catalog.add_resource(@dupe) }.should raise_error(Puppet::Resource::Catalog::DuplicateResourceError) end - it "should ignore implicit resources that conflict with existing resources" do - @catalog.add_resource(@one) - - @dupe.implicit = true - - yielded = [] - @catalog.add_resource(@dupe) { |r| yielded << r } - yielded.should be_empty - end - - it "should not set the catalog for ignored implicit resources" do - @catalog.add_resource(@one) - - @dupe.implicit = true - - @catalog.add_resource(@dupe) - @dupe.catalog.should be_nil - end - - it "should log when implicit resources are ignored" do - @catalog.add_resource(@one) - - @dupe.implicit = true - - @dupe.expects(:debug) - @catalog.add_resource(@dupe) - end - - it "should replace implicit resources if a conflicting explicit resource is added" do - @catalog.add_resource(@one) - @one.implicit = true - - proc { @catalog.add_resource(@dupe) }.should_not raise_error - @catalog.resource(:notify, "one").should equal(@dupe) - end - - it "should log when implicit resources are removed from the catalog" do - @catalog.add_resource(@one) - @one.implicit = true - - @one.expects(:debug) - @catalog.add_resource(@dupe) - end - it "should not store objects that do not respond to :ref" do proc { @catalog.add_resource("thing") }.should raise_error(ArgumentError) end diff --git a/spec/unit/transaction.rb b/spec/unit/transaction.rb index 60705c7fb..86ee02ce5 100755 --- a/spec/unit/transaction.rb +++ b/spec/unit/transaction.rb @@ -17,6 +17,40 @@ describe Puppet::Transaction do @transaction.prefetch end + + describe "when generating resources" do + it "should finish all resources" do + generator = stub 'generator', :depthfirst? => true + resource = stub 'resource' + + @catalog = Puppet::Resource::Catalog.new + @transaction = Puppet::Transaction.new(@catalog) + + generator.expects(:generate).returns [resource] + + @catalog.expects(:add_resource).yields(resource) + + resource.expects(:finish) + + @transaction.generate_additional_resources(generator, :generate) + end + + it "should skip generated resources that conflict with existing resources" do + generator = mock 'generator' + resource = stub 'resource' + + @catalog = Puppet::Resource::Catalog.new + @transaction = Puppet::Transaction.new(@catalog) + + generator.expects(:generate).returns [resource] + + @catalog.expects(:add_resource).raises(Puppet::Resource::Catalog::DuplicateResourceError.new("foo")) + + resource.expects(:finish).never + + @transaction.generate_additional_resources(generator, :generate) + end + end end describe Puppet::Transaction, " when determining tags" do diff --git a/spec/unit/type.rb b/spec/unit/type.rb index 3523d4e8b..304eb4017 100755 --- a/spec/unit/type.rb +++ b/spec/unit/type.rb @@ -61,7 +61,7 @@ describe Puppet::Type do Puppet::Type.type(:mount).new(resource).title.should == "User[foo]" end - [:line, :file, :catalog, :implicit].each do |param| + [:line, :file, :catalog].each do |param| it "should copy '#{param}' from the resource if present" do resource = Puppet::Resource.new(:mount, "/foo") resource.send(param.to_s + "=", "foo") @@ -112,7 +112,7 @@ describe Puppet::Type do @type.stubs(:namevar).returns :myname end - [:catalog, :implicit].each do |param| + [:catalog].each do |param| it "should extract '#{param}' from the hash if present" do Puppet::Type.type(:mount).new(:name => "/yay", param => "foo").send(param).should == "foo" end @@ -220,7 +220,7 @@ describe Puppet::Type do lambda { @type.hash2resource(:myname => "foo", :name => 'bar') }.should raise_error(Puppet::Error) end - [:catalog, :implicit].each do |attr| + [:catalog].each do |attr| it "should use any provided #{attr}" do @type.hash2resource(:name => "foo", attr => "eh").send(attr).should == "eh" end diff --git a/spec/unit/type/file.rb b/spec/unit/type/file.rb index 094596966..1c6976440 100755 --- a/spec/unit/type/file.rb +++ b/spec/unit/type/file.rb @@ -609,10 +609,6 @@ describe Puppet::Type.type(:file) do end describe "and making a new child resource" do - it "should create an implicit resource using the provided relative path joined with the file's path" do - @file.newchild("my/path").should be_implicit - end - it "should not copy the parent resource's parent" do Puppet::Type.type(:file).expects(:new).with { |options| ! options.include?(:parent) } @file.newchild("my/path") -- cgit