From 36b126630d44f29cd1a4b681eecc4461ebad56fb Mon Sep 17 00:00:00 2001 From: Maciej Kwiek Date: Tue, 1 Mar 2016 14:05:28 +0100 Subject: [PATCH] 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 --- solar/cli/orch.py | 33 ++++++++++++++------------ solar/orchestration/graph.py | 10 ++++---- solar/test/orchestration/test_graph.py | 22 +++++++++++++++++ 3 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 solar/test/orchestration/test_graph.py diff --git a/solar/cli/orch.py b/solar/cli/orch.py index f53b43d1..ccb49e5e 100755 --- a/solar/cli/orch.py +++ b/solar/cli/orch.py @@ -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() diff --git a/solar/orchestration/graph.py b/solar/orchestration/graph.py index 2201fbff..758ff865 100644 --- a/solar/orchestration/graph.py +++ b/solar/orchestration/graph.py @@ -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 node_start is 0.0 or node_end is 0.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): diff --git a/solar/test/orchestration/test_graph.py b/solar/test/orchestration/test_graph.py new file mode 100644 index 00000000..47d9b091 --- /dev/null +++ b/solar/test/orchestration/test_graph.py @@ -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