mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 1 | # Copyright Martin J. Bligh, Google Inc 2008 |
| 2 | # Released under the GPL v2 |
| 3 | |
| 4 | """ |
| 5 | This class allows you to communicate with the frontend to submit jobs etc |
| 6 | It is designed for writing more sophisiticated server-side control files that |
| 7 | can recursively add and manage other jobs. |
| 8 | |
| 9 | We turn the JSON dictionaries into real objects that are more idiomatic |
| 10 | |
mbligh | c31e402 | 2008-12-11 19:32:30 +0000 | [diff] [blame] | 11 | For docs, see: |
Aviv Keshet | 2c709f6 | 2013-05-07 12:52:15 -0700 | [diff] [blame] | 12 | http://www.chromium.org/chromium-os/testing/afe-rpc-infrastructure |
mbligh | c31e402 | 2008-12-11 19:32:30 +0000 | [diff] [blame] | 13 | http://docs.djangoproject.com/en/dev/ref/models/querysets/#queryset-api |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 14 | """ |
| 15 | |
Dan Shi | e8e0c05 | 2015-09-01 00:27:27 -0700 | [diff] [blame] | 16 | import getpass |
| 17 | import os |
| 18 | import re |
| 19 | import time |
| 20 | import traceback |
| 21 | |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 22 | import common |
| 23 | from autotest_lib.frontend.afe import rpc_client_lib |
Dan Shi | e8e0c05 | 2015-09-01 00:27:27 -0700 | [diff] [blame] | 24 | from autotest_lib.client.common_lib import control_data |
mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 25 | from autotest_lib.client.common_lib import global_config |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 26 | from autotest_lib.client.common_lib import utils |
Dan Shi | e8e0c05 | 2015-09-01 00:27:27 -0700 | [diff] [blame] | 27 | from autotest_lib.client.common_lib.cros.graphite import autotest_stats |
Scott Zawalski | 63470dd | 2012-09-05 00:49:43 -0400 | [diff] [blame] | 28 | from autotest_lib.tko import db |
| 29 | |
| 30 | |
mbligh | 4e57661 | 2008-12-22 14:56:36 +0000 | [diff] [blame] | 31 | try: |
| 32 | from autotest_lib.server.site_common import site_utils as server_utils |
| 33 | except: |
| 34 | from autotest_lib.server import utils as server_utils |
| 35 | form_ntuples_from_machines = server_utils.form_ntuples_from_machines |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 36 | |
mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 37 | GLOBAL_CONFIG = global_config.global_config |
| 38 | DEFAULT_SERVER = 'autotest' |
| 39 | |
Dan Shi | e8e0c05 | 2015-09-01 00:27:27 -0700 | [diff] [blame] | 40 | _tko_timer = autotest_stats.Timer('tko') |
| 41 | |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 42 | def dump_object(header, obj): |
| 43 | """ |
| 44 | Standard way to print out the frontend objects (eg job, host, acl, label) |
| 45 | in a human-readable fashion for debugging |
| 46 | """ |
| 47 | result = header + '\n' |
| 48 | for key in obj.hash: |
| 49 | if key == 'afe' or key == 'hash': |
| 50 | continue |
| 51 | result += '%20s: %s\n' % (key, obj.hash[key]) |
| 52 | return result |
| 53 | |
| 54 | |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 55 | class RpcClient(object): |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 56 | """ |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 57 | Abstract RPC class for communicating with the autotest frontend |
| 58 | Inherited for both TKO and AFE uses. |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 59 | |
mbligh | 1ef218d | 2009-08-03 16:57:56 +0000 | [diff] [blame] | 60 | All the constructors go in the afe / tko class. |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 61 | Manipulating methods go in the object classes themselves |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 62 | """ |
mbligh | 99b24f4 | 2009-06-08 16:45:55 +0000 | [diff] [blame] | 63 | def __init__(self, path, user, server, print_log, debug, reply_debug): |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 64 | """ |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 65 | Create a cached instance of a connection to the frontend |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 66 | |
| 67 | user: username to connect as |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 68 | server: frontend server to connect to |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 69 | print_log: pring a logging message to stdout on every operation |
| 70 | debug: print out all RPC traffic |
| 71 | """ |
Dan Shi | ff78f11 | 2015-06-12 13:34:02 -0700 | [diff] [blame] | 72 | if not user and utils.is_in_container(): |
| 73 | user = GLOBAL_CONFIG.get_config_value('SSP', 'user', default=None) |
mbligh | c31e402 | 2008-12-11 19:32:30 +0000 | [diff] [blame] | 74 | if not user: |
mbligh | db59e3c | 2009-11-21 01:45:18 +0000 | [diff] [blame] | 75 | user = getpass.getuser() |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 76 | if not server: |
mbligh | 475f776 | 2009-01-30 00:34:04 +0000 | [diff] [blame] | 77 | if 'AUTOTEST_WEB' in os.environ: |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 78 | server = os.environ['AUTOTEST_WEB'] |
mbligh | 475f776 | 2009-01-30 00:34:04 +0000 | [diff] [blame] | 79 | else: |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 80 | server = GLOBAL_CONFIG.get_config_value('SERVER', 'hostname', |
| 81 | default=DEFAULT_SERVER) |
| 82 | self.server = server |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 83 | self.user = user |
| 84 | self.print_log = print_log |
| 85 | self.debug = debug |
mbligh | 99b24f4 | 2009-06-08 16:45:55 +0000 | [diff] [blame] | 86 | self.reply_debug = reply_debug |
Scott Zawalski | 347aaf4 | 2012-04-03 16:33:00 -0400 | [diff] [blame] | 87 | headers = {'AUTHORIZATION': self.user} |
| 88 | rpc_server = 'http://' + server + path |
mbligh | 1354c9d | 2008-12-22 14:56:13 +0000 | [diff] [blame] | 89 | if debug: |
| 90 | print 'SERVER: %s' % rpc_server |
| 91 | print 'HEADERS: %s' % headers |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 92 | self.proxy = rpc_client_lib.get_proxy(rpc_server, headers=headers) |
| 93 | |
| 94 | |
| 95 | def run(self, call, **dargs): |
| 96 | """ |
| 97 | Make a RPC call to the AFE server |
| 98 | """ |
| 99 | rpc_call = getattr(self.proxy, call) |
| 100 | if self.debug: |
| 101 | print 'DEBUG: %s %s' % (call, dargs) |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 102 | try: |
mbligh | 99b24f4 | 2009-06-08 16:45:55 +0000 | [diff] [blame] | 103 | result = utils.strip_unicode(rpc_call(**dargs)) |
| 104 | if self.reply_debug: |
| 105 | print result |
| 106 | return result |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 107 | except Exception: |
| 108 | print 'FAILED RPC CALL: %s %s' % (call, dargs) |
| 109 | raise |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 110 | |
| 111 | |
| 112 | def log(self, message): |
| 113 | if self.print_log: |
| 114 | print message |
| 115 | |
| 116 | |
jamesren | c394022 | 2010-02-19 21:57:37 +0000 | [diff] [blame] | 117 | class Planner(RpcClient): |
| 118 | def __init__(self, user=None, server=None, print_log=True, debug=False, |
| 119 | reply_debug=False): |
| 120 | super(Planner, self).__init__(path='/planner/server/rpc/', |
| 121 | user=user, |
| 122 | server=server, |
| 123 | print_log=print_log, |
| 124 | debug=debug, |
| 125 | reply_debug=reply_debug) |
| 126 | |
| 127 | |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 128 | class TKO(RpcClient): |
mbligh | 99b24f4 | 2009-06-08 16:45:55 +0000 | [diff] [blame] | 129 | def __init__(self, user=None, server=None, print_log=True, debug=False, |
| 130 | reply_debug=False): |
Scott Zawalski | 347aaf4 | 2012-04-03 16:33:00 -0400 | [diff] [blame] | 131 | super(TKO, self).__init__(path='/new_tko/server/noauth/rpc/', |
mbligh | 99b24f4 | 2009-06-08 16:45:55 +0000 | [diff] [blame] | 132 | user=user, |
| 133 | server=server, |
| 134 | print_log=print_log, |
| 135 | debug=debug, |
| 136 | reply_debug=reply_debug) |
Scott Zawalski | 63470dd | 2012-09-05 00:49:43 -0400 | [diff] [blame] | 137 | self._db = None |
| 138 | |
| 139 | |
Dan Shi | e8e0c05 | 2015-09-01 00:27:27 -0700 | [diff] [blame] | 140 | @_tko_timer.decorate |
Scott Zawalski | 63470dd | 2012-09-05 00:49:43 -0400 | [diff] [blame] | 141 | def get_job_test_statuses_from_db(self, job_id): |
| 142 | """Get job test statuses from the database. |
| 143 | |
| 144 | Retrieve a set of fields from a job that reflect the status of each test |
| 145 | run within a job. |
| 146 | fields retrieved: status, test_name, reason, test_started_time, |
| 147 | test_finished_time, afe_job_id, job_owner, hostname. |
| 148 | |
| 149 | @param job_id: The afe job id to look up. |
| 150 | @returns a TestStatus object of the resulting information. |
| 151 | """ |
| 152 | if self._db is None: |
Dan Shi | e8e0c05 | 2015-09-01 00:27:27 -0700 | [diff] [blame] | 153 | self._db = db.db() |
Fang Deng | 5c50833 | 2014-03-19 10:26:00 -0700 | [diff] [blame] | 154 | fields = ['status', 'test_name', 'subdir', 'reason', |
| 155 | 'test_started_time', 'test_finished_time', 'afe_job_id', |
| 156 | 'job_owner', 'hostname', 'job_tag'] |
Scott Zawalski | 63470dd | 2012-09-05 00:49:43 -0400 | [diff] [blame] | 157 | table = 'tko_test_view_2' |
| 158 | where = 'job_tag like "%s-%%"' % job_id |
| 159 | test_status = [] |
| 160 | # Run commit before we query to ensure that we are pulling the latest |
| 161 | # results. |
| 162 | self._db.commit() |
| 163 | for entry in self._db.select(','.join(fields), table, (where, None)): |
| 164 | status_dict = {} |
| 165 | for key,value in zip(fields, entry): |
| 166 | # All callers expect values to be a str object. |
| 167 | status_dict[key] = str(value) |
| 168 | # id is used by TestStatus to uniquely identify each Test Status |
| 169 | # obj. |
| 170 | status_dict['id'] = [status_dict['reason'], status_dict['hostname'], |
| 171 | status_dict['test_name']] |
| 172 | test_status.append(status_dict) |
| 173 | |
| 174 | return [TestStatus(self, e) for e in test_status] |
mbligh | c31e402 | 2008-12-11 19:32:30 +0000 | [diff] [blame] | 175 | |
| 176 | |
| 177 | def get_status_counts(self, job, **data): |
| 178 | entries = self.run('get_status_counts', |
mbligh | 1ef218d | 2009-08-03 16:57:56 +0000 | [diff] [blame] | 179 | group_by=['hostname', 'test_name', 'reason'], |
mbligh | c31e402 | 2008-12-11 19:32:30 +0000 | [diff] [blame] | 180 | job_tag__startswith='%s-' % job, **data) |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 181 | return [TestStatus(self, e) for e in entries['groups']] |
mbligh | c31e402 | 2008-12-11 19:32:30 +0000 | [diff] [blame] | 182 | |
| 183 | |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 184 | class AFE(RpcClient): |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 185 | def __init__(self, user=None, server=None, print_log=True, debug=False, |
mbligh | 99b24f4 | 2009-06-08 16:45:55 +0000 | [diff] [blame] | 186 | reply_debug=False, job=None): |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 187 | self.job = job |
Scott Zawalski | 347aaf4 | 2012-04-03 16:33:00 -0400 | [diff] [blame] | 188 | super(AFE, self).__init__(path='/afe/server/noauth/rpc/', |
mbligh | 99b24f4 | 2009-06-08 16:45:55 +0000 | [diff] [blame] | 189 | user=user, |
| 190 | server=server, |
| 191 | print_log=print_log, |
| 192 | debug=debug, |
| 193 | reply_debug=reply_debug) |
mbligh | c31e402 | 2008-12-11 19:32:30 +0000 | [diff] [blame] | 194 | |
mbligh | 1ef218d | 2009-08-03 16:57:56 +0000 | [diff] [blame] | 195 | |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 196 | def host_statuses(self, live=None): |
jamesren | 121eee6 | 2010-04-13 19:10:12 +0000 | [diff] [blame] | 197 | dead_statuses = ['Repair Failed', 'Repairing'] |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 198 | statuses = self.run('get_static_data')['host_statuses'] |
| 199 | if live == True: |
mbligh | c2847b7 | 2009-03-25 19:32:20 +0000 | [diff] [blame] | 200 | return list(set(statuses) - set(dead_statuses)) |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 201 | if live == False: |
| 202 | return dead_statuses |
| 203 | else: |
| 204 | return statuses |
| 205 | |
| 206 | |
mbligh | 7109401 | 2009-12-19 05:35:21 +0000 | [diff] [blame] | 207 | @staticmethod |
| 208 | def _dict_for_host_query(hostnames=(), status=None, label=None): |
| 209 | query_args = {} |
mbligh | 4e545a5 | 2009-12-19 05:30:39 +0000 | [diff] [blame] | 210 | if hostnames: |
| 211 | query_args['hostname__in'] = hostnames |
| 212 | if status: |
| 213 | query_args['status'] = status |
| 214 | if label: |
| 215 | query_args['labels__name'] = label |
mbligh | 7109401 | 2009-12-19 05:35:21 +0000 | [diff] [blame] | 216 | return query_args |
| 217 | |
| 218 | |
| 219 | def get_hosts(self, hostnames=(), status=None, label=None, **dargs): |
| 220 | query_args = dict(dargs) |
| 221 | query_args.update(self._dict_for_host_query(hostnames=hostnames, |
| 222 | status=status, |
| 223 | label=label)) |
| 224 | hosts = self.run('get_hosts', **query_args) |
| 225 | return [Host(self, h) for h in hosts] |
| 226 | |
| 227 | |
| 228 | def get_hostnames(self, status=None, label=None, **dargs): |
| 229 | """Like get_hosts() but returns hostnames instead of Host objects.""" |
| 230 | # This implementation can be replaced with a more efficient one |
| 231 | # that does not query for entire host objects in the future. |
| 232 | return [host_obj.hostname for host_obj in |
| 233 | self.get_hosts(status=status, label=label, **dargs)] |
| 234 | |
| 235 | |
| 236 | def reverify_hosts(self, hostnames=(), status=None, label=None): |
| 237 | query_args = dict(locked=False, |
| 238 | aclgroup__users__login=self.user) |
| 239 | query_args.update(self._dict_for_host_query(hostnames=hostnames, |
| 240 | status=status, |
| 241 | label=label)) |
mbligh | 4e545a5 | 2009-12-19 05:30:39 +0000 | [diff] [blame] | 242 | return self.run('reverify_hosts', **query_args) |
| 243 | |
| 244 | |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 245 | def create_host(self, hostname, **dargs): |
mbligh | 54459c7 | 2009-01-21 19:26:44 +0000 | [diff] [blame] | 246 | id = self.run('add_host', hostname=hostname, **dargs) |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 247 | return self.get_hosts(id=id)[0] |
| 248 | |
| 249 | |
MK Ryu | acf3592 | 2014-10-03 14:56:49 -0700 | [diff] [blame] | 250 | def get_host_attribute(self, attr, **dargs): |
| 251 | host_attrs = self.run('get_host_attribute', attribute=attr, **dargs) |
| 252 | return [HostAttribute(self, a) for a in host_attrs] |
| 253 | |
| 254 | |
Chris Masone | 8abb6fc | 2012-01-31 09:27:36 -0800 | [diff] [blame] | 255 | def set_host_attribute(self, attr, val, **dargs): |
| 256 | self.run('set_host_attribute', attribute=attr, value=val, **dargs) |
| 257 | |
| 258 | |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 259 | def get_labels(self, **dargs): |
| 260 | labels = self.run('get_labels', **dargs) |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 261 | return [Label(self, l) for l in labels] |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 262 | |
| 263 | |
| 264 | def create_label(self, name, **dargs): |
mbligh | 54459c7 | 2009-01-21 19:26:44 +0000 | [diff] [blame] | 265 | id = self.run('add_label', name=name, **dargs) |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 266 | return self.get_labels(id=id)[0] |
| 267 | |
| 268 | |
| 269 | def get_acls(self, **dargs): |
| 270 | acls = self.run('get_acl_groups', **dargs) |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 271 | return [Acl(self, a) for a in acls] |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 272 | |
| 273 | |
| 274 | def create_acl(self, name, **dargs): |
mbligh | 54459c7 | 2009-01-21 19:26:44 +0000 | [diff] [blame] | 275 | id = self.run('add_acl_group', name=name, **dargs) |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 276 | return self.get_acls(id=id)[0] |
| 277 | |
| 278 | |
mbligh | 54459c7 | 2009-01-21 19:26:44 +0000 | [diff] [blame] | 279 | def get_users(self, **dargs): |
| 280 | users = self.run('get_users', **dargs) |
| 281 | return [User(self, u) for u in users] |
| 282 | |
| 283 | |
mbligh | 1354c9d | 2008-12-22 14:56:13 +0000 | [diff] [blame] | 284 | def generate_control_file(self, tests, **dargs): |
| 285 | ret = self.run('generate_control_file', tests=tests, **dargs) |
| 286 | return ControlFile(self, ret) |
| 287 | |
| 288 | |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 289 | def get_jobs(self, summary=False, **dargs): |
| 290 | if summary: |
| 291 | jobs_data = self.run('get_jobs_summary', **dargs) |
| 292 | else: |
| 293 | jobs_data = self.run('get_jobs', **dargs) |
mbligh | afbba0c | 2009-06-08 16:44:45 +0000 | [diff] [blame] | 294 | jobs = [] |
| 295 | for j in jobs_data: |
| 296 | job = Job(self, j) |
| 297 | # Set up some extra information defaults |
| 298 | job.testname = re.sub('\s.*', '', job.name) # arbitrary default |
| 299 | job.platform_results = {} |
| 300 | job.platform_reasons = {} |
| 301 | jobs.append(job) |
| 302 | return jobs |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 303 | |
| 304 | |
| 305 | def get_host_queue_entries(self, **data): |
| 306 | entries = self.run('get_host_queue_entries', **data) |
mbligh | f9e3586 | 2009-02-26 01:03:11 +0000 | [diff] [blame] | 307 | job_statuses = [JobStatus(self, e) for e in entries] |
mbligh | 99b24f4 | 2009-06-08 16:45:55 +0000 | [diff] [blame] | 308 | |
| 309 | # Sadly, get_host_queue_entries doesn't return platforms, we have |
| 310 | # to get those back from an explicit get_hosts queury, then patch |
| 311 | # the new host objects back into the host list. |
| 312 | hostnames = [s.host.hostname for s in job_statuses if s.host] |
| 313 | host_hash = {} |
| 314 | for host in self.get_hosts(hostname__in=hostnames): |
| 315 | host_hash[host.hostname] = host |
| 316 | for status in job_statuses: |
| 317 | if status.host: |
Fang Deng | 97dafbc | 2015-04-23 23:06:18 -0700 | [diff] [blame] | 318 | status.host = host_hash.get(status.host.hostname) |
mbligh | f9e3586 | 2009-02-26 01:03:11 +0000 | [diff] [blame] | 319 | # filter job statuses that have either host or meta_host |
| 320 | return [status for status in job_statuses if (status.host or |
| 321 | status.meta_host)] |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 322 | |
| 323 | |
MK Ryu | 1b2d7f9 | 2015-02-24 17:45:02 -0800 | [diff] [blame] | 324 | def get_special_tasks(self, **data): |
| 325 | tasks = self.run('get_special_tasks', **data) |
| 326 | return [SpecialTask(self, t) for t in tasks] |
| 327 | |
| 328 | |
J. Richard Barnette | 9f10c9f | 2015-04-13 16:44:50 -0700 | [diff] [blame] | 329 | def get_host_special_tasks(self, host_id, **data): |
| 330 | tasks = self.run('get_host_special_tasks', |
| 331 | host_id=host_id, **data) |
| 332 | return [SpecialTask(self, t) for t in tasks] |
| 333 | |
| 334 | |
J. Richard Barnette | 8dbd6d3 | 2015-05-01 11:01:12 -0700 | [diff] [blame] | 335 | def get_host_status_task(self, host_id, end_time): |
| 336 | task = self.run('get_host_status_task', |
J. Richard Barnette | 8abbfd6 | 2015-06-23 12:46:54 -0700 | [diff] [blame] | 337 | host_id=host_id, end_time=end_time) |
J. Richard Barnette | bc9a795 | 2015-04-16 17:43:27 -0700 | [diff] [blame] | 338 | return SpecialTask(self, task) if task else None |
| 339 | |
| 340 | |
J. Richard Barnette | 8abbfd6 | 2015-06-23 12:46:54 -0700 | [diff] [blame] | 341 | def get_host_diagnosis_interval(self, host_id, end_time, success): |
| 342 | return self.run('get_host_diagnosis_interval', |
| 343 | host_id=host_id, end_time=end_time, |
| 344 | success=success) |
| 345 | |
| 346 | |
mbligh | b9db516 | 2009-04-17 22:21:41 +0000 | [diff] [blame] | 347 | def create_job_by_test(self, tests, kernel=None, use_container=False, |
Eric Li | e0493a4 | 2010-11-15 13:05:43 -0800 | [diff] [blame] | 348 | kernel_cmdline=None, **dargs): |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 349 | """ |
| 350 | Given a test name, fetch the appropriate control file from the server |
mbligh | 4e57661 | 2008-12-22 14:56:36 +0000 | [diff] [blame] | 351 | and submit it. |
| 352 | |
Eric Li | e0493a4 | 2010-11-15 13:05:43 -0800 | [diff] [blame] | 353 | @param kernel: A comma separated list of kernel versions to boot. |
| 354 | @param kernel_cmdline: The command line used to boot all kernels listed |
| 355 | in the kernel parameter. |
| 356 | |
mbligh | 4e57661 | 2008-12-22 14:56:36 +0000 | [diff] [blame] | 357 | Returns a list of job objects |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 358 | """ |
mbligh | b9db516 | 2009-04-17 22:21:41 +0000 | [diff] [blame] | 359 | assert ('hosts' in dargs or |
| 360 | 'atomic_group_name' in dargs and 'synch_count' in dargs) |
showard | a2cd72b | 2009-10-01 18:43:53 +0000 | [diff] [blame] | 361 | if kernel: |
| 362 | kernel_list = re.split('[\s,]+', kernel.strip()) |
Eric Li | e0493a4 | 2010-11-15 13:05:43 -0800 | [diff] [blame] | 363 | kernel_info = [] |
| 364 | for version in kernel_list: |
| 365 | kernel_dict = {'version': version} |
| 366 | if kernel_cmdline is not None: |
| 367 | kernel_dict['cmdline'] = kernel_cmdline |
| 368 | kernel_info.append(kernel_dict) |
showard | a2cd72b | 2009-10-01 18:43:53 +0000 | [diff] [blame] | 369 | else: |
| 370 | kernel_info = None |
| 371 | control_file = self.generate_control_file( |
Dale Curtis | 74a314b | 2011-06-23 14:55:46 -0700 | [diff] [blame] | 372 | tests=tests, kernel=kernel_info, use_container=use_container) |
mbligh | 1354c9d | 2008-12-22 14:56:13 +0000 | [diff] [blame] | 373 | if control_file.is_server: |
Aviv Keshet | 3dd8beb | 2013-05-13 17:36:04 -0700 | [diff] [blame] | 374 | dargs['control_type'] = control_data.CONTROL_TYPE_NAMES.SERVER |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 375 | else: |
Aviv Keshet | 3dd8beb | 2013-05-13 17:36:04 -0700 | [diff] [blame] | 376 | dargs['control_type'] = control_data.CONTROL_TYPE_NAMES.CLIENT |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 377 | dargs['dependencies'] = dargs.get('dependencies', []) + \ |
mbligh | 1354c9d | 2008-12-22 14:56:13 +0000 | [diff] [blame] | 378 | control_file.dependencies |
| 379 | dargs['control_file'] = control_file.control_file |
mbligh | 672666c | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 380 | if not dargs.get('synch_count', None): |
mbligh | c99fccf | 2009-07-11 00:59:33 +0000 | [diff] [blame] | 381 | dargs['synch_count'] = control_file.synch_count |
mbligh | b9db516 | 2009-04-17 22:21:41 +0000 | [diff] [blame] | 382 | if 'hosts' in dargs and len(dargs['hosts']) < dargs['synch_count']: |
| 383 | # will not be able to satisfy this request |
mbligh | 38b0915 | 2009-04-28 18:34:25 +0000 | [diff] [blame] | 384 | return None |
| 385 | return self.create_job(**dargs) |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 386 | |
| 387 | |
| 388 | def create_job(self, control_file, name=' ', priority='Medium', |
Aviv Keshet | 3dd8beb | 2013-05-13 17:36:04 -0700 | [diff] [blame] | 389 | control_type=control_data.CONTROL_TYPE_NAMES.CLIENT, **dargs): |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 390 | id = self.run('create_job', name=name, priority=priority, |
| 391 | control_file=control_file, control_type=control_type, **dargs) |
| 392 | return self.get_jobs(id=id)[0] |
| 393 | |
| 394 | |
mbligh | 282ce89 | 2010-01-06 18:40:17 +0000 | [diff] [blame] | 395 | def run_test_suites(self, pairings, kernel, kernel_label=None, |
| 396 | priority='Medium', wait=True, poll_interval=10, |
Simran Basi | 7e60574 | 2013-11-12 13:43:36 -0800 | [diff] [blame] | 397 | email_from=None, email_to=None, timeout_mins=10080, |
Simran Basi | 3421702 | 2012-11-06 13:43:15 -0800 | [diff] [blame] | 398 | max_runtime_mins=10080, kernel_cmdline=None): |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 399 | """ |
| 400 | Run a list of test suites on a particular kernel. |
mbligh | 1ef218d | 2009-08-03 16:57:56 +0000 | [diff] [blame] | 401 | |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 402 | Poll for them to complete, and return whether they worked or not. |
mbligh | 1ef218d | 2009-08-03 16:57:56 +0000 | [diff] [blame] | 403 | |
mbligh | 282ce89 | 2010-01-06 18:40:17 +0000 | [diff] [blame] | 404 | @param pairings: List of MachineTestPairing objects to invoke. |
| 405 | @param kernel: Name of the kernel to run. |
| 406 | @param kernel_label: Label (string) of the kernel to run such as |
| 407 | '<kernel-version> : <config> : <date>' |
| 408 | If any pairing object has its job_label attribute set it |
| 409 | will override this value for that particular job. |
Eric Li | e0493a4 | 2010-11-15 13:05:43 -0800 | [diff] [blame] | 410 | @param kernel_cmdline: The command line to boot the kernel(s) with. |
mbligh | 282ce89 | 2010-01-06 18:40:17 +0000 | [diff] [blame] | 411 | @param wait: boolean - Wait for the results to come back? |
| 412 | @param poll_interval: Interval between polling for job results (in mins) |
| 413 | @param email_from: Send notification email upon completion from here. |
| 414 | @param email_from: Send notification email upon completion to here. |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 415 | """ |
| 416 | jobs = [] |
| 417 | for pairing in pairings: |
mbligh | 0c4f8d7 | 2009-05-12 20:52:18 +0000 | [diff] [blame] | 418 | try: |
| 419 | new_job = self.invoke_test(pairing, kernel, kernel_label, |
Simran Basi | 7e60574 | 2013-11-12 13:43:36 -0800 | [diff] [blame] | 420 | priority, timeout_mins=timeout_mins, |
Eric Li | e0493a4 | 2010-11-15 13:05:43 -0800 | [diff] [blame] | 421 | kernel_cmdline=kernel_cmdline, |
Simran Basi | 3421702 | 2012-11-06 13:43:15 -0800 | [diff] [blame] | 422 | max_runtime_mins=max_runtime_mins) |
mbligh | 0c4f8d7 | 2009-05-12 20:52:18 +0000 | [diff] [blame] | 423 | if not new_job: |
| 424 | continue |
mbligh | 0c4f8d7 | 2009-05-12 20:52:18 +0000 | [diff] [blame] | 425 | jobs.append(new_job) |
| 426 | except Exception, e: |
| 427 | traceback.print_exc() |
mbligh | b9db516 | 2009-04-17 22:21:41 +0000 | [diff] [blame] | 428 | if not wait or not jobs: |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 429 | return |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 430 | tko = TKO() |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 431 | while True: |
| 432 | time.sleep(60 * poll_interval) |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 433 | result = self.poll_all_jobs(tko, jobs, email_from, email_to) |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 434 | if result is not None: |
| 435 | return result |
| 436 | |
| 437 | |
mbligh | 45ffc43 | 2008-12-09 23:35:17 +0000 | [diff] [blame] | 438 | def result_notify(self, job, email_from, email_to): |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 439 | """ |
mbligh | 45ffc43 | 2008-12-09 23:35:17 +0000 | [diff] [blame] | 440 | Notify about the result of a job. Will always print, if email data |
| 441 | is provided, will send email for it as well. |
| 442 | |
| 443 | job: job object to notify about |
| 444 | email_from: send notification email upon completion from here |
| 445 | email_from: send notification email upon completion to here |
| 446 | """ |
| 447 | if job.result == True: |
| 448 | subject = 'Testing PASSED: ' |
| 449 | else: |
| 450 | subject = 'Testing FAILED: ' |
| 451 | subject += '%s : %s\n' % (job.name, job.id) |
| 452 | text = [] |
| 453 | for platform in job.results_platform_map: |
| 454 | for status in job.results_platform_map[platform]: |
| 455 | if status == 'Total': |
| 456 | continue |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 457 | for host in job.results_platform_map[platform][status]: |
| 458 | text.append('%20s %10s %10s' % (platform, status, host)) |
| 459 | if status == 'Failed': |
| 460 | for test_status in job.test_status[host].fail: |
| 461 | text.append('(%s, %s) : %s' % \ |
| 462 | (host, test_status.test_name, |
| 463 | test_status.reason)) |
| 464 | text.append('') |
mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 465 | |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 466 | base_url = 'http://' + self.server |
mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 467 | |
| 468 | params = ('columns=test', |
| 469 | 'rows=machine_group', |
| 470 | "condition=tag~'%s-%%25'" % job.id, |
| 471 | 'title=Report') |
| 472 | query_string = '&'.join(params) |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 473 | url = '%s/tko/compose_query.cgi?%s' % (base_url, query_string) |
| 474 | text.append(url + '\n') |
| 475 | url = '%s/afe/#tab_id=view_job&object_id=%s' % (base_url, job.id) |
| 476 | text.append(url + '\n') |
mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 477 | |
| 478 | body = '\n'.join(text) |
| 479 | print '---------------------------------------------------' |
| 480 | print 'Subject: ', subject |
mbligh | 45ffc43 | 2008-12-09 23:35:17 +0000 | [diff] [blame] | 481 | print body |
mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 482 | print '---------------------------------------------------' |
mbligh | 45ffc43 | 2008-12-09 23:35:17 +0000 | [diff] [blame] | 483 | if email_from and email_to: |
mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 484 | print 'Sending email ...' |
mbligh | 45ffc43 | 2008-12-09 23:35:17 +0000 | [diff] [blame] | 485 | utils.send_email(email_from, email_to, subject, body) |
| 486 | print |
mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 487 | |
mbligh | 45ffc43 | 2008-12-09 23:35:17 +0000 | [diff] [blame] | 488 | |
mbligh | 1354c9d | 2008-12-22 14:56:13 +0000 | [diff] [blame] | 489 | def print_job_result(self, job): |
| 490 | """ |
| 491 | Print the result of a single job. |
| 492 | job: a job object |
| 493 | """ |
| 494 | if job.result is None: |
| 495 | print 'PENDING', |
| 496 | elif job.result == True: |
| 497 | print 'PASSED', |
| 498 | elif job.result == False: |
| 499 | print 'FAILED', |
mbligh | 912c3f3 | 2009-03-25 19:31:30 +0000 | [diff] [blame] | 500 | elif job.result == "Abort": |
| 501 | print 'ABORT', |
mbligh | 1354c9d | 2008-12-22 14:56:13 +0000 | [diff] [blame] | 502 | print ' %s : %s' % (job.id, job.name) |
| 503 | |
| 504 | |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 505 | def poll_all_jobs(self, tko, jobs, email_from=None, email_to=None): |
mbligh | 45ffc43 | 2008-12-09 23:35:17 +0000 | [diff] [blame] | 506 | """ |
| 507 | Poll all jobs in a list. |
| 508 | jobs: list of job objects to poll |
| 509 | email_from: send notification email upon completion from here |
| 510 | email_from: send notification email upon completion to here |
| 511 | |
| 512 | Returns: |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 513 | a) All complete successfully (return True) |
| 514 | b) One or more has failed (return False) |
| 515 | c) Cannot tell yet (return None) |
| 516 | """ |
mbligh | 45ffc43 | 2008-12-09 23:35:17 +0000 | [diff] [blame] | 517 | results = [] |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 518 | for job in jobs: |
mbligh | 676dcbe | 2009-06-15 21:57:27 +0000 | [diff] [blame] | 519 | if getattr(job, 'result', None) is None: |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 520 | job.result = self.poll_job_results(tko, job) |
mbligh | 676dcbe | 2009-06-15 21:57:27 +0000 | [diff] [blame] | 521 | if job.result is not None: |
| 522 | self.result_notify(job, email_from, email_to) |
mbligh | 45ffc43 | 2008-12-09 23:35:17 +0000 | [diff] [blame] | 523 | |
mbligh | 676dcbe | 2009-06-15 21:57:27 +0000 | [diff] [blame] | 524 | results.append(job.result) |
mbligh | 1354c9d | 2008-12-22 14:56:13 +0000 | [diff] [blame] | 525 | self.print_job_result(job) |
mbligh | 45ffc43 | 2008-12-09 23:35:17 +0000 | [diff] [blame] | 526 | |
| 527 | if None in results: |
| 528 | return None |
mbligh | 912c3f3 | 2009-03-25 19:31:30 +0000 | [diff] [blame] | 529 | elif False in results or "Abort" in results: |
mbligh | 45ffc43 | 2008-12-09 23:35:17 +0000 | [diff] [blame] | 530 | return False |
| 531 | else: |
| 532 | return True |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 533 | |
| 534 | |
mbligh | 1f23f36 | 2008-12-22 14:46:12 +0000 | [diff] [blame] | 535 | def _included_platform(self, host, platforms): |
| 536 | """ |
| 537 | See if host's platforms matches any of the patterns in the included |
| 538 | platforms list. |
| 539 | """ |
| 540 | if not platforms: |
| 541 | return True # No filtering of platforms |
| 542 | for platform in platforms: |
| 543 | if re.search(platform, host.platform): |
| 544 | return True |
| 545 | return False |
| 546 | |
| 547 | |
mbligh | 7b31228 | 2009-01-07 16:45:43 +0000 | [diff] [blame] | 548 | def invoke_test(self, pairing, kernel, kernel_label, priority='Medium', |
Eric Li | e0493a4 | 2010-11-15 13:05:43 -0800 | [diff] [blame] | 549 | kernel_cmdline=None, **dargs): |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 550 | """ |
| 551 | Given a pairing of a control file to a machine label, find all machines |
| 552 | with that label, and submit that control file to them. |
mbligh | 1ef218d | 2009-08-03 16:57:56 +0000 | [diff] [blame] | 553 | |
mbligh | 282ce89 | 2010-01-06 18:40:17 +0000 | [diff] [blame] | 554 | @param kernel_label: Label (string) of the kernel to run such as |
| 555 | '<kernel-version> : <config> : <date>' |
| 556 | If any pairing object has its job_label attribute set it |
| 557 | will override this value for that particular job. |
| 558 | |
| 559 | @returns A list of job objects. |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 560 | """ |
mbligh | 282ce89 | 2010-01-06 18:40:17 +0000 | [diff] [blame] | 561 | # The pairing can override the job label. |
| 562 | if pairing.job_label: |
| 563 | kernel_label = pairing.job_label |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 564 | job_name = '%s : %s' % (pairing.machine_label, kernel_label) |
| 565 | hosts = self.get_hosts(multiple_labels=[pairing.machine_label]) |
mbligh | 1f23f36 | 2008-12-22 14:46:12 +0000 | [diff] [blame] | 566 | platforms = pairing.platforms |
| 567 | hosts = [h for h in hosts if self._included_platform(h, platforms)] |
mbligh | c2847b7 | 2009-03-25 19:32:20 +0000 | [diff] [blame] | 568 | dead_statuses = self.host_statuses(live=False) |
| 569 | host_list = [h.hostname for h in hosts if h.status not in dead_statuses] |
mbligh | 1f23f36 | 2008-12-22 14:46:12 +0000 | [diff] [blame] | 570 | print 'HOSTS: %s' % host_list |
mbligh | b9db516 | 2009-04-17 22:21:41 +0000 | [diff] [blame] | 571 | if pairing.atomic_group_sched: |
mbligh | c99fccf | 2009-07-11 00:59:33 +0000 | [diff] [blame] | 572 | dargs['synch_count'] = pairing.synch_count |
mbligh | b9db516 | 2009-04-17 22:21:41 +0000 | [diff] [blame] | 573 | dargs['atomic_group_name'] = pairing.machine_label |
| 574 | else: |
| 575 | dargs['hosts'] = host_list |
mbligh | 38b0915 | 2009-04-28 18:34:25 +0000 | [diff] [blame] | 576 | new_job = self.create_job_by_test(name=job_name, |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 577 | dependencies=[pairing.machine_label], |
| 578 | tests=[pairing.control_file], |
| 579 | priority=priority, |
| 580 | kernel=kernel, |
Eric Li | e0493a4 | 2010-11-15 13:05:43 -0800 | [diff] [blame] | 581 | kernel_cmdline=kernel_cmdline, |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 582 | use_container=pairing.container, |
| 583 | **dargs) |
mbligh | 38b0915 | 2009-04-28 18:34:25 +0000 | [diff] [blame] | 584 | if new_job: |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 585 | if pairing.testname: |
| 586 | new_job.testname = pairing.testname |
mbligh | 4e57661 | 2008-12-22 14:56:36 +0000 | [diff] [blame] | 587 | print 'Invoked test %s : %s' % (new_job.id, job_name) |
mbligh | 38b0915 | 2009-04-28 18:34:25 +0000 | [diff] [blame] | 588 | return new_job |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 589 | |
| 590 | |
mbligh | b9db516 | 2009-04-17 22:21:41 +0000 | [diff] [blame] | 591 | def _job_test_results(self, tko, job, debug, tests=[]): |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 592 | """ |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 593 | Retrieve test results for a job |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 594 | """ |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 595 | job.test_status = {} |
| 596 | try: |
| 597 | test_statuses = tko.get_status_counts(job=job.id) |
| 598 | except Exception: |
| 599 | print "Ignoring exception on poll job; RPC interface is flaky" |
| 600 | traceback.print_exc() |
| 601 | return |
| 602 | |
| 603 | for test_status in test_statuses: |
mbligh | 7479a18 | 2009-01-07 16:46:24 +0000 | [diff] [blame] | 604 | # SERVER_JOB is buggy, and often gives false failures. Ignore it. |
| 605 | if test_status.test_name == 'SERVER_JOB': |
| 606 | continue |
mbligh | b9db516 | 2009-04-17 22:21:41 +0000 | [diff] [blame] | 607 | # if tests is not empty, restrict list of test_statuses to tests |
| 608 | if tests and test_status.test_name not in tests: |
| 609 | continue |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 610 | if debug: |
| 611 | print test_status |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 612 | hostname = test_status.hostname |
| 613 | if hostname not in job.test_status: |
| 614 | job.test_status[hostname] = TestResults() |
| 615 | job.test_status[hostname].add(test_status) |
| 616 | |
| 617 | |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 618 | def _job_results_platform_map(self, job, debug): |
mbligh | c9e427e | 2009-04-28 18:35:06 +0000 | [diff] [blame] | 619 | # Figure out which hosts passed / failed / aborted in a job |
| 620 | # Creates a 2-dimensional hash, stored as job.results_platform_map |
| 621 | # 1st index - platform type (string) |
| 622 | # 2nd index - Status (string) |
| 623 | # 'Completed' / 'Failed' / 'Aborted' |
| 624 | # Data indexed by this hash is a list of hostnames (text strings) |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 625 | job.results_platform_map = {} |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 626 | try: |
mbligh | 45ffc43 | 2008-12-09 23:35:17 +0000 | [diff] [blame] | 627 | job_statuses = self.get_host_queue_entries(job=job.id) |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 628 | except Exception: |
| 629 | print "Ignoring exception on poll job; RPC interface is flaky" |
| 630 | traceback.print_exc() |
| 631 | return None |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 632 | |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 633 | platform_map = {} |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 634 | job.job_status = {} |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 635 | job.metahost_index = {} |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 636 | for job_status in job_statuses: |
mbligh | c9e427e | 2009-04-28 18:35:06 +0000 | [diff] [blame] | 637 | # This is basically "for each host / metahost in the job" |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 638 | if job_status.host: |
| 639 | hostname = job_status.host.hostname |
| 640 | else: # This is a metahost |
| 641 | metahost = job_status.meta_host |
| 642 | index = job.metahost_index.get(metahost, 1) |
| 643 | job.metahost_index[metahost] = index + 1 |
| 644 | hostname = '%s.%s' % (metahost, index) |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 645 | job.job_status[hostname] = job_status.status |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 646 | status = job_status.status |
mbligh | 0ecbe63 | 2009-05-13 21:34:56 +0000 | [diff] [blame] | 647 | # Skip hosts that failed verify or repair: |
| 648 | # that's a machine failure, not a job failure |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 649 | if hostname in job.test_status: |
| 650 | verify_failed = False |
| 651 | for failure in job.test_status[hostname].fail: |
mbligh | 0ecbe63 | 2009-05-13 21:34:56 +0000 | [diff] [blame] | 652 | if (failure.test_name == 'verify' or |
| 653 | failure.test_name == 'repair'): |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 654 | verify_failed = True |
| 655 | break |
| 656 | if verify_failed: |
| 657 | continue |
mbligh | c9e427e | 2009-04-28 18:35:06 +0000 | [diff] [blame] | 658 | if hostname in job.test_status and job.test_status[hostname].fail: |
| 659 | # If the any tests failed in the job, we want to mark the |
| 660 | # job result as failed, overriding the default job status. |
| 661 | if status != "Aborted": # except if it's an aborted job |
| 662 | status = 'Failed' |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 663 | if job_status.host: |
| 664 | platform = job_status.host.platform |
| 665 | else: # This is a metahost |
| 666 | platform = job_status.meta_host |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 667 | if platform not in platform_map: |
| 668 | platform_map[platform] = {'Total' : [hostname]} |
| 669 | else: |
| 670 | platform_map[platform]['Total'].append(hostname) |
| 671 | new_host_list = platform_map[platform].get(status, []) + [hostname] |
| 672 | platform_map[platform][status] = new_host_list |
mbligh | 45ffc43 | 2008-12-09 23:35:17 +0000 | [diff] [blame] | 673 | job.results_platform_map = platform_map |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 674 | |
| 675 | |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 676 | def set_platform_results(self, test_job, platform, result): |
| 677 | """ |
| 678 | Result must be None, 'FAIL', 'WARN' or 'GOOD' |
| 679 | """ |
| 680 | if test_job.platform_results[platform] is not None: |
| 681 | # We're already done, and results recorded. This can't change later. |
| 682 | return |
| 683 | test_job.platform_results[platform] = result |
| 684 | # Note that self.job refers to the metajob we're IN, not the job |
| 685 | # that we're excuting from here. |
| 686 | testname = '%s.%s' % (test_job.testname, platform) |
| 687 | if self.job: |
| 688 | self.job.record(result, None, testname, status='') |
| 689 | |
MK Ryu | 9c5fbbe | 2015-02-11 15:46:22 -0800 | [diff] [blame] | 690 | |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 691 | def poll_job_results(self, tko, job, enough=1, debug=False): |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 692 | """ |
Chris Masone | 3a560bd | 2011-11-14 16:53:56 -0800 | [diff] [blame] | 693 | Analyse all job results by platform |
mbligh | 1ef218d | 2009-08-03 16:57:56 +0000 | [diff] [blame] | 694 | |
Chris Masone | 3a560bd | 2011-11-14 16:53:56 -0800 | [diff] [blame] | 695 | params: |
| 696 | tko: a TKO object representing the results DB. |
| 697 | job: the job to be examined. |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 698 | enough: the acceptable delta between the number of completed |
| 699 | tests and the total number of tests. |
Chris Masone | 3a560bd | 2011-11-14 16:53:56 -0800 | [diff] [blame] | 700 | debug: enable debugging output. |
| 701 | |
| 702 | returns: |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 703 | False: if any platform has more than |enough| failures |
| 704 | None: if any platform has less than |enough| machines |
Chris Masone | 3a560bd | 2011-11-14 16:53:56 -0800 | [diff] [blame] | 705 | not yet Good. |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 706 | True: if all platforms have at least |enough| machines |
Chris Masone | 3a560bd | 2011-11-14 16:53:56 -0800 | [diff] [blame] | 707 | Good. |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 708 | """ |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 709 | self._job_test_results(tko, job, debug) |
mbligh | e7fcf56 | 2009-05-21 01:43:17 +0000 | [diff] [blame] | 710 | if job.test_status == {}: |
| 711 | return None |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 712 | self._job_results_platform_map(job, debug) |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 713 | |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 714 | good_platforms = [] |
mbligh | 912c3f3 | 2009-03-25 19:31:30 +0000 | [diff] [blame] | 715 | failed_platforms = [] |
| 716 | aborted_platforms = [] |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 717 | unknown_platforms = [] |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 718 | platform_map = job.results_platform_map |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 719 | for platform in platform_map: |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 720 | if not job.platform_results.has_key(platform): |
| 721 | # record test start, but there's no way to do this right now |
| 722 | job.platform_results[platform] = None |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 723 | total = len(platform_map[platform]['Total']) |
| 724 | completed = len(platform_map[platform].get('Completed', [])) |
mbligh | 912c3f3 | 2009-03-25 19:31:30 +0000 | [diff] [blame] | 725 | failed = len(platform_map[platform].get('Failed', [])) |
| 726 | aborted = len(platform_map[platform].get('Aborted', [])) |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 727 | |
mbligh | 1ef218d | 2009-08-03 16:57:56 +0000 | [diff] [blame] | 728 | # We set up what we want to record here, but don't actually do |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 729 | # it yet, until we have a decisive answer for this platform |
| 730 | if aborted or failed: |
| 731 | bad = aborted + failed |
| 732 | if (bad > 1) or (bad * 2 >= total): |
| 733 | platform_test_result = 'FAIL' |
| 734 | else: |
| 735 | platform_test_result = 'WARN' |
| 736 | |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 737 | if aborted > enough: |
mbligh | 912c3f3 | 2009-03-25 19:31:30 +0000 | [diff] [blame] | 738 | aborted_platforms.append(platform) |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 739 | self.set_platform_results(job, platform, platform_test_result) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 740 | elif (failed * 2 >= total) or (failed > enough): |
mbligh | 912c3f3 | 2009-03-25 19:31:30 +0000 | [diff] [blame] | 741 | failed_platforms.append(platform) |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 742 | self.set_platform_results(job, platform, platform_test_result) |
Chris Masone | 6fed646 | 2011-10-20 16:36:43 -0700 | [diff] [blame] | 743 | elif (completed >= enough) and (completed + enough >= total): |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 744 | good_platforms.append(platform) |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 745 | self.set_platform_results(job, platform, 'GOOD') |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 746 | else: |
| 747 | unknown_platforms.append(platform) |
| 748 | detail = [] |
| 749 | for status in platform_map[platform]: |
| 750 | if status == 'Total': |
| 751 | continue |
| 752 | detail.append('%s=%s' % (status,platform_map[platform][status])) |
| 753 | if debug: |
mbligh | 1ef218d | 2009-08-03 16:57:56 +0000 | [diff] [blame] | 754 | print '%20s %d/%d %s' % (platform, completed, total, |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 755 | ' '.join(detail)) |
| 756 | print |
mbligh | 1ef218d | 2009-08-03 16:57:56 +0000 | [diff] [blame] | 757 | |
mbligh | 912c3f3 | 2009-03-25 19:31:30 +0000 | [diff] [blame] | 758 | if len(aborted_platforms) > 0: |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 759 | if debug: |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 760 | print 'Result aborted - platforms: ', |
| 761 | print ' '.join(aborted_platforms) |
mbligh | 912c3f3 | 2009-03-25 19:31:30 +0000 | [diff] [blame] | 762 | return "Abort" |
| 763 | if len(failed_platforms) > 0: |
| 764 | if debug: |
| 765 | print 'Result bad - platforms: ' + ' '.join(failed_platforms) |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 766 | return False |
| 767 | if len(unknown_platforms) > 0: |
| 768 | if debug: |
| 769 | platform_list = ' '.join(unknown_platforms) |
| 770 | print 'Result unknown - platforms: ', platform_list |
| 771 | return None |
| 772 | if debug: |
| 773 | platform_list = ' '.join(good_platforms) |
| 774 | print 'Result good - all platforms passed: ', platform_list |
| 775 | return True |
| 776 | |
| 777 | |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 778 | class TestResults(object): |
| 779 | """ |
| 780 | Container class used to hold the results of the tests for a job |
| 781 | """ |
| 782 | def __init__(self): |
| 783 | self.good = [] |
| 784 | self.fail = [] |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 785 | self.pending = [] |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 786 | |
| 787 | |
| 788 | def add(self, result): |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 789 | if result.complete_count > result.pass_count: |
| 790 | self.fail.append(result) |
| 791 | elif result.incomplete_count > 0: |
| 792 | self.pending.append(result) |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 793 | else: |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 794 | self.good.append(result) |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 795 | |
| 796 | |
| 797 | class RpcObject(object): |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 798 | """ |
| 799 | Generic object used to construct python objects from rpc calls |
| 800 | """ |
| 801 | def __init__(self, afe, hash): |
| 802 | self.afe = afe |
| 803 | self.hash = hash |
| 804 | self.__dict__.update(hash) |
| 805 | |
| 806 | |
| 807 | def __str__(self): |
| 808 | return dump_object(self.__repr__(), self) |
| 809 | |
| 810 | |
mbligh | 1354c9d | 2008-12-22 14:56:13 +0000 | [diff] [blame] | 811 | class ControlFile(RpcObject): |
| 812 | """ |
| 813 | AFE control file object |
| 814 | |
| 815 | Fields: synch_count, dependencies, control_file, is_server |
| 816 | """ |
| 817 | def __repr__(self): |
| 818 | return 'CONTROL FILE: %s' % self.control_file |
| 819 | |
| 820 | |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 821 | class Label(RpcObject): |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 822 | """ |
| 823 | AFE label object |
| 824 | |
| 825 | Fields: |
| 826 | name, invalid, platform, kernel_config, id, only_if_needed |
| 827 | """ |
| 828 | def __repr__(self): |
| 829 | return 'LABEL: %s' % self.name |
| 830 | |
| 831 | |
| 832 | def add_hosts(self, hosts): |
Chris Masone | 3a560bd | 2011-11-14 16:53:56 -0800 | [diff] [blame] | 833 | return self.afe.run('label_add_hosts', id=self.id, hosts=hosts) |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 834 | |
| 835 | |
| 836 | def remove_hosts(self, hosts): |
Chris Masone | 3a560bd | 2011-11-14 16:53:56 -0800 | [diff] [blame] | 837 | return self.afe.run('label_remove_hosts', id=self.id, hosts=hosts) |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 838 | |
| 839 | |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 840 | class Acl(RpcObject): |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 841 | """ |
| 842 | AFE acl object |
| 843 | |
| 844 | Fields: |
| 845 | users, hosts, description, name, id |
| 846 | """ |
| 847 | def __repr__(self): |
| 848 | return 'ACL: %s' % self.name |
| 849 | |
| 850 | |
| 851 | def add_hosts(self, hosts): |
| 852 | self.afe.log('Adding hosts %s to ACL %s' % (hosts, self.name)) |
| 853 | return self.afe.run('acl_group_add_hosts', self.id, hosts) |
| 854 | |
| 855 | |
| 856 | def remove_hosts(self, hosts): |
| 857 | self.afe.log('Removing hosts %s from ACL %s' % (hosts, self.name)) |
| 858 | return self.afe.run('acl_group_remove_hosts', self.id, hosts) |
| 859 | |
| 860 | |
mbligh | 54459c7 | 2009-01-21 19:26:44 +0000 | [diff] [blame] | 861 | def add_users(self, users): |
| 862 | self.afe.log('Adding users %s to ACL %s' % (users, self.name)) |
| 863 | return self.afe.run('acl_group_add_users', id=self.name, users=users) |
| 864 | |
| 865 | |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 866 | class Job(RpcObject): |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 867 | """ |
| 868 | AFE job object |
| 869 | |
| 870 | Fields: |
| 871 | name, control_file, control_type, synch_count, reboot_before, |
| 872 | run_verify, priority, email_list, created_on, dependencies, |
| 873 | timeout, owner, reboot_after, id |
| 874 | """ |
| 875 | def __repr__(self): |
| 876 | return 'JOB: %s' % self.id |
| 877 | |
| 878 | |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 879 | class JobStatus(RpcObject): |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 880 | """ |
| 881 | AFE job_status object |
| 882 | |
| 883 | Fields: |
| 884 | status, complete, deleted, meta_host, host, active, execution_subdir, id |
| 885 | """ |
| 886 | def __init__(self, afe, hash): |
MK Ryu | 1b2d7f9 | 2015-02-24 17:45:02 -0800 | [diff] [blame] | 887 | super(JobStatus, self).__init__(afe, hash) |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 888 | self.job = Job(afe, self.job) |
Dale Curtis | 8adf789 | 2011-09-08 16:13:36 -0700 | [diff] [blame] | 889 | if getattr(self, 'host'): |
mbligh | 99b24f4 | 2009-06-08 16:45:55 +0000 | [diff] [blame] | 890 | self.host = Host(afe, self.host) |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 891 | |
| 892 | |
| 893 | def __repr__(self): |
mbligh | 451ede1 | 2009-02-12 21:54:03 +0000 | [diff] [blame] | 894 | if self.host and self.host.hostname: |
| 895 | hostname = self.host.hostname |
| 896 | else: |
| 897 | hostname = 'None' |
| 898 | return 'JOB STATUS: %s-%s' % (self.job.id, hostname) |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 899 | |
| 900 | |
MK Ryu | 1b2d7f9 | 2015-02-24 17:45:02 -0800 | [diff] [blame] | 901 | class SpecialTask(RpcObject): |
| 902 | """ |
| 903 | AFE special task object |
| 904 | """ |
| 905 | def __init__(self, afe, hash): |
| 906 | super(SpecialTask, self).__init__(afe, hash) |
| 907 | self.host = Host(afe, self.host) |
| 908 | |
| 909 | |
| 910 | def __repr__(self): |
| 911 | return 'SPECIAL TASK: %s' % self.id |
| 912 | |
| 913 | |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 914 | class Host(RpcObject): |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 915 | """ |
| 916 | AFE host object |
| 917 | |
| 918 | Fields: |
| 919 | status, lock_time, locked_by, locked, hostname, invalid, |
| 920 | synch_id, labels, platform, protection, dirty, id |
| 921 | """ |
| 922 | def __repr__(self): |
| 923 | return 'HOST OBJECT: %s' % self.hostname |
| 924 | |
| 925 | |
| 926 | def show(self): |
| 927 | labels = list(set(self.labels) - set([self.platform])) |
| 928 | print '%-6s %-7s %-7s %-16s %s' % (self.hostname, self.status, |
| 929 | self.locked, self.platform, |
| 930 | ', '.join(labels)) |
| 931 | |
| 932 | |
mbligh | 54459c7 | 2009-01-21 19:26:44 +0000 | [diff] [blame] | 933 | def delete(self): |
| 934 | return self.afe.run('delete_host', id=self.id) |
| 935 | |
| 936 | |
mbligh | 6463c4b | 2009-01-30 00:33:37 +0000 | [diff] [blame] | 937 | def modify(self, **dargs): |
| 938 | return self.afe.run('modify_host', id=self.id, **dargs) |
| 939 | |
| 940 | |
mbligh | 6764715 | 2008-11-19 00:18:14 +0000 | [diff] [blame] | 941 | def get_acls(self): |
| 942 | return self.afe.get_acls(hosts__hostname=self.hostname) |
| 943 | |
| 944 | |
| 945 | def add_acl(self, acl_name): |
| 946 | self.afe.log('Adding ACL %s to host %s' % (acl_name, self.hostname)) |
| 947 | return self.afe.run('acl_group_add_hosts', id=acl_name, |
| 948 | hosts=[self.hostname]) |
| 949 | |
| 950 | |
| 951 | def remove_acl(self, acl_name): |
| 952 | self.afe.log('Removing ACL %s from host %s' % (acl_name, self.hostname)) |
| 953 | return self.afe.run('acl_group_remove_hosts', id=acl_name, |
| 954 | hosts=[self.hostname]) |
| 955 | |
| 956 | |
| 957 | def get_labels(self): |
| 958 | return self.afe.get_labels(host__hostname__in=[self.hostname]) |
| 959 | |
| 960 | |
| 961 | def add_labels(self, labels): |
| 962 | self.afe.log('Adding labels %s to host %s' % (labels, self.hostname)) |
| 963 | return self.afe.run('host_add_labels', id=self.id, labels=labels) |
| 964 | |
| 965 | |
| 966 | def remove_labels(self, labels): |
| 967 | self.afe.log('Removing labels %s from host %s' % (labels,self.hostname)) |
| 968 | return self.afe.run('host_remove_labels', id=self.id, labels=labels) |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 969 | |
| 970 | |
mbligh | 54459c7 | 2009-01-21 19:26:44 +0000 | [diff] [blame] | 971 | class User(RpcObject): |
| 972 | def __repr__(self): |
| 973 | return 'USER: %s' % self.login |
| 974 | |
| 975 | |
mbligh | 5280e3b | 2008-12-22 14:39:28 +0000 | [diff] [blame] | 976 | class TestStatus(RpcObject): |
mbligh | c31e402 | 2008-12-11 19:32:30 +0000 | [diff] [blame] | 977 | """ |
| 978 | TKO test status object |
| 979 | |
| 980 | Fields: |
| 981 | test_idx, hostname, testname, id |
| 982 | complete_count, incomplete_count, group_count, pass_count |
| 983 | """ |
| 984 | def __repr__(self): |
| 985 | return 'TEST STATUS: %s' % self.id |
| 986 | |
| 987 | |
MK Ryu | acf3592 | 2014-10-03 14:56:49 -0700 | [diff] [blame] | 988 | class HostAttribute(RpcObject): |
| 989 | """ |
| 990 | AFE host attribute object |
| 991 | |
| 992 | Fields: |
| 993 | id, host, attribute, value |
| 994 | """ |
| 995 | def __repr__(self): |
| 996 | return 'HOST ATTRIBUTE %d' % self.id |
| 997 | |
| 998 | |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 999 | class MachineTestPairing(object): |
| 1000 | """ |
| 1001 | Object representing the pairing of a machine label with a control file |
mbligh | 1f23f36 | 2008-12-22 14:46:12 +0000 | [diff] [blame] | 1002 | |
| 1003 | machine_label: use machines from this label |
| 1004 | control_file: use this control file (by name in the frontend) |
| 1005 | platforms: list of rexeps to filter platforms by. [] => no filtering |
mbligh | 282ce89 | 2010-01-06 18:40:17 +0000 | [diff] [blame] | 1006 | job_label: The label (name) to give to the autotest job launched |
| 1007 | to run this pairing. '<kernel-version> : <config> : <date>' |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 1008 | """ |
mbligh | 1354c9d | 2008-12-22 14:56:13 +0000 | [diff] [blame] | 1009 | def __init__(self, machine_label, control_file, platforms=[], |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 1010 | container=False, atomic_group_sched=False, synch_count=0, |
mbligh | 282ce89 | 2010-01-06 18:40:17 +0000 | [diff] [blame] | 1011 | testname=None, job_label=None): |
mbligh | 5b61838 | 2008-12-03 15:24:01 +0000 | [diff] [blame] | 1012 | self.machine_label = machine_label |
| 1013 | self.control_file = control_file |
mbligh | 1f23f36 | 2008-12-22 14:46:12 +0000 | [diff] [blame] | 1014 | self.platforms = platforms |
mbligh | 1354c9d | 2008-12-22 14:56:13 +0000 | [diff] [blame] | 1015 | self.container = container |
mbligh | b9db516 | 2009-04-17 22:21:41 +0000 | [diff] [blame] | 1016 | self.atomic_group_sched = atomic_group_sched |
| 1017 | self.synch_count = synch_count |
mbligh | 17c75e6 | 2009-06-08 16:18:21 +0000 | [diff] [blame] | 1018 | self.testname = testname |
mbligh | 282ce89 | 2010-01-06 18:40:17 +0000 | [diff] [blame] | 1019 | self.job_label = job_label |
mbligh | 1354c9d | 2008-12-22 14:56:13 +0000 | [diff] [blame] | 1020 | |
| 1021 | |
| 1022 | def __repr__(self): |
| 1023 | return '%s %s %s %s' % (self.machine_label, self.control_file, |
| 1024 | self.platforms, self.container) |