forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ManageIQ#15814 from cben/graph-viz
Refresh graph logging: use graphviz syntax
- Loading branch information
Showing
4 changed files
with
119 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
describe ManagerRefresh::Graph do | ||
let(:node1) { OpenStruct.new(:whatever => 'foo') } | ||
let(:node2) { OpenStruct.new(:name => 'bar', :x => 2) } | ||
let(:node3) { OpenStruct.new(:name => 'bar', :x => 3) } | ||
let(:node4) { OpenStruct.new(:name => 'quux') } | ||
let(:edges) { [[node1, node2], [node1, node3], [node2, node4]] } | ||
let(:fixed_edges) { [] } | ||
|
||
class TestGraph < described_class | ||
def initialize(nodes, edges, fixed_edges) | ||
@nodes = nodes | ||
@edges = edges | ||
@fixed_edges = fixed_edges | ||
end | ||
end | ||
|
||
let(:graph) { TestGraph.new([node1, node2, node3, node4], edges, fixed_edges) } | ||
|
||
describe '#to_graphviz' do | ||
it 'prints the graph' do | ||
# sensitive to node and edge order, but test controls this | ||
expect(graph.to_graphviz).to eq(<<-'DOT'.strip_heredoc) | ||
digraph { | ||
"#<OpenStruct whatever=\"foo\">"; // #<OpenStruct whatever="foo"> | ||
bar_0; // #<OpenStruct name="bar", x=2> | ||
bar_1; // #<OpenStruct name="bar", x=3> | ||
quux; // #<OpenStruct name="quux"> | ||
// edges: | ||
"#<OpenStruct whatever=\"foo\">" -> bar_0; | ||
"#<OpenStruct whatever=\"foo\">" -> bar_1; | ||
bar_0 -> quux; | ||
} | ||
DOT | ||
end | ||
|
||
it 'prints the graph with layers' do | ||
layers = ManagerRefresh::Graph::TopologicalSort.new(graph).topological_sort | ||
expect(graph.to_graphviz(:layers => layers)).to eq(<<-'DOT'.strip_heredoc) | ||
digraph { | ||
subgraph cluster_0 { label = "Layer 0"; | ||
"#<OpenStruct whatever=\"foo\">"; // #<OpenStruct whatever="foo"> | ||
} | ||
subgraph cluster_1 { label = "Layer 1"; | ||
bar_0; // #<OpenStruct name="bar", x=2> | ||
bar_1; // #<OpenStruct name="bar", x=3> | ||
} | ||
subgraph cluster_2 { label = "Layer 2"; | ||
quux; // #<OpenStruct name="quux"> | ||
} | ||
// edges: | ||
"#<OpenStruct whatever=\"foo\">" -> bar_0; | ||
"#<OpenStruct whatever=\"foo\">" -> bar_1; | ||
bar_0 -> quux; | ||
} | ||
DOT | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
# During graph refresh something like this is printed to log: | ||
# ... Topological sorting of manager ... resulted in these layers ...: | ||
# digraph { | ||
# ... | ||
# } | ||
|
||
# This is suggested command to render a pretty graph from it. | ||
# Requires Graphviz installed. | ||
|
||
echo 'Paste the lines from `digraph {` to `}` inclusive on stdin.' | ||
|
||
set -v | ||
|
||
# unflatten's -l2 flag is arbitrary heuristic, might be better without. | ||
unflatten -l2 -f | | ||
dot -Gstyle=dotted -Grankdir=LR -Granksep=1 -Gfontname=sans -Nshape=box -Nstyle=rounded -Ncolor=gray -Nfontname=monospace | | ||
edgepaint | | ||
dot -Tsvg -o refresh-graph.svg | ||
|
||
xdg-open refresh-graph.svg |