Solar orch report doesn't fail for empty graph

Additional message is printed for the case when there are no tasks in
graph to report.

Change-Id: I0074e8e8b0d5a4e25cdb90187790820c4f1c73e0
Closes-bug: 1547537
This commit is contained in:
Maciej Kwiek 2016-03-01 14:05:28 +01:00
parent 3a4910e5cd
commit 36b126630d
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): 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()

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 node_start is 0.0 or node_end is 0.0: if node_start is 0.0 or node_end is 0.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