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

Side by Side Diff: tools/perf/core/trybot_command.py

Issue 2400003002: Remove CL upload logic from Perf Try Job workflow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 2 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
« no previous file with comments | « no previous file | tools/perf/core/trybot_command_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import argparse 5 import argparse
6 import json 6 import json
7 import logging 7 import logging
8 import os 8 import os
9 import platform 9 import platform
10 import re
11 import subprocess 10 import subprocess
11 import tempfile
12 import urllib2 12 import urllib2
13 13
14 14
15 from core import path_util 15 from core import path_util
16 16
17 from telemetry import benchmark 17 from telemetry import benchmark
18 from telemetry import decorators 18 from telemetry import decorators
19 from telemetry.core import discover 19 from telemetry.core import discover
20 from telemetry.util import command_line 20 from telemetry.util import command_line
21 from telemetry.util import matching 21 from telemetry.util import matching
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 if branch_name == 'HEAD': 439 if branch_name == 'HEAD':
440 raise TrybotError('Not on a valid branch, looks like branch ' 440 raise TrybotError('Not on a valid branch, looks like branch '
441 'is dettached. [branch:%s]' % branch_name) 441 'is dettached. [branch:%s]' % branch_name)
442 442
443 # Check if the tree is dirty: make sure the index is up to date and then 443 # Check if the tree is dirty: make sure the index is up to date and then
444 # run diff-index 444 # run diff-index
445 RunGit(['update-index', '--refresh', '-q'], ignore_return_code=True) 445 RunGit(['update-index', '--refresh', '-q'], ignore_return_code=True)
446 output = RunGit(['diff-index', 'HEAD']) 446 output = RunGit(['diff-index', 'HEAD'])
447 if output: 447 if output:
448 raise TrybotError( 448 raise TrybotError(
449 'Cannot send a try job with a dirty tree. Please commit ' 449 'Cannot send a try job with a dirty tree.\nPlease commit locally and '
450 'your changes locally first in %s repository.' % repo_path) 450 'upload your changes to rietveld in %s repository.' % repo_path)
451
452 # Make sure the tree does have local commits.
453 output = RunGit(['footers', 'HEAD'])
454 if output:
455 raise TrybotError('No local changes found in %s repository.' % repo_path)
456 451
457 return (repo_name, branch_name) 452 return (repo_name, branch_name)
458 453
459 def _GetBaseGitHashForRepo(self, branch_name, git_url): 454 def _GetBaseGitHashForRepo(self, branch_name, git_url):
460 """Gets the base revision for the repo on which local changes are made. 455 """Gets the base revision for the repo on which local changes are made.
461 456
462 Finds the upstream of the current branch that it is set to and gets 457 Finds the upstream of the current branch that it is set to and gets
463 the HEAD revision from upstream. This also checks if the remote URL on 458 the HEAD revision from upstream. This also checks if the remote URL on
464 the upstream is supported by Perf Try job. 459 the upstream is supported by Perf Try job.
465 460
(...skipping 28 matching lines...) Expand all
494 if cur_remote == '.': 489 if cur_remote == '.':
495 return False 490 return False
496 cur_remote_url = RunGit( 491 cur_remote_url = RunGit(
497 ['config', 'remote.%s.url' % cur_remote], 492 ['config', 'remote.%s.url' % cur_remote],
498 'Failed to get remote.%s.url from git config' % cur_remote) 493 'Failed to get remote.%s.url from git config' % cur_remote)
499 if cur_remote_url.lower() == repo_git_url: 494 if cur_remote_url.lower() == repo_git_url:
500 return True 495 return True
501 raise TrybotError('URL %s on remote %s is not recognized on branch.'% ( 496 raise TrybotError('URL %s on remote %s is not recognized on branch.'% (
502 cur_remote_url, cur_remote)) 497 cur_remote_url, cur_remote))
503 498
499 def _GetChangeList(self):
500 """Gets the codereview URL for the current changes."""
501 temp_file = None
502 json_output = None
503 try:
504 fd, temp_file = tempfile.mkstemp(suffix='.json', prefix='cl')
Michael Achenbach 2016/10/08 09:43:29 nit: Maybe add a slightly longer and more verbose
prasadv1 2016/10/10 18:22:56 Done.
505 os.close(fd)
506 RunGit(['cl', 'issue', '--json', temp_file],
507 'Failed to run "git cl issue" command.')
508 try:
509 with open(temp_file, 'r') as f:
510 json_output = json.load(f)
511 except (IOError, ValueError):
Michael Achenbach 2016/10/08 09:43:29 Catching this here and setting json_output to None
prasadv1 2016/10/10 18:22:56 Done.
512 json_output = None
513 finally:
514 try:
515 if temp_file:
516 os.remove(temp_file)
517 except OSError:
518 pass
519
520 # Make sure the local commits are uploaded to rietveld.
521 if not json_output.get('issue'):
522 raise TrybotError(
523 'PLEASE NOTE: The workflow for Perf Try jobs is changed. '
524 'In order to run the perf try job, you must first upload your '
525 'changes to rietveld.')
526 return json_output.get('issue_url')
527
504 def _AttemptTryjob(self, options, extra_args): 528 def _AttemptTryjob(self, options, extra_args):
505 """Attempts to run a tryjob from a repo directory. 529 """Attempts to run a tryjob from a repo directory.
506 530
507 Args: 531 Args:
508 options: Command line arguments to run benchmark. 532 options: Command line arguments to run benchmark.
509 extra_args: Extra arugments to run benchmark. 533 extra_args: Extra arugments to run benchmark.
510 534
511 Returns: 535 Returns:
512 If successful returns 0, otherwise 1. 536 If successful returns 0, otherwise 1.
513 """ 537 """
(...skipping 12 matching lines...) Expand all
526 if not repo_info: 550 if not repo_info:
527 raise TrybotError('Unsupported repository %s' % repo_name) 551 raise TrybotError('Unsupported repository %s' % repo_name)
528 552
529 deps_override = None 553 deps_override = None
530 if repo_name != 'src': 554 if repo_name != 'src':
531 if not options.deps_revision: 555 if not options.deps_revision:
532 options.deps_revision = self._GetBaseGitHashForRepo( 556 options.deps_revision = self._GetBaseGitHashForRepo(
533 branch_name, repo_info.get('url')) 557 branch_name, repo_info.get('url'))
534 deps_override = {repo_info.get('src'): options.deps_revision} 558 deps_override = {repo_info.get('src'): options.deps_revision}
535 559
536 arguments = [options.benchmark_name] + extra_args 560 rietveld_url = self._GetChangeList()
537 561 print ('\nRunning try job....\nview progress here %s.'
538 rietveld_url = self._UploadPatchToRietveld(repo_name, options)
539 print ('\nUploaded try job to rietveld.\nview progress here %s.'
540 '\n\tRepo Name: %s\n\tPath: %s\n\tBranch: %s' % ( 562 '\n\tRepo Name: %s\n\tPath: %s\n\tBranch: %s' % (
541 rietveld_url, repo_name, repo_path, branch_name)) 563 rietveld_url, repo_name, repo_path, branch_name))
542 564
543 for bot_platform in self._builder_names: 565 for bot_platform in self._builder_names:
544 if not self._builder_names[bot_platform]: 566 if not self._builder_names[bot_platform]:
545 logging.warning('No builder is found for %s', bot_platform) 567 logging.warning('No builder is found for %s', bot_platform)
546 continue 568 continue
547 try: 569 try:
570 arguments = [options.benchmark_name] + extra_args
548 self._RunTryJob(bot_platform, arguments, deps_override) 571 self._RunTryJob(bot_platform, arguments, deps_override)
549 # Even if git cl try throws TrybotError exception for any platform, 572 # Even if git cl try throws TrybotError exception for any platform,
550 # keep sending try jobs to other platforms. 573 # keep sending try jobs to other platforms.
551 except TrybotError, err: 574 except TrybotError, err:
552 print err 575 print err
553 except TrybotError, error: 576 except TrybotError, error:
554 print error 577 print error
555 return 1 578 return 1
556 finally: 579 finally:
557 # Restore to original working directory. 580 # Restore to original working directory.
558 os.chdir(original_workdir) 581 os.chdir(original_workdir)
559 return 0 582 return 0
560 583
561 def _UploadPatchToRietveld(self, repo_name, options):
562 """Uploads the patch to rietveld and returns rietveld URL."""
563 output = RunGit(['cl', 'upload', '-f', '--bypass-hooks', '-m',
564 ('CL for %s perf tryjob to run %s benchmark '
565 'on %s platform(s)' % (
566 repo_name, options.benchmark_name, options.trybot))],
567 'Could not upload to rietveld for %s' % repo_name)
568
569 match = re.search(r'https://codereview.chromium.org/[\d]+', output)
570 if not match:
571 raise TrybotError('Could not upload CL to rietveld for %s! Output %s' %
572 (repo_name, output))
573 return match.group(0)
574
575 def _RunTryJob(self, bot_platform, arguments, deps_override): 584 def _RunTryJob(self, bot_platform, arguments, deps_override):
576 """Executes perf try job with benchmark test properties. 585 """Executes perf try job with benchmark test properties.
577 586
578 Args: 587 Args:
579 bot_platform: Name of the platform to be generated. 588 bot_platform: Name of the platform to be generated.
580 arguments: Command line arguments. 589 arguments: Command line arguments.
581 deps_override: DEPS revision if needs to be overridden. 590 deps_override: DEPS revision if needs to be overridden.
582 591
583 Raises: 592 Raises:
584 TrybotError: When trybot fails to upload CL or run git try. 593 TrybotError: When trybot fails to upload CL or run git try.
(...skipping 10 matching lines...) Expand all
595 # Add deps overrides to git try --properties arg. 604 # Add deps overrides to git try --properties arg.
596 if deps_override: 605 if deps_override:
597 git_try_command.extend([ 606 git_try_command.extend([
598 '-p', 'deps_revision_overrides=%s' % json.dumps(deps_override)]) 607 '-p', 'deps_revision_overrides=%s' % json.dumps(deps_override)])
599 error_msg_on_fail += ' with DEPS override (%s)' % deps_override 608 error_msg_on_fail += ' with DEPS override (%s)' % deps_override
600 for bot in self._builder_names[bot_platform]: 609 for bot in self._builder_names[bot_platform]:
601 git_try_command.extend(['-b', bot]) 610 git_try_command.extend(['-b', bot])
602 611
603 RunGit(git_try_command, error_msg_on_fail) 612 RunGit(git_try_command, error_msg_on_fail)
604 print 'Perf Try job sent to rietveld for %s platform.' % bot_platform 613 print 'Perf Try job sent to rietveld for %s platform.' % bot_platform
OLDNEW
« no previous file with comments | « no previous file | tools/perf/core/trybot_command_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698