Merge "Solar orch report doesn't fail for empty graph"
This commit is contained in:
commit
0fddb19034
@ -65,22 +65,25 @@ def wait_report(uid, timeout, interval=3):
|
|||||||
|
|
||||||
|
|
||||||
def click_report(uid):
|
def click_report(uid):
|
||||||
colors = {
|
|
||||||
'PENDING': 'cyan',
|
|
||||||
'ERROR': 'red',
|
|
||||||
'SUCCESS': 'green',
|
|
||||||
'INPROGRESS': 'yellow',
|
|
||||||
'SKIPPED': 'blue',
|
|
||||||
'NOOP': 'black'}
|
|
||||||
|
|
||||||
report = graph.report_progress(uid)
|
report = graph.report_progress(uid)
|
||||||
for item in report['tasks']:
|
if len(report['tasks']) == 0:
|
||||||
msg = '{} -> {}'.format(item[0], item[1])
|
click.echo('Nothing to report')
|
||||||
if item[2]:
|
else:
|
||||||
msg += ' :: {}'.format(item[2])
|
colors = {
|
||||||
click.echo(click.style(msg, fg=colors[item[1]]))
|
'PENDING': 'cyan',
|
||||||
click.echo('Total Delta: {}'.format(report['total_delta']))
|
'ERROR': 'red',
|
||||||
click.echo('Total Time: {}'.format(report['total_time']))
|
'SUCCESS': 'green',
|
||||||
|
'INPROGRESS': 'yellow',
|
||||||
|
'SKIPPED': 'blue',
|
||||||
|
'NOOP': 'black'}
|
||||||
|
|
||||||
|
for item in report['tasks']:
|
||||||
|
msg = '{} -> {}'.format(item[0], item[1])
|
||||||
|
if item[2]:
|
||||||
|
msg += ' :: {}'.format(item[2])
|
||||||
|
click.echo(click.style(msg, fg=colors[item[1]]))
|
||||||
|
click.echo('Total Delta: {}'.format(report['total_delta']))
|
||||||
|
click.echo('Total Time: {}'.format(report['total_time']))
|
||||||
|
|
||||||
|
|
||||||
@orchestration.command()
|
@orchestration.command()
|
||||||
|
@ -103,20 +103,20 @@ def longest_path_time(graph):
|
|||||||
"""We are not interested in the path itself, just get the start
|
"""We are not interested in the path itself, just get the start
|
||||||
of execution and the end of it.
|
of execution and the end of it.
|
||||||
"""
|
"""
|
||||||
start = None
|
start = float('inf')
|
||||||
end = None
|
end = float('-inf')
|
||||||
for n in graph:
|
for n in graph:
|
||||||
node_start = graph.node[n]['start_time']
|
node_start = graph.node[n]['start_time']
|
||||||
node_end = graph.node[n]['end_time']
|
node_end = graph.node[n]['end_time']
|
||||||
if int(node_start) == 0 or int(node_end) == 0:
|
if int(node_start) == 0 or int(node_end) == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if node_start < start or start is None:
|
if node_start < start:
|
||||||
start = node_start
|
start = node_start
|
||||||
|
|
||||||
if node_end > end or end is None:
|
if node_end > end:
|
||||||
end = node_end
|
end = node_end
|
||||||
return end - start
|
return max(end - start, 0.0)
|
||||||
|
|
||||||
|
|
||||||
def total_delta(graph):
|
def total_delta(graph):
|
||||||
|
22
solar/test/orchestration/test_graph.py
Normal file
22
solar/test/orchestration/test_graph.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Copyright 2016 Mirantis, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
import networkx as nx
|
||||||
|
|
||||||
|
from solar.orchestration import graph
|
||||||
|
|
||||||
|
|
||||||
|
def test_longest_path_time_returns_0_for_empty_graph():
|
||||||
|
g = nx.MultiDiGraph()
|
||||||
|
assert graph.longest_path_time(g) == 0.0
|
Loading…
x
Reference in New Issue
Block a user