summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@rimspace.net>2011-01-21 23:32:40 -0800
committerDaniel Pittman <daniel@rimspace.net>2011-02-03 16:45:30 -0800
commit1ad6470e3df59caf67c484ef4e43274314c0bc40 (patch)
treeb1d4713b2e8c47948ccdadf88f7a32479a9ef725
parentea348761df0b5297dbac50c7f1c48d22746524fa (diff)
Feature #2597 -- fix cycle relationship notification format.
The SimpleGraph class was reporting duplicate data when printing cycles: Notify[c]Notify[c] => Notify[d] Notify[a]Notify[a] => Notify[b] This was caused by throwing the array representation of the edge into a string, rather than just the relationship data; we only care about the later, so now we only emit that later and have the correct text in the error.
-rw-r--r--lib/puppet/simple_graph.rb8
-rwxr-xr-xspec/unit/simple_graph_spec.rb6
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/puppet/simple_graph.rb b/lib/puppet/simple_graph.rb
index 9d7f218a6..29e46c9bd 100644
--- a/lib/puppet/simple_graph.rb
+++ b/lib/puppet/simple_graph.rb
@@ -109,7 +109,7 @@ class Puppet::SimpleGraph
# each of its out-edges.
while v = zeros.pop
result << v
- @out_from[v].each { |v2,es|
+ @out_from[v].each { |v2,es|
degree[v2].delete(v)
zeros << v2 if degree[v2].empty?
}
@@ -117,7 +117,9 @@ class Puppet::SimpleGraph
# If we have any vertices left with non-zero in-degrees, then we've found a cycle.
if cycles = degree.values.reject { |ns| ns.empty? } and cycles.length > 0
- message = cycles.collect { |edges| '('+edges.collect { |e| e.to_s }.join(", ")+')' }.join(", ")
+ message = cycles.collect { |edges|
+ '(' + edges.collect { |e| e[1].to_s }.join(", ") + ')'
+ }.join(", ")
raise Puppet::Error, "Found dependency cycles in the following relationships: #{message}; try using the '--graph' option and open the '.dot' files in OmniGraffle or GraphViz"
end
@@ -141,7 +143,7 @@ class Puppet::SimpleGraph
# each of its out-edges.
while v = zeros.pop
result << v
- @out_from[v].each { |v2,es|
+ @out_from[v].each { |v2,es|
zeros << v2 if (degree[v2] -= 1) == 0
}
end
diff --git a/spec/unit/simple_graph_spec.rb b/spec/unit/simple_graph_spec.rb
index e49811ea7..0d1a3b4a7 100755
--- a/spec/unit/simple_graph_spec.rb
+++ b/spec/unit/simple_graph_spec.rb
@@ -303,6 +303,12 @@ describe Puppet::SimpleGraph do
proc { @graph.topsort }.should_not raise_error
end
+ it "should produce the correct relationship text" do
+ add_edges :a => :b, :b => :a
+ want = %r{following relationships: \(b => a\), \(a => b\)}
+ expect { @graph.topsort }.to raise_error(Puppet::Error, want)
+ end
+
# Our graph's add_edge method is smart enough not to add
# duplicate edges, so we use the objects, which it doesn't
# check.