From 97815db4557d9cd1487adbb85aab602966fd46a4 Mon Sep 17 00:00:00 2001 From: Maciej Kwiek Date: Thu, 12 May 2016 15:44:21 +0200 Subject: [PATCH] --stop-on-error flag added to watching reports This flag works only when -w option is used, it causes the report command to end prematurely with exit code 1 and display all tasks status when it encounters NEW error in orchestration task. Change-Id: I7998bb1e1e8da1c76a69aa066af6460eb2fcee1c --- solar/cli/orch.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/solar/cli/orch.py b/solar/cli/orch.py index a493b2e4..2eabb26a 100755 --- a/solar/cli/orch.py +++ b/solar/cli/orch.py @@ -47,15 +47,23 @@ def create(plan): click.echo(uid) -def wait_report(uid, timeout, interval=3): +def wait_report(uid, timeout, stop_on_error=False, interval=3): try: if timeout: + initial_error_count = None for summary in graph.wait_finish(uid, timeout=timeout): stringified_summary = '\r' + ' '.join( ['{}: {}'.format(state, count) for state, count in summary.items()]) click.echo(stringified_summary, nl=False) sys.stdout.flush() + + error = states.ERROR.name + if initial_error_count is None: + initial_error_count = summary[error] + if initial_error_count < summary[error] and stop_on_error: + raise errors.SolarError('Error encountered. Stopping') + pending = states.PENDING.name in_progress = states.INPROGRESS.name if summary[pending] + summary[in_progress] != 0: @@ -94,8 +102,9 @@ def click_report(uid): @orchestration.command() @click.argument('uid', type=SOLARUID, default='last') @click.option('-w', 'wait', default=0) -def report(uid, wait): - wait_report(uid, wait) +@click.option('-s', '--stop-on-error', is_flag=True, default=False) +def report(uid, wait, stop_on_error): + wait_report(uid, wait, stop_on_error) @orchestration.command() @@ -123,18 +132,20 @@ def noop(uid, task): @orchestration.command(name='run-once') @click.argument('uid', type=SOLARUID, default='last') @click.option('-w', 'wait', default=0) -def run_once(uid, wait): +@click.option('-s', '--stop-on-error', is_flag=True, default=False) +def run_once(uid, wait, stop_on_error): SCHEDULER_CLIENT.next({}, uid) - wait_report(uid, wait) + wait_report(uid, wait, stop_on_error) @orchestration.command() @click.argument('uid', type=SOLARUID) @click.option('-w', 'wait', default=0) -def restart(uid, wait): +@click.option('-s', '--stop-on-error', is_flag=True, default=False) +def restart(uid, wait, stop_on_error): graph.reset_by_uid(uid) SCHEDULER_CLIENT.next({}, uid) - wait_report(uid, wait) + wait_report(uid, wait, stop_on_error) @orchestration.command()