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,6 +65,10 @@ def wait_report(uid, timeout, interval=3):
def click_report(uid): def click_report(uid):
report = graph.report_progress(uid)
if len(report['tasks']) == 0:
click.echo('Nothing to report')
else:
colors = { colors = {
'PENDING': 'cyan', 'PENDING': 'cyan',
'ERROR': 'red', 'ERROR': 'red',
@ -73,7 +77,6 @@ def click_report(uid):
'SKIPPED': 'blue', 'SKIPPED': 'blue',
'NOOP': 'black'} 'NOOP': 'black'}
report = graph.report_progress(uid)
for item in report['tasks']: for item in report['tasks']:
msg = '{} -> {}'.format(item[0], item[1]) msg = '{} -> {}'.format(item[0], item[1])
if item[2]: if item[2]:

View File

@ -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):

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