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