[prev in list] [next in list] [prev in thread] [next in thread] 

List:       puppet-commit
Subject:    [Puppet-commit] puppet revision 2007
From:       svn () madstop ! com
Date:       2006-12-31 22:10:43
Message-ID: 20061231221043.2AC8516F614 () culain ! madstop ! com
[Download RAW message or body]

luke 2006-12-31 16:10:42 -0600 (Sun, 31 Dec 2006)
Fixing #390.  You can now add --graph to produce dot files, and you can then produce \
                pngs or whatever from those.
Modified: trunk/lib/puppet/transaction.rb
===================================================================
--- trunk/lib/puppet/transaction.rb	2006-12-31 06:27:24 UTC (rev 2006)
+++ trunk/lib/puppet/transaction.rb	2006-12-31 22:10:42 UTC (rev 2007)
@@ -13,6 +13,16 @@
 
     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 @@
         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 @@
             @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,10 +442,9 @@
                 graph.add_edge!(edge)
             end
         end
+
+        graph(graph, :relationships)
         
-        # Then splice in the container information
-        graph.splice!(@resources, Puppet::Type::Component)
-        
         # Lastly, add in any autorequires
         graph.vertices.each do |vertex|
             vertex.autorequire.each do |edge|
@@ -433,6 +454,11 @@
             end
         end
         
+        # Then splice in the container information
+        graph.splice!(@resources, Puppet::Type::Component)
+
+        graph(graph, :expanded_relationships)
+        
         return graph
     end
 

Modified: trunk/test/other/transactions.rb
===================================================================
--- trunk/test/other/transactions.rb	2006-12-31 06:27:24 UTC (rev 2006)
+++ trunk/test/other/transactions.rb	2006-12-31 22:10:42 UTC (rev 2007)
@@ -888,6 +888,46 @@
         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$


[Attachment #3 (text/html)]

<p><b>luke</b> 2006-12-31 16:10:42 -0600 (Sun, 31 Dec 2006)</p><p>Fixing #390.  You \
can now add --graph to produce dot files, and you can then produce pngs or whatever \
from those.<br> </p><hr noshade><pre><font color="gray">Modified: \
trunk/lib/puppet/transaction.rb \
                ===================================================================
--- trunk/lib/puppet/transaction.rb	2006-12-31 06:27:24 UTC (rev 2006)
+++ trunk/lib/puppet/transaction.rb	2006-12-31 22:10:42 UTC (rev 2007)
@@ -13,6 +13,16 @@
 
     include Puppet::Util
 
+    Puppet.config.setdefaults(:puppet,
+        :graph =&gt; [false, &quot;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).&quot;],
+        :graphdir =&gt; { :default =&gt; &quot;$statedir/graphs&quot;,
+            :mode =&gt; 0775,
+            :owner =&gt; &quot;$user&quot;,
+            :group =&gt; &quot;$group&quot;,
+        }
+    )
     Puppet.config.setdefaults(:transaction,
         :tags =&gt; [&quot;&quot;, &quot;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 @@
         end
     end
 
+    # Produce the graph files if requested.
+    def graph(gr, name)
+        return unless Puppet[:graph]
+
+        file = File.join(Puppet[:graphdir], &quot;%s.dot&quot; % name.to_s)
+        File.open(file, &quot;w&quot;) { |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 @@
             @resources = resources.to_graph
         end
 
+        graph(@resources, :resources)
+
         @resourcemetrics = {
             :total =&gt; @resources.vertices.length,
             :out_of_sync =&gt; 0,    # The number of resources that had changes
@@ -420,10 +442,9 @@
                 graph.add_edge!(edge)
             end
         end
+
+        graph(graph, :relationships)
         
-        # Then splice in the container information
-        graph.splice!(@resources, Puppet::Type::Component)
-        
         # Lastly, add in any autorequires
         graph.vertices.each do |vertex|
             vertex.autorequire.each do |edge|
@@ -433,6 +454,11 @@
             end
         end
         
+        # Then splice in the container information
+        graph.splice!(@resources, Puppet::Type::Component)
+
+        graph(graph, :expanded_relationships)
+        
         return graph
     end
 

Modified: trunk/test/other/transactions.rb
===================================================================
--- trunk/test/other/transactions.rb	2006-12-31 06:27:24 UTC (rev 2006)
+++ trunk/test/other/transactions.rb	2006-12-31 22:10:42 UTC (rev 2007)
@@ -888,6 +888,46 @@
         assert(trans.triggered?(c, :refresh),
             &quot;Transaction did not store the trigger&quot;)
     end
+
+    def test_graph
+        Puppet.config.use(:puppet)
+        # Make a graph
+        graph = Puppet::PGraph.new
+        graph.add_edge!(&quot;a&quot;, &quot;b&quot;)
+
+        # Create our transaction
+        trans = Puppet::Transaction.new(graph)
+
+        assert_nothing_raised do
+            trans.graph(graph, :testing)
+        end
+
+        dotfile = File.join(Puppet[:graphdir], &quot;testing.dot&quot;)
+        assert(! FileTest.exists?(dotfile), &quot;Enabled graphing even tho \
disabled&quot;) +
+        # Now enable graphing
+        Puppet[:graph] = true
+
+        assert_nothing_raised do
+            trans.graph(graph, :testing)
+        end
+        assert(FileTest.exists?(dotfile), &quot;Did not create graph.&quot;)
+    end
+
+    def test_created_graphs
+        FileUtils.mkdir_p(Puppet[:graphdir])
+        file = Puppet::Type.newfile(:path =&gt; tempfile, :content =&gt; \
&quot;yay&quot;) +        exec = Puppet::Type.type(:exec).create(:command =&gt; \
&quot;echo yay&quot;, :path =&gt; ENV['PATH'], +            :require =&gt; file)
+
+        Puppet[:graph] = true
+        assert_apply(file, exec)
+
+        %w{resources relationships expanded_relationships}.each do |name|
+            file = File.join(Puppet[:graphdir], &quot;%s.dot&quot; % name)
+            assert(FileTest.exists?(file), &quot;graph for %s was not created&quot; \
% name) +        end
+    end
 end
 
 # $Id$

</font>
</pre>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic