blob: 19a74a22d17361ed95e1607bbe95627f9d36837e [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
Scott Zawalski63470dd2012-09-05 00:49:43 -040021from autotest_lib.tko import db
22
23
mbligh4e576612008-12-22 14:56:36 +000024try:
25 from autotest_lib.server.site_common import site_utils as server_utils
26except:
27 from autotest_lib.server import utils as server_utils
28form_ntuples_from_machines = server_utils.form_ntuples_from_machines
mbligh67647152008-11-19 00:18:14 +000029
mbligh37eceaa2008-12-15 22:56:37 +000030GLOBAL_CONFIG = global_config.global_config
31DEFAULT_SERVER = 'autotest'
32
mbligh67647152008-11-19 00:18:14 +000033def dump_object(header, obj):
34 """
35 Standard way to print out the frontend objects (eg job, host, acl, label)
36 in a human-readable fashion for debugging
37 """
38 result = header + '\n'
39 for key in obj.hash:
40 if key == 'afe' or key == 'hash':
41 continue
42 result += '%20s: %s\n' % (key, obj.hash[key])
43 return result
44
45
mbligh5280e3b2008-12-22 14:39:28 +000046class RpcClient(object):
mbligh67647152008-11-19 00:18:14 +000047 """
mbligh451ede12009-02-12 21:54:03 +000048 Abstract RPC class for communicating with the autotest frontend
49 Inherited for both TKO and AFE uses.
mbligh67647152008-11-19 00:18:14 +000050
mbligh1ef218d2009-08-03 16:57:56 +000051 All the constructors go in the afe / tko class.
mbligh451ede12009-02-12 21:54:03 +000052 Manipulating methods go in the object classes themselves
mbligh67647152008-11-19 00:18:14 +000053 """
mbligh99b24f42009-06-08 16:45:55 +000054 def __init__(self, path, user, server, print_log, debug, reply_debug):
mbligh67647152008-11-19 00:18:14 +000055 """
mbligh451ede12009-02-12 21:54:03 +000056 Create a cached instance of a connection to the frontend
mbligh67647152008-11-19 00:18:14 +000057
58 user: username to connect as
mbligh451ede12009-02-12 21:54:03 +000059 server: frontend server to connect to
mbligh67647152008-11-19 00:18:14 +000060 print_log: pring a logging message to stdout on every operation
61 debug: print out all RPC traffic
62 """
mblighc31e4022008-12-11 19:32:30 +000063 if not user:
mblighdb59e3c2009-11-21 01:45:18 +000064 user = getpass.getuser()
mbligh451ede12009-02-12 21:54:03 +000065 if not server:
mbligh475f7762009-01-30 00:34:04 +000066 if 'AUTOTEST_WEB' in os.environ:
mbligh451ede12009-02-12 21:54:03 +000067 server = os.environ['AUTOTEST_WEB']
mbligh475f7762009-01-30 00:34:04 +000068 else:
mbligh451ede12009-02-12 21:54:03 +000069 server = GLOBAL_CONFIG.get_config_value('SERVER', 'hostname',
70 default=DEFAULT_SERVER)
71 self.server = server
mbligh67647152008-11-19 00:18:14 +000072 self.user = user
73 self.print_log = print_log
74 self.debug = debug
mbligh99b24f42009-06-08 16:45:55 +000075 self.reply_debug = reply_debug
Scott Zawalski347aaf42012-04-03 16:33:00 -040076 headers = {'AUTHORIZATION': self.user}
77 rpc_server = 'http://' + server + path
mbligh1354c9d2008-12-22 14:56:13 +000078 if debug:
79 print 'SERVER: %s' % rpc_server
80 print 'HEADERS: %s' % headers
mbligh67647152008-11-19 00:18:14 +000081 self.proxy = rpc_client_lib.get_proxy(rpc_server, headers=headers)
82
83
84 def run(self, call, **dargs):
85 """
86 Make a RPC call to the AFE server
87 """
88 rpc_call = getattr(self.proxy, call)
89 if self.debug:
90 print 'DEBUG: %s %s' % (call, dargs)
mbligh451ede12009-02-12 21:54:03 +000091 try:
mbligh99b24f42009-06-08 16:45:55 +000092 result = utils.strip_unicode(rpc_call(**dargs))
93 if self.reply_debug:
94 print result
95 return result
mbligh451ede12009-02-12 21:54:03 +000096 except Exception:
97 print 'FAILED RPC CALL: %s %s' % (call, dargs)
98 raise
mbligh67647152008-11-19 00:18:14 +000099
100
101 def log(self, message):
102 if self.print_log:
103 print message
104
105
jamesrenc3940222010-02-19 21:57:37 +0000106class Planner(RpcClient):
107 def __init__(self, user=None, server=None, print_log=True, debug=False,
108 reply_debug=False):
109 super(Planner, self).__init__(path='/planner/server/rpc/',
110 user=user,
111 server=server,
112 print_log=print_log,
113 debug=debug,
114 reply_debug=reply_debug)
115
116
mbligh5280e3b2008-12-22 14:39:28 +0000117class TKO(RpcClient):
mbligh99b24f42009-06-08 16:45:55 +0000118 def __init__(self, user=None, server=None, print_log=True, debug=False,
119 reply_debug=False):
Scott Zawalski347aaf42012-04-03 16:33:00 -0400120 super(TKO, self).__init__(path='/new_tko/server/noauth/rpc/',
mbligh99b24f42009-06-08 16:45:55 +0000121 user=user,
122 server=server,
123 print_log=print_log,
124 debug=debug,
125 reply_debug=reply_debug)
Scott Zawalski63470dd2012-09-05 00:49:43 -0400126 self._db = None
127
128
129 def get_job_test_statuses_from_db(self, job_id):
130 """Get job test statuses from the database.
131
132 Retrieve a set of fields from a job that reflect the status of each test
133 run within a job.
134 fields retrieved: status, test_name, reason, test_started_time,
135 test_finished_time, afe_job_id, job_owner, hostname.
136
137 @param job_id: The afe job id to look up.
138 @returns a TestStatus object of the resulting information.
139 """
140 if self._db is None:
141 self._db = db.db()
142 fields = ['status', 'test_name', 'reason', 'test_started_time',
143 'test_finished_time', 'afe_job_id', 'job_owner', 'hostname']
144 table = 'tko_test_view_2'
145 where = 'job_tag like "%s-%%"' % job_id
146 test_status = []
147 # Run commit before we query to ensure that we are pulling the latest
148 # results.
149 self._db.commit()
150 for entry in self._db.select(','.join(fields), table, (where, None)):
151 status_dict = {}
152 for key,value in zip(fields, entry):
153 # All callers expect values to be a str object.
154 status_dict[key] = str(value)
155 # id is used by TestStatus to uniquely identify each Test Status
156 # obj.
157 status_dict['id'] = [status_dict['reason'], status_dict['hostname'],
158 status_dict['test_name']]
159 test_status.append(status_dict)
160
161 return [TestStatus(self, e) for e in test_status]
mblighc31e4022008-12-11 19:32:30 +0000162
163
164 def get_status_counts(self, job, **data):
165 entries = self.run('get_status_counts',
mbligh1ef218d2009-08-03 16:57:56 +0000166 group_by=['hostname', 'test_name', 'reason'],
mblighc31e4022008-12-11 19:32:30 +0000167 job_tag__startswith='%s-' % job, **data)
mbligh5280e3b2008-12-22 14:39:28 +0000168 return [TestStatus(self, e) for e in entries['groups']]
mblighc31e4022008-12-11 19:32:30 +0000169
170
mbligh5280e3b2008-12-22 14:39:28 +0000171class AFE(RpcClient):
mbligh17c75e62009-06-08 16:18:21 +0000172 def __init__(self, user=None, server=None, print_log=True, debug=False,
mbligh99b24f42009-06-08 16:45:55 +0000173 reply_debug=False, job=None):
mbligh17c75e62009-06-08 16:18:21 +0000174 self.job = job
Scott Zawalski347aaf42012-04-03 16:33:00 -0400175 super(AFE, self).__init__(path='/afe/server/noauth/rpc/',
mbligh99b24f42009-06-08 16:45:55 +0000176 user=user,
177 server=server,
178 print_log=print_log,
179 debug=debug,
180 reply_debug=reply_debug)
mblighc31e4022008-12-11 19:32:30 +0000181
mbligh1ef218d2009-08-03 16:57:56 +0000182
mbligh67647152008-11-19 00:18:14 +0000183 def host_statuses(self, live=None):
jamesren121eee62010-04-13 19:10:12 +0000184 dead_statuses = ['Repair Failed', 'Repairing']
mbligh67647152008-11-19 00:18:14 +0000185 statuses = self.run('get_static_data')['host_statuses']
186 if live == True:
mblighc2847b72009-03-25 19:32:20 +0000187 return list(set(statuses) - set(dead_statuses))
mbligh67647152008-11-19 00:18:14 +0000188 if live == False:
189 return dead_statuses
190 else:
191 return statuses
192
193
mbligh71094012009-12-19 05:35:21 +0000194 @staticmethod
195 def _dict_for_host_query(hostnames=(), status=None, label=None):
196 query_args = {}
mbligh4e545a52009-12-19 05:30:39 +0000197 if hostnames:
198 query_args['hostname__in'] = hostnames
199 if status:
200 query_args['status'] = status
201 if label:
202 query_args['labels__name'] = label
mbligh71094012009-12-19 05:35:21 +0000203 return query_args
204
205
206 def get_hosts(self, hostnames=(), status=None, label=None, **dargs):
207 query_args = dict(dargs)
208 query_args.update(self._dict_for_host_query(hostnames=hostnames,
209 status=status,
210 label=label))
211 hosts = self.run('get_hosts', **query_args)
212 return [Host(self, h) for h in hosts]
213
214
215 def get_hostnames(self, status=None, label=None, **dargs):
216 """Like get_hosts() but returns hostnames instead of Host objects."""
217 # This implementation can be replaced with a more efficient one
218 # that does not query for entire host objects in the future.
219 return [host_obj.hostname for host_obj in
220 self.get_hosts(status=status, label=label, **dargs)]
221
222
223 def reverify_hosts(self, hostnames=(), status=None, label=None):
224 query_args = dict(locked=False,
225 aclgroup__users__login=self.user)
226 query_args.update(self._dict_for_host_query(hostnames=hostnames,
227 status=status,
228 label=label))
mbligh4e545a52009-12-19 05:30:39 +0000229 return self.run('reverify_hosts', **query_args)
230
231
mbligh67647152008-11-19 00:18:14 +0000232 def create_host(self, hostname, **dargs):
mbligh54459c72009-01-21 19:26:44 +0000233 id = self.run('add_host', hostname=hostname, **dargs)
mbligh67647152008-11-19 00:18:14 +0000234 return self.get_hosts(id=id)[0]
235
236
Chris Masone8abb6fc2012-01-31 09:27:36 -0800237 def set_host_attribute(self, attr, val, **dargs):
238 self.run('set_host_attribute', attribute=attr, value=val, **dargs)
239
240
mbligh67647152008-11-19 00:18:14 +0000241 def get_labels(self, **dargs):
242 labels = self.run('get_labels', **dargs)
mbligh5280e3b2008-12-22 14:39:28 +0000243 return [Label(self, l) for l in labels]
mbligh67647152008-11-19 00:18:14 +0000244
245
246 def create_label(self, name, **dargs):
mbligh54459c72009-01-21 19:26:44 +0000247 id = self.run('add_label', name=name, **dargs)
mbligh67647152008-11-19 00:18:14 +0000248 return self.get_labels(id=id)[0]
249
250
251 def get_acls(self, **dargs):
252 acls = self.run('get_acl_groups', **dargs)
mbligh5280e3b2008-12-22 14:39:28 +0000253 return [Acl(self, a) for a in acls]
mbligh67647152008-11-19 00:18:14 +0000254
255
256 def create_acl(self, name, **dargs):
mbligh54459c72009-01-21 19:26:44 +0000257 id = self.run('add_acl_group', name=name, **dargs)
mbligh67647152008-11-19 00:18:14 +0000258 return self.get_acls(id=id)[0]
259
260
mbligh54459c72009-01-21 19:26:44 +0000261 def get_users(self, **dargs):
262 users = self.run('get_users', **dargs)
263 return [User(self, u) for u in users]
264
265
mbligh1354c9d2008-12-22 14:56:13 +0000266 def generate_control_file(self, tests, **dargs):
267 ret = self.run('generate_control_file', tests=tests, **dargs)
268 return ControlFile(self, ret)
269
270
mbligh67647152008-11-19 00:18:14 +0000271 def get_jobs(self, summary=False, **dargs):
272 if summary:
273 jobs_data = self.run('get_jobs_summary', **dargs)
274 else:
275 jobs_data = self.run('get_jobs', **dargs)
mblighafbba0c2009-06-08 16:44:45 +0000276 jobs = []
277 for j in jobs_data:
278 job = Job(self, j)
279 # Set up some extra information defaults
280 job.testname = re.sub('\s.*', '', job.name) # arbitrary default
281 job.platform_results = {}
282 job.platform_reasons = {}
283 jobs.append(job)
284 return jobs
mbligh67647152008-11-19 00:18:14 +0000285
286
287 def get_host_queue_entries(self, **data):
288 entries = self.run('get_host_queue_entries', **data)
mblighf9e35862009-02-26 01:03:11 +0000289 job_statuses = [JobStatus(self, e) for e in entries]
mbligh99b24f42009-06-08 16:45:55 +0000290
291 # Sadly, get_host_queue_entries doesn't return platforms, we have
292 # to get those back from an explicit get_hosts queury, then patch
293 # the new host objects back into the host list.
294 hostnames = [s.host.hostname for s in job_statuses if s.host]
295 host_hash = {}
296 for host in self.get_hosts(hostname__in=hostnames):
297 host_hash[host.hostname] = host
298 for status in job_statuses:
299 if status.host:
300 status.host = host_hash[status.host.hostname]
mblighf9e35862009-02-26 01:03:11 +0000301 # filter job statuses that have either host or meta_host
302 return [status for status in job_statuses if (status.host or
303 status.meta_host)]
mbligh67647152008-11-19 00:18:14 +0000304
305
mblighb9db5162009-04-17 22:21:41 +0000306 def create_job_by_test(self, tests, kernel=None, use_container=False,
Eric Lie0493a42010-11-15 13:05:43 -0800307 kernel_cmdline=None, **dargs):
mbligh67647152008-11-19 00:18:14 +0000308 """
309 Given a test name, fetch the appropriate control file from the server
mbligh4e576612008-12-22 14:56:36 +0000310 and submit it.
311
Eric Lie0493a42010-11-15 13:05:43 -0800312 @param kernel: A comma separated list of kernel versions to boot.
313 @param kernel_cmdline: The command line used to boot all kernels listed
314 in the kernel parameter.
315
mbligh4e576612008-12-22 14:56:36 +0000316 Returns a list of job objects
mbligh67647152008-11-19 00:18:14 +0000317 """
mblighb9db5162009-04-17 22:21:41 +0000318 assert ('hosts' in dargs or
319 'atomic_group_name' in dargs and 'synch_count' in dargs)
showarda2cd72b2009-10-01 18:43:53 +0000320 if kernel:
321 kernel_list = re.split('[\s,]+', kernel.strip())
Eric Lie0493a42010-11-15 13:05:43 -0800322 kernel_info = []
323 for version in kernel_list:
324 kernel_dict = {'version': version}
325 if kernel_cmdline is not None:
326 kernel_dict['cmdline'] = kernel_cmdline
327 kernel_info.append(kernel_dict)
showarda2cd72b2009-10-01 18:43:53 +0000328 else:
329 kernel_info = None
330 control_file = self.generate_control_file(
Dale Curtis74a314b2011-06-23 14:55:46 -0700331 tests=tests, kernel=kernel_info, use_container=use_container)
mbligh1354c9d2008-12-22 14:56:13 +0000332 if control_file.is_server:
mbligh67647152008-11-19 00:18:14 +0000333 dargs['control_type'] = 'Server'
334 else:
335 dargs['control_type'] = 'Client'
336 dargs['dependencies'] = dargs.get('dependencies', []) + \
mbligh1354c9d2008-12-22 14:56:13 +0000337 control_file.dependencies
338 dargs['control_file'] = control_file.control_file
mbligh672666c2009-07-28 23:22:13 +0000339 if not dargs.get('synch_count', None):
mblighc99fccf2009-07-11 00:59:33 +0000340 dargs['synch_count'] = control_file.synch_count
mblighb9db5162009-04-17 22:21:41 +0000341 if 'hosts' in dargs and len(dargs['hosts']) < dargs['synch_count']:
342 # will not be able to satisfy this request
mbligh38b09152009-04-28 18:34:25 +0000343 return None
344 return self.create_job(**dargs)
mbligh67647152008-11-19 00:18:14 +0000345
346
347 def create_job(self, control_file, name=' ', priority='Medium',
348 control_type='Client', **dargs):
349 id = self.run('create_job', name=name, priority=priority,
350 control_file=control_file, control_type=control_type, **dargs)
351 return self.get_jobs(id=id)[0]
352
353
mbligh282ce892010-01-06 18:40:17 +0000354 def run_test_suites(self, pairings, kernel, kernel_label=None,
355 priority='Medium', wait=True, poll_interval=10,
jamesren37d4a612010-06-04 22:30:56 +0000356 email_from=None, email_to=None, timeout=168,
Simran Basi34217022012-11-06 13:43:15 -0800357 max_runtime_mins=10080, kernel_cmdline=None):
mbligh5b618382008-12-03 15:24:01 +0000358 """
359 Run a list of test suites on a particular kernel.
mbligh1ef218d2009-08-03 16:57:56 +0000360
mbligh5b618382008-12-03 15:24:01 +0000361 Poll for them to complete, and return whether they worked or not.
mbligh1ef218d2009-08-03 16:57:56 +0000362
mbligh282ce892010-01-06 18:40:17 +0000363 @param pairings: List of MachineTestPairing objects to invoke.
364 @param kernel: Name of the kernel to run.
365 @param kernel_label: Label (string) of the kernel to run such as
366 '<kernel-version> : <config> : <date>'
367 If any pairing object has its job_label attribute set it
368 will override this value for that particular job.
Eric Lie0493a42010-11-15 13:05:43 -0800369 @param kernel_cmdline: The command line to boot the kernel(s) with.
mbligh282ce892010-01-06 18:40:17 +0000370 @param wait: boolean - Wait for the results to come back?
371 @param poll_interval: Interval between polling for job results (in mins)
372 @param email_from: Send notification email upon completion from here.
373 @param email_from: Send notification email upon completion to here.
mbligh5b618382008-12-03 15:24:01 +0000374 """
375 jobs = []
376 for pairing in pairings:
mbligh0c4f8d72009-05-12 20:52:18 +0000377 try:
378 new_job = self.invoke_test(pairing, kernel, kernel_label,
jamesren37d4a612010-06-04 22:30:56 +0000379 priority, timeout=timeout,
Eric Lie0493a42010-11-15 13:05:43 -0800380 kernel_cmdline=kernel_cmdline,
Simran Basi34217022012-11-06 13:43:15 -0800381 max_runtime_mins=max_runtime_mins)
mbligh0c4f8d72009-05-12 20:52:18 +0000382 if not new_job:
383 continue
mbligh0c4f8d72009-05-12 20:52:18 +0000384 jobs.append(new_job)
385 except Exception, e:
386 traceback.print_exc()
mblighb9db5162009-04-17 22:21:41 +0000387 if not wait or not jobs:
mbligh5b618382008-12-03 15:24:01 +0000388 return
mbligh5280e3b2008-12-22 14:39:28 +0000389 tko = TKO()
mbligh5b618382008-12-03 15:24:01 +0000390 while True:
391 time.sleep(60 * poll_interval)
mbligh5280e3b2008-12-22 14:39:28 +0000392 result = self.poll_all_jobs(tko, jobs, email_from, email_to)
mbligh5b618382008-12-03 15:24:01 +0000393 if result is not None:
394 return result
395
396
mbligh45ffc432008-12-09 23:35:17 +0000397 def result_notify(self, job, email_from, email_to):
mbligh5b618382008-12-03 15:24:01 +0000398 """
mbligh45ffc432008-12-09 23:35:17 +0000399 Notify about the result of a job. Will always print, if email data
400 is provided, will send email for it as well.
401
402 job: job object to notify about
403 email_from: send notification email upon completion from here
404 email_from: send notification email upon completion to here
405 """
406 if job.result == True:
407 subject = 'Testing PASSED: '
408 else:
409 subject = 'Testing FAILED: '
410 subject += '%s : %s\n' % (job.name, job.id)
411 text = []
412 for platform in job.results_platform_map:
413 for status in job.results_platform_map[platform]:
414 if status == 'Total':
415 continue
mbligh451ede12009-02-12 21:54:03 +0000416 for host in job.results_platform_map[platform][status]:
417 text.append('%20s %10s %10s' % (platform, status, host))
418 if status == 'Failed':
419 for test_status in job.test_status[host].fail:
420 text.append('(%s, %s) : %s' % \
421 (host, test_status.test_name,
422 test_status.reason))
423 text.append('')
mbligh37eceaa2008-12-15 22:56:37 +0000424
mbligh451ede12009-02-12 21:54:03 +0000425 base_url = 'http://' + self.server
mbligh37eceaa2008-12-15 22:56:37 +0000426
427 params = ('columns=test',
428 'rows=machine_group',
429 "condition=tag~'%s-%%25'" % job.id,
430 'title=Report')
431 query_string = '&'.join(params)
mbligh451ede12009-02-12 21:54:03 +0000432 url = '%s/tko/compose_query.cgi?%s' % (base_url, query_string)
433 text.append(url + '\n')
434 url = '%s/afe/#tab_id=view_job&object_id=%s' % (base_url, job.id)
435 text.append(url + '\n')
mbligh37eceaa2008-12-15 22:56:37 +0000436
437 body = '\n'.join(text)
438 print '---------------------------------------------------'
439 print 'Subject: ', subject
mbligh45ffc432008-12-09 23:35:17 +0000440 print body
mbligh37eceaa2008-12-15 22:56:37 +0000441 print '---------------------------------------------------'
mbligh45ffc432008-12-09 23:35:17 +0000442 if email_from and email_to:
mbligh37eceaa2008-12-15 22:56:37 +0000443 print 'Sending email ...'
mbligh45ffc432008-12-09 23:35:17 +0000444 utils.send_email(email_from, email_to, subject, body)
445 print
mbligh37eceaa2008-12-15 22:56:37 +0000446
mbligh45ffc432008-12-09 23:35:17 +0000447
mbligh1354c9d2008-12-22 14:56:13 +0000448 def print_job_result(self, job):
449 """
450 Print the result of a single job.
451 job: a job object
452 """
453 if job.result is None:
454 print 'PENDING',
455 elif job.result == True:
456 print 'PASSED',
457 elif job.result == False:
458 print 'FAILED',
mbligh912c3f32009-03-25 19:31:30 +0000459 elif job.result == "Abort":
460 print 'ABORT',
mbligh1354c9d2008-12-22 14:56:13 +0000461 print ' %s : %s' % (job.id, job.name)
462
463
mbligh451ede12009-02-12 21:54:03 +0000464 def poll_all_jobs(self, tko, jobs, email_from=None, email_to=None):
mbligh45ffc432008-12-09 23:35:17 +0000465 """
466 Poll all jobs in a list.
467 jobs: list of job objects to poll
468 email_from: send notification email upon completion from here
469 email_from: send notification email upon completion to here
470
471 Returns:
mbligh5b618382008-12-03 15:24:01 +0000472 a) All complete successfully (return True)
473 b) One or more has failed (return False)
474 c) Cannot tell yet (return None)
475 """
mbligh45ffc432008-12-09 23:35:17 +0000476 results = []
mbligh5b618382008-12-03 15:24:01 +0000477 for job in jobs:
mbligh676dcbe2009-06-15 21:57:27 +0000478 if getattr(job, 'result', None) is None:
Chris Masone6fed6462011-10-20 16:36:43 -0700479 job.result = self.poll_job_results(tko, job)
mbligh676dcbe2009-06-15 21:57:27 +0000480 if job.result is not None:
481 self.result_notify(job, email_from, email_to)
mbligh45ffc432008-12-09 23:35:17 +0000482
mbligh676dcbe2009-06-15 21:57:27 +0000483 results.append(job.result)
mbligh1354c9d2008-12-22 14:56:13 +0000484 self.print_job_result(job)
mbligh45ffc432008-12-09 23:35:17 +0000485
486 if None in results:
487 return None
mbligh912c3f32009-03-25 19:31:30 +0000488 elif False in results or "Abort" in results:
mbligh45ffc432008-12-09 23:35:17 +0000489 return False
490 else:
491 return True
mbligh5b618382008-12-03 15:24:01 +0000492
493
mbligh1f23f362008-12-22 14:46:12 +0000494 def _included_platform(self, host, platforms):
495 """
496 See if host's platforms matches any of the patterns in the included
497 platforms list.
498 """
499 if not platforms:
500 return True # No filtering of platforms
501 for platform in platforms:
502 if re.search(platform, host.platform):
503 return True
504 return False
505
506
mbligh7b312282009-01-07 16:45:43 +0000507 def invoke_test(self, pairing, kernel, kernel_label, priority='Medium',
Eric Lie0493a42010-11-15 13:05:43 -0800508 kernel_cmdline=None, **dargs):
mbligh5b618382008-12-03 15:24:01 +0000509 """
510 Given a pairing of a control file to a machine label, find all machines
511 with that label, and submit that control file to them.
mbligh1ef218d2009-08-03 16:57:56 +0000512
mbligh282ce892010-01-06 18:40:17 +0000513 @param kernel_label: Label (string) of the kernel to run such as
514 '<kernel-version> : <config> : <date>'
515 If any pairing object has its job_label attribute set it
516 will override this value for that particular job.
517
518 @returns A list of job objects.
mbligh5b618382008-12-03 15:24:01 +0000519 """
mbligh282ce892010-01-06 18:40:17 +0000520 # The pairing can override the job label.
521 if pairing.job_label:
522 kernel_label = pairing.job_label
mbligh5b618382008-12-03 15:24:01 +0000523 job_name = '%s : %s' % (pairing.machine_label, kernel_label)
524 hosts = self.get_hosts(multiple_labels=[pairing.machine_label])
mbligh1f23f362008-12-22 14:46:12 +0000525 platforms = pairing.platforms
526 hosts = [h for h in hosts if self._included_platform(h, platforms)]
mblighc2847b72009-03-25 19:32:20 +0000527 dead_statuses = self.host_statuses(live=False)
528 host_list = [h.hostname for h in hosts if h.status not in dead_statuses]
mbligh1f23f362008-12-22 14:46:12 +0000529 print 'HOSTS: %s' % host_list
mblighb9db5162009-04-17 22:21:41 +0000530 if pairing.atomic_group_sched:
mblighc99fccf2009-07-11 00:59:33 +0000531 dargs['synch_count'] = pairing.synch_count
mblighb9db5162009-04-17 22:21:41 +0000532 dargs['atomic_group_name'] = pairing.machine_label
533 else:
534 dargs['hosts'] = host_list
mbligh38b09152009-04-28 18:34:25 +0000535 new_job = self.create_job_by_test(name=job_name,
mbligh17c75e62009-06-08 16:18:21 +0000536 dependencies=[pairing.machine_label],
537 tests=[pairing.control_file],
538 priority=priority,
539 kernel=kernel,
Eric Lie0493a42010-11-15 13:05:43 -0800540 kernel_cmdline=kernel_cmdline,
mbligh17c75e62009-06-08 16:18:21 +0000541 use_container=pairing.container,
542 **dargs)
mbligh38b09152009-04-28 18:34:25 +0000543 if new_job:
mbligh17c75e62009-06-08 16:18:21 +0000544 if pairing.testname:
545 new_job.testname = pairing.testname
mbligh4e576612008-12-22 14:56:36 +0000546 print 'Invoked test %s : %s' % (new_job.id, job_name)
mbligh38b09152009-04-28 18:34:25 +0000547 return new_job
mbligh5b618382008-12-03 15:24:01 +0000548
549
mblighb9db5162009-04-17 22:21:41 +0000550 def _job_test_results(self, tko, job, debug, tests=[]):
mbligh5b618382008-12-03 15:24:01 +0000551 """
mbligh5280e3b2008-12-22 14:39:28 +0000552 Retrieve test results for a job
mbligh5b618382008-12-03 15:24:01 +0000553 """
mbligh5280e3b2008-12-22 14:39:28 +0000554 job.test_status = {}
555 try:
556 test_statuses = tko.get_status_counts(job=job.id)
557 except Exception:
558 print "Ignoring exception on poll job; RPC interface is flaky"
559 traceback.print_exc()
560 return
561
562 for test_status in test_statuses:
mbligh7479a182009-01-07 16:46:24 +0000563 # SERVER_JOB is buggy, and often gives false failures. Ignore it.
564 if test_status.test_name == 'SERVER_JOB':
565 continue
mblighb9db5162009-04-17 22:21:41 +0000566 # if tests is not empty, restrict list of test_statuses to tests
567 if tests and test_status.test_name not in tests:
568 continue
mbligh451ede12009-02-12 21:54:03 +0000569 if debug:
570 print test_status
mbligh5280e3b2008-12-22 14:39:28 +0000571 hostname = test_status.hostname
572 if hostname not in job.test_status:
573 job.test_status[hostname] = TestResults()
574 job.test_status[hostname].add(test_status)
575
576
mbligh451ede12009-02-12 21:54:03 +0000577 def _job_results_platform_map(self, job, debug):
mblighc9e427e2009-04-28 18:35:06 +0000578 # Figure out which hosts passed / failed / aborted in a job
579 # Creates a 2-dimensional hash, stored as job.results_platform_map
580 # 1st index - platform type (string)
581 # 2nd index - Status (string)
582 # 'Completed' / 'Failed' / 'Aborted'
583 # Data indexed by this hash is a list of hostnames (text strings)
mbligh5280e3b2008-12-22 14:39:28 +0000584 job.results_platform_map = {}
mbligh5b618382008-12-03 15:24:01 +0000585 try:
mbligh45ffc432008-12-09 23:35:17 +0000586 job_statuses = self.get_host_queue_entries(job=job.id)
mbligh5b618382008-12-03 15:24:01 +0000587 except Exception:
588 print "Ignoring exception on poll job; RPC interface is flaky"
589 traceback.print_exc()
590 return None
mbligh5280e3b2008-12-22 14:39:28 +0000591
mbligh5b618382008-12-03 15:24:01 +0000592 platform_map = {}
mbligh5280e3b2008-12-22 14:39:28 +0000593 job.job_status = {}
mbligh451ede12009-02-12 21:54:03 +0000594 job.metahost_index = {}
mbligh5b618382008-12-03 15:24:01 +0000595 for job_status in job_statuses:
mblighc9e427e2009-04-28 18:35:06 +0000596 # This is basically "for each host / metahost in the job"
mbligh451ede12009-02-12 21:54:03 +0000597 if job_status.host:
598 hostname = job_status.host.hostname
599 else: # This is a metahost
600 metahost = job_status.meta_host
601 index = job.metahost_index.get(metahost, 1)
602 job.metahost_index[metahost] = index + 1
603 hostname = '%s.%s' % (metahost, index)
mbligh5280e3b2008-12-22 14:39:28 +0000604 job.job_status[hostname] = job_status.status
mbligh5b618382008-12-03 15:24:01 +0000605 status = job_status.status
mbligh0ecbe632009-05-13 21:34:56 +0000606 # Skip hosts that failed verify or repair:
607 # that's a machine failure, not a job failure
mbligh451ede12009-02-12 21:54:03 +0000608 if hostname in job.test_status:
609 verify_failed = False
610 for failure in job.test_status[hostname].fail:
mbligh0ecbe632009-05-13 21:34:56 +0000611 if (failure.test_name == 'verify' or
612 failure.test_name == 'repair'):
mbligh451ede12009-02-12 21:54:03 +0000613 verify_failed = True
614 break
615 if verify_failed:
616 continue
mblighc9e427e2009-04-28 18:35:06 +0000617 if hostname in job.test_status and job.test_status[hostname].fail:
618 # If the any tests failed in the job, we want to mark the
619 # job result as failed, overriding the default job status.
620 if status != "Aborted": # except if it's an aborted job
621 status = 'Failed'
mbligh451ede12009-02-12 21:54:03 +0000622 if job_status.host:
623 platform = job_status.host.platform
624 else: # This is a metahost
625 platform = job_status.meta_host
mbligh5b618382008-12-03 15:24:01 +0000626 if platform not in platform_map:
627 platform_map[platform] = {'Total' : [hostname]}
628 else:
629 platform_map[platform]['Total'].append(hostname)
630 new_host_list = platform_map[platform].get(status, []) + [hostname]
631 platform_map[platform][status] = new_host_list
mbligh45ffc432008-12-09 23:35:17 +0000632 job.results_platform_map = platform_map
mbligh5280e3b2008-12-22 14:39:28 +0000633
634
mbligh17c75e62009-06-08 16:18:21 +0000635 def set_platform_results(self, test_job, platform, result):
636 """
637 Result must be None, 'FAIL', 'WARN' or 'GOOD'
638 """
639 if test_job.platform_results[platform] is not None:
640 # We're already done, and results recorded. This can't change later.
641 return
642 test_job.platform_results[platform] = result
643 # Note that self.job refers to the metajob we're IN, not the job
644 # that we're excuting from here.
645 testname = '%s.%s' % (test_job.testname, platform)
646 if self.job:
647 self.job.record(result, None, testname, status='')
648
Chris Masone6fed6462011-10-20 16:36:43 -0700649 def poll_job_results(self, tko, job, enough=1, debug=False):
mbligh5280e3b2008-12-22 14:39:28 +0000650 """
Chris Masone3a560bd2011-11-14 16:53:56 -0800651 Analyse all job results by platform
mbligh1ef218d2009-08-03 16:57:56 +0000652
Chris Masone3a560bd2011-11-14 16:53:56 -0800653 params:
654 tko: a TKO object representing the results DB.
655 job: the job to be examined.
Chris Masone6fed6462011-10-20 16:36:43 -0700656 enough: the acceptable delta between the number of completed
657 tests and the total number of tests.
Chris Masone3a560bd2011-11-14 16:53:56 -0800658 debug: enable debugging output.
659
660 returns:
Chris Masone6fed6462011-10-20 16:36:43 -0700661 False: if any platform has more than |enough| failures
662 None: if any platform has less than |enough| machines
Chris Masone3a560bd2011-11-14 16:53:56 -0800663 not yet Good.
Chris Masone6fed6462011-10-20 16:36:43 -0700664 True: if all platforms have at least |enough| machines
Chris Masone3a560bd2011-11-14 16:53:56 -0800665 Good.
mbligh5280e3b2008-12-22 14:39:28 +0000666 """
mbligh451ede12009-02-12 21:54:03 +0000667 self._job_test_results(tko, job, debug)
mblighe7fcf562009-05-21 01:43:17 +0000668 if job.test_status == {}:
669 return None
mbligh451ede12009-02-12 21:54:03 +0000670 self._job_results_platform_map(job, debug)
mbligh5280e3b2008-12-22 14:39:28 +0000671
mbligh5b618382008-12-03 15:24:01 +0000672 good_platforms = []
mbligh912c3f32009-03-25 19:31:30 +0000673 failed_platforms = []
674 aborted_platforms = []
mbligh5b618382008-12-03 15:24:01 +0000675 unknown_platforms = []
mbligh5280e3b2008-12-22 14:39:28 +0000676 platform_map = job.results_platform_map
mbligh5b618382008-12-03 15:24:01 +0000677 for platform in platform_map:
mbligh17c75e62009-06-08 16:18:21 +0000678 if not job.platform_results.has_key(platform):
679 # record test start, but there's no way to do this right now
680 job.platform_results[platform] = None
mbligh5b618382008-12-03 15:24:01 +0000681 total = len(platform_map[platform]['Total'])
682 completed = len(platform_map[platform].get('Completed', []))
mbligh912c3f32009-03-25 19:31:30 +0000683 failed = len(platform_map[platform].get('Failed', []))
684 aborted = len(platform_map[platform].get('Aborted', []))
mbligh17c75e62009-06-08 16:18:21 +0000685
mbligh1ef218d2009-08-03 16:57:56 +0000686 # We set up what we want to record here, but don't actually do
mbligh17c75e62009-06-08 16:18:21 +0000687 # it yet, until we have a decisive answer for this platform
688 if aborted or failed:
689 bad = aborted + failed
690 if (bad > 1) or (bad * 2 >= total):
691 platform_test_result = 'FAIL'
692 else:
693 platform_test_result = 'WARN'
694
Chris Masone6fed6462011-10-20 16:36:43 -0700695 if aborted > enough:
mbligh912c3f32009-03-25 19:31:30 +0000696 aborted_platforms.append(platform)
mbligh17c75e62009-06-08 16:18:21 +0000697 self.set_platform_results(job, platform, platform_test_result)
Chris Masone6fed6462011-10-20 16:36:43 -0700698 elif (failed * 2 >= total) or (failed > enough):
mbligh912c3f32009-03-25 19:31:30 +0000699 failed_platforms.append(platform)
mbligh17c75e62009-06-08 16:18:21 +0000700 self.set_platform_results(job, platform, platform_test_result)
Chris Masone6fed6462011-10-20 16:36:43 -0700701 elif (completed >= enough) and (completed + enough >= total):
mbligh5b618382008-12-03 15:24:01 +0000702 good_platforms.append(platform)
mbligh17c75e62009-06-08 16:18:21 +0000703 self.set_platform_results(job, platform, 'GOOD')
mbligh5b618382008-12-03 15:24:01 +0000704 else:
705 unknown_platforms.append(platform)
706 detail = []
707 for status in platform_map[platform]:
708 if status == 'Total':
709 continue
710 detail.append('%s=%s' % (status,platform_map[platform][status]))
711 if debug:
mbligh1ef218d2009-08-03 16:57:56 +0000712 print '%20s %d/%d %s' % (platform, completed, total,
mbligh5b618382008-12-03 15:24:01 +0000713 ' '.join(detail))
714 print
mbligh1ef218d2009-08-03 16:57:56 +0000715
mbligh912c3f32009-03-25 19:31:30 +0000716 if len(aborted_platforms) > 0:
mbligh5b618382008-12-03 15:24:01 +0000717 if debug:
mbligh17c75e62009-06-08 16:18:21 +0000718 print 'Result aborted - platforms: ',
719 print ' '.join(aborted_platforms)
mbligh912c3f32009-03-25 19:31:30 +0000720 return "Abort"
721 if len(failed_platforms) > 0:
722 if debug:
723 print 'Result bad - platforms: ' + ' '.join(failed_platforms)
mbligh5b618382008-12-03 15:24:01 +0000724 return False
725 if len(unknown_platforms) > 0:
726 if debug:
727 platform_list = ' '.join(unknown_platforms)
728 print 'Result unknown - platforms: ', platform_list
729 return None
730 if debug:
731 platform_list = ' '.join(good_platforms)
732 print 'Result good - all platforms passed: ', platform_list
733 return True
734
735
mbligh5280e3b2008-12-22 14:39:28 +0000736class TestResults(object):
737 """
738 Container class used to hold the results of the tests for a job
739 """
740 def __init__(self):
741 self.good = []
742 self.fail = []
mbligh451ede12009-02-12 21:54:03 +0000743 self.pending = []
mbligh5280e3b2008-12-22 14:39:28 +0000744
745
746 def add(self, result):
mbligh451ede12009-02-12 21:54:03 +0000747 if result.complete_count > result.pass_count:
748 self.fail.append(result)
749 elif result.incomplete_count > 0:
750 self.pending.append(result)
mbligh5280e3b2008-12-22 14:39:28 +0000751 else:
mbligh451ede12009-02-12 21:54:03 +0000752 self.good.append(result)
mbligh5280e3b2008-12-22 14:39:28 +0000753
754
755class RpcObject(object):
mbligh67647152008-11-19 00:18:14 +0000756 """
757 Generic object used to construct python objects from rpc calls
758 """
759 def __init__(self, afe, hash):
760 self.afe = afe
761 self.hash = hash
762 self.__dict__.update(hash)
763
764
765 def __str__(self):
766 return dump_object(self.__repr__(), self)
767
768
mbligh1354c9d2008-12-22 14:56:13 +0000769class ControlFile(RpcObject):
770 """
771 AFE control file object
772
773 Fields: synch_count, dependencies, control_file, is_server
774 """
775 def __repr__(self):
776 return 'CONTROL FILE: %s' % self.control_file
777
778
mbligh5280e3b2008-12-22 14:39:28 +0000779class Label(RpcObject):
mbligh67647152008-11-19 00:18:14 +0000780 """
781 AFE label object
782
783 Fields:
784 name, invalid, platform, kernel_config, id, only_if_needed
785 """
786 def __repr__(self):
787 return 'LABEL: %s' % self.name
788
789
790 def add_hosts(self, hosts):
Chris Masone3a560bd2011-11-14 16:53:56 -0800791 return self.afe.run('label_add_hosts', id=self.id, hosts=hosts)
mbligh67647152008-11-19 00:18:14 +0000792
793
794 def remove_hosts(self, hosts):
Chris Masone3a560bd2011-11-14 16:53:56 -0800795 return self.afe.run('label_remove_hosts', id=self.id, hosts=hosts)
mbligh67647152008-11-19 00:18:14 +0000796
797
mbligh5280e3b2008-12-22 14:39:28 +0000798class Acl(RpcObject):
mbligh67647152008-11-19 00:18:14 +0000799 """
800 AFE acl object
801
802 Fields:
803 users, hosts, description, name, id
804 """
805 def __repr__(self):
806 return 'ACL: %s' % self.name
807
808
809 def add_hosts(self, hosts):
810 self.afe.log('Adding hosts %s to ACL %s' % (hosts, self.name))
811 return self.afe.run('acl_group_add_hosts', self.id, hosts)
812
813
814 def remove_hosts(self, hosts):
815 self.afe.log('Removing hosts %s from ACL %s' % (hosts, self.name))
816 return self.afe.run('acl_group_remove_hosts', self.id, hosts)
817
818
mbligh54459c72009-01-21 19:26:44 +0000819 def add_users(self, users):
820 self.afe.log('Adding users %s to ACL %s' % (users, self.name))
821 return self.afe.run('acl_group_add_users', id=self.name, users=users)
822
823
mbligh5280e3b2008-12-22 14:39:28 +0000824class Job(RpcObject):
mbligh67647152008-11-19 00:18:14 +0000825 """
826 AFE job object
827
828 Fields:
829 name, control_file, control_type, synch_count, reboot_before,
830 run_verify, priority, email_list, created_on, dependencies,
831 timeout, owner, reboot_after, id
832 """
833 def __repr__(self):
834 return 'JOB: %s' % self.id
835
836
mbligh5280e3b2008-12-22 14:39:28 +0000837class JobStatus(RpcObject):
mbligh67647152008-11-19 00:18:14 +0000838 """
839 AFE job_status object
840
841 Fields:
842 status, complete, deleted, meta_host, host, active, execution_subdir, id
843 """
844 def __init__(self, afe, hash):
845 # This should call super
846 self.afe = afe
847 self.hash = hash
848 self.__dict__.update(hash)
mbligh5280e3b2008-12-22 14:39:28 +0000849 self.job = Job(afe, self.job)
Dale Curtis8adf7892011-09-08 16:13:36 -0700850 if getattr(self, 'host'):
mbligh99b24f42009-06-08 16:45:55 +0000851 self.host = Host(afe, self.host)
mbligh67647152008-11-19 00:18:14 +0000852
853
854 def __repr__(self):
mbligh451ede12009-02-12 21:54:03 +0000855 if self.host and self.host.hostname:
856 hostname = self.host.hostname
857 else:
858 hostname = 'None'
859 return 'JOB STATUS: %s-%s' % (self.job.id, hostname)
mbligh67647152008-11-19 00:18:14 +0000860
861
mbligh5280e3b2008-12-22 14:39:28 +0000862class Host(RpcObject):
mbligh67647152008-11-19 00:18:14 +0000863 """
864 AFE host object
865
866 Fields:
867 status, lock_time, locked_by, locked, hostname, invalid,
868 synch_id, labels, platform, protection, dirty, id
869 """
870 def __repr__(self):
871 return 'HOST OBJECT: %s' % self.hostname
872
873
874 def show(self):
875 labels = list(set(self.labels) - set([self.platform]))
876 print '%-6s %-7s %-7s %-16s %s' % (self.hostname, self.status,
877 self.locked, self.platform,
878 ', '.join(labels))
879
880
mbligh54459c72009-01-21 19:26:44 +0000881 def delete(self):
882 return self.afe.run('delete_host', id=self.id)
883
884
mbligh6463c4b2009-01-30 00:33:37 +0000885 def modify(self, **dargs):
886 return self.afe.run('modify_host', id=self.id, **dargs)
887
888
mbligh67647152008-11-19 00:18:14 +0000889 def get_acls(self):
890 return self.afe.get_acls(hosts__hostname=self.hostname)
891
892
893 def add_acl(self, acl_name):
894 self.afe.log('Adding ACL %s to host %s' % (acl_name, self.hostname))
895 return self.afe.run('acl_group_add_hosts', id=acl_name,
896 hosts=[self.hostname])
897
898
899 def remove_acl(self, acl_name):
900 self.afe.log('Removing ACL %s from host %s' % (acl_name, self.hostname))
901 return self.afe.run('acl_group_remove_hosts', id=acl_name,
902 hosts=[self.hostname])
903
904
905 def get_labels(self):
906 return self.afe.get_labels(host__hostname__in=[self.hostname])
907
908
909 def add_labels(self, labels):
910 self.afe.log('Adding labels %s to host %s' % (labels, self.hostname))
911 return self.afe.run('host_add_labels', id=self.id, labels=labels)
912
913
914 def remove_labels(self, labels):
915 self.afe.log('Removing labels %s from host %s' % (labels,self.hostname))
916 return self.afe.run('host_remove_labels', id=self.id, labels=labels)
mbligh5b618382008-12-03 15:24:01 +0000917
918
mbligh54459c72009-01-21 19:26:44 +0000919class User(RpcObject):
920 def __repr__(self):
921 return 'USER: %s' % self.login
922
923
mbligh5280e3b2008-12-22 14:39:28 +0000924class TestStatus(RpcObject):
mblighc31e4022008-12-11 19:32:30 +0000925 """
926 TKO test status object
927
928 Fields:
929 test_idx, hostname, testname, id
930 complete_count, incomplete_count, group_count, pass_count
931 """
932 def __repr__(self):
933 return 'TEST STATUS: %s' % self.id
934
935
mbligh5b618382008-12-03 15:24:01 +0000936class MachineTestPairing(object):
937 """
938 Object representing the pairing of a machine label with a control file
mbligh1f23f362008-12-22 14:46:12 +0000939
940 machine_label: use machines from this label
941 control_file: use this control file (by name in the frontend)
942 platforms: list of rexeps to filter platforms by. [] => no filtering
mbligh282ce892010-01-06 18:40:17 +0000943 job_label: The label (name) to give to the autotest job launched
944 to run this pairing. '<kernel-version> : <config> : <date>'
mbligh5b618382008-12-03 15:24:01 +0000945 """
mbligh1354c9d2008-12-22 14:56:13 +0000946 def __init__(self, machine_label, control_file, platforms=[],
mbligh17c75e62009-06-08 16:18:21 +0000947 container=False, atomic_group_sched=False, synch_count=0,
mbligh282ce892010-01-06 18:40:17 +0000948 testname=None, job_label=None):
mbligh5b618382008-12-03 15:24:01 +0000949 self.machine_label = machine_label
950 self.control_file = control_file
mbligh1f23f362008-12-22 14:46:12 +0000951 self.platforms = platforms
mbligh1354c9d2008-12-22 14:56:13 +0000952 self.container = container
mblighb9db5162009-04-17 22:21:41 +0000953 self.atomic_group_sched = atomic_group_sched
954 self.synch_count = synch_count
mbligh17c75e62009-06-08 16:18:21 +0000955 self.testname = testname
mbligh282ce892010-01-06 18:40:17 +0000956 self.job_label = job_label
mbligh1354c9d2008-12-22 14:56:13 +0000957
958
959 def __repr__(self):
960 return '%s %s %s %s' % (self.machine_label, self.control_file,
961 self.platforms, self.container)