Merge "Solar orch report doesn't fail for empty graph"

This commit is contained in:
Jenkins 2016-03-03 10:09:09 +00:00 committed by Gerrit Code Review
commit 0fddb19034
3 changed files with 45 additions and 20 deletions

View File

@ -65,22 +65,25 @@ def wait_report(uid, timeout, interval=3):
def click_report(uid):
colors = {
'PENDING': 'cyan',
'ERROR': 'red',
'SUCCESS': 'green',
'INPROGRESS': 'yellow',
'SKIPPED': 'blue',
'NOOP': 'black'}
report = graph.report_progress(uid)
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']))
if len(report['tasks']) == 0:
click.echo('Nothing to report')
else:
colors = {
'PENDING': 'cyan',
'ERROR': 'red',
'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()

View File

@ -103,20 +103,20 @@ def longest_path_time(graph):
"""We are not interested in the path itself, just get the start
of execution and the end of it.
"""
start = None
end = None
start = float('inf')
end = float('-inf')
for n in graph:
node_start = graph.node[n]['start_time']
node_end = graph.node[n]['end_time']
if int(node_start) == 0 or int(node_end) == 0:
continue
if node_start < start or start is None:
if node_start < start:
start = node_start
if node_end > end or end is None:
if node_end > end:
end = node_end
return end - start
return max(end - start, 0.0)
def total_delta(graph):

View 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