Commit 28bcf52a authored by Sergiy Belozorov's avatar Sergiy Belozorov Committed by Commit Bot

Implement review command in the update_wpr script

R=perezju@chromium.org

Bug: 895891
Change-Id: I0bfd1342187e809cbe4e51daaa5eebfa145d3389
Reviewed-on: https://chromium-review.googlesource.com/c/1477709
Commit-Queue: Sergiy Belozorov <sergiyb@chromium.org>
Reviewed-by: default avatarJuan Antonio Navarro Pérez <perezju@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634636}
parent a4d7bf62
......@@ -26,6 +26,7 @@ HISTOGRAM2CSV = os.path.join(
RUN_BENCHMARK = os.path.join(SRC_ROOT, 'tools', 'perf', 'run_benchmark')
DATA_DIR = os.path.join(SRC_ROOT, 'tools', 'perf', 'page_sets', 'data')
RECORD_WPR = os.path.join(SRC_ROOT, 'tools', 'perf', 'record_wpr')
DEFAULT_REVIEWERS = ['perezju@chromium.org']
class WprUpdater(object):
......@@ -38,6 +39,8 @@ class WprUpdater(object):
self.repeat = args.repeat
self.binary = args.binary
self.output_dir = tempfile.mkdtemp()
self.bug_id = args.bug_id
self.reviewers = args.reviewers or DEFAULT_REVIEWERS
def _PrepareEnv(self):
# Enforce the same local settings for recording and replays on the bots.
......@@ -252,6 +255,26 @@ class WprUpdater(object):
self._UploadArchiveToGoogleStorage(archive)
return self._GitAddArtifactHash(archive)
def UploadCL(self, short_description=False):
cli_helpers.Step('UPLOAD CL: %s' % self.story)
if short_description:
commit_message = 'Automated upload'
else:
commit_message = (
'Add %s system health story\n\nThis CL was created automatically '
'with tools/perf/update_wpr script' % self.story)
if self.bug_id:
commit_message += '\n\nBug: %s' % self.bug_id
cli_helpers.Run(['git', 'commit', '-a', '-m', commit_message])
commit_msg_file = os.path.join(self.output_dir, 'commit_message.tmp')
with open(commit_msg_file, 'w') as fd:
fd.write(commit_message)
return cli_helpers.Run([
'git', 'cl', 'upload',
'--reviewers', ','.join(self.reviewers),
'--force', # to prevent message editor from appearing
'--message-file', commit_msg_file], ok_fail=True)
def Main(argv):
parser = argparse.ArgumentParser()
......@@ -262,6 +285,12 @@ def Main(argv):
'-d', '--device-id', dest='device_id',
help='Specify the device serial number listed by `adb devices`. When not '
'specified, the script runs in desktop mode.')
parser.add_argument(
'-b', '--bug', dest='bug_id',
help='Bug ID to be referenced on created CL')
parser.add_argument(
'-r', '--reviewer', action='append', dest='reviewers',
help='Email of the reviewer(s) for the created CL.')
parser.add_argument(
'--pageset-repeat', type=int, default=1, dest='repeat',
help='Number of times to repeat the entire pageset.')
......@@ -270,7 +299,7 @@ def Main(argv):
help='Path to the Chromium/Chrome binary relative to output directory. '
'Defaults to default Chrome browser installed if not specified.')
parser.add_argument(
'command', choices=['live', 'record', 'replay', 'upload'],
'command', choices=['live', 'record', 'replay', 'upload', 'review'],
help='Mode in which to run this script.')
args = parser.parse_args(argv)
......@@ -284,4 +313,6 @@ def Main(argv):
updater.ReplayWpr()
elif args.command == 'upload':
updater.UploadWpr()
elif args.command == 'review':
updater.UploadCL()
updater.Cleanup()
......@@ -44,7 +44,8 @@ class UpdateWprTest(unittest.TestCase):
mock.patch('os.path.exists', return_value=True).start()
self.wpr_updater = update_wpr.WprUpdater(argparse.Namespace(
story='<story>', device_id=None, repeat=1, binary=None))
story='<story>', device_id=None, repeat=1, binary=None, bug_id=None,
reviewers=['someone@chromium.org']))
def tearDown(self):
mock.patch.stopall()
......@@ -55,12 +56,16 @@ class UpdateWprTest(unittest.TestCase):
'live',
'-s', 'foo:bar:story:2019',
'-d', 'H2345234FC33',
'--binary', '<binary>'
'--binary', '<binary>',
'-b', '1234',
'-r', 'test_user1@chromium.org',
'-r', 'test_user2@chromium.org',
])
self.assertListEqual(wpr_updater_cls.mock_calls, [
mock.call(argparse.Namespace(
binary='<binary>', command='live', device_id='H2345234FC33',
repeat=1, story='foo:bar:story:2019')),
repeat=1, story='foo:bar:story:2019', bug_id='1234',
reviewers=['test_user1@chromium.org', 'test_user2@chromium.org'])),
mock.call().LiveRun(),
mock.call().Cleanup(),
])
......@@ -205,6 +210,20 @@ class UpdateWprTest(unittest.TestCase):
mock.call(['git', 'add', '<archive>.sha1'])
])
def testUploadCL(self):
self._run.return_value = 42
self.assertEqual(self.wpr_updater.UploadCL(), 42)
self.assertListEqual(self._run.mock_calls, [
mock.call([
'git', 'commit', '-a', '-m', 'Add <story> system health story\n\n'
'This CL was created automatically with tools/perf/update_wpr script'
]),
mock.call([
'git', 'cl', 'upload', '--reviewers', 'someone@chromium.org',
'--force', '--message-file', '/tmp/dir/commit_message.tmp'
], ok_fail=True),
])
if __name__ == "__main__":
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment