summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/node/configuration.rb27
-rw-r--r--lib/puppet/pgraph.rb26
-rw-r--r--lib/puppet/transportable.rb2
-rwxr-xr-xspec/unit/node/configuration.rb23
-rwxr-xr-xspec/unit/other/pgraph.rb25
5 files changed, 50 insertions, 53 deletions
diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb
index 4f93fdbe5..be30ddb68 100644
--- a/lib/puppet/node/configuration.rb
+++ b/lib/puppet/node/configuration.rb
@@ -4,7 +4,7 @@ require 'puppet/external/gratr/digraph'
# meant to be passed from server to client, and it contains all
# of the information in the configuration, including the resources
# and the relationships between them.
-class Puppet::Node::Configuration < GRATR::Digraph
+class Puppet::Node::Configuration < Puppet::PGraph
attr_accessor :name, :version
attr_reader :extraction_format
@@ -18,6 +18,25 @@ class Puppet::Node::Configuration < GRATR::Digraph
tag(*classes)
end
+ # Add a resource to our graph and to our resource table.
+ def add_resource(resource)
+ unless resource.respond_to?(:ref)
+ raise ArgumentError, "Can only add objects that respond to :ref"
+ end
+
+ ref = resource.ref
+ if @resource_table.include?(ref)
+ raise ArgumentError, "Resource %s is already defined" % ref
+ else
+ @resource_table[ref] = resource
+ end
+ end
+
+ def clear
+ super
+ @resource_table.clear
+ end
+
def classes
@classes.dup
end
@@ -100,6 +119,12 @@ class Puppet::Node::Configuration < GRATR::Digraph
@extraction_format ||= :transportable
@tags = []
@classes = []
+ @resource_table = {}
+ end
+
+ # Look a resource up by its reference (e.g., File[/etc/passwd]).
+ def resource(ref)
+ @resource_table[ref]
end
# Add a tag.
diff --git a/lib/puppet/pgraph.rb b/lib/puppet/pgraph.rb
index ddecc731d..7a3869dcf 100644
--- a/lib/puppet/pgraph.rb
+++ b/lib/puppet/pgraph.rb
@@ -19,20 +19,6 @@ class Puppet::PGraph < GRATR::Digraph
super
end
- # Add a resource to our graph and to our resource table.
- def add_resource(resource)
- unless resource.respond_to?(:ref)
- raise ArgumentError, "Can only add objects that respond to :ref"
- end
-
- ref = resource.ref
- if @resource_table.include?(ref)
- raise ArgumentError, "Resource %s is already defined" % ref
- else
- @resource_table[ref] = resource
- end
- end
-
def add_vertex!(*args)
@reversal = nil
super
@@ -40,7 +26,6 @@ class Puppet::PGraph < GRATR::Digraph
def clear
@vertex_dict.clear
- #@resource_table.clear
if defined? @edge_number
@edge_number.clear
end
@@ -86,12 +71,6 @@ class Puppet::PGraph < GRATR::Digraph
def edge_class()
Puppet::Relationship
end
-
- def initialize(*args)
- super
- # Create a table to keep references to all of our resources.
- @resource_table = {}
- end
# Determine all of the leaf nodes below a given vertex.
def leaves(vertex, type = :dfs)
@@ -118,11 +97,6 @@ class Puppet::PGraph < GRATR::Digraph
end
end.flatten
end
-
- # Look a resource up by its reference (e.g., File["/etc/passwd"]).
- def resource(ref)
- @resource_table[ref]
- end
# Take container information from another graph and use it
# to replace any container vertices with their respective leaves.
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index 7a04e1f63..782ba2467 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -201,7 +201,7 @@ module Puppet
# Create a resource graph from our structure.
def to_graph
- graph = Puppet::PGraph.new
+ graph = Puppet::Node::Configuration.new(Facter.value(:hostname))
delver = proc do |obj|
obj.each do |child|
diff --git a/spec/unit/node/configuration.rb b/spec/unit/node/configuration.rb
index 4429fe3a3..774a1550f 100755
--- a/spec/unit/node/configuration.rb
+++ b/spec/unit/node/configuration.rb
@@ -133,3 +133,26 @@ describe Puppet::Node::Configuration, " when extracting transobjects" do
botarray.include?(:botres).should be_true
end
end
+
+describe Puppet::Node::Configuration, " functioning as a resource container" do
+ before do
+ @graph = Puppet::Node::Configuration.new("host")
+ @one = stub 'resource1', :ref => "Me[you]"
+ @two = stub 'resource2', :ref => "Me[him]"
+ @dupe = stub 'resource3', :ref => "Me[you]"
+ end
+
+ it "should make all vertices available by resource reference" do
+ @graph.add_resource(@one)
+ @graph.resource(@one.ref).should equal(@one)
+ end
+
+ it "should not allow two resources with the same resource reference" do
+ @graph.add_resource(@one)
+ proc { @graph.add_resource(@dupe) }.should raise_error(ArgumentError)
+ end
+
+ it "should not store objects that do not respond to :ref" do
+ proc { @graph.add_resource("thing") }.should raise_error(ArgumentError)
+ end
+end
diff --git a/spec/unit/other/pgraph.rb b/spec/unit/other/pgraph.rb
index d4af87ba0..19809ac1e 100755
--- a/spec/unit/other/pgraph.rb
+++ b/spec/unit/other/pgraph.rb
@@ -283,28 +283,3 @@ describe Puppet::PGraph, " when sorting the graph" do
proc { @graph.topsort }.should_not raise_error
end
end
-
-describe Puppet::PGraph, " functioning as a resource container" do
- before do
- @graph = Puppet::PGraph.new
- @one = stub 'resource1', :ref => "Me[you]"
- @two = stub 'resource2', :ref => "Me[him]"
- @dupe = stub 'resource3', :ref => "Me[you]"
- end
-
- it "should make all vertices available by resource reference" do
- @graph.add_vertex!(@one)
- @graph.resource(@one.ref).should equal(@one)
- end
-
- it "should not allow two resources with the same resource reference" do
- @graph.add_vertex!(@one)
- proc { @graph.add_vertex!(@dupe) }.should raise_error(ArgumentError)
- end
-
- it "should not store objects that do not respond to :ref" do
- str = "thing"
- @graph.add_vertex!(str)
- @graph.resource(str).should be_nil
- end
-end