Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(524)

Side by Side Diff: recipe_engine/run.py

Issue 2802693003: include Package proto into Result proto (Closed)
Patch Set: rebased and addressed comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « recipe_engine/result_pb2.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 """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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 engine, 149 engine,
150 recipe_test_api.DisabledTestData()) 150 recipe_test_api.DisabledTestData())
151 151
152 s.add_step_text('running recipe: "%s"' % recipe) 152 s.add_step_text('running recipe: "%s"' % recipe)
153 except (loader.LoaderError, ImportError, AssertionError) as e: 153 except (loader.LoaderError, ImportError, AssertionError) as e:
154 for line in str(e).splitlines(): 154 for line in str(e).splitlines():
155 s.add_step_text(line) 155 s.add_step_text(line)
156 s.set_step_status('EXCEPTION') 156 s.set_step_status('EXCEPTION')
157 if engine_flags and engine_flags.use_result_proto: 157 if engine_flags and engine_flags.use_result_proto:
158 return result_pb2.Result( 158 return result_pb2.Result(
159 recipe_package=universe_view.universe.config_file.read(),
159 failure=result_pb2.Failure( 160 failure=result_pb2.Failure(
160 human_reason=str(e), 161 human_reason=str(e),
161 exception=result_pb2.Exception( 162 exception=result_pb2.Exception(
162 traceback=traceback.format_exc().splitlines() 163 traceback=traceback.format_exc().splitlines()
163 ))) 164 )))
164 return RecipeResult({ 165 return RecipeResult({
165 'status_code': 2, 166 'status_code': 2,
166 'reason': str(e), 167 'reason': str(e),
167 }) 168 })
168 169
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 self._get_client('paths')._initialize_with_recipe_api(api) 302 self._get_client('paths')._initialize_with_recipe_api(api)
302 303
303 # TODO(martiniss): Remove this once we've transitioned to the new results 304 # TODO(martiniss): Remove this once we've transitioned to the new results
304 # format 305 # format
305 if self._engine_flags and self._engine_flags.use_result_proto: 306 if self._engine_flags and self._engine_flags.use_result_proto:
306 logging.info("Using new result proto logic") 307 logging.info("Using new result proto logic")
307 return self._new_run(recipe_script, api, properties) 308 return self._new_run(recipe_script, api, properties)
308 return self._old_run(recipe_script, api, properties) 309 return self._old_run(recipe_script, api, properties)
309 310
310 def _new_run(self, recipe_script, api, properties): 311 def _new_run(self, recipe_script, api, properties):
311 result = None 312 result = result_pb2.Result(
313 recipe_package=self.universe.config_file.read(),
314 )
312 315
313 with self._step_runner.run_context(): 316 with self._step_runner.run_context():
314 try: 317 try:
315 try: 318 try:
316 recipe_result = recipe_script.run(api, properties) 319 recipe_result = recipe_script.run(api, properties)
317 result = result_pb2.Result(json_result=json.dumps(recipe_result)) 320 result.json_result = json.dumps(recipe_result)
318 finally: 321 finally:
319 self._close_through_level(0) 322 self._close_through_level(0)
320 except recipe_api.StepFailure as f: 323 except recipe_api.StepFailure as f:
321 result = result_pb2.Result( 324 result.failure.human_reason = f.reason
322 failure=result_pb2.Failure( 325 result.failure.failure.step = f.name
323 human_reason=f.reason,
324 failure=result_pb2.StepFailure(
325 step=f.name
326 )))
327 326
328 except types.StepDataAttributeError as ex: 327 except types.StepDataAttributeError as ex:
329 result = result_pb2.Result( 328 result.failure.human_reason = ex.message
330 failure=result_pb2.Failure( 329 result.failure.step_data.step = f.name
331 human_reason=ex.message,
332 step_data=result_pb2.StepData(
333 step=f.name
334 )))
335 330
336 # Let the step runner run_context decide what to do. 331 # Let the step runner run_context decide what to do.
337 raise 332 raise
338 333
339 except subprocess42.TimeoutExpired as ex: 334 except subprocess42.TimeoutExpired as ex:
340 result = result_pb2.Result( 335 result.failure.human_reason = "Step time out: %r" % ex
341 failure=result_pb2.Failure( 336 result.failure.timeout.timeout_s = ex.timeout
342 human_reason="Step time out: %r" % ex,
343 timeout= result_pb2.Timeout(
344 timeout_s=ex.timeout
345 )))
346 337
347 except Exception as ex: 338 except Exception as ex:
348 result = result_pb2.Result( 339 result.failure.human_reason = "Uncaught Exception: %r" % ex
349 failure=result_pb2.Failure( 340 result.failure.exception.traceback[:] = (
350 human_reason="Uncaught Exception: %r" % ex, 341 traceback.format_exc().splitlines())
351 exception=result_pb2.Exception(
352 traceback=traceback.format_exc().splitlines()
353 )))
354 342
355 # Let the step runner run_context decide what to do. 343 # Let the step runner run_context decide what to do.
356 raise 344 raise
357 345
358 return result 346 return result
359 347
360 def _old_run(self, recipe_script, api, properties): 348 def _old_run(self, recipe_script, api, properties):
361 with self._step_runner.run_context(): 349 with self._step_runner.run_context():
362 try: 350 try:
363 try: 351 try:
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 results.append( 415 results.append(
428 loader._invoke_with_properties( 416 loader._invoke_with_properties(
429 run_recipe, properties, recipe_script.PROPERTIES, 417 run_recipe, properties, recipe_script.PROPERTIES,
430 properties.keys())) 418 properties.keys()))
431 except TypeError as e: 419 except TypeError as e:
432 raise TypeError( 420 raise TypeError(
433 "Got %r while trying to call recipe %s with properties %r" % ( 421 "Got %r while trying to call recipe %s with properties %r" % (
434 e, recipe, properties)) 422 e, recipe, properties))
435 423
436 return results 424 return results
OLDNEW
« no previous file with comments | « recipe_engine/result_pb2.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698