blob: bca99f8391c2961a76e93765d954f2862dc55541 [file] [log] [blame]
mbligh67647152008-11-19 00:18:14 +00001# Copyright Martin J. Bligh, Google Inc 2008
2# Released under the GPL v2
3
4"""
5This class allows you to communicate with the frontend to submit jobs etc
6It is designed for writing more sophisiticated server-side control files that
7can recursively add and manage other jobs.
8
9We turn the JSON dictionaries into real objects that are more idiomatic
10
mblighc31e4022008-12-11 19:32:30 +000011For docs, see:
Aviv Keshet2c709f62013-05-07 12:52:15 -070012 http://www.chromium.org/chromium-os/testing/afe-rpc-infrastructure
mblighc31e4022008-12-11 19:32:30 +000013 http://docs.djangoproject.com/en/dev/ref/models/querysets/#queryset-api
mbligh67647152008-11-19 00:18:14 +000014"""
15
mblighdb59e3c2009-11-21 01:45:18 +000016import getpass, os, time, traceback, re
mbligh67647152008-11-19 00:18:14 +000017import common
18from autotest_lib.frontend.afe import rpc_client_lib
mbligh37eceaa2008-12-15 22:56:37 +000019from autotest_lib.client.common_lib import global_config
mbligh67647152008-11-19 00:18:14 +000020from autotest_lib.client.common_lib import utils
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070021from autotest_lib.client.common_lib import control_data
Scott Zawalski63470dd2012-09-05 00:49:43 -040022from autotest_lib.tko import db
23
24
mbligh4e576612008-12-22 14:56:36 +000025try:
26 from autotest_lib.server.site_common import site_utils as server_utils
27except:
28 from autotest_lib.server import utils as server_utils
29form_ntuples_from_machines = server_utils.form_ntuples_from_machines
mbligh67647152008-11-19 00:18:14 +000030
mbligh37eceaa2008-12-15 22:56:37 +000031GLOBAL_CONFIG = global_config.global_config
32DEFAULT_SERVER = 'autotest'
33
mbligh67647152008-11-19 00:18:14 +000034def dump_object(header, obj):
35 """
36 Standard way to print out the frontend objects (eg job, host, acl, label)
37 in a human-readable fashion for debugging
38 """
39 result = header + '\n'
40 for key in obj.hash:
41 if key == 'afe' or key == 'hash':
42 continue
43 result += '%20s: %s\n' % (key, obj.hash[key])
44 return result
45
46
mbligh5280e3b2008-12-22 14:39:28 +000047class RpcClient(object):
mbligh67647152008-11-19 00:18:14 +000048 """
mbligh451ede12009-02-12 21:54:03 +000049 Abstract RPC class for communicating with the autotest frontend
50 Inherited for both TKO and AFE uses.
mbligh67647152008-11-19 00:18:14 +000051
mbligh1ef218d2009-08-03 16:57:56 +000052 All the constructors go in the afe / tko class.
mbligh451ede12009-02-12 21:54:03 +000053 Manipulating methods go in the object classes themselves
mbligh67647152008-11-19 00:18:14 +000054 """
mbligh99b24f42009-06-08 16:45:55 +000055 def __init__(self, path, user, server, print_log, debug, reply_debug):
mbligh67647152008-11-19 00:18:14 +000056 """
mbligh451ede12009-02-12 21:54:03 +000057 Create a cached instance of a connection to the frontend
mbligh67647152008-11-19 00:18:14 +000058
59 user: username to connect as
mbligh451ede12009-02-12 21:54:03 +000060 server: frontend server to connect to
mbligh67647152008-11-19 00:18:14 +000061 print_log: pring a logging message to stdout on every operation
62 debug: print out all RPC traffic
63 """
Dan Shiff78f112015-06-12 13:34:02 -070064 if not user and utils.is_in_container():
65 user = GLOBAL_CONFIG.get_config_value('SSP', 'user', default=None)
mblighc31e4022008-12-11 19:32:30 +000066 if not user:
mblighdb59e3c2009-11-21 01:45:18 +000067 user = getpass.getuser()
mbligh451ede12009-02-12 21:54:03 +000068 if not server:
mbligh475f7762009-01-30 00:34:04 +000069 if 'AUTOTEST_WEB' in os.environ:
mbligh451ede12009-02-12 21:54:03 +000070 server = os.environ['AUTOTEST_WEB']
mbligh475f7762009-01-30 00:34:04 +000071 else:
mbligh451ede12009-02-12 21:54:03 +000072 server = GLOBAL_CONFIG.get_config_value('SERVER', 'hostname',
73 default=DEFAULT_SERVER)
74 self.server = server
mbligh67647152008-11-19 00:18:14 +000075 self.user = user
76 self.print_log = print_log
77 self.debug = debug
mbligh99b24f42009-06-08 16:45:55 +000078 self.reply_debug = reply_debug
Scott Zawalski347aaf42012-04-03 16:33:00 -040079 headers = {'AUTHORIZATION': self.user}
80 rpc_server = 'http://' + server + path
mbligh1354c9d2008-12-22 14:56:13 +000081 if debug:
82 print 'SERVER: %s' % rpc_server
83 print 'HEADERS: %s' % headers
mbligh67647152008-11-19 00:18:14 +000084 self.proxy = rpc_client_lib.get_proxy(rpc_server, headers=headers)
85
86
87 def run(self, call, **dargs):
88 """
89 Make a RPC call to the AFE server
90 """
91 rpc_call = getattr(self.proxy, call)
92 if self.debug:
93 print 'DEBUG: %s %s' % (call, dargs)
mbligh451ede12009-02-12 21:54:03 +000094 try:
mbligh99b24f42009-06-08 16:45:55 +000095 result = utils.strip_unicode(rpc_call(**dargs))
96 if self.reply_debug:
97 print result
98 return result
mbligh451ede12009-02-12 21:54:03 +000099 except Exception:
100 print 'FAILED RPC CALL: %s %s' % (call, dargs)
101 raise
mbligh67647152008-11-19 00:18:14 +0000102
103
104 def log(self, message):
105 if self.print_log:
106 print message
107
108
jamesrenc3940222010-02-19 21:57:37 +0000109class Planner(RpcClient):
110 def __init__(self, user=None, server=None, print_log=True, debug=False,
111 reply_debug=False):
112 super(Planner, self).__init__(path='/planner/server/rpc/',
113 user=user,
114 server=server,
115 print_log=print_log,
116 debug=debug,
117 reply_debug=reply_debug)
118
119
mbligh5280e3b2008-12-22 14:39:28 +0000120class TKO(RpcClient):
mbligh99b24f42009-06-08 16:45:55 +0000121 def __init__(self, user=None, server=None, print_log=True, debug=False,
122 reply_debug=False):
Scott Zawalski347aaf42012-04-03 16:33:00 -0400123 super(TKO, self).__init__(path='/new_tko/server/noauth/rpc/',
mbligh99b24f42009-06-08 16:45:55 +0000124 user=user,
125 server=server,
126 print_log=print_log,
127 debug=debug,
128 reply_debug=reply_debug)
Scott Zawalski63470dd2012-09-05 00:49:43 -0400129 self._db = None
130
131
132 def get_job_test_statuses_from_db(self, job_id):
133 """Get job test statuses from the database.
134
135 Retrieve a set of fields from a job that reflect the status of each test
136 run within a job.
137 fields retrieved: status, test_name, reason, test_started_time,
138 test_finished_time, afe_job_id, job_owner, hostname.
139
140 @param job_id: The afe job id to look up.
141 @returns a TestStatus object of the resulting information.
142 """
143 if self._db is None:
144 self._db = db.db()
Fang Deng5c508332014-03-19 10:26:00 -0700145 fields = ['status', 'test_name', 'subdir', 'reason',
146 'test_started_time', 'test_finished_time', 'afe_job_id',
147 'job_owner', 'hostname', 'job_tag']
Scott Zawalski63470dd2012-09-05 00:49:43 -0400148 table = 'tko_test_view_2'
149 where = 'job_tag like "%s-%%"' % job_id
150 test_status = []
151 # Run commit before we query to ensure that we are pulling the latest
152 # results.
153 self._db.commit()
154 for entry in self._db.select(','.join(fields), table, (where, None)):
155 status_dict = {}
156 for key,value in zip(fields, entry):
157 # All callers expect values to be a str object.
158 status_dict[key] = str(value)
159 # id is used by TestStatus to uniquely identify each Test Status
160 # obj.
161 status_dict['id'] = [status_dict['reason'], status_dict['hostname'],
162 status_dict['test_name']]
163 test_status.append(status_dict)
164
165 return [TestStatus(self, e) for e in test_status]
mblighc31e4022008-12-11 19:32:30 +0000166
167
168 def get_status_counts(self, job, **data):
169 entries = self.run('get_status_counts',
mbligh1ef218d2009-08-03 16:57:56 +0000170 group_by=['hostname', 'test_name', 'reason'],
mblighc31e4022008-12-11 19:32:30 +0000171 job_tag__startswith='%s-' % job, **data)
mbligh5280e3b2008-12-22 14:39:28 +0000172 return [TestStatus(self, e) for e in entries['groups']]
mblighc31e4022008-12-11 19:32:30 +0000173
174
mbligh5280e3b2008-12-22 14:39:28 +0000175class AFE(RpcClient):
mbligh17c75e62009-06-08 16:18:21 +0000176 def __init__(self, user=None, server=None, print_log=True, debug=False,
mbligh99b24f42009-06-08 16:45:55 +0000177 reply_debug=False, job=None):
mbligh17c75e62009-06-08 16:18:21 +0000178 self.job = job
Scott Zawalski347aaf42012-04-03 16:33:00 -0400179 super(AFE, self).__init__(path='/afe/server/noauth/rpc/',
mbligh99b24f42009-06-08 16:45:55 +0000180 user=user,
181 server=server,
182 print_log=print_log,
183 debug=debug,
184 reply_debug=reply_debug)
mblighc31e4022008-12-11 19:32:30 +0000185
mbligh1ef218d2009-08-03 16:57:56 +0000186
mbligh67647152008-11-19 00:18:14 +0000187 def host_statuses(self, live=None):
jamesren121eee62010-04-13 19:10:12 +0000188 dead_statuses = ['Repair Failed', 'Repairing']
mbligh67647152008-11-19 00:18:14 +0000189 statuses = self.run('get_static_data')['host_statuses']
190 if live == True:
mblighc2847b72009-03-25 19:32:20 +0000191 return list(set(statuses) - set(dead_statuses))
mbligh67647152008-11-19 00:18:14 +0000192 if live == False:
193 return dead_statuses
194 else:
195 return statuses
196
197
mbligh71094012009-12-19 05:35:21 +0000198 @staticmethod
199 def _dict_for_host_query(hostnames=(), status=None, label=None):
200 query_args = {}
mbligh4e545a52009-12-19 05:30:39 +0000201 if hostnames:
202 query_args['hostname__in'] = hostnames
203 if status:
204 query_args['status'] = status
205 if label:
206 query_args['labels__name'] = label
mbligh71094012009-12-19 05:35:21 +0000207 return query_args
208
209
210 def get_hosts(self, hostnames=(), status=None, label=None, **dargs):
211 query_args = dict(dargs)
212 query_args.update(self._dict_for_host_query(hostnames=hostnames,
213 status=status,
214 label=label))
215 hosts = self.run('get_hosts', **query_args)
216 return [Host(self, h) for h in hosts]
217
218
219 def get_hostnames(self, status=None, label=None, **dargs):
220 """Like get_hosts() but returns hostnames instead of Host objects."""
221 # This implementation can be replaced with a more efficient one
222 # that does not query for entire host objects in the future.
223 return [host_obj.hostname for host_obj in
224 self.get_hosts(status=status, label=label, **dargs)]
225
226
227 def reverify_hosts(self, hostnames=(), status=None, label=None):
228 query_args = dict(locked=False,
229 aclgroup__users__login=self.user)
230 query_args.update(self._dict_for_host_query(hostnames=hostnames,
231 status=status,
232 label=label))
mbligh4e545a52009-12-19 05:30:39 +0000233 return self.run('reverify_hosts', **query_args)
234
235
mbligh67647152008-11-19 00:18:14 +0000236 def create_host(self, hostname, **dargs):
mbligh54459c72009-01-21 19:26:44 +0000237 id = self.run('add_host', hostname=hostname, **dargs)
mbligh67647152008-11-19 00:18:14 +0000238 return self.get_hosts(id=id)[0]
239
240
MK Ryuacf35922014-10-03 14:56:49 -0700241 def get_host_attribute(self, attr, **dargs):
242 host_attrs = self.run('get_host_attribute', attribute=attr, **dargs)
243 return [HostAttribute(self, a) for a in host_attrs]
244
245
Chris Masone8abb6fc2012-01-31 09:27:36 -0800246 def set_host_attribute(self, attr, val, **dargs):
247 self.run('set_host_attribute', attribute=attr, value=val, **dargs)
248
249
mbligh67647152008-11-19 00:18:14 +0000250 def get_labels(self, **dargs):
251 labels = self.run('get_labels', **dargs)
mbligh5280e3b2008-12-22 14:39:28 +0000252 return [Label(self, l) for l in labels]
mbligh67647152008-11-19 00:18:14 +0000253
254
255 def create_label(self, name, **dargs):
mbligh54459c72009-01-21 19:26:44 +0000256 id = self.run('add_label', name=name, **dargs)
mbligh67647152008-11-19 00:18:14 +0000257 return self.get_labels(id=id)[0]
258
259
260 def get_acls(self, **dargs):
261 acls = self.run('get_acl_groups', **dargs)
mbligh5280e3b2008-12-22 14:39:28 +0000262 return [Acl(self, a) for a in acls]
mbligh67647152008-11-19 00:18:14 +0000263
264
265 def create_acl(self, name, **dargs):
mbligh54459c72009-01-21 19:26:44 +0000266 id = self.run('add_acl_group', name=name, **dargs)
mbligh67647152008-11-19 00:18:14 +0000267 return self.get_acls(id=id)[0]
268
269
mbligh54459c72009-01-21 19:26:44 +0000270 def get_users(self, **dargs):
271 users = self.run('get_users', **dargs)
272 return [User(self, u) for u in users]
273
274
mbligh1354c9d2008-12-22 14:56:13 +0000275 def generate_control_file(self, tests, **dargs):
276 ret = self.run('generate_control_file', tests=tests, **dargs)
277 return ControlFile(self, ret)
278
279
mbligh67647152008-11-19 00:18:14 +0000280 def get_jobs(self, summary=False, **dargs):
281 if summary:
282 jobs_data = self.run('get_jobs_summary', **dargs)
283 else:
284 jobs_data = self.run('get_jobs', **dargs)
mblighafbba0c2009-06-08 16:44:45 +0000285 jobs = []
286 for j in jobs_data:
287 job = Job(self, j)
288 # Set up some extra information defaults
289 job.testname = re.sub('\s.*', '', job.name) # arbitrary default
290 job.platform_results = {}
291 job.platform_reasons = {}
292 jobs.append(job)
293 return jobs
mbligh67647152008-11-19 00:18:14 +0000294
295
296 def get_host_queue_entries(self, **data):
297 entries = self.run('get_host_queue_entries', **data)
mblighf9e35862009-02-26 01:03:11 +0000298 job_statuses = [JobStatus(self, e) for e in entries]
mbligh99b24f42009-06-08 16:45:55 +0000299
300 # Sadly, get_host_queue_entries doesn't return platforms, we have
301 # to get those back from an explicit get_hosts queury, then patch
302 # the new host objects back into the host list.
303 hostnames = [s.host.hostname for s in job_statuses if s.host]
304 host_hash = {}
305 for host in self.get_hosts(hostname__in=hostnames):
306 host_hash[host.hostname] = host
307 for status in job_statuses:
308 if status.host:
Fang Deng97dafbc2015-04-23 23:06:18 -0700309 status.host = host_hash.get(status.host.hostname)
mblighf9e35862009-02-26 01:03:11 +0000310 # filter job statuses that have either host or meta_host
311 return [status for status in job_statuses if (status.host or
312 status.meta_host)]
mbligh67647152008-11-19 00:18:14 +0000313
314
MK Ryu1b2d7f92015-02-24 17:45:02 -0800315 def get_special_tasks(self, **data):
316 tasks = self.run('get_special_tasks', **data)
317 return [SpecialTask(self, t) for t in tasks]
318
319
J. Richard Barnette9f10c9f2015-04-13 16:44:50 -0700320 def get_host_special_tasks(self, host_id, **data):
321 tasks = self.run('get_host_special_tasks',
322 host_id=host_id, **data)
323 return [SpecialTask(self, t) for t in tasks]
324
325
J. Richard Barnette8dbd6d32015-05-01 11:01:12 -0700326 def get_host_status_task(self, host_id, end_time):
327 task = self.run('get_host_status_task',
J. Richard Barnettebc9a7952015-04-16 17:43:27 -0700328 host_id=host_id, end_time=end_time)
329 return SpecialTask(self, task) if task else None
330
331
mblighb9db5162009-04-17 22:21:41 +0000332 def create_job_by_test(self, tests, kernel=None, use_container=False,
Eric Lie0493a42010-11-15 13:05:43 -0800333 kernel_cmdline=None, **dargs):
mbligh67647152008-11-19 00:18:14 +0000334 """
335 Given a test name, fetch the appropriate control file from the server
mbligh4e576612008-12-22 14:56:36 +0000336 and submit it.
337
Eric Lie0493a42010-11-15 13:05:43 -0800338 @param kernel: A comma separated list of kernel versions to boot.
339 @param kernel_cmdline: The command line used to boot all kernels listed
340 in the kernel parameter.
341
mbligh4e576612008-12-22 14:56:36 +0000342 Returns a list of job objects
mbligh67647152008-11-19 00:18:14 +0000343 """
mblighb9db5162009-04-17 22:21:41 +0000344 assert ('hosts' in dargs or
345 'atomic_group_name' in dargs and 'synch_count' in dargs)
showarda2cd72b2009-10-01 18:43:53 +0000346 if kernel:
347 kernel_list = re.split('[\s,]+', kernel.strip())
Eric Lie0493a42010-11-15 13:05:43 -0800348 kernel_info = []
349 for version in kernel_list:
350 kernel_dict = {'version': version}
351 if kernel_cmdline is not None:
352 kernel_dict['cmdline'] = kernel_cmdline
353 kernel_info.append(kernel_dict)
showarda2cd72b2009-10-01 18:43:53 +0000354 else:
355 kernel_info = None
356 control_file = self.generate_control_file(
Dale Curtis74a314b2011-06-23 14:55:46 -0700357 tests=tests, kernel=kernel_info, use_container=use_container)
mbligh1354c9d2008-12-22 14:56:13 +0000358 if control_file.is_server:
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700359 dargs['control_type'] = control_data.CONTROL_TYPE_NAMES.SERVER
mbligh67647152008-11-19 00:18:14 +0000360 else:
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700361 dargs['control_type'] = control_data.CONTROL_TYPE_NAMES.CLIENT
mbligh67647152008-11-19 00:18:14 +0000362 dargs['dependencies'] = dargs.get('dependencies', []) + \
mbligh1354c9d2008-12-22 14:56:13 +0000363 control_file.dependencies
364 dargs['control_file'] = control_file.control_file
mbligh672666c2009-07-28 23:22:13 +0000365 if not dargs.get('synch_count', None):
mblighc99fccf2009-07-11 00:59:33 +0000366 dargs['synch_count'] = control_file.synch_count
mblighb9db5162009-04-17 22:21:41 +0000367 if 'hosts' in dargs and len(dargs['hosts']) < dargs['synch_count']:
368 # will not be able to satisfy this request
mbligh38b09152009-04-28 18:34:25 +0000369 return None
370 return self.create_job(**dargs)
mbligh67647152008-11-19 00:18:14 +0000371
372
373 def create_job(self, control_file, name=' ', priority='Medium',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700374 control_type=control_data.CONTROL_TYPE_NAMES.CLIENT, **dargs):
mbligh67647152008-11-19 00:18:14 +0000375 id = self.run('create_job', name=name, priority=priority,
376 control_file=control_file, control_type=control_type, **dargs)
377 return self.get_jobs(id=id)[0]
378
379
mbligh282ce892010-01-06 18:40:17 +0000380 def run_test_suites(self, pairings, kernel, kernel_label=None,
381 priority='Medium', wait=True, poll_interval=10,
Simran Basi7e605742013-11-12 13:43:36 -0800382 email_from=None, email_to=None, timeout_mins=10080,
Simran Basi34217022012-11-06 13:43:15 -0800383 max_runtime_mins=10080, kernel_cmdline=None):
mbligh5b618382008-12-03 15:24:01 +0000384 """
385 Run a list of test suites on a particular kernel.
mbligh1ef218d2009-08-03 16:57:56 +0000386
mbligh5b618382008-12-03 15:24:01 +0000387 Poll for them to complete, and return whether they worked or not.
mbligh1ef218d2009-08-03 16:57:56 +0000388
mbligh282ce892010-01-06 18:40:17 +0000389 @param pairings: List of MachineTestPairing objects to invoke.
390 @param kernel: Name of the kernel to run.
391 @param kernel_label: Label (string) of the kernel to run such as
392 '<kernel-version> : <config> : <date>'
393 If any pairing object has its job_label attribute set it
394 will override this value for that particular job.
Eric Lie0493a42010-11-15 13:05:43 -0800395 @param kernel_cmdline: The command line to boot the kernel(s) with.
mbligh282ce892010-01-06 18:40:17 +0000396 @param wait: boolean - Wait for the results to come back?
397 @param poll_interval: Interval between polling for job results (in mins)
398 @param email_from: Send notification email upon completion from here.
399 @param email_from: Send notification email upon completion to here.
mbligh5b618382008-12-03 15:24:01 +0000400 """
401 jobs = []
402 for pairing in pairings:
mbligh0c4f8d72009-05-12 20:52:18 +0000403 try:
404 new_job = self.invoke_test(pairing, kernel, kernel_label,
Simran Basi7e605742013-11-12 13:43:36 -0800405 priority, timeout_mins=timeout_mins,
Eric Lie0493a42010-11-15 13:05:43 -0800406 kernel_cmdline=kernel_cmdline,
Simran Basi34217022012-11-06 13:43:15 -0800407 max_runtime_mins=max_runtime_mins)
mbligh0c4f8d72009-05-12 20:52:18 +0000408 if not new_job:
409 continue
mbligh0c4f8d72009-05-12 20:52:18 +0000410 jobs.append(new_job)
411 except Exception, e:
412 traceback.print_exc()
mblighb9db5162009-04-17 22:21:41 +0000413 if not wait or not jobs:
mbligh5b618382008-12-03 15:24:01 +0000414 return
mbligh5280e3b2008-12-22 14:39:28 +0000415 tko = TKO()
mbligh5b618382008-12-03 15:24:01 +0000416 while True:
417 time.sleep(60 * poll_interval)
mbligh5280e3b2008-12-22 14:39:28 +0000418 result = self.poll_all_jobs(tko, jobs, email_from, email_to)
mbligh5b618382008-12-03 15:24:01 +0000419 if result is not None:
420 return result
421
422
mbligh45ffc432008-12-09 23:35:17 +0000423 def result_notify(self, job, email_from, email_to):
mbligh5b618382008-12-03 15:24:01 +0000424 """
mbligh45ffc432008-12-09 23:35:17 +0000425 Notify about the result of a job. Will always print, if email data
426 is provided, will send email for it as well.
427
428 job: job object to notify about
429 email_from: send notification email upon completion from here
430 email_from: send notification email upon completion to here
431 """
432 if job.result == True:
433 subject = 'Testing PASSED: '
434 else:
435 subject = 'Testing FAILED: '
436 subject += '%s : %s\n' % (job.name, job.id)
437 text = []
438 for platform in job.results_platform_map:
439 for status in job.results_platform_map[platform]:
440 if status == 'Total':
441 continue
mbligh451ede12009-02-12 21:54:03 +0000442 for host in job.results_platform_map[platform][status]:
443 text.append('%20s %10s %10s' % (platform, status, host))
444 if status == 'Failed':
445 for test_status in job.test_status[host].fail:
446 text.append('(%s, %s) : %s' % \
447 (host, test_status.test_name,
448 test_status.reason))
449 text.append('')
mbligh37eceaa2008-12-15 22:56:37 +0000450
mbligh451ede12009-02-12 21:54:03 +0000451 base_url = 'http://' + self.server
mbligh37eceaa2008-12-15 22:56:37 +0000452
453 params = ('columns=test',
454 'rows=machine_group',
455 "condition=tag~'%s-%%25'" % job.id,
456 'title=Report')
457 query_string = '&'.join(params)
mbligh451ede12009-02-12 21:54:03 +0000458 url = '%s/tko/compose_query.cgi?%s' % (base_url, query_string)
459 text.append(url + '\n')
460 url = '%s/afe/#tab_id=view_job&object_id=%s' % (base_url, job.id)
461 text.append(url + '\n')
mbligh37eceaa2008-12-15 22:56:37 +0000462
463 body = '\n'.join(text)
464 print '---------------------------------------------------'
465 print 'Subject: ', subject
mbligh45ffc432008-12-09 23:35:17 +0000466 print body
mbligh37eceaa2008-12-15 22:56:37 +0000467 print '---------------------------------------------------'
mbligh45ffc432008-12-09 23:35:17 +0000468 if email_from and email_to:
mbligh37eceaa2008-12-15 22:56:37 +0000469 print 'Sending email ...'
mbligh45ffc432008-12-09 23:35:17 +0000470 utils.send_email(email_from, email_to, subject, body)
471 print
mbligh37eceaa2008-12-15 22:56:37 +0000472
mbligh45ffc432008-12-09 23:35:17 +0000473
mbligh1354c9d2008-12-22 14:56:13 +0000474 def print_job_result(self, job):
475 """
476 Print the result of a single job.
477 job: a job object
478 """
479 if job.result is None:
480 print 'PENDING',
481 elif job.result == True:
482 print 'PASSED',
483 elif job.result == False:
484 print 'FAILED',
mbligh912c3f32009-03-25 19:31:30 +0000485 elif job.result == "Abort":
486 print 'ABORT',
mbligh1354c9d2008-12-22 14:56:13 +0000487 print ' %s : %s' % (job.id, job.name)
488
489
mbligh451ede12009-02-12 21:54:03 +0000490 def poll_all_jobs(self, tko, jobs, email_from=None, email_to=None):
mbligh45ffc432008-12-09 23:35:17 +0000491 """
492 Poll all jobs in a list.
493 jobs: list of job objects to poll
494 email_from: send notification email upon completion from here
495 email_from: send notification email upon completion to here
496
497 Returns:
mbligh5b618382008-12-03 15:24:01 +0000498 a) All complete successfully (return True)
499 b) One or more has failed (return False)
500 c) Cannot tell yet (return None)
501 """
mbligh45ffc432008-12-09 23:35:17 +0000502 results = []
mbligh5b618382008-12-03 15:24:01 +0000503 for job in jobs:
mbligh676dcbe2009-06-15 21:57:27 +0000504 if getattr(job, 'result', None) is None:
Chris Masone6fed6462011-10-20 16:36:43 -0700505 job.result = self.poll_job_results(tko, job)
mbligh676dcbe2009-06-15 21:57:27 +0000506 if job.result is not None:
507 self.result_notify(job, email_from, email_to)
mbligh45ffc432008-12-09 23:35:17 +0000508
mbligh676dcbe2009-06-15 21:57:27 +0000509 results.append(job.result)
mbligh1354c9d2008-12-22 14:56:13 +0000510 self.print_job_result(job)
mbligh45ffc432008-12-09 23:35:17 +0000511
512 if None in results:
513 return None
mbligh912c3f32009-03-25 19:31:30 +0000514 elif False in results or "Abort" in results:
mbligh45ffc432008-12-09 23:35:17 +0000515 return False
516 else:
517 return True
mbligh5b618382008-12-03 15:24:01 +0000518
519
mbligh1f23f362008-12-22 14:46:12 +0000520 def _included_platform(self, host, platforms):
521 """
522 See if host's platforms matches any of the patterns in the included
523 platforms list.
524 """
525 if not platforms:
526 return True # No filtering of platforms
527 for platform in platforms:
528 if re.search(platform, host.platform):
529 return True
530 return False
531
532
mbligh7b312282009-01-07 16:45:43 +0000533 def invoke_test(self, pairing, kernel, kernel_label, priority='Medium',
Eric Lie0493a42010-11-15 13:05:43 -0800534 kernel_cmdline=None, **dargs):
mbligh5b618382008-12-03 15:24:01 +0000535 """
536 Given a pairing of a control file to a machine label, find all machines
537 with that label, and submit that control file to them.
mbligh1ef218d2009-08-03 16:57:56 +0000538
mbligh282ce892010-01-06 18:40:17 +0000539 @param kernel_label: Label (string) of the kernel to run such as
540 '<kernel-version> : <config> : <date>'
541 If any pairing object has its job_label attribute set it
542 will override this value for that particular job.
543
544 @returns A list of job objects.
mbligh5b618382008-12-03 15:24:01 +0000545 """
mbligh282ce892010-01-06 18:40:17 +0000546 # The pairing can override the job label.
547 if pairing.job_label:
548 kernel_label = pairing.job_label
mbligh5b618382008-12-03 15:24:01 +0000549 job_name = '%s : %s' % (pairing.machine_label, kernel_label)
550 hosts = self.get_hosts(multiple_labels=[pairing.machine_label])
mbligh1f23f362008-12-22 14:46:12 +0000551 platforms = pairing.platforms
552 hosts = [h for h in hosts if self._included_platform(h, platforms)]
mblighc2847b72009-03-25 19:32:20 +0000553 dead_statuses = self.host_statuses(live=False)
554 host_list = [h.hostname for h in hosts if h.status not in dead_statuses]
mbligh1f23f362008-12-22 14:46:12 +0000555 print 'HOSTS: %s' % host_list
mblighb9db5162009-04-17 22:21:41 +0000556 if pairing.atomic_group_sched:
mblighc99fccf2009-07-11 00:59:33 +0000557 dargs['synch_count'] = pairing.synch_count
mblighb9db5162009-04-17 22:21:41 +0000558 dargs['atomic_group_name'] = pairing.machine_label
559 else:
560 dargs['hosts'] = host_list
mbligh38b09152009-04-28 18:34:25 +0000561 new_job = self.create_job_by_test(name=job_name,
mbligh17c75e62009-06-08 16:18:21 +0000562 dependencies=[pairing.machine_label],
563 tests=[pairing.control_file],
564 priority=priority,
565 kernel=kernel,
Eric Lie0493a42010-11-15 13:05:43 -0800566 kernel_cmdline=kernel_cmdline,
mbligh17c75e62009-06-08 16:18:21 +0000567 use_container=pairing.container,
568 **dargs)
mbligh38b09152009-04-28 18:34:25 +0000569 if new_job:
mbligh17c75e62009-06-08 16:18:21 +0000570 if pairing.testname:
571 new_job.testname = pairing.testname
mbligh4e576612008-12-22 14:56:36 +0000572 print 'Invoked test %s : %s' % (new_job.id, job_name)
mbligh38b09152009-04-28 18:34:25 +0000573 return new_job
mbligh5b618382008-12-03 15:24:01 +0000574
575
mblighb9db5162009-04-17 22:21:41 +0000576 def _job_test_results(self, tko, job, debug, tests=[]):
mbligh5b618382008-12-03 15:24:01 +0000577 """
mbligh5280e3b2008-12-22 14:39:28 +0000578 Retrieve test results for a job
mbligh5b618382008-12-03 15:24:01 +0000579 """
mbligh5280e3b2008-12-22 14:39:28 +0000580 job.test_status = {}
581 try:
582 test_statuses = tko.get_status_counts(job=job.id)
583 except Exception:
584 print "Ignoring exception on poll job; RPC interface is flaky"
585 traceback.print_exc()
586 return
587
588 for test_status in test_statuses:
mbligh7479a182009-01-07 16:46:24 +0000589 # SERVER_JOB is buggy, and often gives false failures. Ignore it.
590 if test_status.test_name == 'SERVER_JOB':
591 continue
mblighb9db5162009-04-17 22:21:41 +0000592 # if tests is not empty, restrict list of test_statuses to tests
593 if tests and test_status.test_name not in tests:
594 continue
mbligh451ede12009-02-12 21:54:03 +0000595 if debug:
596 print test_status
mbligh5280e3b2008-12-22 14:39:28 +0000597 hostname = test_status.hostname
598 if hostname not in job.test_status:
599 job.test_status[hostname] = TestResults()
600 job.test_status[hostname].add(test_status)
601
602
mbligh451ede12009-02-12 21:54:03 +0000603 def _job_results_platform_map(self, job, debug):
mblighc9e427e2009-04-28 18:35:06 +0000604 # Figure out which hosts passed / failed / aborted in a job
605 # Creates a 2-dimensional hash, stored as job.results_platform_map
606 # 1st index - platform type (string)
607 # 2nd index - Status (string)
608 # 'Completed' / 'Failed' / 'Aborted'
609 # Data indexed by this hash is a list of hostnames (text strings)
mbligh5280e3b2008-12-22 14:39:28 +0000610 job.results_platform_map = {}
mbligh5b618382008-12-03 15:24:01 +0000611 try:
mbligh45ffc432008-12-09 23:35:17 +0000612 job_statuses = self.get_host_queue_entries(job=job.id)
mbligh5b618382008-12-03 15:24:01 +0000613 except Exception:
614 print "Ignoring exception on poll job; RPC interface is flaky"
615 traceback.print_exc()
616 return None
mbligh5280e3b2008-12-22 14:39:28 +0000617
mbligh5b618382008-12-03 15:24:01 +0000618 platform_map = {}
mbligh5280e3b2008-12-22 14:39:28 +0000619 job.job_status = {}
mbligh451ede12009-02-12 21:54:03 +0000620 job.metahost_index = {}
mbligh5b618382008-12-03 15:24:01 +0000621 for job_status in job_statuses:
mblighc9e427e2009-04-28 18:35:06 +0000622 # This is basically "for each host / metahost in the job"
mbligh451ede12009-02-12 21:54:03 +0000623 if job_status.host:
624 hostname = job_status.host.hostname
625 else: # This is a metahost
626 metahost = job_status.meta_host
627 index = job.metahost_index.get(metahost, 1)
628 job.metahost_index[metahost] = index + 1
629 hostname = '%s.%s' % (metahost, index)
mbligh5280e3b2008-12-22 14:39:28 +0000630 job.job_status[hostname] = job_status.status
mbligh5b618382008-12-03 15:24:01 +0000631 status = job_status.status
mbligh0ecbe632009-05-13 21:34:56 +0000632 # Skip hosts that failed verify or repair:
633 # that's a machine failure, not a job failure
mbligh451ede12009-02-12 21:54:03 +0000634 if hostname in job.test_status:
635 verify_failed = False
636 for failure in job.test_status[hostname].fail:
mbligh0ecbe632009-05-13 21:34:56 +0000637 if (failure.test_name == 'verify' or
638 failure.test_name == 'repair'):
mbligh451ede12009-02-12 21:54:03 +0000639 verify_failed = True
640 break
641 if verify_failed:
642 continue
mblighc9e427e2009-04-28 18:35:06 +0000643 if hostname in job.test_status and job.test_status[hostname].fail:
644 # If the any tests failed in the job, we want to mark the
645 # job result as failed, overriding the default job status.
646 if status != "Aborted": # except if it's an aborted job
647 status = 'Failed'
mbligh451ede12009-02-12 21:54:03 +0000648 if job_status.host:
649 platform = job_status.host.platform
650 else: # This is a metahost
651 platform = job_status.meta_host
mbligh5b618382008-12-03 15:24:01 +0000652 if platform not in platform_map:
653 platform_map[platform] = {'Total' : [hostname]}
654 else:
655 platform_map[platform]['Total'].append(hostname)
656 new_host_list = platform_map[platform].get(status, []) + [hostname]
657 platform_map[platform][status] = new_host_list
mbligh45ffc432008-12-09 23:35:17 +0000658 job.results_platform_map = platform_map
mbligh5280e3b2008-12-22 14:39:28 +0000659
660
mbligh17c75e62009-06-08 16:18:21 +0000661 def set_platform_results(self, test_job, platform, result):
662 """
663 Result must be None, 'FAIL', 'WARN' or 'GOOD'
664 """
665 if test_job.platform_results[platform] is not None:
666 # We're already done, and results recorded. This can't change later.
667 return
668 test_job.platform_results[platform] = result
669 # Note that self.job refers to the metajob we're IN, not the job
670 # that we're excuting from here.
671 testname = '%s.%s' % (test_job.testname, platform)
672 if self.job:
673 self.job.record(result, None, testname, status='')
674
MK Ryu9c5fbbe2015-02-11 15:46:22 -0800675
Chris Masone6fed6462011-10-20 16:36:43 -0700676 def poll_job_results(self, tko, job, enough=1, debug=False):
mbligh5280e3b2008-12-22 14:39:28 +0000677 """
Chris Masone3a560bd2011-11-14 16:53:56 -0800678 Analyse all job results by platform
mbligh1ef218d2009-08-03 16:57:56 +0000679
Chris Masone3a560bd2011-11-14 16:53:56 -0800680 params:
681 tko: a TKO object representing the results DB.
682 job: the job to be examined.
Chris Masone6fed6462011-10-20 16:36:43 -0700683 enough: the acceptable delta between the number of completed
684 tests and the total number of tests.
Chris Masone3a560bd2011-11-14 16:53:56 -0800685 debug: enable debugging output.
686
687 returns:
Chris Masone6fed6462011-10-20 16:36:43 -0700688 False: if any platform has more than |enough| failures
689 None: if any platform has less than |enough| machines
Chris Masone3a560bd2011-11-14 16:53:56 -0800690 not yet Good.
Chris Masone6fed6462011-10-20 16:36:43 -0700691 True: if all platforms have at least |enough| machines
Chris Masone3a560bd2011-11-14 16:53:56 -0800692 Good.
mbligh5280e3b2008-12-22 14:39:28 +0000693 """
mbligh451ede12009-02-12 21:54:03 +0000694 self._job_test_results(tko, job, debug)
mblighe7fcf562009-05-21 01:43:17 +0000695 if job.test_status == {}:
696 return None
mbligh451ede12009-02-12 21:54:03 +0000697 self._job_results_platform_map(job, debug)
mbligh5280e3b2008-12-22 14:39:28 +0000698
mbligh5b618382008-12-03 15:24:01 +0000699 good_platforms = []
mbligh912c3f32009-03-25 19:31:30 +0000700 failed_platforms = []
701 aborted_platforms = []
mbligh5b618382008-12-03 15:24:01 +0000702 unknown_platforms = []
mbligh5280e3b2008-12-22 14:39:28 +0000703 platform_map = job.results_platform_map
mbligh5b618382008-12-03 15:24:01 +0000704 for platform in platform_map:
mbligh17c75e62009-06-08 16:18:21 +0000705 if not job.platform_results.has_key(platform):
706 # record test start, but there's no way to do this right now
707 job.platform_results[platform] = None
mbligh5b618382008-12-03 15:24:01 +0000708 total = len(platform_map[platform]['Total'])
709 completed = len(platform_map[platform].get('Completed', []))
mbligh912c3f32009-03-25 19:31:30 +0000710 failed = len(platform_map[platform].get('Failed', []))
711 aborted = len(platform_map[platform].get('Aborted', []))
mbligh17c75e62009-06-08 16:18:21 +0000712
mbligh1ef218d2009-08-03 16:57:56 +0000713 # We set up what we want to record here, but don't actually do
mbligh17c75e62009-06-08 16:18:21 +0000714 # it yet, until we have a decisive answer for this platform
715 if aborted or failed:
716 bad = aborted + failed
717 if (bad > 1) or (bad * 2 >= total):
718 platform_test_result = 'FAIL'
719 else:
720 platform_test_result = 'WARN'
721
Chris Masone6fed6462011-10-20 16:36:43 -0700722 if aborted > enough:
mbligh912c3f32009-03-25 19:31:30 +0000723 aborted_platforms.append(platform)
mbligh17c75e62009-06-08 16:18:21 +0000724 self.set_platform_results(job, platform, platform_test_result)
Chris Masone6fed6462011-10-20 16:36:43 -0700725 elif (failed * 2 >= total) or (failed > enough):
mbligh912c3f32009-03-25 19:31:30 +0000726 failed_platforms.append(platform)
mbligh17c75e62009-06-08 16:18:21 +0000727 self.set_platform_results(job, platform, platform_test_result)
Chris Masone6fed6462011-10-20 16:36:43 -0700728 elif (completed >= enough) and (completed + enough >= total):
mbligh5b618382008-12-03 15:24:01 +0000729 good_platforms.append(platform)
mbligh17c75e62009-06-08 16:18:21 +0000730 self.set_platform_results(job, platform, 'GOOD')
mbligh5b618382008-12-03 15:24:01 +0000731 else:
732 unknown_platforms.append(platform)
733 detail = []
734 for status in platform_map[platform]:
735 if status == 'Total':
736 continue
737 detail.append('%s=%s' % (status,platform_map[platform][status]))
738 if debug:
mbligh1ef218d2009-08-03 16:57:56 +0000739 print '%20s %d/%d %s' % (platform, completed, total,
mbligh5b618382008-12-03 15:24:01 +0000740 ' '.join(detail))
741 print
mbligh1ef218d2009-08-03 16:57:56 +0000742
mbligh912c3f32009-03-25 19:31:30 +0000743 if len(aborted_platforms) > 0:
mbligh5b618382008-12-03 15:24:01 +0000744 if debug:
mbligh17c75e62009-06-08 16:18:21 +0000745 print 'Result aborted - platforms: ',
746 print ' '.join(aborted_platforms)
mbligh912c3f32009-03-25 19:31:30 +0000747 return "Abort"
748 if len(failed_platforms) > 0:
749 if debug:
750 print 'Result bad - platforms: ' + ' '.join(failed_platforms)
mbligh5b618382008-12-03 15:24:01 +0000751 return False
752 if len(unknown_platforms) > 0:
753 if debug:
754 platform_list = ' '.join(unknown_platforms)
755 print 'Result unknown - platforms: ', platform_list
756 return None
757 if debug:
758 platform_list = ' '.join(good_platforms)
759 print 'Result good - all platforms passed: ', platform_list
760 return True
761
762
mbligh5280e3b2008-12-22 14:39:28 +0000763class TestResults(object):
764 """
765 Container class used to hold the results of the tests for a job
766 """
767 def __init__(self):
768 self.good = []
769 self.fail = []
mbligh451ede12009-02-12 21:54:03 +0000770 self.pending = []
mbligh5280e3b2008-12-22 14:39:28 +0000771
772
773 def add(self, result):
mbligh451ede12009-02-12 21:54:03 +0000774 if result.complete_count > result.pass_count:
775 self.fail.append(result)
776 elif result.incomplete_count > 0:
777 self.pending.append(result)
mbligh5280e3b2008-12-22 14:39:28 +0000778 else:
mbligh451ede12009-02-12 21:54:03 +0000779 self.good.append(result)
mbligh5280e3b2008-12-22 14:39:28 +0000780
781
782class RpcObject(object):
mbligh67647152008-11-19 00:18:14 +0000783 """
784 Generic object used to construct python objects from rpc calls
785 """
786 def __init__(self, afe, hash):
787 self.afe = afe
788 self.hash = hash
789 self.__dict__.update(hash)
790
791
792 def __str__(self):
793 return dump_object(self.__repr__(), self)
794
795
mbligh1354c9d2008-12-22 14:56:13 +0000796class ControlFile(RpcObject):
797 """
798 AFE control file object
799
800 Fields: synch_count, dependencies, control_file, is_server
801 """
802 def __repr__(self):
803 return 'CONTROL FILE: %s' % self.control_file
804
805
mbligh5280e3b2008-12-22 14:39:28 +0000806class Label(RpcObject):
mbligh67647152008-11-19 00:18:14 +0000807 """
808 AFE label object
809
810 Fields:
811 name, invalid, platform, kernel_config, id, only_if_needed
812 """
813 def __repr__(self):
814 return 'LABEL: %s' % self.name
815
816
817 def add_hosts(self, hosts):
Chris Masone3a560bd2011-11-14 16:53:56 -0800818 return self.afe.run('label_add_hosts', id=self.id, hosts=hosts)
mbligh67647152008-11-19 00:18:14 +0000819
820
821 def remove_hosts(self, hosts):
Chris Masone3a560bd2011-11-14 16:53:56 -0800822 return self.afe.run('label_remove_hosts', id=self.id, hosts=hosts)
mbligh67647152008-11-19 00:18:14 +0000823
824
mbligh5280e3b2008-12-22 14:39:28 +0000825class Acl(RpcObject):
mbligh67647152008-11-19 00:18:14 +0000826 """
827 AFE acl object
828
829 Fields:
830 users, hosts, description, name, id
831 """
832 def __repr__(self):
833 return 'ACL: %s' % self.name
834
835
836 def add_hosts(self, hosts):
837 self.afe.log('Adding hosts %s to ACL %s' % (hosts, self.name))
838 return self.afe.run('acl_group_add_hosts', self.id, hosts)
839
840
841 def remove_hosts(self, hosts):
842 self.afe.log('Removing hosts %s from ACL %s' % (hosts, self.name))
843 return self.afe.run('acl_group_remove_hosts', self.id, hosts)
844
845
mbligh54459c72009-01-21 19:26:44 +0000846 def add_users(self, users):
847 self.afe.log('Adding users %s to ACL %s' % (users, self.name))
848 return self.afe.run('acl_group_add_users', id=self.name, users=users)
849
850
mbligh5280e3b2008-12-22 14:39:28 +0000851class Job(RpcObject):
mbligh67647152008-11-19 00:18:14 +0000852 """
853 AFE job object
854
855 Fields:
856 name, control_file, control_type, synch_count, reboot_before,
857 run_verify, priority, email_list, created_on, dependencies,
858 timeout, owner, reboot_after, id
859 """
860 def __repr__(self):
861 return 'JOB: %s' % self.id
862
863
mbligh5280e3b2008-12-22 14:39:28 +0000864class JobStatus(RpcObject):
mbligh67647152008-11-19 00:18:14 +0000865 """
866 AFE job_status object
867
868 Fields:
869 status, complete, deleted, meta_host, host, active, execution_subdir, id
870 """
871 def __init__(self, afe, hash):
MK Ryu1b2d7f92015-02-24 17:45:02 -0800872 super(JobStatus, self).__init__(afe, hash)
mbligh5280e3b2008-12-22 14:39:28 +0000873 self.job = Job(afe, self.job)
Dale Curtis8adf7892011-09-08 16:13:36 -0700874 if getattr(self, 'host'):
mbligh99b24f42009-06-08 16:45:55 +0000875 self.host = Host(afe, self.host)
mbligh67647152008-11-19 00:18:14 +0000876
877
878 def __repr__(self):
mbligh451ede12009-02-12 21:54:03 +0000879 if self.host and self.host.hostname:
880 hostname = self.host.hostname
881 else:
882 hostname = 'None'
883 return 'JOB STATUS: %s-%s' % (self.job.id, hostname)
mbligh67647152008-11-19 00:18:14 +0000884
885
MK Ryu1b2d7f92015-02-24 17:45:02 -0800886class SpecialTask(RpcObject):
887 """
888 AFE special task object
889 """
890 def __init__(self, afe, hash):
891 super(SpecialTask, self).__init__(afe, hash)
892 self.host = Host(afe, self.host)
893
894
895 def __repr__(self):
896 return 'SPECIAL TASK: %s' % self.id
897
898
mbligh5280e3b2008-12-22 14:39:28 +0000899class Host(RpcObject):
mbligh67647152008-11-19 00:18:14 +0000900 """
901 AFE host object
902
903 Fields:
904 status, lock_time, locked_by, locked, hostname, invalid,
905 synch_id, labels, platform, protection, dirty, id
906 """
907 def __repr__(self):
908 return 'HOST OBJECT: %s' % self.hostname
909
910
911 def show(self):
912 labels = list(set(self.labels) - set([self.platform]))
913 print '%-6s %-7s %-7s %-16s %s' % (self.hostname, self.status,
914 self.locked, self.platform,
915 ', '.join(labels))
916
917
mbligh54459c72009-01-21 19:26:44 +0000918 def delete(self):
919 return self.afe.run('delete_host', id=self.id)
920
921
mbligh6463c4b2009-01-30 00:33:37 +0000922 def modify(self, **dargs):
923 return self.afe.run('modify_host', id=self.id, **dargs)
924
925
mbligh67647152008-11-19 00:18:14 +0000926 def get_acls(self):
927 return self.afe.get_acls(hosts__hostname=self.hostname)
928
929
930 def add_acl(self, acl_name):
931 self.afe.log('Adding ACL %s to host %s' % (acl_name, self.hostname))
932 return self.afe.run('acl_group_add_hosts', id=acl_name,
933 hosts=[self.hostname])
934
935
936 def remove_acl(self, acl_name):
937 self.afe.log('Removing ACL %s from host %s' % (acl_name, self.hostname))
938 return self.afe.run('acl_group_remove_hosts', id=acl_name,
939 hosts=[self.hostname])
940
941
942 def get_labels(self):
943 return self.afe.get_labels(host__hostname__in=[self.hostname])
944
945
946 def add_labels(self, labels):
947 self.afe.log('Adding labels %s to host %s' % (labels, self.hostname))
948 return self.afe.run('host_add_labels', id=self.id, labels=labels)
949
950
951 def remove_labels(self, labels):
952 self.afe.log('Removing labels %s from host %s' % (labels,self.hostname))
953 return self.afe.run('host_remove_labels', id=self.id, labels=labels)
mbligh5b618382008-12-03 15:24:01 +0000954
955
mbligh54459c72009-01-21 19:26:44 +0000956class User(RpcObject):
957 def __repr__(self):
958 return 'USER: %s' % self.login
959
960
mbligh5280e3b2008-12-22 14:39:28 +0000961class TestStatus(RpcObject):
mblighc31e4022008-12-11 19:32:30 +0000962 """
963 TKO test status object
964
965 Fields:
966 test_idx, hostname, testname, id
967 complete_count, incomplete_count, group_count, pass_count
968 """
969 def __repr__(self):
970 return 'TEST STATUS: %s' % self.id
971
972
MK Ryuacf35922014-10-03 14:56:49 -0700973class HostAttribute(RpcObject):
974 """
975 AFE host attribute object
976
977 Fields:
978 id, host, attribute, value
979 """
980 def __repr__(self):
981 return 'HOST ATTRIBUTE %d' % self.id
982
983
mbligh5b618382008-12-03 15:24:01 +0000984class MachineTestPairing(object):
985 """
986 Object representing the pairing of a machine label with a control file
mbligh1f23f362008-12-22 14:46:12 +0000987
988 machine_label: use machines from this label
989 control_file: use this control file (by name in the frontend)
990 platforms: list of rexeps to filter platforms by. [] => no filtering
mbligh282ce892010-01-06 18:40:17 +0000991 job_label: The label (name) to give to the autotest job launched
992 to run this pairing. '<kernel-version> : <config> : <date>'
mbligh5b618382008-12-03 15:24:01 +0000993 """
mbligh1354c9d2008-12-22 14:56:13 +0000994 def __init__(self, machine_label, control_file, platforms=[],
mbligh17c75e62009-06-08 16:18:21 +0000995 container=False, atomic_group_sched=False, synch_count=0,
mbligh282ce892010-01-06 18:40:17 +0000996 testname=None, job_label=None):
mbligh5b618382008-12-03 15:24:01 +0000997 self.machine_label = machine_label
998 self.control_file = control_file
mbligh1f23f362008-12-22 14:46:12 +0000999 self.platforms = platforms
mbligh1354c9d2008-12-22 14:56:13 +00001000 self.container = container
mblighb9db5162009-04-17 22:21:41 +00001001 self.atomic_group_sched = atomic_group_sched
1002 self.synch_count = synch_count
mbligh17c75e62009-06-08 16:18:21 +00001003 self.testname = testname
mbligh282ce892010-01-06 18:40:17 +00001004 self.job_label = job_label
mbligh1354c9d2008-12-22 14:56:13 +00001005
1006
1007 def __repr__(self):
1008 return '%s %s %s %s' % (self.machine_label, self.control_file,
1009 self.platforms, self.container)