summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-11-06 12:39:40 -0600
committerLuke Kanies <luke@madstop.com>2008-11-06 12:39:40 -0600
commit7e20f06136f524187f64269e39cb95a0a81d4100 (patch)
treee490a3b11c8753b08862af8ce7dc6eb30ea190e4
parent2ba03364309c2347ba4e5bf7dd815beef7563b7b (diff)
downloadpuppet-7e20f06136f524187f64269e39cb95a0a81d4100.tar.gz
puppet-7e20f06136f524187f64269e39cb95a0a81d4100.tar.xz
puppet-7e20f06136f524187f64269e39cb95a0a81d4100.zip
Changing the catalog's relationship graph into a normal graph.
It was previously another catalog instance, but I was only ever actually using the graphing abilities. Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r--lib/puppet/node/catalog.rb11
-rw-r--r--lib/puppet/type/component.rb1
-rwxr-xr-xspec/unit/node/catalog.rb141
3 files changed, 77 insertions, 76 deletions
diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb
index 0138fd8cb..76fc8f940 100644
--- a/lib/puppet/node/catalog.rb
+++ b/lib/puppet/node/catalog.rb
@@ -38,11 +38,6 @@ class Puppet::Node::Catalog < Puppet::SimpleGraph
# that the host catalog needs.
attr_accessor :host_config
- # Whether this graph is another catalog's relationship graph.
- # We don't want to accidentally create a relationship graph for another
- # relationship graph.
- attr_accessor :is_relationship_graph
-
# Whether this catalog was retrieved from the cache, which affects
# whether it is written back out again.
attr_accessor :from_cache
@@ -77,7 +72,7 @@ class Puppet::Node::Catalog < Puppet::SimpleGraph
self.alias(resource, resource.name) if resource.isomorphic?
end
- resource.catalog = self if resource.respond_to?(:catalog=) and ! is_relationship_graph
+ resource.catalog = self if resource.respond_to?(:catalog=)
add_vertex(resource)
end
@@ -157,7 +152,7 @@ class Puppet::Node::Catalog < Puppet::SimpleGraph
@resource_table.clear
if defined?(@relationship_graph) and @relationship_graph
- @relationship_graph.clear(false)
+ @relationship_graph.clear
@relationship_graph = nil
end
end
@@ -202,7 +197,7 @@ class Puppet::Node::Catalog < Puppet::SimpleGraph
add_resource(resource)
if @relationship_graph
- @relationship_graph.add_resource(resource) unless @relationship_graph.resource(resource.ref)
+ @relationship_graph.add_vertex(resource)
end
resource
end
diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb
index 1d1bc9ee8..17ab5b130 100644
--- a/lib/puppet/type/component.rb
+++ b/lib/puppet/type/component.rb
@@ -5,7 +5,6 @@
require 'puppet'
require 'puppet/type'
require 'puppet/transaction'
-require 'puppet/pgraph'
Puppet::Type.newtype(:component) do
include Enumerable
diff --git a/spec/unit/node/catalog.rb b/spec/unit/node/catalog.rb
index 6451632d5..f12550c7c 100755
--- a/spec/unit/node/catalog.rb
+++ b/spec/unit/node/catalog.rb
@@ -359,12 +359,6 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do
@catalog.add_resource @one
end
- it "should not set itself as the resource's catalog if it is a relationship graph" do
- @one.expects(:catalog=).never
- @catalog.is_relationship_graph = true
- @catalog.add_resource @one
- end
-
it "should make all vertices available by resource reference" do
@catalog.add_resource(@one)
@catalog.resource(@one.ref).should equal(@one)
@@ -544,6 +538,54 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do
raise "Aliased non-isomorphic resource"
end
end
+
+ it "should provide a method to create additional resources that also registers the resource" do
+ args = {:name => "/yay", :ensure => :file}
+ resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay"
+ Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
+ @catalog.create_resource :file, args
+ @catalog.resource("File[/yay]").should equal(resource)
+ end
+
+ it "should provide a mechanism for creating implicit resources" do
+ args = {:name => "/yay", :ensure => :file}
+ resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay"
+ Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
+ resource.expects(:implicit=).with(true)
+ @catalog.create_implicit_resource :file, args
+ @catalog.resource("File[/yay]").should equal(resource)
+ end
+
+ it "should remove resources created mid-transaction" do
+ args = {:name => "/yay", :ensure => :file}
+ resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay"
+ @transaction = mock 'transaction'
+ Puppet::Transaction.stubs(:new).returns(@transaction)
+ @transaction.stubs(:evaluate)
+ @transaction.stubs(:cleanup)
+ @transaction.stubs(:addtimes)
+ Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
+ resource.expects :remove
+ @catalog.apply do |trans|
+ @catalog.create_resource :file, args
+ @catalog.resource("File[/yay]").should equal(resource)
+ end
+ @catalog.resource("File[/yay]").should be_nil
+ end
+
+ it "should remove resources added mid-transaction" do
+ @transaction = mock 'transaction'
+ Puppet::Transaction.stubs(:new).returns(@transaction)
+ @transaction.stubs(:evaluate)
+ @transaction.stubs(:cleanup)
+ @transaction.stubs(:addtimes)
+ file = Puppet::Type.type(:file).create(:name => "/yay", :ensure => :file)
+ @catalog.apply do |trans|
+ @catalog.add_resource file
+ @catalog.resource("File[/yay]").should_not be_nil
+ end
+ @catalog.resource("File[/yay]").should be_nil
+ end
end
describe Puppet::Node::Catalog do
@@ -689,12 +731,6 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do
@relationships.should be_instance_of(Puppet::SimpleGraph)
end
- it "should copy its host_config setting to the relationship graph" do
- config = Puppet::Node::Catalog.new
- config.host_config = true
- config.relationship_graph.host_config.should be_true
- end
-
it "should not have any components" do
@relationships.vertices.find { |r| r.instance_of?(Puppet::Type::Component) }.should be_nil
end
@@ -717,38 +753,40 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do
end
it "should get removed when the catalog is cleaned up" do
- @relationships.expects(:clear).with(false)
+ @relationships.expects(:clear)
@catalog.clear
@catalog.instance_variable_get("@relationship_graph").should be_nil
end
- it "should create a new relationship graph after clearing the old one" do
- @relationships.expects(:clear).with(false)
+ it "should write :relationships and :expanded_relationships graph files if the catalog is a host catalog" do
@catalog.clear
- @catalog.relationship_graph.should be_instance_of(Puppet::Node::Catalog)
- end
+ graph = Puppet::SimpleGraph.new
+ Puppet::SimpleGraph.expects(:new).returns graph
+
+ graph.expects(:write_graph).with(:relationships)
+ graph.expects(:write_graph).with(:expanded_relationships)
- it "should look up resources in the relationship graph if not found in the main catalog" do
- five = stub 'five', :ref => "File[five]", :catalog= => nil, :title => "five", :[] => "five"
- @relationships.add_resource five
- @catalog.resource(five.ref).should equal(five)
+ @catalog.host_config = true
+
+ @catalog.relationship_graph
end
- it "should provide a method to create additional resources that also registers the resource" do
- args = {:name => "/yay", :ensure => :file}
- resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay"
- Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
- @catalog.create_resource :file, args
- @catalog.resource("File[/yay]").should equal(resource)
+ it "should not write graph files if the catalog is not a host catalog" do
+ @catalog.clear
+ graph = Puppet::SimpleGraph.new
+ Puppet::SimpleGraph.expects(:new).returns graph
+
+ graph.expects(:write_graph).never
+
+ @catalog.host_config = false
+
+ @catalog.relationship_graph
end
- it "should provide a mechanism for creating implicit resources" do
- args = {:name => "/yay", :ensure => :file}
- resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay"
- Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
- resource.expects(:implicit=).with(true)
- @catalog.create_implicit_resource :file, args
- @catalog.resource("File[/yay]").should equal(resource)
+ it "should create a new relationship graph after clearing the old one" do
+ @relationships.expects(:clear)
+ @catalog.clear
+ @catalog.relationship_graph.should be_instance_of(Puppet::SimpleGraph)
end
it "should add implicit resources to the relationship graph if there is one" do
@@ -760,41 +798,10 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do
relgraph = @catalog.relationship_graph
@catalog.create_implicit_resource :file, args
- relgraph.resource("File[/yay]").should equal(resource)
- end
-
- it "should remove resources created mid-transaction" do
- args = {:name => "/yay", :ensure => :file}
- resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay"
- @transaction = mock 'transaction'
- Puppet::Transaction.stubs(:new).returns(@transaction)
- @transaction.stubs(:evaluate)
- @transaction.stubs(:cleanup)
- @transaction.stubs(:addtimes)
- Puppet::Type.type(:file).expects(:create).with(args).returns(resource)
- resource.expects :remove
- @catalog.apply do |trans|
- @catalog.create_resource :file, args
- @catalog.resource("File[/yay]").should equal(resource)
- end
- @catalog.resource("File[/yay]").should be_nil
- end
-
- it "should remove resources added mid-transaction" do
- @transaction = mock 'transaction'
- Puppet::Transaction.stubs(:new).returns(@transaction)
- @transaction.stubs(:evaluate)
- @transaction.stubs(:cleanup)
- @transaction.stubs(:addtimes)
- file = Puppet::Type.type(:file).create(:name => "/yay", :ensure => :file)
- @catalog.apply do |trans|
- @catalog.add_resource file
- @catalog.resource("File[/yay]").should_not be_nil
- end
- @catalog.resource("File[/yay]").should be_nil
+ relgraph.should be_vertex(resource)
end
- it "should remove resources from the relationship graph if it exists" do
+ it "should remove removed resources from the relationship graph if it exists" do
@catalog.remove_resource(@one)
@catalog.relationship_graph.vertex?(@one).should be_false
end