summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-31 22:10:42 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-31 22:10:42 +0000
commitb8f798f0ad88c990b5f9fe4c2d7b830aeb36a446 (patch)
treeb39ef323763b33e3b82bbdb80954e92388e680c1
parent0a1dd1ae8e5d77c22596579fbedfbe1db19b4445 (diff)
downloadpuppet-b8f798f0ad88c990b5f9fe4c2d7b830aeb36a446.tar.gz
puppet-b8f798f0ad88c990b5f9fe4c2d7b830aeb36a446.tar.xz
puppet-b8f798f0ad88c990b5f9fe4c2d7b830aeb36a446.zip
Fixing #390. You can now add --graph to produce dot files, and you can then produce pngs or whatever from those.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2007 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/transaction.rb32
-rwxr-xr-xtest/other/transactions.rb40
2 files changed, 69 insertions, 3 deletions
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 6b19902cf..b6d0bfa3f 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -13,6 +13,16 @@ class Transaction
include Puppet::Util
+ Puppet.config.setdefaults(:puppet,
+ :graph => [false, "Whether to create dot graph files for the different
+ configuration graphs. These dot files can be interpreted by tools
+ like OmniGraffle or dot (which is part of ImageMagick)."],
+ :graphdir => { :default => "$statedir/graphs",
+ :mode => 0775,
+ :owner => "$user",
+ :group => "$group",
+ }
+ )
Puppet.config.setdefaults(:transaction,
:tags => ["", "Tags to use to find resources. If this is set, then
only resources tagged with the specified tags will be applied.
@@ -334,6 +344,16 @@ class Transaction
end
end
+ # Produce the graph files if requested.
+ def graph(gr, name)
+ return unless Puppet[:graph]
+
+ file = File.join(Puppet[:graphdir], "%s.dot" % name.to_s)
+ File.open(file, "w") { |f|
+ f.puts gr.to_dot
+ }
+ end
+
# this should only be called by a Puppet::Type::Component resource now
# and it should only receive an array
def initialize(resources)
@@ -343,6 +363,8 @@ class Transaction
@resources = resources.to_graph
end
+ graph(@resources, :resources)
+
@resourcemetrics = {
:total => @resources.vertices.length,
:out_of_sync => 0, # The number of resources that had changes
@@ -420,9 +442,8 @@ class Transaction
graph.add_edge!(edge)
end
end
-
- # Then splice in the container information
- graph.splice!(@resources, Puppet::Type::Component)
+
+ graph(graph, :relationships)
# Lastly, add in any autorequires
graph.vertices.each do |vertex|
@@ -433,6 +454,11 @@ class Transaction
end
end
+ # Then splice in the container information
+ graph.splice!(@resources, Puppet::Type::Component)
+
+ graph(graph, :expanded_relationships)
+
return graph
end
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index 89b1fd8e2..4a5fee9a0 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -888,6 +888,46 @@ class TestTransactions < Test::Unit::TestCase
assert(trans.triggered?(c, :refresh),
"Transaction did not store the trigger")
end
+
+ def test_graph
+ Puppet.config.use(:puppet)
+ # Make a graph
+ graph = Puppet::PGraph.new
+ graph.add_edge!("a", "b")
+
+ # Create our transaction
+ trans = Puppet::Transaction.new(graph)
+
+ assert_nothing_raised do
+ trans.graph(graph, :testing)
+ end
+
+ dotfile = File.join(Puppet[:graphdir], "testing.dot")
+ assert(! FileTest.exists?(dotfile), "Enabled graphing even tho disabled")
+
+ # Now enable graphing
+ Puppet[:graph] = true
+
+ assert_nothing_raised do
+ trans.graph(graph, :testing)
+ end
+ assert(FileTest.exists?(dotfile), "Did not create graph.")
+ end
+
+ def test_created_graphs
+ FileUtils.mkdir_p(Puppet[:graphdir])
+ file = Puppet::Type.newfile(:path => tempfile, :content => "yay")
+ exec = Puppet::Type.type(:exec).create(:command => "echo yay", :path => ENV['PATH'],
+ :require => file)
+
+ Puppet[:graph] = true
+ assert_apply(file, exec)
+
+ %w{resources relationships expanded_relationships}.each do |name|
+ file = File.join(Puppet[:graphdir], "%s.dot" % name)
+ assert(FileTest.exists?(file), "graph for %s was not created" % name)
+ end
+ end
end
# $Id$