| OLD | NEW |
| 1 # coding: utf-8 | 1 # coding: utf-8 |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Defines class Rietveld to easily access a rietveld instance. | 5 """Defines class Rietveld to easily access a rietveld instance. |
| 6 | 6 |
| 7 Security implications: | 7 Security implications: |
| 8 | 8 |
| 9 The following hypothesis are made: | 9 The following hypothesis are made: |
| 10 - Rietveld enforces: | 10 - Rietveld enforces: |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 # It's an error message. Return as no result. | 324 # It's an error message. Return as no result. |
| 325 break | 325 break |
| 326 data = json.loads(output) or {} | 326 data = json.loads(output) or {} |
| 327 if not data.get('results'): | 327 if not data.get('results'): |
| 328 break | 328 break |
| 329 for i in data['results']: | 329 for i in data['results']: |
| 330 yield i | 330 yield i |
| 331 cursor = '&cursor=%s' % data['cursor'] | 331 cursor = '&cursor=%s' % data['cursor'] |
| 332 | 332 |
| 333 def trigger_try_jobs( | 333 def trigger_try_jobs( |
| 334 self, issue, patchset, reason, clobber, revision, builders_and_tests): | 334 self, issue, patchset, reason, clobber, revision, builders_and_tests, |
| 335 master=None): |
| 335 """Requests new try jobs. | 336 """Requests new try jobs. |
| 336 | 337 |
| 337 |builders_and_tests| is a map of builders: [tests] to run. | 338 |builders_and_tests| is a map of builders: [tests] to run. |
| 339 |master| is the name of the try master the builders belong to. |
| 338 | 340 |
| 339 Returns the keys of the new TryJobResult entites. | 341 Returns the keys of the new TryJobResult entites. |
| 340 """ | 342 """ |
| 341 params = [ | 343 params = [ |
| 342 ('reason', reason), | 344 ('reason', reason), |
| 343 ('clobber', 'True' if clobber else 'False'), | 345 ('clobber', 'True' if clobber else 'False'), |
| 344 ('builders', json.dumps(builders_and_tests)), | 346 ('builders', json.dumps(builders_and_tests)), |
| 345 ('xsrf_token', self.xsrf_token()), | 347 ('xsrf_token', self.xsrf_token()), |
| 346 ] | 348 ] |
| 347 if revision: | 349 if revision: |
| 348 params.append(('revision', revision)) | 350 params.append(('revision', revision)) |
| 351 if master: |
| 352 # Temporarily allow empty master names for old configurations. The try |
| 353 # job will not be associated with a master name on rietveld. This is |
| 354 # going to be deprecated. |
| 355 params.append(('master', master)) |
| 349 return self.post('/%d/try/%d' % (issue, patchset), params) | 356 return self.post('/%d/try/%d' % (issue, patchset), params) |
| 350 | 357 |
| 358 def trigger_distributed_try_jobs( |
| 359 self, issue, patchset, reason, clobber, revision, masters): |
| 360 """Requests new try jobs. |
| 361 |
| 362 |masters| is a map of masters: map of builders: [tests] to run. |
| 363 """ |
| 364 for (master, builders_and_tests) in masters.iteritems(): |
| 365 self.trigger_try_jobs( |
| 366 issue, patchset, reason, clobber, revision, builders_and_tests, |
| 367 master) |
| 368 |
| 351 def get_pending_try_jobs(self, cursor=None, limit=100): | 369 def get_pending_try_jobs(self, cursor=None, limit=100): |
| 352 """Retrieves the try job requests in pending state. | 370 """Retrieves the try job requests in pending state. |
| 353 | 371 |
| 354 Returns a tuple of the list of try jobs and the cursor for the next request. | 372 Returns a tuple of the list of try jobs and the cursor for the next request. |
| 355 """ | 373 """ |
| 356 url = '/get_pending_try_patchsets?limit=%d' % limit | 374 url = '/get_pending_try_patchsets?limit=%d' % limit |
| 357 extra = ('&cursor=' + cursor) if cursor else '' | 375 extra = ('&cursor=' + cursor) if cursor else '' |
| 358 data = json.loads(self.get(url + extra)) | 376 data = json.loads(self.get(url + extra)) |
| 359 return data['jobs'], data['cursor'] | 377 return data['jobs'], data['cursor'] |
| 360 | 378 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 add_as_reviewer=False): | 550 add_as_reviewer=False): |
| 533 logging.info('ReadOnlyRietveld: posting comment "%s" to issue %d' % | 551 logging.info('ReadOnlyRietveld: posting comment "%s" to issue %d' % |
| 534 (message, issue)) | 552 (message, issue)) |
| 535 | 553 |
| 536 def set_flag(self, issue, patchset, flag, value): # pylint:disable=R0201 | 554 def set_flag(self, issue, patchset, flag, value): # pylint:disable=R0201 |
| 537 logging.info('ReadOnlyRietveld: setting flag "%s" to "%s" for issue %d' % | 555 logging.info('ReadOnlyRietveld: setting flag "%s" to "%s" for issue %d' % |
| 538 (flag, value, issue)) | 556 (flag, value, issue)) |
| 539 ReadOnlyRietveld._local_changes.setdefault(issue, {})[flag] = value | 557 ReadOnlyRietveld._local_changes.setdefault(issue, {})[flag] = value |
| 540 | 558 |
| 541 def trigger_try_jobs( # pylint:disable=R0201 | 559 def trigger_try_jobs( # pylint:disable=R0201 |
| 542 self, issue, patchset, reason, clobber, revision, builders_and_tests): | 560 self, issue, patchset, reason, clobber, revision, builders_and_tests, |
| 561 master=None): |
| 543 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % | 562 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % |
| 544 (builders_and_tests, issue)) | 563 (builders_and_tests, issue)) |
| 564 |
| 565 def trigger_distributed_try_jobs( # pylint:disable=R0201 |
| 566 self, issue, patchset, reason, clobber, revision, masters): |
| 567 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % |
| 568 (masters, issue)) |
| OLD | NEW |