| 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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 break | 330 break |
| 331 data = json.loads(output) or {} | 331 data = json.loads(output) or {} |
| 332 if not data.get('results'): | 332 if not data.get('results'): |
| 333 break | 333 break |
| 334 for i in data['results']: | 334 for i in data['results']: |
| 335 yield i | 335 yield i |
| 336 cursor = '&cursor=%s' % data['cursor'] | 336 cursor = '&cursor=%s' % data['cursor'] |
| 337 | 337 |
| 338 def trigger_try_jobs( | 338 def trigger_try_jobs( |
| 339 self, issue, patchset, reason, clobber, revision, builders_and_tests, | 339 self, issue, patchset, reason, clobber, revision, builders_and_tests, |
| 340 master=None): | 340 master=None, category='cq'): |
| 341 """Requests new try jobs. | 341 """Requests new try jobs. |
| 342 | 342 |
| 343 |builders_and_tests| is a map of builders: [tests] to run. | 343 |builders_and_tests| is a map of builders: [tests] to run. |
| 344 |master| is the name of the try master the builders belong to. | 344 |master| is the name of the try master the builders belong to. |
| 345 |category| is used to distinguish regular jobs and experimental jobs. |
| 345 | 346 |
| 346 Returns the keys of the new TryJobResult entites. | 347 Returns the keys of the new TryJobResult entites. |
| 347 """ | 348 """ |
| 348 params = [ | 349 params = [ |
| 349 ('reason', reason), | 350 ('reason', reason), |
| 350 ('clobber', 'True' if clobber else 'False'), | 351 ('clobber', 'True' if clobber else 'False'), |
| 351 ('builders', json.dumps(builders_and_tests)), | 352 ('builders', json.dumps(builders_and_tests)), |
| 352 ('xsrf_token', self.xsrf_token()), | 353 ('xsrf_token', self.xsrf_token()), |
| 354 ('category', category), |
| 353 ] | 355 ] |
| 354 if revision: | 356 if revision: |
| 355 params.append(('revision', revision)) | 357 params.append(('revision', revision)) |
| 356 if master: | 358 if master: |
| 357 # Temporarily allow empty master names for old configurations. The try | 359 # Temporarily allow empty master names for old configurations. The try |
| 358 # job will not be associated with a master name on rietveld. This is | 360 # job will not be associated with a master name on rietveld. This is |
| 359 # going to be deprecated. | 361 # going to be deprecated. |
| 360 params.append(('master', master)) | 362 params.append(('master', master)) |
| 361 return self.post('/%d/try/%d' % (issue, patchset), params) | 363 return self.post('/%d/try/%d' % (issue, patchset), params) |
| 362 | 364 |
| 363 def trigger_distributed_try_jobs( | 365 def trigger_distributed_try_jobs( |
| 364 self, issue, patchset, reason, clobber, revision, masters): | 366 self, issue, patchset, reason, clobber, revision, masters, |
| 367 category='cq'): |
| 365 """Requests new try jobs. | 368 """Requests new try jobs. |
| 366 | 369 |
| 367 |masters| is a map of masters: map of builders: [tests] to run. | 370 |masters| is a map of masters: map of builders: [tests] to run. |
| 371 |category| is used to distinguish regular jobs and experimental jobs. |
| 368 """ | 372 """ |
| 369 for (master, builders_and_tests) in masters.iteritems(): | 373 for (master, builders_and_tests) in masters.iteritems(): |
| 370 self.trigger_try_jobs( | 374 self.trigger_try_jobs( |
| 371 issue, patchset, reason, clobber, revision, builders_and_tests, | 375 issue, patchset, reason, clobber, revision, builders_and_tests, |
| 372 master) | 376 master, category) |
| 373 | 377 |
| 374 def get_pending_try_jobs(self, cursor=None, limit=100): | 378 def get_pending_try_jobs(self, cursor=None, limit=100): |
| 375 """Retrieves the try job requests in pending state. | 379 """Retrieves the try job requests in pending state. |
| 376 | 380 |
| 377 Returns a tuple of the list of try jobs and the cursor for the next request. | 381 Returns a tuple of the list of try jobs and the cursor for the next request. |
| 378 """ | 382 """ |
| 379 url = '/get_pending_try_patchsets?limit=%d' % limit | 383 url = '/get_pending_try_patchsets?limit=%d' % limit |
| 380 extra = ('&cursor=' + cursor) if cursor else '' | 384 extra = ('&cursor=' + cursor) if cursor else '' |
| 381 data = json.loads(self.get(url + extra)) | 385 data = json.loads(self.get(url + extra)) |
| 382 return data['jobs'], data['cursor'] | 386 return data['jobs'], data['cursor'] |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 logging.info('ReadOnlyRietveld: posting comment "%s" to issue %d' % | 716 logging.info('ReadOnlyRietveld: posting comment "%s" to issue %d' % |
| 713 (message, issue)) | 717 (message, issue)) |
| 714 | 718 |
| 715 def set_flag(self, issue, patchset, flag, value): # pylint:disable=R0201 | 719 def set_flag(self, issue, patchset, flag, value): # pylint:disable=R0201 |
| 716 logging.info('ReadOnlyRietveld: setting flag "%s" to "%s" for issue %d' % | 720 logging.info('ReadOnlyRietveld: setting flag "%s" to "%s" for issue %d' % |
| 717 (flag, value, issue)) | 721 (flag, value, issue)) |
| 718 ReadOnlyRietveld._local_changes.setdefault(issue, {})[flag] = value | 722 ReadOnlyRietveld._local_changes.setdefault(issue, {})[flag] = value |
| 719 | 723 |
| 720 def trigger_try_jobs( # pylint:disable=R0201 | 724 def trigger_try_jobs( # pylint:disable=R0201 |
| 721 self, issue, patchset, reason, clobber, revision, builders_and_tests, | 725 self, issue, patchset, reason, clobber, revision, builders_and_tests, |
| 722 master=None): | 726 master=None, category='cq'): |
| 723 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % | 727 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % |
| 724 (builders_and_tests, issue)) | 728 (builders_and_tests, issue)) |
| 725 | 729 |
| 726 def trigger_distributed_try_jobs( # pylint:disable=R0201 | 730 def trigger_distributed_try_jobs( # pylint:disable=R0201 |
| 727 self, issue, patchset, reason, clobber, revision, masters): | 731 self, issue, patchset, reason, clobber, revision, masters, |
| 732 category='cq'): |
| 728 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % | 733 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % |
| 729 (masters, issue)) | 734 (masters, issue)) |
| OLD | NEW |