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

Side by Side Diff: scripts/slave/recipe_modules/step/example.py

Issue 1241323004: Cross-repo recipe package system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: PRESUBMIT-related touchups Created 5 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 DEPS = [
6 'properties',
7 'step',
8 ]
9
10 from recipe_engine import recipe_api
11
12 def RunSteps(api):
13 # TODO(martinis) change this
14 # The api.step object is directly callable.
15 api.step('hello', ['echo', 'Hello World'])
16 api.step('hello', ['echo', 'Why hello, there.'])
17
18 # You can also manipulate various aspects of the step, such as env.
19 # These are passed straight through to subprocess.Popen.
20 # Also, abusing bash -c in this way is a TERRIBLE IDEA DON'T DO IT.
21 api.step('goodbye', ['bash', '-c', 'echo Good bye, $friend.'],
22 env={'friend': 'Darth Vader'})
23
24 # Finally, you can make your step accept any return code
25 api.step('anything is cool', ['bash', '-c', 'exit 3'],
26 ok_ret='any')
27
28 # We can manipulate the step presentation arbitrarily until we run
29 # the next step.
30 step_result = api.step('hello', ['echo', 'hello'])
31 step_result.presentation.status = api.step.EXCEPTION
32 step_result.presentation.logs['the reason'] = ['The reason\nit failed']
33
34 try:
35 api.step('goodbye', ['echo', 'goodbye'])
36 # Modifying step_result now would raise an AssertionError.
37 except api.step.StepFailure:
38 # Raising anything besides StepFailure causes the build to go purple.
39 raise ValueError('goodbye must exit 0!')
40
41 # Aggregate failures from tests!
42 try:
43 with recipe_api.defer_results():
44 api.step('testa', ['echo', 'testa'])
45 api.step('testb', ['echo', 'testb'])
46 except recipe_api.AggregatedStepFailure as f:
47 raise api.step.StepFailure("You can catch step failures.")
48
49 # Some steps are needed from an infrastructure point of view. If these
50 # steps fail, the build stops, but doesn't get turned red because it's
51 # not the developers' fault.
52 try:
53 api.step('cleanup', ['echo', 'cleaning', 'up', 'build'], infra_step=True)
54 except api.step.InfraFailure as f:
55 assert f.result.presentation.status == api.step.EXCEPTION
56
57 # Run a step through a made-up wrapper program.
58 api.step('application', ['echo', 'main', 'application'],
59 wrapper=['python', 'test-wrapper.py', '-v', '--'])
60
61 if api.properties.get('access_invalid_data'):
62 result = api.step('no-op', ['echo', 'I', 'do', 'nothing'])
63 # Trying to access non-existent attributes on the result should raise.
64 _ = result.json.output
65
66 # You can also raise a warning, which will act like a step failure, but
67 # will turn the build yellow, and stop the build.
68 raise api.step.StepWarning("Warning, robots approaching!")
69
70
71 def GenTests(api):
72 yield (
73 api.test('basic') +
74 api.step_data('anything is cool', retcode=3)
75 )
76
77 # If you don't have the expect_exception in this test, you will get something
78 # like this output.
79 # ======================================================================
80 # ERROR: step:example.exceptional (..../exceptional.json)
81 # ----------------------------------------------------------------------
82 # Traceback (most recent call last):
83 # <full stack trace ommitted>
84 # File "annotated_run.py", line 537, in run
85 # retcode = steps_function(api)
86 # File "recipe_modules/step/example.py", line 39, in RunSteps
87 # raise ValueError('goodbye must exit 0!')
88 # ValueError: goodbye must exit 0!
89
90 yield (
91 api.test('exceptional') +
92 api.step_data('goodbye (2)', retcode=1) +
93 api.expect_exception('ValueError')
94 )
95
96 yield (
97 api.test('defer_results') +
98 api.step_data('testa', retcode=1)
99 )
100
101 yield (
102 api.test('invalid_access') +
103 api.properties(access_invalid_data=True) +
104 api.expect_exception('StepDataAttributeError')
105 )
106
107 yield (
108 api.test('infra_failure') +
109 api.properties(raise_infra_failure=True) +
110 api.step_data('cleanup', retcode=1)
111 )
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698