OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Wrapper for tests that are run on builders.""" | 7 """Wrapper for tests that are run on builders.""" |
8 | 8 |
9 import fileinput | 9 import fileinput |
10 import optparse | 10 import optparse |
11 import os | 11 import os |
12 import re | 12 import re |
13 import sys | 13 import sys |
14 import traceback | 14 import traceback |
15 import urllib | 15 import urllib |
16 import HTMLParser | 16 import HTMLParser |
17 | 17 |
18 import constants | 18 import constants |
19 sys.path.append(constants.SOURCE_ROOT) | 19 sys.path.append(constants.SOURCE_ROOT) |
20 import chromite.lib.cros_build_lib as cros_lib | 20 import chromite.lib.cros_build_lib as cros_lib |
21 | 21 |
22 _IMAGE_TO_EXTRACT = 'chromiumos_test_image.bin' | 22 _IMAGE_TO_EXTRACT = 'chromiumos_test_image.bin' |
23 _NEW_STYLE_VERSION = '0.9.131.0' | 23 _NEW_STYLE_VERSION = '0.9.131.0' |
24 | 24 |
| 25 class CrosImageDoesNotExistError(Exception): |
| 26 """Error thrown when no image can be found.""" |
| 27 pass |
| 28 |
| 29 |
25 class HTMLDirectoryParser(HTMLParser.HTMLParser): | 30 class HTMLDirectoryParser(HTMLParser.HTMLParser): |
26 """HTMLParser for parsing the default apache file index.""" | 31 """HTMLParser for parsing the default apache file index.""" |
27 | 32 |
28 def __init__(self, regex): | 33 def __init__(self, regex): |
29 HTMLParser.HTMLParser.__init__(self) | 34 HTMLParser.HTMLParser.__init__(self) |
30 self.regex_object = re.compile(regex) | 35 self.regex_object = re.compile(regex) |
31 self.link_list = [] | 36 self.link_list = [] |
32 | 37 |
33 def handle_starttag(self, tag, attrs): | 38 def handle_starttag(self, tag, attrs): |
34 """Overrides from HTMLParser and is called at the start of every tag. | 39 """Overrides from HTMLParser and is called at the start of every tag. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 return version_b | 109 return version_b |
105 return version_a | 110 return version_a |
106 | 111 |
107 | 112 |
108 def GetLatestLinkFromPage(url, regex): | 113 def GetLatestLinkFromPage(url, regex): |
109 """Returns the latest link from the given url that matches regex. | 114 """Returns the latest link from the given url that matches regex. |
110 | 115 |
111 Args: | 116 Args: |
112 url: Url to download and parse. | 117 url: Url to download and parse. |
113 regex: Regular expression to match links against. | 118 regex: Regular expression to match links against. |
| 119 Raises: |
| 120 CrosImageDoesNotExistError if no image found using args. |
114 """ | 121 """ |
115 url_file = urllib.urlopen(url) | 122 url_file = urllib.urlopen(url) |
116 url_html = url_file.read() | 123 url_html = url_file.read() |
117 | 124 |
118 url_file.close() | 125 url_file.close() |
119 | 126 |
120 # Parses links with versions embedded. | 127 # Parses links with versions embedded. |
121 url_parser = HTMLDirectoryParser(regex=regex) | 128 url_parser = HTMLDirectoryParser(regex=regex) |
122 url_parser.feed(url_html) | 129 url_parser.feed(url_html) |
123 return reduce(_GreaterVersion, url_parser.link_list) | 130 try: |
| 131 return reduce(_GreaterVersion, url_parser.link_list) |
| 132 except TypeError: |
| 133 raise CrosImageDoesNotExistError('No image found at %s' % url) |
124 | 134 |
125 | 135 |
126 def GetNewestLinkFromZipBase(board, channel, zip_server_base): | 136 def GetNewestLinkFromZipBase(board, channel, zip_server_base): |
127 """Returns the url to the newest image from the zip server. | 137 """Returns the url to the newest image from the zip server. |
128 | 138 |
129 Args: | 139 Args: |
130 board: board for the image zip. | 140 board: board for the image zip. |
131 channel: channel for the image zip. | 141 channel: channel for the image zip. |
132 zip_server_base: base url for zipped images. | 142 zip_server_base: base url for zipped images. |
| 143 Raises: |
| 144 CrosImageDoesNotExistError if no image found using args. |
133 """ | 145 """ |
134 zip_base = os.path.join(zip_server_base, channel, board) | 146 zip_base = os.path.join(zip_server_base, channel, board) |
135 latest_version = GetLatestLinkFromPage(zip_base, '\d+\.\d+\.\d+\.\d+/') | 147 latest_version = GetLatestLinkFromPage(zip_base, '\d+\.\d+\.\d+\.\d+/') |
136 | 148 |
137 zip_dir = os.path.join(zip_base, latest_version) | 149 zip_dir = os.path.join(zip_base, latest_version) |
138 zip_name = GetLatestLinkFromPage(zip_dir, | 150 zip_name = GetLatestLinkFromPage(zip_dir, |
139 'ChromeOS-\d+\.\d+\.\d+\.\d+-.*\.zip') | 151 'ChromeOS-\d+\.\d+\.\d+\.\d+-.*\.zip') |
140 return os.path.join(zip_dir, zip_name) | 152 return os.path.join(zip_dir, zip_name) |
141 | 153 |
142 | 154 |
143 def GetLatestZipUrl(board, channel, zip_server_base): | 155 def GetLatestZipUrl(board, channel, zip_server_base): |
144 """Returns the url of the latest image zip for the given arguments. | 156 """Returns the url of the latest image zip for the given arguments. |
145 | 157 |
146 If the latest does not exist, tries to find the rc equivalent. | 158 If the latest does not exist, tries to find the rc equivalent. If neither |
| 159 exist, returns None. |
147 | 160 |
148 Args: | 161 Args: |
149 board: board for the image zip. | 162 board: board for the image zip. |
150 channel: channel for the image zip. | 163 channel: channel for the image zip. |
151 zip_server_base: base url for zipped images. | 164 zip_server_base: base url for zipped images. |
152 """ | 165 """ |
153 try: | 166 try: |
154 return GetNewestLinkFromZipBase(board, channel, zip_server_base) | 167 return GetNewestLinkFromZipBase(board, channel, zip_server_base) |
155 except: | 168 except CrosImageDoesNotExistError as ce: |
156 cros_lib.Warning('Failed to get url from standard zip base. Trying rc.') | 169 cros_lib.Warning(str(ce)) |
| 170 try: |
157 return GetNewestLinkFromZipBase(board + '-rc', channel, zip_server_base) | 171 return GetNewestLinkFromZipBase(board + '-rc', channel, zip_server_base) |
| 172 except CrosImageDoesNotExistError as ce: |
| 173 cros_lib.Warning(str(ce)) |
| 174 return None |
158 | 175 |
159 | 176 |
160 def GrabZipAndExtractImage(zip_url, download_folder, image_name) : | 177 def GrabZipAndExtractImage(zip_url, download_folder, image_name) : |
161 """Downloads the zip and extracts the given image. | 178 """Downloads the zip and extracts the given image. |
162 | 179 |
163 Doesn't re-download if matching version found already in download folder. | 180 Doesn't re-download if matching version found already in download folder. |
164 Args: | 181 Args: |
165 zip_url - url for the image. | 182 zip_url - url for the image. |
166 download_folder - download folder to store zip file and extracted images. | 183 download_folder - download folder to store zip file and extracted images. |
167 image_name - name of the image to extract from the zip file. | 184 image_name - name of the image to extract from the zip file. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 board: the board for the latest image. | 252 board: the board for the latest image. |
236 channel: the channel to run the au test harness against. | 253 channel: the channel to run the au test harness against. |
237 zip_server_base: base url for zipped images. | 254 zip_server_base: base url for zipped images. |
238 no_graphics: boolean - If True, disable graphics during vm test. | 255 no_graphics: boolean - If True, disable graphics during vm test. |
239 type: which test harness to run. Possible values: real, vm. | 256 type: which test harness to run. Possible values: real, vm. |
240 remote: ip address for real test harness run. | 257 remote: ip address for real test harness run. |
241 clean: Clean the state of test harness before running. | 258 clean: Clean the state of test harness before running. |
242 test_results_root: Root directory to store au_test_harness results. | 259 test_results_root: Root directory to store au_test_harness results. |
243 """ | 260 """ |
244 crosutils_root = os.path.join(constants.SOURCE_ROOT, 'src', 'scripts') | 261 crosutils_root = os.path.join(constants.SOURCE_ROOT, 'src', 'scripts') |
| 262 |
| 263 # Grab the latest image we've built. |
| 264 return_object = cros_lib.RunCommand( |
| 265 ['./get_latest_image.sh', '--board=%s' % board], cwd=crosutils_root, |
| 266 redirect_stdout=True, print_cmd=True) |
| 267 |
| 268 latest_image_dir = return_object.output.strip() |
| 269 target_image = os.path.join(latest_image_dir, _IMAGE_TO_EXTRACT) |
| 270 |
| 271 # Grab the latest official build for this board to use as the base image. |
| 272 # If it doesn't exist, run the update test against itself. |
245 download_folder = os.path.abspath('latest_download') | 273 download_folder = os.path.abspath('latest_download') |
246 zip_url = GetLatestZipUrl(board, channel, zip_server_base) | 274 zip_url = GetLatestZipUrl(board, channel, zip_server_base) |
247 GrabZipAndExtractImage(zip_url, download_folder, _IMAGE_TO_EXTRACT) | |
248 | 275 |
249 # Tests go here. | 276 base_image = None |
250 return_object = cros_lib.RunCommand( | 277 if zip_url: |
251 ['./get_latest_image.sh', '--board=%s' % board], cwd=crosutils_root, | 278 GrabZipAndExtractImage(zip_url, download_folder, _IMAGE_TO_EXTRACT) |
252 redirect_stdout=True, print_cmd=True) | 279 base_image = os.path.join(download_folder, _IMAGE_TO_EXTRACT) |
253 | 280 else: |
254 latest_image = return_object.output.strip() | 281 base_image = target_image |
255 | 282 |
256 update_engine_path = os.path.join(crosutils_root, '..', 'platform', | 283 update_engine_path = os.path.join(crosutils_root, '..', 'platform', |
257 'update_engine') | 284 'update_engine') |
258 | 285 |
259 private_key_path = os.path.join(update_engine_path, 'unittest_key.pem') | 286 private_key_path = os.path.join(update_engine_path, 'unittest_key.pem') |
260 public_key_path = GeneratePublicKey(private_key_path) | 287 public_key_path = GeneratePublicKey(private_key_path) |
261 | 288 |
262 cmd = ['bin/cros_au_test_harness', | 289 cmd = ['bin/cros_au_test_harness', |
263 '--base_image=%s' % os.path.join(download_folder, | 290 '--base_image=%s' % base_image, |
264 _IMAGE_TO_EXTRACT), | 291 '--target_image=%s' % target_image, |
265 '--target_image=%s' % os.path.join(latest_image, | |
266 _IMAGE_TO_EXTRACT), | |
267 '--board=%s' % board, | 292 '--board=%s' % board, |
268 '--type=%s' % type, | 293 '--type=%s' % type, |
269 '--remote=%s' % remote, | 294 '--remote=%s' % remote, |
270 '--private_key=%s' % private_key_path, | 295 '--private_key=%s' % private_key_path, |
271 '--public_key=%s' % public_key_path, | 296 '--public_key=%s' % public_key_path, |
272 ] | 297 ] |
273 if test_results_root: cmd.append('--test_results_root=%s' % test_results_root) | 298 if test_results_root: cmd.append('--test_results_root=%s' % test_results_root) |
274 if no_graphics: cmd.append('--no_graphics') | 299 if no_graphics: cmd.append('--no_graphics') |
275 if clean: cmd.append('--clean') | 300 if clean: cmd.append('--clean') |
276 | 301 |
(...skipping 30 matching lines...) Expand all Loading... |
307 if not options.zipbase: parser.error('Need zip url base to get images.') | 332 if not options.zipbase: parser.error('Need zip url base to get images.') |
308 | 333 |
309 RunAUTestHarness(options.board, options.channel, options.zipbase, | 334 RunAUTestHarness(options.board, options.channel, options.zipbase, |
310 options.no_graphics, options.type, options.remote, | 335 options.no_graphics, options.type, options.remote, |
311 not options.cache, options.test_results_root) | 336 not options.cache, options.test_results_root) |
312 | 337 |
313 | 338 |
314 if __name__ == '__main__': | 339 if __name__ == '__main__': |
315 main() | 340 main() |
316 | 341 |
OLD | NEW |