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

Side by Side Diff: scripts/slave/kitchen_run.py

Issue 2018393002: kitchen_run: use infra/recipes-py instead of kitchen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved. 2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse 6 import argparse
7 import copy 7 import copy
8 import json 8 import json
9 import logging 9 import logging
10 import os 10 import os
(...skipping 15 matching lines...) Expand all
26 from slave import robust_tempdir 26 from slave import robust_tempdir
27 from slave import update_scripts 27 from slave import update_scripts
28 28
29 29
30 LOGGER = logging.getLogger('kitchen_run') 30 LOGGER = logging.getLogger('kitchen_run')
31 31
32 32
33 KITCHEN_CIPD_VERSION = 'latest' 33 KITCHEN_CIPD_VERSION = 'latest'
34 34
35 35
36 CIPD_BINARIES = { 36 CIPD_BINARIES = {
Sergiy Byelozyorov 2016/05/30 11:41:50 That can probably be removed as well now.
Paweł Hajdan Jr. 2016/05/30 11:44:10 Yeah, good catch. Done.
37 ('linux', 32): cipd.CipdBinary( 37 ('linux', 32): cipd.CipdBinary(
38 cipd.CipdPackage('infra/tools/luci/kitchen/linux-386', 38 cipd.CipdPackage('infra/tools/luci/kitchen/linux-386',
39 KITCHEN_CIPD_VERSION), 39 KITCHEN_CIPD_VERSION),
40 'kitchen'), 40 'kitchen'),
41 ('linux', 64): cipd.CipdBinary( 41 ('linux', 64): cipd.CipdBinary(
42 cipd.CipdPackage('infra/tools/luci/kitchen/linux-amd64', 42 cipd.CipdPackage('infra/tools/luci/kitchen/linux-amd64',
43 KITCHEN_CIPD_VERSION), 43 KITCHEN_CIPD_VERSION),
44 'kitchen'), 44 'kitchen'),
45 ('mac', 64): cipd.CipdBinary( 45 ('mac', 64): cipd.CipdBinary(
46 cipd.CipdPackage('infra/tools/luci/kitchen/mac-amd64', 46 cipd.CipdPackage('infra/tools/luci/kitchen/mac-amd64',
(...skipping 10 matching lines...) Expand all
57 } 57 }
58 58
59 59
60 def _call(cmd, **kwargs): 60 def _call(cmd, **kwargs):
61 LOGGER.info('Executing command: %s', cmd) 61 LOGGER.info('Executing command: %s', cmd)
62 exit_code = subprocess.call(cmd, **kwargs) 62 exit_code = subprocess.call(cmd, **kwargs)
63 LOGGER.info('Command %s finished with exit code %d.', cmd, exit_code) 63 LOGGER.info('Command %s finished with exit code %d.', cmd, exit_code)
64 return exit_code 64 return exit_code
65 65
66 66
67 def _install_cipd_packages(path, *binaries): 67 def _install_cipd_packages(path, *packages):
68 """Bootstraps CIPD in |path| and installs requested |binaries|. 68 """Bootstraps CIPD in |path| and installs requested |packages|.
69 69
70 Args: 70 Args:
71 path (str): The CIPD installation root. 71 path (str): The CIPD installation root.
72 binaries (list of CipdBinary): The set of CIPD binaries to install. 72 packages (list of CipdPackage): The set of CIPD packages to install.
73
74 Returns (list): The paths to the binaries.
75 """ 73 """
76 cmd = [ 74 cmd = [
77 sys.executable, 75 sys.executable,
78 os.path.join(env.Build, 'scripts', 'slave', 'cipd.py'), 76 os.path.join(env.Build, 'scripts', 'slave', 'cipd.py'),
79 '--dest-directory', path, 77 '--dest-directory', path,
80 '-vv' if logging.getLogger().level == logging.DEBUG else '-v', 78 '-vv' if logging.getLogger().level == logging.DEBUG else '-v',
81 ] 79 ]
82 for b in binaries: 80 for p in packages:
83 cmd += ['-P', '%s@%s' % (b.package.name, b.package.version)] 81 cmd += ['-P', '%s@%s' % (p.name, p.version)]
84 82
85 exit_code = _call(cmd) 83 exit_code = _call(cmd)
86 if exit_code != 0: 84 if exit_code != 0:
87 raise Exception('Failed to install CIPD packages.') 85 raise Exception('Failed to install CIPD packages.')
88 return [os.path.join(path, b.relpath) for b in binaries]
89 86
90 87
91 def main(argv): 88 def main(argv):
92 parser = argparse.ArgumentParser() 89 parser = argparse.ArgumentParser()
93 parser.add_argument('--repository', required=True, 90 parser.add_argument('--repository', required=True,
94 help='URL of a git repository to fetch.') 91 help='URL of a git repository to fetch.')
95 parser.add_argument('--revision', 92 parser.add_argument('--revision',
96 help='Git commit hash to check out.') 93 help='Git commit hash to check out.')
97 parser.add_argument('--recipe', required=True, 94 parser.add_argument('--recipe', required=True,
98 help='Name of the recipe to run') 95 help='Name of the recipe to run')
99 parser.add_argument('--build-properties-gz', dest='build_properties', 96 parser.add_argument('--build-properties-gz', dest='build_properties',
100 type=chromium_utils.convert_gz_json_type, default={}, 97 type=chromium_utils.convert_gz_json_type, default={},
101 help='Build properties in b64 gz JSON format') 98 help='Build properties in b64 gz JSON format')
102 parser.add_argument('--factory-properties-gz', dest='factory_properties', 99 parser.add_argument('--factory-properties-gz', dest='factory_properties',
103 type=chromium_utils.convert_gz_json_type, default={}, 100 type=chromium_utils.convert_gz_json_type, default={},
104 help='factory properties in b64 gz JSON format') 101 help='factory properties in b64 gz JSON format')
105 parser.add_argument('--leak', action='store_true', 102 parser.add_argument('--leak', action='store_true',
106 help='Refrain from cleaning up generated artifacts.') 103 help='Refrain from cleaning up generated artifacts.')
107 parser.add_argument('--verbose', action='store_true') 104 parser.add_argument('--verbose', action='store_true')
108 args = parser.parse_args(argv[1:]) 105 args = parser.parse_args(argv[1:])
109 106
110 basedir = os.getcwd() 107 basedir = os.getcwd()
111 cipd_path = os.path.join(basedir, '.kitchen_cipd') 108 cipd_path = os.path.join(basedir, '.kitchen_cipd')
112 (kitchen,) = _install_cipd_packages( 109 _install_cipd_packages(
113 cipd_path, CIPD_BINARIES[infra_platform.get()]) 110 cipd_path, cipd.CipdPackage('infra/recipes-py', 'latest'))
114 111
115 with robust_tempdir.RobustTempdir( 112 with robust_tempdir.RobustTempdir(
116 prefix='.kitchen_run', leak=args.leak) as rt: 113 prefix='.kitchen_run', leak=args.leak) as rt:
117 # Explicitly clean up possibly leaked temporary directories 114 # Explicitly clean up possibly leaked temporary directories
118 # from previous runs. 115 # from previous runs.
119 rt.cleanup(basedir) 116 rt.cleanup(basedir)
120 117
121 tempdir = rt.tempdir(basedir) 118 tempdir = rt.tempdir(basedir)
122 LOGGER.info('Using temporary directory: [%s].', tempdir) 119 LOGGER.info('Using temporary directory: [%s].', tempdir)
123 120
124 build_data_dir = rt.tempdir(basedir) 121 build_data_dir = rt.tempdir(basedir)
125 LOGGER.info('Using build data directory: [%s].', build_data_dir) 122 LOGGER.info('Using build data directory: [%s].', build_data_dir)
126 123
127 properties = copy.copy(args.factory_properties) 124 properties = copy.copy(args.factory_properties)
128 properties.update(args.build_properties) 125 properties.update(args.build_properties)
129 properties['build_data_dir'] = build_data_dir 126 properties['build_data_dir'] = build_data_dir
130 LOGGER.info('Using properties: %r', properties) 127 LOGGER.info('Using properties: %r', properties)
131 properties_file = os.path.join(tempdir, 'kitchen_properties.json') 128 properties_file = os.path.join(tempdir, 'kitchen_properties.json')
132 with open(properties_file, 'w') as f: 129 with open(properties_file, 'w') as f:
133 json.dump(properties, f) 130 json.dump(properties, f)
134 131
135 monitoring_utils.write_build_monitoring_event(build_data_dir, properties) 132 monitoring_utils.write_build_monitoring_event(build_data_dir, properties)
136 133
137 return _call([ 134 return _call([
138 kitchen, 'cook', 135 sys.executable,
139 '-repository', args.repository, 136 os.path.join(cipd_path, 'recipes.py'),
140 '-revision', args.revision, 137 'remote_run',
141 '-recipe', args.recipe, 138 '--repository', args.repository,
142 '-properties-file', properties_file, 139 '--revision', args.revision,
143 '-workdir', tempdir, 140 '--workdir', os.path.join(tempdir, 'remote_run_workdir'),
141 '--',
142 '--properties-file', properties_file,
143 '--workdir', os.path.join(tempdir, 'run_workdir'),
144 args.recipe,
144 ]) 145 ])
145 146
146 147
147 def shell_main(argv): 148 def shell_main(argv):
148 logging.basicConfig( 149 logging.basicConfig(
149 level=(logging.DEBUG if '--verbose' in argv else logging.INFO)) 150 level=(logging.DEBUG if '--verbose' in argv else logging.INFO))
150 151
151 if update_scripts.update_scripts(): 152 if update_scripts.update_scripts():
152 # Re-execute with the updated kitchen_run.py. 153 # Re-execute with the updated kitchen_run.py.
153 return _call([sys.executable] + argv) 154 return _call([sys.executable] + argv)
154 155
155 return main(argv) 156 return main(argv)
156 157
157 158
158 if __name__ == '__main__': 159 if __name__ == '__main__':
159 sys.exit(shell_main(sys.argv)) 160 sys.exit(shell_main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698