| OLD | NEW |
| 1 # Copyright 2017 The LUCI Authors. All rights reserved. | 1 # Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Entry point for fully-annotated builds. | 5 """Entry point for fully-annotated builds. |
| 6 | 6 |
| 7 This script is part of the effort to move all builds to annotator-based | 7 This script is part of the effort to move all builds to annotator-based |
| 8 systems. Any builder configured to use the AnnotatorFactory.BaseFactory() | 8 systems. Any builder configured to use the AnnotatorFactory.BaseFactory() |
| 9 found in scripts/master/factory/annotator_factory.py executes a single | 9 found in scripts/master/factory/annotator_factory.py executes a single |
| 10 AddAnnotatedScript step. That step (found in annotator_commands.py) calls | 10 AddAnnotatedScript step. That step (found in annotator_commands.py) calls |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 recipe_result.result['recipe_result'], indent=2) | 532 recipe_result.result['recipe_result'], indent=2) |
| 533 if result_filename: | 533 if result_filename: |
| 534 with open(result_filename, 'w') as f: | 534 with open(result_filename, 'w') as f: |
| 535 f.write(result_string) | 535 f.write(result_string) |
| 536 with stream_engine.make_step_stream('recipe result') as s: | 536 with stream_engine.make_step_stream('recipe result') as s: |
| 537 with s.new_log_stream('result') as l: | 537 with s.new_log_stream('result') as l: |
| 538 l.write_split(result_string) | 538 l.write_split(result_string) |
| 539 | 539 |
| 540 if 'traceback' in recipe_result.result: | 540 if 'traceback' in recipe_result.result: |
| 541 with stream_engine.make_step_stream('Uncaught Exception') as s: | 541 with stream_engine.make_step_stream('Uncaught Exception') as s: |
| 542 s.set_step_status('EXCEPTION') |
| 542 with s.new_log_stream('exception') as l: | 543 with s.new_log_stream('exception') as l: |
| 543 for line in recipe_result.result['traceback']: | 544 for line in recipe_result.result['traceback']: |
| 544 l.write_line(line) | 545 l.write_line(line) |
| 545 | 546 |
| 546 if 'reason' in recipe_result.result: | 547 if 'reason' in recipe_result.result: |
| 547 with stream_engine.make_step_stream('Failure reason') as s: | 548 with stream_engine.make_step_stream('Failure reason') as s: |
| 549 s.set_step_status('FAILURE') |
| 548 with s.new_log_stream('reason') as l: | 550 with s.new_log_stream('reason') as l: |
| 549 for line in recipe_result.result['reason'].splitlines(): | 551 for line in recipe_result.result['reason'].splitlines(): |
| 550 l.write_line(line) | 552 l.write_line(line) |
| 551 | 553 |
| 552 if 'status_code' in recipe_result.result: | 554 if 'status_code' in recipe_result.result: |
| 553 return recipe_result.result['status_code'] | 555 return recipe_result.result['status_code'] |
| 554 else: | 556 else: |
| 555 return 0 | 557 return 0 |
| 556 | 558 |
| 557 | 559 |
| 558 def new_handle_recipe_return(result, result_filename, stream_engine): | 560 def new_handle_recipe_return(result, result_filename, stream_engine): |
| 559 if result_filename: | 561 if result_filename: |
| 560 with open(result_filename, 'w') as fil: | 562 with open(result_filename, 'w') as fil: |
| 561 fil.write(jsonpb.MessageToJson( | 563 fil.write(jsonpb.MessageToJson( |
| 562 result, including_default_value_fields=True)) | 564 result, including_default_value_fields=True)) |
| 563 | 565 |
| 564 if result.json_result: | 566 if result.json_result: |
| 565 with stream_engine.make_step_stream('recipe result') as s: | 567 with stream_engine.make_step_stream('recipe result') as s: |
| 566 with s.new_log_stream('result') as l: | 568 with s.new_log_stream('result') as l: |
| 567 l.write_split(result.json_result) | 569 l.write_split(result.json_result) |
| 568 | 570 |
| 569 if result.HasField('failure'): | 571 if result.HasField('failure'): |
| 570 f = result.failure | 572 f = result.failure |
| 571 if f.HasField('exception'): | 573 if f.HasField('exception'): |
| 572 with stream_engine.make_step_stream('Uncaught Exception') as s: | 574 with stream_engine.make_step_stream('Uncaught Exception') as s: |
| 575 s.set_step_status('EXCEPTION') |
| 573 s.add_step_text(f.human_reason) | 576 s.add_step_text(f.human_reason) |
| 574 with s.new_log_stream('exception') as l: | 577 with s.new_log_stream('exception') as l: |
| 575 for line in f.exception.traceback: | 578 for line in f.exception.traceback: |
| 576 l.write_line(line) | 579 l.write_line(line) |
| 577 # TODO(martiniss): Remove this code once calling code handles these states | 580 # TODO(martiniss): Remove this code once calling code handles these states |
| 578 elif f.HasField('timeout'): | 581 elif f.HasField('timeout'): |
| 579 with stream_engine.make_step_stream('Step Timed Out') as s: | 582 with stream_engine.make_step_stream('Step Timed Out') as s: |
| 583 s.set_step_status('FAILURE') |
| 580 with s.new_log_stream('timeout_s') as l: | 584 with s.new_log_stream('timeout_s') as l: |
| 581 l.write_line(f.timeout.timeout_s) | 585 l.write_line(f.timeout.timeout_s) |
| 582 elif f.HasField('step_data'): | 586 elif f.HasField('step_data'): |
| 583 with stream_engine.make_step_stream('Invalid Step Data Access') as s: | 587 with stream_engine.make_step_stream('Invalid Step Data Access') as s: |
| 588 s.set_step_status('FAILURE') |
| 584 with s.new_log_stream('step') as l: | 589 with s.new_log_stream('step') as l: |
| 585 l.write_line(f.step_data.step) | 590 l.write_line(f.step_data.step) |
| 586 | 591 |
| 587 with stream_engine.make_step_stream('Failure reason') as s: | 592 with stream_engine.make_step_stream('Failure reason') as s: |
| 593 s.set_step_status('FAILURE') |
| 588 with s.new_log_stream('reason') as l: | 594 with s.new_log_stream('reason') as l: |
| 589 l.write_split(f.human_reason) | 595 l.write_split(f.human_reason) |
| 590 | 596 |
| 591 return 1 | 597 return 1 |
| 592 | 598 |
| 593 return 0 | 599 return 0 |
| 594 | 600 |
| 595 | 601 |
| 596 # Map of arguments_pb2.Property "value" oneof conversion functions. | 602 # Map of arguments_pb2.Property "value" oneof conversion functions. |
| 597 # | 603 # |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 ret = run_steps( | 725 ret = run_steps( |
| 720 properties, stream_engine, | 726 properties, stream_engine, |
| 721 step_runner.SubprocessStepRunner(stream_engine, engine_flags), | 727 step_runner.SubprocessStepRunner(stream_engine, engine_flags), |
| 722 universe_view, engine_flags=engine_flags, | 728 universe_view, engine_flags=engine_flags, |
| 723 emit_initial_properties=emit_initial_properties) | 729 emit_initial_properties=emit_initial_properties) |
| 724 finally: | 730 finally: |
| 725 os.chdir(old_cwd) | 731 os.chdir(old_cwd) |
| 726 | 732 |
| 727 return handle_recipe_return( | 733 return handle_recipe_return( |
| 728 ret, args.output_result_json, stream_engine, engine_flags) | 734 ret, args.output_result_json, stream_engine, engine_flags) |
| OLD | NEW |