| OLD | NEW |
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 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 import calendar | 5 import calendar |
| 6 import collections | 6 import collections |
| 7 import contextlib | 7 import contextlib |
| 8 import datetime | 8 import datetime |
| 9 import itertools | 9 import itertools |
| 10 import json | 10 import json |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 165 |
| 166 def finalize(inner): | 166 def finalize(inner): |
| 167 step_stream.close() | 167 step_stream.close() |
| 168 | 168 |
| 169 @property | 169 @property |
| 170 def stream(inner): | 170 def stream(inner): |
| 171 return step_stream | 171 return step_stream |
| 172 | 172 |
| 173 return EmptyOpenStep() | 173 return EmptyOpenStep() |
| 174 | 174 |
| 175 rendered_step = render_step( | 175 try: |
| 176 step_config, recipe_test_api.DisabledTestData() | 176 rendered_step = render_step( |
| 177 ) | 177 step_config, recipe_test_api.DisabledTestData() |
| 178 step_config = None # Make sure we use rendered step config. | 178 ) |
| 179 step_config = None # Make sure we use rendered step config. |
| 180 except: |
| 181 with self.stream_engine.make_step_stream('Placeholder Exception') as s: |
| 182 with s.new_log_stream('exception') as l: |
| 183 l.write_split(traceback.format_exc()) |
| 184 raise |
| 179 | 185 |
| 180 step_env = _merge_envs(os.environ, (rendered_step.config.env or {})) | 186 step_env = _merge_envs(os.environ, (rendered_step.config.env or {})) |
| 181 # Now that the step's environment is all sorted, evaluate PATH on windows | 187 # Now that the step's environment is all sorted, evaluate PATH on windows |
| 182 # to find the actual intended executable. | 188 # to find the actual intended executable. |
| 183 rendered_step = _hunt_path(rendered_step, step_env) | 189 rendered_step = _hunt_path(rendered_step, step_env) |
| 184 self._print_step(step_stream, rendered_step, step_env) | 190 self._print_step(step_stream, rendered_step, step_env) |
| 185 | 191 |
| 186 class ReturnOpenStep(OpenStep): | 192 class ReturnOpenStep(OpenStep): |
| 187 def run(inner): | 193 def run(inner): |
| 188 step_config = rendered_step.config | 194 step_config = rendered_step.config |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 self._test_data = test_data | 409 self._test_data = test_data |
| 404 self._stream_engine = stream_engine | 410 self._stream_engine = stream_engine |
| 405 self._annotator = annotator | 411 self._annotator = annotator |
| 406 self._step_history = collections.OrderedDict() | 412 self._step_history = collections.OrderedDict() |
| 407 | 413 |
| 408 @property | 414 @property |
| 409 def stream_engine(self): | 415 def stream_engine(self): |
| 410 return self._stream_engine | 416 return self._stream_engine |
| 411 | 417 |
| 412 def open_step(self, step_config): | 418 def open_step(self, step_config): |
| 413 test_data_fn = step_config.step_test_data or recipe_test_api.StepTestData | 419 try: |
| 414 step_test = self._test_data.pop_step_test_data(step_config.name, | 420 test_data_fn = step_config.step_test_data or recipe_test_api.StepTestData |
| 415 test_data_fn) | 421 step_test = self._test_data.pop_step_test_data(step_config.name, |
| 416 rendered_step = render_step(step_config, step_test) | 422 test_data_fn) |
| 417 step_config = None # Make sure we use rendered step config. | 423 rendered_step = render_step(step_config, step_test) |
| 424 step_config = None # Make sure we use rendered step config. |
| 425 except: |
| 426 with self.stream_engine.make_step_stream('Placeholder Exception') as s: |
| 427 with s.new_log_stream('exception') as l: |
| 428 l.write_split(traceback.format_exc()) |
| 429 raise |
| 418 | 430 |
| 419 # Layer the simulation step on top of the given stream engine. | 431 # Layer the simulation step on top of the given stream engine. |
| 420 step_stream = self._stream_engine.new_step_stream(rendered_step.config) | 432 step_stream = self._stream_engine.new_step_stream(rendered_step.config) |
| 421 | 433 |
| 422 class ReturnOpenStep(OpenStep): | 434 class ReturnOpenStep(OpenStep): |
| 423 def run(inner): | 435 def run(inner): |
| 424 timeout = rendered_step.config.timeout | 436 timeout = rendered_step.config.timeout |
| 425 if (timeout and step_test.times_out_after and | 437 if (timeout and step_test.times_out_after and |
| 426 step_test.times_out_after > timeout): | 438 step_test.times_out_after > timeout): |
| 427 raise recipe_api.StepTimeout(rendered_step.config.name, timeout) | 439 raise recipe_api.StepTimeout(rendered_step.config.name, timeout) |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 supplied command, and only uses the |env| kwarg for modifying the environment | 738 supplied command, and only uses the |env| kwarg for modifying the environment |
| 727 of the child process. | 739 of the child process. |
| 728 """ | 740 """ |
| 729 saved_path = os.environ['PATH'] | 741 saved_path = os.environ['PATH'] |
| 730 try: | 742 try: |
| 731 if path is not None: | 743 if path is not None: |
| 732 os.environ['PATH'] = path | 744 os.environ['PATH'] = path |
| 733 yield | 745 yield |
| 734 finally: | 746 finally: |
| 735 os.environ['PATH'] = saved_path | 747 os.environ['PATH'] = saved_path |
| OLD | NEW |