blob: daec6ab702879f2dacc91e24dcbbe64586cac140 [file] [log] [blame]
mblighbe630eb2008-08-01 16:41:48 +00001#!/usr/bin/python
2#
3# Copyright 2008 Google Inc. All Rights Reserved.
4
5"""Tests for job."""
6
7import copy, getpass, unittest, sys, os
8
9import common
10from autotest_lib.cli import cli_mock, topic_common, job
11
12
13class job_unittest(cli_mock.cli_unittest):
14 def setUp(self):
15 super(job_unittest, self).setUp()
16 self.god.stub_function(getpass, 'getuser')
17 getpass.getuser.expect_call().and_return('user0')
18 self.values = copy.deepcopy(self.values_template)
19
20 results = [{u'status_counts': {u'Aborted': 1},
21 u'control_file':
22 u"job.run_test('sleeptest')\n",
23 u'name': u'test_job0',
24 u'control_type': u'Server',
25 u'synchronizing': 0,
26 u'priority':
27 u'Medium',
28 u'owner': u'user0',
29 u'created_on':
30 u'2008-07-08 17:45:44',
31 u'synch_count': 1,
32 u'synch_type':
33 u'Synchronous',
34 u'id': 180},
35 {u'status_counts': {u'Queued': 1},
36 u'control_file':
37 u"job.run_test('sleeptest')\n",
38 u'name': u'test_job1',
39 u'control_type': u'Client',
40 u'synchronizing':0,
41 u'priority':
42 u'High',
43 u'owner': u'user0',
44 u'created_on':
45 u'2008-07-08 12:17:47',
46 u'synch_count': 1,
47 u'synch_type':
48 u'Asynchronous',
49 u'id': 338}]
50
51
52 values_template = [{u'id': 180, # Valid job
53 u'priority': u'Low',
54 u'name': u'test_job0',
55 u'owner': u'Cringer',
56 u'invalid': 0,
57 u'created_on': u'2008-07-02 13:02:40',
58 u'control_type': u'Server',
59 u'status_counts': {u'Queued': 1},
60 u'synch_type': u'Synchornous'},
61 {u'id': 338, # Valid job
62 u'priority': 'High',
63 u'name': u'test_job1',
64 u'owner': u'Fisto',
65 u'invalid': 0,
66 u'created_on': u'2008-07-06 14:05:33',
67 u'control_type': u'Client',
68 u'status_counts': {u'Queued': 1},
69 u'synch_type': u'Asynchronous'},
70 {u'id': 339, # Valid job
71 u'priority': 'Medium',
72 u'name': u'test_job2',
73 u'owner': u'Roboto',
74 u'invalid': 0,
75 u'created_on': u'2008-07-07 15:33:18',
76 u'control_type': u'Server',
77 u'status_counts': {u'Queued': 1},
78 u'synch_type': u'Asynchronous'},
79 {u'id': 340, # Invalid job priority
80 u'priority': u'Uber',
81 u'name': u'test_job3',
82 u'owner': u'Panthor',
83 u'invalid': 1,
84 u'created_on': u'2008-07-04 00:00:01',
85 u'control_type': u'Server',
86 u'status_counts': {u'Queued': 1},
87 u'synch_type': u'Synchronous'},
88 {u'id': 350, # Invalid job created_on
89 u'priority': 'Medium',
90 u'name': u'test_job4',
91 u'owner': u'Icer',
92 u'invalid': 1,
93 u'created_on': u'Today',
94 u'control_type': u'Client',
95 u'status_counts': {u'Queued': 1},
96 u'synch_type': u'Asynchronous'},
97 {u'id': 420, # Invalid job control_type
98 u'priority': 'Urgent',
99 u'name': u'test_job5',
100 u'owner': u'Spikor',
101 u'invalid': 1,
102 u'created_on': u'2012-08-08 18:54:37',
103 u'control_type': u'Child',
104 u'status_counts': {u'Queued': 1},
105 u'synch_type': u'Synchronous'}]
106
107
108class job_list_unittest(job_unittest):
109 def test_job_list_jobs(self):
110 getpass.getuser.expect_call().and_return('user0')
111 self.run_cmd(argv=['atest', 'job', 'list'],
112 rpcs=[('get_jobs_summary', {'owner': 'user0',
113 'running': None},
114 True, self.values)],
115 out_words_ok=['test_job0', 'test_job1', 'test_job2'],
116 out_words_no=['Uber', 'Today', 'Child'])
117
118
119 def test_job_list_jobs_only_user(self):
120 values = [item for item in self.values if item['owner'] == 'Cringer']
121 self.run_cmd(argv=['atest', 'job', 'list', '-u', 'Cringer'],
122 rpcs=[('get_jobs_summary', {'owner': 'Cringer',
123 'running': None},
124 True, values)],
125 out_words_ok=['Cringer'],
126 out_words_no=['Fisto', 'Roboto', 'Panthor', 'Icer',
127 'Spikor'])
128
129
130 def test_job_list_jobs_all(self):
131 self.run_cmd(argv=['atest', 'job', 'list', '--all'],
132 rpcs=[('get_jobs_summary', {'running': None},
133 True, self.values)],
134 out_words_ok=['Fisto', 'Roboto', 'Panthor',
135 'Icer', 'Spikor', 'Cringer'],
136 out_words_no=['Created', 'Priority'])
137
138
139 def test_job_list_jobs_id(self):
140 self.run_cmd(argv=['atest', 'job', 'list', '5964'],
141 rpcs=[('get_jobs_summary', {'id__in': ['5964'],
142 'running': None},
143 True,
144 [{u'status_counts': {u'Completed': 1},
145 u'control_file': u'kernel = \'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\'\ndef step_init():\n job.next_step([step_test])\n testkernel = job.kernel(\'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\')\n \n testkernel.install()\n testkernel.boot(args=\'console_always_print=1\')\n\ndef step_test():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME = "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1 second by default. It\'s a good way to test\n profilers and double check that autotest is working.\n The seconds argument can also be modified to make the machine sleep for as\n long as needed.\n """\n \n job.run_test(\'sleeptest\', seconds = 1)',
146 u'name': u'mytest',
147 u'control_type': u'Client',
148 u'synchronizing': 0,
149 u'run_verify': 1,
150 u'priority': u'Medium',
151 u'owner': u'user0',
152 u'created_on': u'2008-07-28 12:42:52',
153 u'timeout': 144,
154 u'synch_count': None,
155 u'synch_type': u'Asynchronous',
156 u'id': 5964}])],
157 out_words_ok=['user0', 'Completed', '1', '5964'],
158 out_words_no=['sleeptest', 'Priority', 'Client', '2008'])
159
160
161 def test_job_list_jobs_id_verbose(self):
162 self.run_cmd(argv=['atest', 'job', 'list', '5964', '-v'],
163 rpcs=[('get_jobs_summary', {'id__in': ['5964'],
164 'running': None},
165 True,
166 [{u'status_counts': {u'Completed': 1},
167 u'control_file': u'kernel = \'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\'\ndef step_init():\n job.next_step([step_test])\n testkernel = job.kernel(\'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\')\n \n testkernel.install()\n testkernel.boot(args=\'console_always_print=1\')\n\ndef step_test():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME = "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1 second by default. It\'s a good way to test\n profilers and double check that autotest is working.\n The seconds argument can also be modified to make the machine sleep for as\n long as needed.\n """\n \n job.run_test(\'sleeptest\', seconds = 1)',
168 u'name': u'mytest',
169 u'control_type': u'Client',
170 u'synchronizing': 0,
171 u'run_verify': 1,
172 u'priority': u'Medium',
173 u'owner': u'user0',
174 u'created_on': u'2008-07-28 12:42:52',
175 u'timeout': 144,
176 u'synch_count': None,
177 u'synch_type': u'Asynchronous',
178 u'id': 5964}])],
179 out_words_ok=['user0', 'Completed', '1', '5964',
180 'Client', '2008', 'Priority'],
181 out_words_no=['sleeptest'])
182
183
184 def test_job_list_jobs_name(self):
185 self.run_cmd(argv=['atest', 'job', 'list', 'myt*'],
186 rpcs=[('get_jobs_summary', {'name__startswith': 'myt',
187 'running': None},
188 True,
189 [{u'status_counts': {u'Completed': 1},
190 u'control_file': u'kernel = \'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\'\ndef step_init():\n job.next_step([step_test])\n testkernel = job.kernel(\'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\')\n \n testkernel.install()\n testkernel.boot(args=\'console_always_print=1\')\n\ndef step_test():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME = "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1 second by default. It\'s a good way to test\n profilers and double check that autotest is working.\n The seconds argument can also be modified to make the machine sleep for as\n long as needed.\n """\n \n job.run_test(\'sleeptest\', seconds = 1)',
191 u'name': u'mytest',
192 u'control_type': u'Client',
193 u'synchronizing': 0,
194 u'run_verify': 1,
195 u'priority': u'Medium',
196 u'owner': u'user0',
197 u'created_on': u'2008-07-28 12:42:52',
198 u'timeout': 144,
199 u'synch_count': None,
200 u'synch_type': u'Asynchronous',
201 u'id': 5964}])],
202 out_words_ok=['user0', 'Completed', '1', '5964'],
203 out_words_no=['sleeptest', 'Priority', 'Client', '2008'])
204
205
206 def test_job_list_jobs_all_verbose(self):
207 self.run_cmd(argv=['atest', 'job', 'list', '--all', '--verbose'],
208 rpcs=[('get_jobs_summary', {'running': None},
209 True, self.values)],
210 out_words_ok=['Fisto', 'Spikor', 'Cringer', 'Priority',
211 'Created'])
212
213
214 def test_job_list_jobs_all_and_user(self):
215 testjob = job.job_list()
216 sys.argv = ['atest', 'job', 'list', '-a', '-u', 'user0']
217 self.god.mock_io()
218 sys.exit.expect_call(1).and_raises(cli_mock.ExitException)
219 self.assertRaises(cli_mock.ExitException, testjob.parse)
220 self.god.unmock_io()
221
222
223class job_stat_unittest(job_unittest):
224 def test_job_stat_job(self):
225 results = copy.deepcopy(self.results)
226 self.run_cmd(argv=['atest', 'job', 'stat', '180'],
227 rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,
228 [results[0]]),
229 ('get_host_queue_entries', {'job__in': ['180']},
230 True,
231 [{u'status': u'Failed',
232 u'complete': 1,
233 u'host': {u'status': u'Repair Failed',
234 u'locked': 0,
235 u'hostname': u'host0',
236 u'invalid': 1,
237 u'id': 4432,
238 u'synch_id': None},
239 u'priority': 1,
240 u'meta_host': None,
241 u'job': {u'control_file': u"def run(machine):\n\thost = hosts.SSHHost(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
242 u'name': u'test_sleep',
243 u'control_type': u'Server',
244 u'synchronizing': 0,
245 u'priority': u'Medium',
246 u'owner': u'user0',
247 u'created_on': u'2008-03-18 11:27:29',
248 u'synch_count': None,
249 u'synch_type': u'Asynchronous',
250 u'id': 180},
251 u'active': 0,
252 u'id': 101084}])],
253 out_words_ok=['test_job0', 'host0', 'Failed',
254 'Aborted'])
255
256
257 def test_job_stat_job_multiple_hosts(self):
258 self.run_cmd(argv=['atest', 'job', 'stat', '6761'],
259 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
260 [{u'status_counts': {u'Running': 1,
261 u'Queued': 4},
262 u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
263 u'name': u'test_on_meta_hosts',
264 u'control_type': u'Client',
265 u'synchronizing': 0,
266 u'run_verify': 1,
267 u'priority': u'Medium',
268 u'owner': u'user0',
269 u'created_on': u'2008-07-30 22:15:43',
270 u'timeout': 144,
271 u'synch_count': None,
272 u'synch_type': u'Asynchronous',
273 u'id': 6761}]),
274 ('get_host_queue_entries', {'job__in': ['6761']},
275 True,
276 [{u'status': u'Queued',
277 u'complete': 0,
278 u'deleted': 0,
279 u'host': None,
280 u'priority': 1,
281 u'meta_host': u'Xeon',
282 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
283 u'name': u'test_on_meta_hosts',
284 u'control_type': u'Client',
285 u'synchronizing': 0,
286 u'run_verify': 1,
287 u'priority': u'Medium',
288 u'owner': u'user0',
289 u'created_on': u'2008-07-30 22:15:43',
290 u'timeout': 144,
291 u'synch_count': None,
292 u'synch_type': u'Asynchronous',
293 u'id': 6761},
294 u'active': 0,
295 u'id': 193166},
296 {u'status': u'Queued',
297 u'complete': 0,
298 u'deleted': 0,
299 u'host': None,
300 u'priority': 1,
301 u'meta_host': u'Xeon',
302 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
303 u'name': u'test_on_meta_hosts',
304 u'control_type': u'Client',
305 u'synchronizing': 0,
306 u'run_verify': 1,
307 u'priority': u'Medium',
308 u'owner': u'user0',
309 u'created_on': u'2008-07-30 22:15:43',
310 u'timeout': 144,
311 u'synch_count': None,
312 u'synch_type': u'Asynchronous',
313 u'id': 6761},
314 u'active': 0,
315 u'id': 193167},
316 {u'status': u'Queued',
317 u'complete': 0,
318 u'deleted': 0,
319 u'host': None,
320 u'priority': 1,
321 u'meta_host': u'Athlon',
322 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
323 u'name': u'test_on_meta_hosts',
324 u'control_type': u'Client',
325 u'synchronizing': 0,
326 u'run_verify': 1,
327 u'priority': u'Medium',
328 u'owner': u'user0',
329 u'created_on': u'2008-07-30 22:15:43',
330 u'timeout': 144,
331 u'synch_count': None,
332 u'synch_type': u'Asynchronous',
333 u'id': 6761},
334 u'active': 0,
335 u'id': 193168},
336 {u'status': u'Queued',
337 u'complete': 0,
338 u'deleted': 0,
339 u'host': None,
340 u'priority': 1,
341 u'meta_host': u'x286',
342 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
343 u'name': u'test_on_meta_hosts',
344 u'control_type': u'Client',
345 u'synchronizing': 0,
346 u'run_verify': 1,
347 u'priority': u'Medium',
348 u'owner': u'user0',
349 u'created_on': u'2008-07-30 22:15:43',
350 u'timeout': 144,
351 u'synch_count': None,
352 u'synch_type': u'Asynchronous',
353 u'id': 6761},
354 u'active': 0,
355 u'id': 193169},
356 {u'status': u'Running',
357 u'complete': 0,
358 u'deleted': 0,
359 u'host': {u'status': u'Running',
360 u'lock_time': None,
361 u'hostname': u'host42',
362 u'locked': 0,
363 u'locked_by': None,
364 u'invalid': 0,
365 u'id': 4833,
366 u'protection': u'Repair filesystem only',
367 u'synch_id': None},
368 u'priority': 1,
369 u'meta_host': u'Athlon',
370 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
371 u'name': u'test_on_meta_hosts',
372 u'control_type': u'Client',
373 u'synchronizing': 0,
374 u'run_verify': 1,
375 u'priority': u'Medium',
376 u'owner': u'user0',
377 u'created_on': u'2008-07-30 22:15:43',
378 u'timeout': 144,
379 u'synch_count': None,
380 u'synch_type': u'Asynchronous',
381 u'id': 6761},
382 u'active': 1,
383 u'id': 193170} ])],
384 out_words_ok=['test_on_meta_hosts',
385 'host42', 'Queued', 'Running'],
386 out_words_no=['Athlon', 'Xeon', 'x286'])
387
388
389 def test_job_stat_job_no_host_in_qes(self):
390 results = copy.deepcopy(self.results)
391 self.run_cmd(argv=['atest', 'job', 'stat', '180'],
392 rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,
393 [results[0]]),
394 ('get_host_queue_entries', {'job__in': ['180']},
395 True,
396 [{u'status': u'Failed',
397 u'complete': 1,
398 u'host': None,
399 u'priority': 1,
400 u'meta_host': None,
401 u'job': {u'control_file': u"def run(machine):\n\thost = hosts.SSHHost(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
402 u'name': u'test_sleep',
403 u'control_type': u'Server',
404 u'synchronizing': 0,
405 u'priority': u'Medium',
406 u'owner': u'user0',
407 u'created_on': u'2008-03-18 11:27:29',
408 u'synch_count': None,
409 u'synch_type': u'Asynchronous',
410 u'id': 180},
411 u'active': 0,
412 u'id': 101084}])],
413 out_words_ok=['test_job0', 'Aborted'])
414
415
416 def test_job_stat_multi_jobs(self):
417 results = copy.deepcopy(self.results)
418 self.run_cmd(argv=['atest', 'job', 'stat', '180', '338'],
419 rpcs=[('get_jobs_summary', {'id__in': ['180', '338']},
420 True, results),
421 ('get_host_queue_entries',
422 {'job__in': ['180', '338']},
423 True,
424 [{u'status': u'Failed',
425 u'complete': 1,
426 u'host': {u'status': u'Repair Failed',
427 u'locked': 0,
428 u'hostname': u'host0',
429 u'invalid': 1,
430 u'id': 4432,
431 u'synch_id': None},
432 u'priority': 1,
433 u'meta_host': None,
434 u'job': {u'control_file': u"def run(machine):\n\thost = hosts.SSHHost(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
435 u'name': u'test_sleep',
436 u'control_type': u'Server',
437 u'synchronizing': 0,
438 u'priority': u'Medium',
439 u'owner': u'user0',
440 u'created_on': u'2008-03-18 11:27:29',
441 u'synch_count': None,
442 u'synch_type': u'Asynchronous',
443 u'id': 180},
444 u'active': 0,
445 u'id': 101084},
446 {u'status': u'Failed',
447 u'complete': 1,
448 u'host': {u'status': u'Repair Failed',
449 u'locked': 0,
450 u'hostname': u'host10',
451 u'invalid': 1,
452 u'id': 4432,
453 u'synch_id': None},
454 u'priority': 1,
455 u'meta_host': None,
456 u'job': {u'control_file': u"def run(machine):\n\thost = hosts.SSHHost(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
457 u'name': u'test_sleep',
458 u'control_type': u'Server',
459 u'synchronizing': 0,
460 u'priority': u'Medium',
461 u'owner': u'user0',
462 u'created_on': u'2008-03-18 11:27:29',
463 u'synch_count': None,
464 u'synch_type': u'Asynchronous',
465 u'id': 338},
466 u'active': 0,
467 u'id': 101084}])],
468 out_words_ok=['test_job0', 'test_job1'])
469
470
471 def test_job_stat_multi_jobs_name_id(self):
472 self.run_cmd(argv=['atest', 'job', 'stat', 'mytest', '180'],
473 rpcs=[('get_jobs_summary', {'id__in': ['180']},
474 True,
475 [{u'status_counts': {u'Aborted': 1},
476 u'control_file':
477 u"job.run_test('sleeptest')\n",
478 u'name': u'job0',
479 u'control_type': u'Server',
480 u'synchronizing': 0,
481 u'priority':
482 u'Medium',
483 u'owner': u'user0',
484 u'created_on':
485 u'2008-07-08 17:45:44',
486 u'synch_count': 1,
487 u'synch_type':
488 u'Synchronous',
489 u'id': 180}]),
490 ('get_jobs_summary', {'name__in': ['mytest']},
491 True,
492 [{u'status_counts': {u'Queued': 1},
493 u'control_file':
494 u"job.run_test('sleeptest')\n",
495 u'name': u'mytest',
496 u'control_type': u'Client',
497 u'synchronizing':0,
498 u'priority':
499 u'High',
500 u'owner': u'user0',
501 u'created_on': u'2008-07-08 12:17:47',
502 u'synch_count': 1,
503 u'synch_type':
504 u'Asynchronous',
505 u'id': 338}]),
506 ('get_host_queue_entries',
507 {'job__in': ['180']},
508 True,
509 [{u'status': u'Failed',
510 u'complete': 1,
511 u'host': {u'status': u'Repair Failed',
512 u'locked': 0,
513 u'hostname': u'host0',
514 u'invalid': 1,
515 u'id': 4432,
516 u'synch_id': None},
517 u'priority': 1,
518 u'meta_host': None,
519 u'job': {u'control_file': u"def run(machine):\n\thost = hosts.SSHHost(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
520 u'name': u'test_sleep',
521 u'control_type': u'Server',
522 u'synchronizing': 0,
523 u'priority': u'Medium',
524 u'owner': u'user0',
525 u'created_on': u'2008-03-18 11:27:29',
526 u'synch_count': None,
527 u'synch_type': u'Asynchronous',
528 u'id': 180},
529 u'active': 0,
530 u'id': 101084}]),
531 ('get_host_queue_entries',
532 {'job__name__in': ['mytest']},
533 True,
534 [{u'status': u'Failed',
535 u'complete': 1,
536 u'host': {u'status': u'Repair Failed',
537 u'locked': 0,
538 u'hostname': u'host10',
539 u'invalid': 1,
540 u'id': 4432,
541 u'synch_id': None},
542 u'priority': 1,
543 u'meta_host': None,
544 u'job': {u'control_file': u"def run(machine):\n\thost = hosts.SSHHost(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
545 u'name': u'test_sleep',
546 u'control_type': u'Server',
547 u'synchronizing': 0,
548 u'priority': u'Medium',
549 u'owner': u'user0',
550 u'created_on': u'2008-03-18 11:27:29',
551 u'synch_count': None,
552 u'synch_type': u'Asynchronous',
553 u'id': 338},
554 u'active': 0,
555 u'id': 101084}])],
556 out_words_ok=['job0', 'mytest', 'Aborted', 'Queued',
557 'Failed', 'Medium', 'High'])
558
559
560class job_create_unittest(cli_mock.cli_unittest):
561 ctrl_file = '\ndef step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME =\n "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1\n second by default. It\'s a good way to test\n profilers and double check\n that autotest is working.\n The seconds argument can also be modified to\n make the machine sleep for as\n long as needed.\n """\n \n\n job.run_test(\'sleeptest\', seconds = 1)'
562
563 kernel_ctrl_file = 'kernel = \'kernel\'\ndef step_init():\n job.next_step([step_test])\n testkernel = job.kernel(\'kernel\')\n \n testkernel.install()\n testkernel.boot(args=\'console_always_print=1\')\n\ndef step_test():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME = "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1 second by default. It\'s a good way to test\n profilers and double check that autotest is working.\n The seconds argument can also be modified to make the machine sleep for as\n long as needed.\n """\n \n job.run_test(\'sleeptest\', seconds = 1)'
564
565 data = {'priority': 'Medium', 'control_file': ctrl_file, 'hosts': ['host0'],
566 'name': 'test_job0', 'control_type': 'Client',
567 'meta_hosts': [], 'is_synchronous': False}
568
569
570 def test_execute_create_job(self):
571 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
572 'test_job0', '-m', 'host0'],
573 rpcs=[('generate_control_file', {'tests': ['sleeptest'],
574 'use_container': False},
575 True, (self.ctrl_file, False, False)),
576 ('create_job', self.data, True, 180)],
577 out_words_ok=['test_job0', 'Created'],
578 out_words_no=['Uploading', 'Done'])
579
580
581 def test_execute_create_job_with_control(self):
582 filename = cli_mock.create_file(self.ctrl_file)
583 self.run_cmd(argv=['atest', 'job', 'create', '-f', filename,
584 'test_job0', '-m', 'host0'],
585 rpcs=[('create_job', self.data, True, 42)],
586 out_words_ok=['test_job0', 'Created'],
587 out_words_no=['Uploading', 'Done'])
588
589
590 def test_execute_create_job_with_kernel(self):
591 data = self.data.copy()
592 data['control_file'] = self.kernel_ctrl_file
593 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
594 '-k', 'kernel', 'test_job0', '-m', 'host0'],
595 rpcs=[('generate_control_file', {'tests': ['sleeptest'],
596 'use_container': False, 'kernel': 'kernel',
597 'do_push_packages': True},
598 True, (self.kernel_ctrl_file, False, False)),
599 ('create_job', data, True, 180)],
600 out_words_ok=['test_job0', 'Created',
601 'Uploading', 'Done'])
602
603
604 def test_execute_create_job_with_kernel_spaces(self):
605 data = self.data.copy()
606 data['control_file'] = self.kernel_ctrl_file
607 data['name'] = 'test job with spaces'
608 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
609 '-k', 'kernel', 'test job with spaces',
610 '-m', 'host0'],
611 rpcs=[('generate_control_file', {'tests': ['sleeptest'],
612 'use_container': False, 'kernel': 'kernel',
613 'do_push_packages': True},
614 True, (self.kernel_ctrl_file, False, False)),
615 ('create_job', data, True, 180)],
616 # This is actually 8 spaces,
617 # the tab has been converted by print.
618 out_words_ok=['test job with spaces', 'Created',
619 'id', '180'])
620
621
622 def test_execute_create_job_no_args(self):
623 testjob = job.job_create()
624 sys.argv = ['atest', 'job', 'create']
625 self.god.mock_io()
626 sys.exit.expect_call(1).and_raises(cli_mock.ExitException)
627 self.assertRaises(cli_mock.ExitException, testjob.parse)
628 self.god.unmock_io()
629
630
631 def test_execute_create_job_no_hosts(self):
632 testjob = job.job_create()
633 filename = cli_mock.create_file(self.ctrl_file)
634 sys.argv = ['atest', '-f', filename, 'test_job0']
635 self.god.mock_io()
636 sys.exit.expect_call(1).and_raises(cli_mock.ExitException)
637 self.assertRaises(cli_mock.ExitException, testjob.parse)
638 self.god.unmock_io()
639
640
641 def test_execute_create_job_cfile_and_tests(self):
642 testjob = job.job_create()
643 sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-f',
644 'control_file', 'test_job0', '-m', 'host0']
645 self.god.mock_io()
646 sys.exit.expect_call(1).and_raises(cli_mock.ExitException)
647 self.assertRaises(cli_mock.ExitException, testjob.parse)
648 self.god.unmock_io()
649
650
651 def test_execute_create_job_container_and_server(self):
652 testjob = job.job_create()
653 sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-s', '-c',
654 'test_job0', '-m', 'host0']
655 self.god.mock_io()
656 sys.exit.expect_call(1).and_raises(cli_mock.ExitException)
657 self.assertRaises(cli_mock.ExitException, testjob.parse)
658 self.god.unmock_io()
659
660
661 def test_execute_create_job_cfile_and_kernel(self):
662 testjob = job.job_create()
663 sys.argv = ['atest', 'job', 'create', '-f', 'control_file', '-k',
664 'kernel', 'test_job0', '-m', 'host0']
665 self.god.mock_io()
666 sys.exit.expect_call(1).and_raises(cli_mock.ExitException)
667 self.assertRaises(cli_mock.ExitException, testjob.parse)
668 self.god.unmock_io()
669
670
671 def test_execute_create_job_cfile_and_container(self):
672 testjob = job.job_create()
673 sys.argv = ['atest', 'job', 'create', '-f', 'control_file', '-c',
674 'test_job0', '-m', 'host0']
675 self.god.mock_io()
676 sys.exit.expect_call(1).and_raises(cli_mock.ExitException)
677 self.assertRaises(cli_mock.ExitException, testjob.parse)
678 self.god.unmock_io()
679
680
681 def test_execute_create_job_bad_cfile(self):
682 testjob = job.job_create()
683 sys.argv = ['atest', 'job', 'create', '-f', 'control_file', 'test_job0',
684 '-m', 'host0']
685 self.god.mock_io()
686 sys.exit.expect_call(1).and_raises(IOError)
687 self.assertRaises(IOError, testjob.parse)
688 self.god.unmock_io()
689
690
691 def test_execute_create_job_bad_priority(self):
692 testjob = job.job_create()
693 sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-p', 'Uber',
694 '-m', 'host0', 'test_job0']
695 self.god.mock_io()
696 sys.exit.expect_call(2).and_raises(cli_mock.ExitException)
697 self.assertRaises(cli_mock.ExitException, testjob.parse)
698 self.god.unmock_io()
699
700
701 def test_execute_create_job_with_mfile(self):
702 data = self.data.copy()
703 data['hosts'] = ['host3', 'host2', 'host1', 'host0']
704 cfile = cli_mock.create_file(self.ctrl_file)
705 filename = cli_mock.create_file('host0\nhost1\nhost2\nhost3')
706 self.run_cmd(argv=['atest', 'job', 'create', '--mlist', filename, '-f',
707 cfile, 'test_job0'],
708 rpcs=[('create_job', data, True, 42)],
709 out_words_ok=['test_job0', 'Created'])
710
711
712 def test_execute_create_job_with_container(self):
713 data = self.data.copy()
714 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
715 '-c', 'test_job0', '-m', 'host0'],
716 rpcs=[('generate_control_file', {'tests': ['sleeptest'],
717 'use_container': True}, True, (self.ctrl_file,
718 False, False)),
719 ('create_job', data, True, 42)],
720 out_words_ok=['test_job0', 'Created'])
721
722
723 def _test_parse_hosts(self, args, exp_hosts=[], exp_meta_hosts=[]):
724 testjob = job.job_create()
725 (hosts, meta_hosts) = testjob.parse_hosts(args)
726 self.assertEqualNoOrder(hosts, exp_hosts)
727 self.assertEqualNoOrder(meta_hosts, exp_meta_hosts)
728
729
730 def test_parse_hosts_regular(self):
731 self._test_parse_hosts(['host0'], ['host0'])
732
733
734 def test_parse_hosts_regulars(self):
735 self._test_parse_hosts(['host0', 'host1'], ['host0', 'host1'])
736
737
738 def test_parse_hosts_meta_one(self):
739 self._test_parse_hosts(['*meta0'], [], ['meta0'])
740
741
742 def test_parse_hosts_meta_five(self):
743 self._test_parse_hosts(['5*meta0'], [], ['meta0']*5)
744
745
746 def test_parse_hosts_metas_five(self):
747 self._test_parse_hosts(['5*meta0', '2*meta1'], [],
748 ['meta0']*5 + ['meta1']*2)
749
750
751 def test_parse_hosts_mix(self):
752 self._test_parse_hosts(['5*meta0', 'host0', '2*meta1', 'host1',
753 '*meta2'], ['host0', 'host1'],
754 ['meta0']*5 + ['meta1']*2 + ['meta2'])
755
756
757class job_abort_unittest(cli_mock.cli_unittest):
758 results = [{u'status_counts': {u'Aborted': 1}, u'control_file':
759 u"job.run_test('sleeptest')\n", u'name': u'test_job0',
760 u'control_type': u'Server', u'synchronizing': 0, u'priority':
761 u'Medium', u'owner': u'user0', u'created_on':
762 u'2008-07-08 17:45:44', u'synch_count': 1, u'synch_type':
763 u'Synchronous', u'id': 180}]
764
765 def test_execute_job_abort(self):
766 self.run_cmd(argv=['atest', 'job', 'abort', '180'],
767 rpcs=[('abort_job', {'id': '180'}, True, None)],
768 out_words_ok=['Aborted', '180'])
769
770
771 def test_execute_job_abort_bad_id(self):
772 self.run_cmd(argv=['atest', 'job', 'abort', '777'],
773 rpcs=[('abort_job', {'id': '777'}, False,
774 'ValidationError:{DoesNotExist: Job matching query'
775 'does not exist}')],
776 err_words_ok=['Operation', 'abort_job', 'failed'])
777
778
779if __name__ == '__main__':
780 unittest.main()