• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3# found in the LICENSE file.
4
5"""Small test to send a put request to buildbucket."""
6
7import re
8
9
10class BisectJob(object):
11  """A buildbot bisect job started and monitored through buildbucket."""
12
13  def __init__(self, try_job_id, good_revision, bad_revision,
14               test_command, metric, repeats, timeout_minutes, bug_id,
15               gs_bucket, recipe_tester_name, builder_host=None,
16               builder_port=None, test_type='perf',
17               required_initial_confidence=None):
18    if not all([good_revision, bad_revision, test_command, metric,
19                repeats, timeout_minutes, recipe_tester_name]):
20      raise ValueError('At least one of the values required for BisectJob '
21                       'construction was not given or was given with a None '
22                       'value.')
23    self.try_job_id = try_job_id
24    self.good_revision = good_revision
25    self.bad_revision = bad_revision
26    self.command = BisectJob.EnsureCommandPath(test_command)
27    self.metric = metric
28    self.repeat_count = repeats
29    self.max_time_minutes = timeout_minutes
30    self.bug_id = bug_id
31    self.gs_bucket = gs_bucket
32    self.builder_host = builder_host
33    self.builder_port = builder_port
34    self.test_type = test_type
35    self.recipe_tester_name = recipe_tester_name
36    self.required_initial_confidence = required_initial_confidence
37
38  @staticmethod
39  def EnsureCommandPath(command):
40    old_perf_path_regex = re.compile(r'(?<!src/)tools/perf')
41    if old_perf_path_regex.search(command):
42      return old_perf_path_regex.sub('src/tools/perf', command)
43    old_perf_path_regex_win = re.compile(r'(?<!src\\)tools\\perf')
44    if old_perf_path_regex_win.search(command):
45      return old_perf_path_regex_win.sub(r'src\\tools\\perf', command)
46    return command
47
48  def GetBuildParameters(self):
49    """Prepares a nested dict containing the bisect config."""
50    # TODO(robertocn): Some of these should be optional.
51    bisect_config = {
52        'try_job_id': self.try_job_id,
53        'test_type': self.test_type,
54        'command': self.command,
55        'good_revision': self.good_revision,
56        'bad_revision': self.bad_revision,
57        'metric': self.metric,
58        'repeat_count': self.repeat_count,
59        'max_time_minutes': self.max_time_minutes,
60        'bug_id': self.bug_id,
61        'gs_bucket': self.gs_bucket,
62        'builder_host': self.builder_host,
63        'builder_port': self.builder_port,
64        'recipe_tester_name': self.recipe_tester_name,
65    }
66    if self.required_initial_confidence:
67      bisect_config['required_initial_confidence'] = (
68          self.required_initial_confidence)
69    properties = {'bisect_config': bisect_config}
70    parameters = {
71        'builder_name': self.recipe_tester_name,
72        'properties': properties,
73    }
74    return parameters
75
76  # TODO(robertocn): Add methods to query the status of a job form buildbucket.
77  # TODO(robertocn): Add static method to get a job by it's buildbucket id.
78  # TODO(robertocn): Add appropriate tests.
79