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