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