mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 1 | """\ |
| 2 | Functions to expose over the RPC interface. |
| 3 | |
| 4 | For all modify* and delete* functions that ask for an 'id' parameter to |
| 5 | identify the object to operate on, the id may be either |
| 6 | * the database row ID |
| 7 | * the name of the object (label name, hostname, user login, etc.) |
| 8 | * a dictionary containing uniquely identifying field (this option should seldom |
| 9 | be used) |
| 10 | |
| 11 | When specifying foreign key fields (i.e. adding hosts to a label, or adding |
| 12 | users to an ACL group), the given value may be either the database row ID or the |
| 13 | name of the object. |
| 14 | |
| 15 | All get* functions return lists of dictionaries. Each dictionary represents one |
| 16 | object and maps field names to values. |
| 17 | |
| 18 | Some examples: |
| 19 | modify_host(2, hostname='myhost') # modify hostname of host with database ID 2 |
| 20 | modify_host('ipaj2', hostname='myhost') # modify hostname of host 'ipaj2' |
| 21 | modify_test('sleeptest', test_type='Client', params=', seconds=60') |
| 22 | delete_acl_group(1) # delete by ID |
| 23 | delete_acl_group('Everyone') # delete by name |
| 24 | acl_group_add_users('Everyone', ['mbligh', 'showard']) |
| 25 | get_jobs(owner='showard', status='Queued') |
| 26 | |
mbligh | 93c80e6 | 2009-02-03 17:48:30 +0000 | [diff] [blame] | 27 | See doctests/001_rpc_test.txt for (lots) more examples. |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 28 | """ |
| 29 | |
| 30 | __author__ = 'showard@google.com (Steve Howard)' |
| 31 | |
showard | ff90138 | 2008-07-07 23:22:16 +0000 | [diff] [blame] | 32 | from frontend import thread_local |
showard | 09096d8 | 2008-07-07 23:20:49 +0000 | [diff] [blame] | 33 | from frontend.afe import models, model_logic, control_file, rpc_utils |
showard | 3bb499f | 2008-07-03 19:42:20 +0000 | [diff] [blame] | 34 | from autotest_lib.client.common_lib import global_config |
| 35 | |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 36 | |
| 37 | # labels |
| 38 | |
showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 39 | def add_label(name, kernel_config=None, platform=None, only_if_needed=None): |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 40 | return models.Label.add_object( |
| 41 | name=name, kernel_config=kernel_config, platform=platform, |
| 42 | only_if_needed=only_if_needed).id |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 43 | |
| 44 | |
| 45 | def modify_label(id, **data): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 46 | models.Label.smart_get(id).update_object(data) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 47 | |
| 48 | |
| 49 | def delete_label(id): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 50 | models.Label.smart_get(id).delete() |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 51 | |
| 52 | |
showard | bbabf50 | 2008-06-06 00:02:02 +0000 | [diff] [blame] | 53 | def label_add_hosts(id, hosts): |
showard | be3ec04 | 2008-11-12 18:16:07 +0000 | [diff] [blame] | 54 | host_objs = models.Host.smart_get_bulk(hosts) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 55 | models.Label.smart_get(id).host_set.add(*host_objs) |
showard | bbabf50 | 2008-06-06 00:02:02 +0000 | [diff] [blame] | 56 | |
| 57 | |
| 58 | def label_remove_hosts(id, hosts): |
showard | be3ec04 | 2008-11-12 18:16:07 +0000 | [diff] [blame] | 59 | host_objs = models.Host.smart_get_bulk(hosts) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 60 | models.Label.smart_get(id).host_set.remove(*host_objs) |
showard | bbabf50 | 2008-06-06 00:02:02 +0000 | [diff] [blame] | 61 | |
| 62 | |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 63 | def get_labels(**filter_data): |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 64 | """\ |
| 65 | @returns A sequence of nested dictionaries of label information. |
| 66 | """ |
| 67 | return rpc_utils.prepare_rows_as_nested_dicts( |
| 68 | models.Label.query_objects(filter_data), |
| 69 | ('atomic_group',)) |
| 70 | |
| 71 | |
| 72 | # atomic groups |
| 73 | |
| 74 | def add_atomic_group(name, max_number_of_machines, description=None): |
| 75 | return models.AtomicGroup.add_object( |
| 76 | name=name, max_number_of_machines=max_number_of_machines, |
| 77 | description=description).id |
| 78 | |
| 79 | |
| 80 | def modify_atomic_group(id, **data): |
| 81 | models.AtomicGroup.smart_get(id).update_object(data) |
| 82 | |
| 83 | |
| 84 | def delete_atomic_group(id): |
| 85 | models.AtomicGroup.smart_get(id).delete() |
| 86 | |
| 87 | |
| 88 | def atomic_group_add_labels(id, labels): |
| 89 | label_objs = models.Label.smart_get_bulk(labels) |
| 90 | models.AtomicGroup.smart_get(id).label_set.add(*label_objs) |
| 91 | |
| 92 | |
| 93 | def atomic_group_remove_labels(id, labels): |
| 94 | label_objs = models.Label.smart_get_bulk(labels) |
| 95 | models.AtomicGroup.smart_get(id).label_set.remove(*label_objs) |
| 96 | |
| 97 | |
| 98 | def get_atomic_groups(**filter_data): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 99 | return rpc_utils.prepare_for_serialization( |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 100 | models.AtomicGroup.list_objects(filter_data)) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 101 | |
| 102 | |
| 103 | # hosts |
| 104 | |
showard | df06256 | 2008-07-03 19:56:37 +0000 | [diff] [blame] | 105 | def add_host(hostname, status=None, locked=None, protection=None): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 106 | return models.Host.add_object(hostname=hostname, status=status, |
showard | df06256 | 2008-07-03 19:56:37 +0000 | [diff] [blame] | 107 | locked=locked, protection=protection).id |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 108 | |
| 109 | |
| 110 | def modify_host(id, **data): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 111 | models.Host.smart_get(id).update_object(data) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 112 | |
| 113 | |
| 114 | def host_add_labels(id, labels): |
showard | be3ec04 | 2008-11-12 18:16:07 +0000 | [diff] [blame] | 115 | labels = models.Label.smart_get_bulk(labels) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 116 | models.Host.smart_get(id).labels.add(*labels) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 117 | |
| 118 | |
| 119 | def host_remove_labels(id, labels): |
showard | be3ec04 | 2008-11-12 18:16:07 +0000 | [diff] [blame] | 120 | labels = models.Label.smart_get_bulk(labels) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 121 | models.Host.smart_get(id).labels.remove(*labels) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 122 | |
| 123 | |
| 124 | def delete_host(id): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 125 | models.Host.smart_get(id).delete() |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 126 | |
| 127 | |
showard | 43a3d26 | 2008-11-12 18:17:05 +0000 | [diff] [blame] | 128 | def get_hosts(multiple_labels=[], exclude_only_if_needed_labels=False, |
| 129 | **filter_data): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 130 | """\ |
| 131 | multiple_labels: match hosts in all of the labels given. Should be a |
| 132 | list of label names. |
showard | 43a3d26 | 2008-11-12 18:17:05 +0000 | [diff] [blame] | 133 | exclude_only_if_needed_labels: exclude hosts with at least one |
| 134 | "only_if_needed" label applied. |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 135 | """ |
showard | 43a3d26 | 2008-11-12 18:17:05 +0000 | [diff] [blame] | 136 | hosts = rpc_utils.get_host_query(multiple_labels, |
| 137 | exclude_only_if_needed_labels, |
| 138 | filter_data) |
| 139 | host_dicts = [] |
| 140 | for host_obj in hosts: |
| 141 | host_dict = host_obj.get_object_dict() |
| 142 | host_dict['labels'] = [label.name for label in host_obj.labels.all()] |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 143 | platform = host_obj.platform() |
showard | 43a3d26 | 2008-11-12 18:17:05 +0000 | [diff] [blame] | 144 | host_dict['platform'] = platform and platform.name or None |
| 145 | host_dicts.append(host_dict) |
| 146 | return rpc_utils.prepare_for_serialization(host_dicts) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 147 | |
| 148 | |
showard | 43a3d26 | 2008-11-12 18:17:05 +0000 | [diff] [blame] | 149 | def get_num_hosts(multiple_labels=[], exclude_only_if_needed_labels=False, |
| 150 | **filter_data): |
| 151 | hosts = rpc_utils.get_host_query(multiple_labels, |
| 152 | exclude_only_if_needed_labels, |
| 153 | filter_data) |
| 154 | return hosts.count() |
showard | 1385b16 | 2008-03-13 15:59:40 +0000 | [diff] [blame] | 155 | |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 156 | |
| 157 | # tests |
| 158 | |
showard | 909c7a6 | 2008-07-15 21:52:38 +0000 | [diff] [blame] | 159 | def add_test(name, test_type, path, author=None, dependencies=None, |
showard | 3d9899a | 2008-07-31 02:11:58 +0000 | [diff] [blame] | 160 | experimental=True, run_verify=None, test_class=None, |
showard | 909c7a6 | 2008-07-15 21:52:38 +0000 | [diff] [blame] | 161 | test_time=None, test_category=None, description=None, |
| 162 | sync_count=1): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 163 | return models.Test.add_object(name=name, test_type=test_type, path=path, |
showard | 909c7a6 | 2008-07-15 21:52:38 +0000 | [diff] [blame] | 164 | author=author, dependencies=dependencies, |
| 165 | experimental=experimental, |
| 166 | run_verify=run_verify, test_time=test_time, |
| 167 | test_category=test_category, |
| 168 | sync_count=sync_count, |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 169 | test_class=test_class, |
| 170 | description=description).id |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 171 | |
| 172 | |
| 173 | def modify_test(id, **data): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 174 | models.Test.smart_get(id).update_object(data) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 175 | |
| 176 | |
| 177 | def delete_test(id): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 178 | models.Test.smart_get(id).delete() |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 179 | |
| 180 | |
| 181 | def get_tests(**filter_data): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 182 | return rpc_utils.prepare_for_serialization( |
| 183 | models.Test.list_objects(filter_data)) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 184 | |
| 185 | |
showard | 2b9a88b | 2008-06-13 20:55:03 +0000 | [diff] [blame] | 186 | # profilers |
| 187 | |
| 188 | def add_profiler(name, description=None): |
| 189 | return models.Profiler.add_object(name=name, description=description).id |
| 190 | |
| 191 | |
| 192 | def modify_profiler(id, **data): |
| 193 | models.Profiler.smart_get(id).update_object(data) |
| 194 | |
| 195 | |
| 196 | def delete_profiler(id): |
| 197 | models.Profiler.smart_get(id).delete() |
| 198 | |
| 199 | |
| 200 | def get_profilers(**filter_data): |
| 201 | return rpc_utils.prepare_for_serialization( |
| 202 | models.Profiler.list_objects(filter_data)) |
| 203 | |
| 204 | |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 205 | # users |
| 206 | |
| 207 | def add_user(login, access_level=None): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 208 | return models.User.add_object(login=login, access_level=access_level).id |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 209 | |
| 210 | |
| 211 | def modify_user(id, **data): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 212 | models.User.smart_get(id).update_object(data) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 213 | |
| 214 | |
| 215 | def delete_user(id): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 216 | models.User.smart_get(id).delete() |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 217 | |
| 218 | |
| 219 | def get_users(**filter_data): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 220 | return rpc_utils.prepare_for_serialization( |
| 221 | models.User.list_objects(filter_data)) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 222 | |
| 223 | |
| 224 | # acl groups |
| 225 | |
| 226 | def add_acl_group(name, description=None): |
showard | 04f2cd8 | 2008-07-25 20:53:31 +0000 | [diff] [blame] | 227 | group = models.AclGroup.add_object(name=name, description=description) |
| 228 | group.users.add(thread_local.get_user()) |
| 229 | return group.id |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 230 | |
| 231 | |
| 232 | def modify_acl_group(id, **data): |
showard | 04f2cd8 | 2008-07-25 20:53:31 +0000 | [diff] [blame] | 233 | group = models.AclGroup.smart_get(id) |
| 234 | group.check_for_acl_violation_acl_group() |
| 235 | group.update_object(data) |
| 236 | group.add_current_user_if_empty() |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 237 | |
| 238 | |
| 239 | def acl_group_add_users(id, users): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 240 | group = models.AclGroup.smart_get(id) |
showard | 04f2cd8 | 2008-07-25 20:53:31 +0000 | [diff] [blame] | 241 | group.check_for_acl_violation_acl_group() |
showard | be3ec04 | 2008-11-12 18:16:07 +0000 | [diff] [blame] | 242 | users = models.User.smart_get_bulk(users) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 243 | group.users.add(*users) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 244 | |
| 245 | |
| 246 | def acl_group_remove_users(id, users): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 247 | group = models.AclGroup.smart_get(id) |
showard | 04f2cd8 | 2008-07-25 20:53:31 +0000 | [diff] [blame] | 248 | group.check_for_acl_violation_acl_group() |
showard | be3ec04 | 2008-11-12 18:16:07 +0000 | [diff] [blame] | 249 | users = models.User.smart_get_bulk(users) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 250 | group.users.remove(*users) |
showard | 04f2cd8 | 2008-07-25 20:53:31 +0000 | [diff] [blame] | 251 | group.add_current_user_if_empty() |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 252 | |
| 253 | |
| 254 | def acl_group_add_hosts(id, hosts): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 255 | group = models.AclGroup.smart_get(id) |
showard | 04f2cd8 | 2008-07-25 20:53:31 +0000 | [diff] [blame] | 256 | group.check_for_acl_violation_acl_group() |
showard | be3ec04 | 2008-11-12 18:16:07 +0000 | [diff] [blame] | 257 | hosts = models.Host.smart_get_bulk(hosts) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 258 | group.hosts.add(*hosts) |
showard | 08f981b | 2008-06-24 21:59:03 +0000 | [diff] [blame] | 259 | group.on_host_membership_change() |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 260 | |
| 261 | |
| 262 | def acl_group_remove_hosts(id, hosts): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 263 | group = models.AclGroup.smart_get(id) |
showard | 04f2cd8 | 2008-07-25 20:53:31 +0000 | [diff] [blame] | 264 | group.check_for_acl_violation_acl_group() |
showard | be3ec04 | 2008-11-12 18:16:07 +0000 | [diff] [blame] | 265 | hosts = models.Host.smart_get_bulk(hosts) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 266 | group.hosts.remove(*hosts) |
showard | 08f981b | 2008-06-24 21:59:03 +0000 | [diff] [blame] | 267 | group.on_host_membership_change() |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 268 | |
| 269 | |
| 270 | def delete_acl_group(id): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 271 | models.AclGroup.smart_get(id).delete() |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 272 | |
| 273 | |
| 274 | def get_acl_groups(**filter_data): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 275 | acl_groups = models.AclGroup.list_objects(filter_data) |
| 276 | for acl_group in acl_groups: |
| 277 | acl_group_obj = models.AclGroup.objects.get(id=acl_group['id']) |
| 278 | acl_group['users'] = [user.login |
| 279 | for user in acl_group_obj.users.all()] |
| 280 | acl_group['hosts'] = [host.hostname |
| 281 | for host in acl_group_obj.hosts.all()] |
| 282 | return rpc_utils.prepare_for_serialization(acl_groups) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 283 | |
| 284 | |
| 285 | # jobs |
| 286 | |
mbligh | 120351e | 2009-01-24 01:40:45 +0000 | [diff] [blame] | 287 | def generate_control_file(tests=(), kernel=None, label=None, profilers=(), |
| 288 | client_control_file='', use_container=False): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 289 | """ |
mbligh | 120351e | 2009-01-24 01:40:45 +0000 | [diff] [blame] | 290 | Generates a client-side control file to load a kernel and run tests. |
| 291 | |
| 292 | @param tests List of tests to run. |
| 293 | @param kernel Kernel to install in generated control file. |
| 294 | @param label Name of label to grab kernel config from. |
| 295 | @param profilers List of profilers to activate during the job. |
| 296 | @param client_control_file The contents of a client-side control file to |
| 297 | run at the end of all tests. If this is supplied, all tests must be |
| 298 | client side. |
| 299 | TODO: in the future we should support server control files directly |
| 300 | to wrap with a kernel. That'll require changing the parameter |
| 301 | name and adding a boolean to indicate if it is a client or server |
| 302 | control file. |
| 303 | @param use_container unused argument today. TODO: Enable containers |
| 304 | on the host during a client side test. |
| 305 | |
| 306 | @returns a dict with the following keys: |
| 307 | control_file: str, The control file text. |
| 308 | is_server: bool, is the control file a server-side control file? |
| 309 | synch_count: How many machines the job uses per autoserv execution. |
| 310 | synch_count == 1 means the job is asynchronous. |
| 311 | dependencies: A list of the names of labels on which the job depends. |
| 312 | """ |
| 313 | if not tests and not control_file: |
showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 314 | return dict(control_file='', is_server=False, synch_count=1, |
showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 315 | dependencies=[]) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 316 | |
showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 317 | cf_info, test_objects, profiler_objects, label = ( |
showard | 2b9a88b | 2008-06-13 20:55:03 +0000 | [diff] [blame] | 318 | rpc_utils.prepare_generate_control_file(tests, kernel, label, |
| 319 | profilers)) |
showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 320 | cf_info['control_file'] = control_file.generate_control( |
| 321 | tests=test_objects, kernel=kernel, platform=label, |
mbligh | 120351e | 2009-01-24 01:40:45 +0000 | [diff] [blame] | 322 | profilers=profiler_objects, is_server=cf_info['is_server'], |
| 323 | client_control_file=client_control_file) |
showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 324 | return cf_info |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 325 | |
| 326 | |
showard | 3bb499f | 2008-07-03 19:42:20 +0000 | [diff] [blame] | 327 | def create_job(name, priority, control_file, control_type, timeout=None, |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 328 | synch_count=None, hosts=(), meta_hosts=(), |
| 329 | run_verify=True, one_time_hosts=(), email_list='', |
| 330 | dependencies=(), reboot_before=None, reboot_after=None, |
| 331 | atomic_group_name=None): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 332 | """\ |
| 333 | Create and enqueue a job. |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 334 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 335 | priority: Low, Medium, High, Urgent |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 336 | control_file: String contents of the control file. |
| 337 | control_type: Type of control file, Client or Server. |
| 338 | timeout: Hours after this call returns until the job times out. |
| 339 | synch_count: How many machines the job uses per autoserv execution. |
| 340 | synch_count == 1 means the job is asynchronous. If an |
| 341 | atomic group is given this value is treated as a minimum. |
| 342 | hosts: List of hosts to run job on. |
| 343 | meta_hosts: List where each entry is a label name, and for each entry |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 344 | one host will be chosen from that label to run the job |
| 345 | on. |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 346 | run_verify: Should the host be verified before running the test? |
| 347 | one_time_hosts: List of hosts not in the database to run the job on. |
| 348 | email_list: String containing emails to mail when the job is done |
| 349 | dependencies: List of label names on which this job depends |
mbligh | 94ae6d6 | 2009-02-03 17:47:49 +0000 | [diff] [blame] | 350 | reboot_before: Never, If dirty, or Always |
| 351 | reboot_after: Never, If all tests passed, or Always |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 352 | atomic_group_name: The name of an atomic group to schedule the job on. |
| 353 | |
| 354 | @returns The created Job id number. |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 355 | """ |
showard | 3bb499f | 2008-07-03 19:42:20 +0000 | [diff] [blame] | 356 | |
| 357 | if timeout is None: |
| 358 | timeout=global_config.global_config.get_config_value( |
| 359 | 'AUTOTEST_WEB', 'job_timeout_default') |
| 360 | |
showard | ff90138 | 2008-07-07 23:22:16 +0000 | [diff] [blame] | 361 | owner = thread_local.get_user().login |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 362 | # input validation |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 363 | if not (hosts or meta_hosts or one_time_hosts or atomic_group_name): |
mbligh | ec5546d | 2008-06-16 16:51:28 +0000 | [diff] [blame] | 364 | raise model_logic.ValidationError({ |
showard | b8471e3 | 2008-07-03 19:51:08 +0000 | [diff] [blame] | 365 | 'arguments' : "You must pass at least one of 'hosts', " |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 366 | "'meta_hosts', 'one_time_hosts', " |
| 367 | "or 'atomic_group_name'" |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 368 | }) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 369 | |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 370 | # Create and sanity check an AtomicGroup object if requested. |
| 371 | if atomic_group_name: |
| 372 | if one_time_hosts: |
| 373 | raise model_logic.ValidationError( |
| 374 | {'one_time_hosts': |
| 375 | 'One time hosts cannot be used with an Atomic Group.'}) |
| 376 | atomic_group = models.AtomicGroup.smart_get(atomic_group_name) |
| 377 | if synch_count and synch_count > atomic_group.max_number_of_machines: |
| 378 | raise model_logic.ValidationError( |
| 379 | {'atomic_group_name' : |
| 380 | 'You have requested a synch_count (%d) greater than the ' |
| 381 | 'maximum machines in the requested Atomic Group (%d).' % |
| 382 | (synch_count, atomic_group.max_number_of_machines)}) |
| 383 | else: |
| 384 | atomic_group = None |
| 385 | |
showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 386 | labels_by_name = dict((label.name, label) |
| 387 | for label in models.Label.objects.all()) |
showard | ba87290 | 2008-06-28 00:51:08 +0000 | [diff] [blame] | 388 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 389 | # convert hostnames & meta hosts to host/label objects |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 390 | host_objects = models.Host.smart_get_bulk(hosts) |
showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 391 | metahost_objects = [] |
| 392 | metahost_counts = {} |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 393 | for label in meta_hosts or []: |
showard | 25087ac | 2008-11-24 22:12:03 +0000 | [diff] [blame] | 394 | if label not in labels_by_name: |
| 395 | raise model_logic.ValidationError( |
| 396 | {'meta_hosts' : 'Label "%s" not found' % label}) |
showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 397 | this_label = labels_by_name[label] |
| 398 | metahost_objects.append(this_label) |
| 399 | metahost_counts.setdefault(this_label, 0) |
| 400 | metahost_counts[this_label] += 1 |
showard | b8471e3 | 2008-07-03 19:51:08 +0000 | [diff] [blame] | 401 | for host in one_time_hosts or []: |
| 402 | this_host = models.Host.create_one_time_host(host) |
| 403 | host_objects.append(this_host) |
showard | ba87290 | 2008-06-28 00:51:08 +0000 | [diff] [blame] | 404 | |
showard | 65c267d | 2009-01-20 23:24:47 +0000 | [diff] [blame] | 405 | all_host_objects = host_objects + metahost_objects |
| 406 | |
showard | ba87290 | 2008-06-28 00:51:08 +0000 | [diff] [blame] | 407 | # check that each metahost request has enough hosts under the label |
showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 408 | for label, requested_count in metahost_counts.iteritems(): |
| 409 | available_count = label.host_set.count() |
| 410 | if requested_count > available_count: |
| 411 | error = ("You have requested %d %s's, but there are only %d." |
| 412 | % (requested_count, label.name, available_count)) |
| 413 | raise model_logic.ValidationError({'meta_hosts' : error}) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 414 | |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 415 | if atomic_group: |
| 416 | rpc_utils.check_atomic_group_create_job( |
| 417 | synch_count, host_objects, metahost_objects, |
| 418 | dependencies, atomic_group, labels_by_name) |
| 419 | else: |
| 420 | if synch_count is not None and synch_count > len(all_host_objects): |
| 421 | raise model_logic.ValidationError( |
| 422 | {'hosts': |
| 423 | 'only %d hosts provided for job with synch_count = %d' % |
| 424 | (len(all_host_objects), synch_count)}) |
showard | 65c267d | 2009-01-20 23:24:47 +0000 | [diff] [blame] | 425 | |
showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 426 | rpc_utils.check_job_dependencies(host_objects, dependencies) |
| 427 | dependency_labels = [labels_by_name[label_name] |
| 428 | for label_name in dependencies] |
| 429 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 430 | job = models.Job.create(owner=owner, name=name, priority=priority, |
| 431 | control_file=control_file, |
| 432 | control_type=control_type, |
showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 433 | synch_count=synch_count, |
showard | 65c267d | 2009-01-20 23:24:47 +0000 | [diff] [blame] | 434 | hosts=all_host_objects, |
showard | 909c7a6 | 2008-07-15 21:52:38 +0000 | [diff] [blame] | 435 | timeout=timeout, |
showard | 542e840 | 2008-09-19 20:16:18 +0000 | [diff] [blame] | 436 | run_verify=run_verify, |
showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 437 | email_list=email_list.strip(), |
showard | 21baa45 | 2008-10-21 00:08:39 +0000 | [diff] [blame] | 438 | dependencies=dependency_labels, |
| 439 | reboot_before=reboot_before, |
| 440 | reboot_after=reboot_after) |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 441 | job.queue(all_host_objects, atomic_group=atomic_group) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 442 | return job.id |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 443 | |
| 444 | |
showard | 9dbdcda | 2008-10-14 17:34:36 +0000 | [diff] [blame] | 445 | def abort_host_queue_entries(**filter_data): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 446 | """\ |
showard | 9dbdcda | 2008-10-14 17:34:36 +0000 | [diff] [blame] | 447 | Abort a set of host queue entries. |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 448 | """ |
showard | 9dbdcda | 2008-10-14 17:34:36 +0000 | [diff] [blame] | 449 | query = models.HostQueueEntry.query_objects(filter_data) |
showard | 0c18519 | 2009-01-16 03:07:57 +0000 | [diff] [blame] | 450 | query = query.filter(complete=False) |
showard | dc81751 | 2008-11-12 18:16:41 +0000 | [diff] [blame] | 451 | models.AclGroup.check_abort_permissions(query) |
showard | 9dbdcda | 2008-10-14 17:34:36 +0000 | [diff] [blame] | 452 | host_queue_entries = list(query.select_related()) |
showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 453 | rpc_utils.check_abort_synchronous_jobs(host_queue_entries) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 454 | |
showard | 9dbdcda | 2008-10-14 17:34:36 +0000 | [diff] [blame] | 455 | user = thread_local.get_user() |
| 456 | for queue_entry in host_queue_entries: |
| 457 | queue_entry.abort(user) |
showard | 9d821ab | 2008-07-11 16:54:29 +0000 | [diff] [blame] | 458 | |
| 459 | |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 460 | def get_jobs(not_yet_run=False, running=False, finished=False, **filter_data): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 461 | """\ |
| 462 | Extra filter args for get_jobs: |
| 463 | -not_yet_run: Include only jobs that have not yet started running. |
| 464 | -running: Include only jobs that have start running but for which not |
| 465 | all hosts have completed. |
| 466 | -finished: Include only jobs for which all hosts have completed (or |
| 467 | aborted). |
| 468 | At most one of these three fields should be specified. |
| 469 | """ |
| 470 | filter_data['extra_args'] = rpc_utils.extra_job_filters(not_yet_run, |
| 471 | running, |
| 472 | finished) |
showard | 989f25d | 2008-10-01 11:38:11 +0000 | [diff] [blame] | 473 | jobs = models.Job.list_objects(filter_data) |
| 474 | models.Job.objects.populate_dependencies(jobs) |
| 475 | return rpc_utils.prepare_for_serialization(jobs) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 476 | |
| 477 | |
| 478 | def get_num_jobs(not_yet_run=False, running=False, finished=False, |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 479 | **filter_data): |
| 480 | """\ |
| 481 | See get_jobs() for documentation of extra filter parameters. |
| 482 | """ |
| 483 | filter_data['extra_args'] = rpc_utils.extra_job_filters(not_yet_run, |
| 484 | running, |
| 485 | finished) |
| 486 | return models.Job.query_count(filter_data) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 487 | |
| 488 | |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 489 | def get_jobs_summary(**filter_data): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 490 | """\ |
showard | a8709c5 | 2008-07-03 19:44:54 +0000 | [diff] [blame] | 491 | Like get_jobs(), but adds a 'status_counts' field, which is a dictionary |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 492 | mapping status strings to the number of hosts currently with that |
| 493 | status, i.e. {'Queued' : 4, 'Running' : 2}. |
| 494 | """ |
| 495 | jobs = get_jobs(**filter_data) |
| 496 | ids = [job['id'] for job in jobs] |
| 497 | all_status_counts = models.Job.objects.get_status_counts(ids) |
| 498 | for job in jobs: |
| 499 | job['status_counts'] = all_status_counts[job['id']] |
| 500 | return rpc_utils.prepare_for_serialization(jobs) |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 501 | |
| 502 | |
showard | 945072f | 2008-09-03 20:34:59 +0000 | [diff] [blame] | 503 | def get_info_for_clone(id, preserve_metahosts): |
showard | a8709c5 | 2008-07-03 19:44:54 +0000 | [diff] [blame] | 504 | """\ |
| 505 | Retrieves all the information needed to clone a job. |
| 506 | """ |
| 507 | info = {} |
| 508 | job = models.Job.objects.get(id=id) |
showard | 4519544 | 2009-02-17 20:55:48 +0000 | [diff] [blame] | 509 | query = job.hostqueueentry_set.filter() |
showard | 945072f | 2008-09-03 20:34:59 +0000 | [diff] [blame] | 510 | |
| 511 | hosts = [] |
| 512 | meta_hosts = [] |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 513 | atomic_group_name = None |
showard | 945072f | 2008-09-03 20:34:59 +0000 | [diff] [blame] | 514 | |
| 515 | # For each queue entry, if the entry contains a host, add the entry into the |
| 516 | # hosts list if either: |
| 517 | # It is not a metahost. |
| 518 | # It was an assigned metahost, and the user wants to keep the specific |
| 519 | # assignments. |
| 520 | # Otherwise, add the metahost to the metahosts list. |
| 521 | for queue_entry in query: |
| 522 | if (queue_entry.host and (preserve_metahosts |
| 523 | or not queue_entry.meta_host)): |
showard | 4519544 | 2009-02-17 20:55:48 +0000 | [diff] [blame] | 524 | if queue_entry.deleted: |
| 525 | continue |
showard | 945072f | 2008-09-03 20:34:59 +0000 | [diff] [blame] | 526 | hosts.append(queue_entry.host) |
| 527 | else: |
| 528 | meta_hosts.append(queue_entry.meta_host.name) |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 529 | if atomic_group_name is None: |
| 530 | atomic_group_name = queue_entry.atomic_group.name |
| 531 | else: |
| 532 | assert atomic_group_name == queue_entry.atomic_group.name, ( |
| 533 | 'DB inconsistency. HostQueueEntries with multiple atomic' |
| 534 | ' groups on job %s: %s != %s' % ( |
| 535 | id, atomic_group_name, queue_entry.atomic_group.name)) |
showard | 945072f | 2008-09-03 20:34:59 +0000 | [diff] [blame] | 536 | |
showard | d9992fe | 2008-07-31 02:15:03 +0000 | [diff] [blame] | 537 | host_dicts = [] |
showard | a8709c5 | 2008-07-03 19:44:54 +0000 | [diff] [blame] | 538 | |
showard | d9992fe | 2008-07-31 02:15:03 +0000 | [diff] [blame] | 539 | for host in hosts: |
showard | d9992fe | 2008-07-31 02:15:03 +0000 | [diff] [blame] | 540 | # one-time host |
| 541 | if host.invalid: |
showard | bad4f2d | 2008-08-15 18:13:47 +0000 | [diff] [blame] | 542 | host_dict = {} |
| 543 | host_dict['hostname'] = host.hostname |
| 544 | host_dict['id'] = host.id |
showard | d9992fe | 2008-07-31 02:15:03 +0000 | [diff] [blame] | 545 | host_dict['platform'] = '(one-time host)' |
| 546 | host_dict['locked_text'] = '' |
showard | d9992fe | 2008-07-31 02:15:03 +0000 | [diff] [blame] | 547 | else: |
showard | bad4f2d | 2008-08-15 18:13:47 +0000 | [diff] [blame] | 548 | host_dict = get_hosts(id=host.id)[0] |
| 549 | other_labels = host_dict['labels'] |
| 550 | if host_dict['platform']: |
| 551 | other_labels.remove(host_dict['platform']) |
| 552 | host_dict['other_labels'] = ', '.join(other_labels) |
showard | d9992fe | 2008-07-31 02:15:03 +0000 | [diff] [blame] | 553 | host_dicts.append(host_dict) |
showard | a8709c5 | 2008-07-03 19:44:54 +0000 | [diff] [blame] | 554 | |
| 555 | meta_host_counts = {} |
| 556 | for meta_host in meta_hosts: |
| 557 | meta_host_counts.setdefault(meta_host, 0) |
| 558 | meta_host_counts[meta_host] += 1 |
| 559 | |
| 560 | info['job'] = job.get_object_dict() |
showard | 2e9415f | 2008-12-05 19:48:38 +0000 | [diff] [blame] | 561 | info['job']['dependencies'] = [label.name for label |
| 562 | in job.dependency_labels.all()] |
showard | a8709c5 | 2008-07-03 19:44:54 +0000 | [diff] [blame] | 563 | info['meta_host_counts'] = meta_host_counts |
showard | d9992fe | 2008-07-31 02:15:03 +0000 | [diff] [blame] | 564 | info['hosts'] = host_dicts |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 565 | info['atomic_group_name'] = atomic_group_name |
showard | a8709c5 | 2008-07-03 19:44:54 +0000 | [diff] [blame] | 566 | |
| 567 | return rpc_utils.prepare_for_serialization(info) |
| 568 | |
| 569 | |
showard | 34dc5fa | 2008-04-24 20:58:40 +0000 | [diff] [blame] | 570 | # host queue entries |
| 571 | |
| 572 | def get_host_queue_entries(**filter_data): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 573 | """\ |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 574 | @returns A sequence of nested dictionaries of host and job information. |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 575 | """ |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 576 | return rpc_utils.prepare_rows_as_nested_dicts( |
| 577 | models.HostQueueEntry.query_objects(filter_data), |
| 578 | ('host', 'atomic_group', 'job')) |
showard | 34dc5fa | 2008-04-24 20:58:40 +0000 | [diff] [blame] | 579 | |
| 580 | |
| 581 | def get_num_host_queue_entries(**filter_data): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 582 | """\ |
| 583 | Get the number of host queue entries associated with this job. |
| 584 | """ |
| 585 | return models.HostQueueEntry.query_count(filter_data) |
showard | 34dc5fa | 2008-04-24 20:58:40 +0000 | [diff] [blame] | 586 | |
| 587 | |
showard | 1e935f1 | 2008-07-11 00:11:36 +0000 | [diff] [blame] | 588 | def get_hqe_percentage_complete(**filter_data): |
| 589 | """ |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 590 | Computes the fraction of host queue entries matching the given filter data |
showard | 1e935f1 | 2008-07-11 00:11:36 +0000 | [diff] [blame] | 591 | that are complete. |
| 592 | """ |
| 593 | query = models.HostQueueEntry.query_objects(filter_data) |
| 594 | complete_count = query.filter(complete=True).count() |
| 595 | total_count = query.count() |
| 596 | if total_count == 0: |
| 597 | return 1 |
| 598 | return float(complete_count) / total_count |
| 599 | |
| 600 | |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 601 | # other |
| 602 | |
showard | e0b6362 | 2008-08-04 20:58:47 +0000 | [diff] [blame] | 603 | def echo(data=""): |
| 604 | """\ |
| 605 | Returns a passed in string. For doing a basic test to see if RPC calls |
| 606 | can successfully be made. |
| 607 | """ |
| 608 | return data |
| 609 | |
| 610 | |
mbligh | e8819cd | 2008-02-15 16:48:40 +0000 | [diff] [blame] | 611 | def get_static_data(): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 612 | """\ |
| 613 | Returns a dictionary containing a bunch of data that shouldn't change |
| 614 | often and is otherwise inaccessible. This includes: |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 615 | |
| 616 | priorities: List of job priority choices. |
| 617 | default_priority: Default priority value for new jobs. |
| 618 | users: Sorted list of all users. |
| 619 | labels: Sorted list of all labels. |
| 620 | atomic_groups: Sorted list of all atomic groups. |
| 621 | tests: Sorted list of all tests. |
| 622 | profilers: Sorted list of all profilers. |
| 623 | current_user: Logged-in username. |
| 624 | host_statuses: Sorted list of possible Host statuses. |
| 625 | job_statuses: Sorted list of possible HostQueueEntry statuses. |
| 626 | job_timeout_default: The default job timeout length in hours. |
| 627 | reboot_before_options: A list of valid RebootBefore string enums. |
| 628 | reboot_after_options: A list of valid RebootAfter string enums. |
| 629 | motd: Server's message of the day. |
| 630 | status_dictionary: A mapping from one word job status names to a more |
| 631 | informative description. |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 632 | """ |
showard | 21baa45 | 2008-10-21 00:08:39 +0000 | [diff] [blame] | 633 | |
| 634 | job_fields = models.Job.get_field_dict() |
| 635 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 636 | result = {} |
| 637 | result['priorities'] = models.Job.Priority.choices() |
showard | 21baa45 | 2008-10-21 00:08:39 +0000 | [diff] [blame] | 638 | default_priority = job_fields['priority'].default |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 639 | default_string = models.Job.Priority.get_string(default_priority) |
| 640 | result['default_priority'] = default_string |
| 641 | result['users'] = get_users(sort_by=['login']) |
| 642 | result['labels'] = get_labels(sort_by=['-platform', 'name']) |
showard | c92da83 | 2009-04-07 18:14:34 +0000 | [diff] [blame^] | 643 | result['atomic_groups'] = get_atomic_groups(sort_by=['name']) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 644 | result['tests'] = get_tests(sort_by=['name']) |
showard | 2b9a88b | 2008-06-13 20:55:03 +0000 | [diff] [blame] | 645 | result['profilers'] = get_profilers(sort_by=['name']) |
showard | 0fc3830 | 2008-10-23 00:44:07 +0000 | [diff] [blame] | 646 | result['current_user'] = rpc_utils.prepare_for_serialization( |
| 647 | thread_local.get_user().get_object_dict()) |
showard | 2b9a88b | 2008-06-13 20:55:03 +0000 | [diff] [blame] | 648 | result['host_statuses'] = sorted(models.Host.Status.names) |
mbligh | 5a198b9 | 2008-12-11 19:33:29 +0000 | [diff] [blame] | 649 | result['job_statuses'] = sorted(models.HostQueueEntry.Status.names) |
showard | b1e5187 | 2008-10-07 11:08:18 +0000 | [diff] [blame] | 650 | result['job_timeout_default'] = models.Job.DEFAULT_TIMEOUT |
showard | 0fc3830 | 2008-10-23 00:44:07 +0000 | [diff] [blame] | 651 | result['reboot_before_options'] = models.RebootBefore.names |
| 652 | result['reboot_after_options'] = models.RebootAfter.names |
showard | 8fbae65 | 2009-01-20 23:23:10 +0000 | [diff] [blame] | 653 | result['motd'] = rpc_utils.get_motd() |
showard | 8ac29b4 | 2008-07-17 17:01:55 +0000 | [diff] [blame] | 654 | |
showard | 95128e5 | 2008-08-04 20:59:34 +0000 | [diff] [blame] | 655 | result['status_dictionary'] = {"Abort": "Abort", |
| 656 | "Aborted": "Aborted", |
showard | 8ac29b4 | 2008-07-17 17:01:55 +0000 | [diff] [blame] | 657 | "Verifying": "Verifying Host", |
| 658 | "Pending": "Waiting on other hosts", |
| 659 | "Running": "Running autoserv", |
| 660 | "Completed": "Autoserv completed", |
| 661 | "Failed": "Failed to complete", |
| 662 | "Aborting": "Abort in progress", |
showard | d823b36 | 2008-07-24 16:35:46 +0000 | [diff] [blame] | 663 | "Queued": "Queued", |
showard | 5deb677 | 2008-11-04 21:54:33 +0000 | [diff] [blame] | 664 | "Starting": "Next in host's queue", |
| 665 | "Stopped": "Other host(s) failed verify", |
| 666 | "Parsing": "Awaiting parse of final results"} |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 667 | return result |