Merge "--stop-on-error flag added to watching reports"

This commit is contained in:
Jenkins 2016-05-13 09:08:28 +00:00 committed by Gerrit Code Review
commit 08f29c530a

View File

@ -47,15 +47,23 @@ def create(plan):
click.echo(uid) click.echo(uid)
def wait_report(uid, timeout, interval=3): def wait_report(uid, timeout, stop_on_error=False, interval=3):
try: try:
if timeout: if timeout:
initial_error_count = None
for summary in graph.wait_finish(uid, timeout=timeout): for summary in graph.wait_finish(uid, timeout=timeout):
stringified_summary = '\r' + ' '.join( stringified_summary = '\r' + ' '.join(
['{}: {}'.format(state, count) ['{}: {}'.format(state, count)
for state, count in summary.items()]) for state, count in summary.items()])
click.echo(stringified_summary, nl=False) click.echo(stringified_summary, nl=False)
sys.stdout.flush() 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 pending = states.PENDING.name
in_progress = states.INPROGRESS.name in_progress = states.INPROGRESS.name
if summary[pending] + summary[in_progress] != 0: if summary[pending] + summary[in_progress] != 0:
@ -94,8 +102,9 @@ def click_report(uid):
@orchestration.command() @orchestration.command()
@click.argument('uid', type=SOLARUID, default='last') @click.argument('uid', type=SOLARUID, default='last')
@click.option('-w', 'wait', default=0) @click.option('-w', 'wait', default=0)
def report(uid, wait): @click.option('-s', '--stop-on-error', is_flag=True, default=False)
wait_report(uid, wait) def report(uid, wait, stop_on_error):
wait_report(uid, wait, stop_on_error)
@orchestration.command() @orchestration.command()
@ -123,18 +132,20 @@ def noop(uid, task):
@orchestration.command(name='run-once') @orchestration.command(name='run-once')
@click.argument('uid', type=SOLARUID, default='last') @click.argument('uid', type=SOLARUID, default='last')
@click.option('-w', 'wait', default=0) @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) SCHEDULER_CLIENT.next({}, uid)
wait_report(uid, wait) wait_report(uid, wait, stop_on_error)
@orchestration.command() @orchestration.command()
@click.argument('uid', type=SOLARUID) @click.argument('uid', type=SOLARUID)
@click.option('-w', 'wait', default=0) @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) graph.reset_by_uid(uid)
SCHEDULER_CLIENT.next({}, uid) SCHEDULER_CLIENT.next({}, uid)
wait_report(uid, wait) wait_report(uid, wait, stop_on_error)
@orchestration.command() @orchestration.command()