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

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: fixes 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 12 matching lines...) Expand all
23 from slave import cipd 23 from slave import cipd
24 from slave import infra_platform 24 from slave import infra_platform
25 from slave import monitoring_utils 25 from slave import monitoring_utils
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'
34
35
36 CIPD_BINARIES = {
37 ('linux', 32): cipd.CipdBinary(
38 cipd.CipdPackage('infra/tools/luci/kitchen/linux-386',
39 KITCHEN_CIPD_VERSION),
40 'kitchen'),
41 ('linux', 64): cipd.CipdBinary(
42 cipd.CipdPackage('infra/tools/luci/kitchen/linux-amd64',
43 KITCHEN_CIPD_VERSION),
44 'kitchen'),
45 ('mac', 64): cipd.CipdBinary(
46 cipd.CipdPackage('infra/tools/luci/kitchen/mac-amd64',
47 KITCHEN_CIPD_VERSION),
48 'kitchen'),
49 ('win', 32): cipd.CipdBinary(
50 cipd.CipdPackage('infra/tools/luci/kitchen/windows-386',
51 KITCHEN_CIPD_VERSION),
52 'kitchen.exe'),
53 ('win', 64): cipd.CipdBinary(
54 cipd.CipdPackage('infra/tools/luci/kitchen/windows-amd64',
55 KITCHEN_CIPD_VERSION),
56 'kitchen.exe'),
57 }
58
59
60 def _call(cmd, **kwargs): 33 def _call(cmd, **kwargs):
61 LOGGER.info('Executing command: %s', cmd) 34 LOGGER.info('Executing command: %s', cmd)
62 exit_code = subprocess.call(cmd, **kwargs) 35 exit_code = subprocess.call(cmd, **kwargs)
63 LOGGER.info('Command %s finished with exit code %d.', cmd, exit_code) 36 LOGGER.info('Command %s finished with exit code %d.', cmd, exit_code)
64 return exit_code 37 return exit_code
65 38
66 39
67 def _install_cipd_packages(path, *binaries): 40 def _install_cipd_packages(path, *packages):
68 """Bootstraps CIPD in |path| and installs requested |binaries|. 41 """Bootstraps CIPD in |path| and installs requested |packages|.
69 42
70 Args: 43 Args:
71 path (str): The CIPD installation root. 44 path (str): The CIPD installation root.
72 binaries (list of CipdBinary): The set of CIPD binaries to install. 45 packages (list of CipdPackage): The set of CIPD packages to install.
73
74 Returns (list): The paths to the binaries.
75 """ 46 """
76 cmd = [ 47 cmd = [
77 sys.executable, 48 sys.executable,
78 os.path.join(env.Build, 'scripts', 'slave', 'cipd.py'), 49 os.path.join(env.Build, 'scripts', 'slave', 'cipd.py'),
79 '--dest-directory', path, 50 '--dest-directory', path,
80 '-vv' if logging.getLogger().level == logging.DEBUG else '-v', 51 '-vv' if logging.getLogger().level == logging.DEBUG else '-v',
81 ] 52 ]
82 for b in binaries: 53 for p in packages:
83 cmd += ['-P', '%s@%s' % (b.package.name, b.package.version)] 54 cmd += ['-P', '%s@%s' % (p.name, p.version)]
84 55
85 exit_code = _call(cmd) 56 exit_code = _call(cmd)
86 if exit_code != 0: 57 if exit_code != 0:
87 raise Exception('Failed to install CIPD packages.') 58 raise Exception('Failed to install CIPD packages.')
88 return [os.path.join(path, b.relpath) for b in binaries]
89 59
90 60
91 def main(argv): 61 def main(argv):
92 parser = argparse.ArgumentParser() 62 parser = argparse.ArgumentParser()
93 parser.add_argument('--repository', required=True, 63 parser.add_argument('--repository', required=True,
94 help='URL of a git repository to fetch.') 64 help='URL of a git repository to fetch.')
95 parser.add_argument('--revision', 65 parser.add_argument('--revision',
96 help='Git commit hash to check out.') 66 help='Git commit hash to check out.')
97 parser.add_argument('--recipe', required=True, 67 parser.add_argument('--recipe', required=True,
98 help='Name of the recipe to run') 68 help='Name of the recipe to run')
99 parser.add_argument('--build-properties-gz', dest='build_properties', 69 parser.add_argument('--build-properties-gz', dest='build_properties',
100 type=chromium_utils.convert_gz_json_type, default={}, 70 type=chromium_utils.convert_gz_json_type, default={},
101 help='Build properties in b64 gz JSON format') 71 help='Build properties in b64 gz JSON format')
102 parser.add_argument('--factory-properties-gz', dest='factory_properties', 72 parser.add_argument('--factory-properties-gz', dest='factory_properties',
103 type=chromium_utils.convert_gz_json_type, default={}, 73 type=chromium_utils.convert_gz_json_type, default={},
104 help='factory properties in b64 gz JSON format') 74 help='factory properties in b64 gz JSON format')
105 parser.add_argument('--leak', action='store_true', 75 parser.add_argument('--leak', action='store_true',
106 help='Refrain from cleaning up generated artifacts.') 76 help='Refrain from cleaning up generated artifacts.')
107 parser.add_argument('--verbose', action='store_true') 77 parser.add_argument('--verbose', action='store_true')
108 args = parser.parse_args(argv[1:]) 78 args = parser.parse_args(argv[1:])
109 79
110 basedir = os.getcwd() 80 basedir = os.getcwd()
111 cipd_path = os.path.join(basedir, '.kitchen_cipd') 81 cipd_path = os.path.join(basedir, '.kitchen_cipd')
112 (kitchen,) = _install_cipd_packages( 82 _install_cipd_packages(
113 cipd_path, CIPD_BINARIES[infra_platform.get()]) 83 cipd_path, cipd.CipdPackage('infra/recipes-py', 'latest'))
114 84
115 with robust_tempdir.RobustTempdir( 85 with robust_tempdir.RobustTempdir(
116 prefix='.kitchen_run', leak=args.leak) as rt: 86 prefix='.kitchen_run', leak=args.leak) as rt:
117 # Explicitly clean up possibly leaked temporary directories 87 # Explicitly clean up possibly leaked temporary directories
118 # from previous runs. 88 # from previous runs.
119 rt.cleanup(basedir) 89 rt.cleanup(basedir)
120 90
121 tempdir = rt.tempdir(basedir) 91 tempdir = rt.tempdir(basedir)
122 LOGGER.info('Using temporary directory: [%s].', tempdir) 92 LOGGER.info('Using temporary directory: [%s].', tempdir)
123 93
124 build_data_dir = rt.tempdir(basedir) 94 build_data_dir = rt.tempdir(basedir)
125 LOGGER.info('Using build data directory: [%s].', build_data_dir) 95 LOGGER.info('Using build data directory: [%s].', build_data_dir)
126 96
127 properties = copy.copy(args.factory_properties) 97 properties = copy.copy(args.factory_properties)
128 properties.update(args.build_properties) 98 properties.update(args.build_properties)
129 properties['build_data_dir'] = build_data_dir 99 properties['build_data_dir'] = build_data_dir
130 LOGGER.info('Using properties: %r', properties) 100 LOGGER.info('Using properties: %r', properties)
131 properties_file = os.path.join(tempdir, 'kitchen_properties.json') 101 properties_file = os.path.join(tempdir, 'kitchen_properties.json')
132 with open(properties_file, 'w') as f: 102 with open(properties_file, 'w') as f:
133 json.dump(properties, f) 103 json.dump(properties, f)
134 104
135 monitoring_utils.write_build_monitoring_event(build_data_dir, properties) 105 monitoring_utils.write_build_monitoring_event(build_data_dir, properties)
136 106
137 return _call([ 107 return _call([
138 kitchen, 'cook', 108 sys.executable,
139 '-repository', args.repository, 109 os.path.join(cipd_path, 'recipes.py'),
140 '-revision', args.revision, 110 'remote_run',
141 '-recipe', args.recipe, 111 '--repository', args.repository,
142 '-properties-file', properties_file, 112 '--revision', args.revision,
143 '-workdir', tempdir, 113 '--workdir', os.path.join(tempdir, 'remote_run_workdir'),
114 '--',
115 '--properties-file', properties_file,
116 '--workdir', os.path.join(tempdir, 'run_workdir'),
117 args.recipe,
144 ]) 118 ])
145 119
146 120
147 def shell_main(argv): 121 def shell_main(argv):
148 logging.basicConfig( 122 logging.basicConfig(
149 level=(logging.DEBUG if '--verbose' in argv else logging.INFO)) 123 level=(logging.DEBUG if '--verbose' in argv else logging.INFO))
150 124
151 if update_scripts.update_scripts(): 125 if update_scripts.update_scripts():
152 # Re-execute with the updated kitchen_run.py. 126 # Re-execute with the updated kitchen_run.py.
153 return _call([sys.executable] + argv) 127 return _call([sys.executable] + argv)
154 128
155 return main(argv) 129 return main(argv)
156 130
157 131
158 if __name__ == '__main__': 132 if __name__ == '__main__':
159 sys.exit(shell_main(sys.argv)) 133 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