3 # Copyright 2008 Google Inc. All Rights Reserved.
8 import copy
, getpass
, unittest
, sys
, os
11 from autotest_lib
.cli
import cli_mock
, topic_common
, job
12 from autotest_lib
.client
.common_lib
.test_utils
import mock
15 class job_unittest(cli_mock
.cli_unittest
):
17 super(job_unittest
, self
).setUp()
18 self
.values
= copy
.deepcopy(self
.values_template
)
20 results
= [{u
'status_counts': {u
'Aborted': 1},
22 u
"job.run_test('sleeptest')\n",
23 u
'name': u
'test_job0',
24 u
'control_type': u
'Server',
29 u
'2008-07-08 17:45:44',
32 {u
'status_counts': {u
'Queued': 1},
34 u
"job.run_test('sleeptest')\n",
35 u
'name': u
'test_job1',
36 u
'control_type': u
'Client',
41 u
'2008-07-08 12:17:47',
46 values_template
= [{u
'id': 180, # Valid job
48 u
'name': u
'test_job0',
51 u
'created_on': u
'2008-07-02 13:02:40',
52 u
'control_type': u
'Server',
53 u
'status_counts': {u
'Queued': 1},
55 {u
'id': 338, # Valid job
57 u
'name': u
'test_job1',
60 u
'created_on': u
'2008-07-06 14:05:33',
61 u
'control_type': u
'Client',
62 u
'status_counts': {u
'Queued': 1},
64 {u
'id': 339, # Valid job
65 u
'priority': 'Medium',
66 u
'name': u
'test_job2',
69 u
'created_on': u
'2008-07-07 15:33:18',
70 u
'control_type': u
'Server',
71 u
'status_counts': {u
'Queued': 1},
73 {u
'id': 340, # Invalid job priority
75 u
'name': u
'test_job3',
78 u
'created_on': u
'2008-07-04 00:00:01',
79 u
'control_type': u
'Server',
80 u
'status_counts': {u
'Queued': 1},
82 {u
'id': 350, # Invalid job created_on
83 u
'priority': 'Medium',
84 u
'name': u
'test_job4',
87 u
'created_on': u
'Today',
88 u
'control_type': u
'Client',
89 u
'status_counts': {u
'Queued': 1},
91 {u
'id': 420, # Invalid job control_type
92 u
'priority': 'Urgent',
93 u
'name': u
'test_job5',
96 u
'created_on': u
'2012-08-08 18:54:37',
97 u
'control_type': u
'Child',
98 u
'status_counts': {u
'Queued': 1},
102 class job_list_unittest(job_unittest
):
103 def test_job_list_jobs(self
):
104 self
.god
.stub_function(getpass
, 'getuser')
105 getpass
.getuser
.expect_call().and_return('user0')
106 self
.run_cmd(argv
=['atest', 'job', 'list', '--ignore_site_file'],
107 rpcs
=[('get_jobs_summary', {'owner': 'user0',
110 out_words_ok
=['test_job0', 'test_job1', 'test_job2'],
111 out_words_no
=['Uber', 'Today', 'Child'])
114 def test_job_list_jobs_only_user(self
):
115 values
= [item
for item
in self
.values
if item
['owner'] == 'Cringer']
116 self
.run_cmd(argv
=['atest', 'job', 'list', '-u', 'Cringer',
117 '--ignore_site_file'],
118 rpcs
=[('get_jobs_summary', {'owner': 'Cringer',
121 out_words_ok
=['Cringer'],
122 out_words_no
=['Fisto', 'Roboto', 'Panthor', 'Icer',
126 def test_job_list_jobs_all(self
):
127 self
.run_cmd(argv
=['atest', 'job', 'list', '--all',
128 '--ignore_site_file'],
129 rpcs
=[('get_jobs_summary', {'running': None},
131 out_words_ok
=['Fisto', 'Roboto', 'Panthor',
132 'Icer', 'Spikor', 'Cringer'],
133 out_words_no
=['Created', 'Priority'])
136 def test_job_list_jobs_id(self
):
137 self
.run_cmd(argv
=['atest', 'job', 'list', '5964',
138 '--ignore_site_file'],
139 rpcs
=[('get_jobs_summary', {'id__in': ['5964'],
142 [{u
'status_counts': {u
'Completed': 1},
143 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)',
145 u
'control_type': u
'Client',
147 u
'priority': u
'Medium',
149 u
'created_on': u
'2008-07-28 12:42:52',
153 out_words_ok
=['user0', 'Completed', '1', '5964'],
154 out_words_no
=['sleeptest', 'Priority', 'Client', '2008'])
157 def test_job_list_jobs_id_verbose(self
):
158 self
.run_cmd(argv
=['atest', 'job', 'list', '5964', '-v',
159 '--ignore_site_file'],
160 rpcs
=[('get_jobs_summary', {'id__in': ['5964'],
163 [{u
'status_counts': {u
'Completed': 1},
164 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)',
166 u
'control_type': u
'Client',
168 u
'priority': u
'Medium',
170 u
'created_on': u
'2008-07-28 12:42:52',
174 out_words_ok
=['user0', 'Completed', '1', '5964',
175 'Client', '2008', 'Priority'],
176 out_words_no
=['sleeptest'])
179 def test_job_list_jobs_name(self
):
180 self
.run_cmd(argv
=['atest', 'job', 'list', 'myt*',
181 '--ignore_site_file'],
182 rpcs
=[('get_jobs_summary', {'name__startswith': 'myt',
185 [{u
'status_counts': {u
'Completed': 1},
186 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)',
188 u
'control_type': u
'Client',
190 u
'priority': u
'Medium',
192 u
'created_on': u
'2008-07-28 12:42:52',
196 out_words_ok
=['user0', 'Completed', '1', '5964'],
197 out_words_no
=['sleeptest', 'Priority', 'Client', '2008'])
200 def test_job_list_jobs_all_verbose(self
):
201 self
.run_cmd(argv
=['atest', 'job', 'list', '--all', '--verbose',
202 '--ignore_site_file'],
203 rpcs
=[('get_jobs_summary', {'running': None},
205 out_words_ok
=['Fisto', 'Spikor', 'Cringer', 'Priority',
209 class job_list_jobs_all_and_user_unittest(cli_mock
.cli_unittest
):
210 def test_job_list_jobs_all_and_user(self
):
211 testjob
= job
.job_list()
212 sys
.argv
= ['atest', 'job', 'list', '-a', '-u', 'user0',
213 '--ignore_site_file']
215 (sys
.exit
.expect_call(mock
.anything_comparator())
216 .and_raises(cli_mock
.ExitException
))
217 self
.assertRaises(cli_mock
.ExitException
, testjob
.parse
)
219 self
.god
.check_playback()
222 class job_stat_unittest(job_unittest
):
223 def test_job_stat_job(self
):
224 results
= copy
.deepcopy(self
.results
)
225 self
.run_cmd(argv
=['atest', 'job', 'stat', '180',
226 '--ignore_site_file'],
227 rpcs
=[('get_jobs_summary', {'id__in': ['180']}, True,
229 ('get_host_queue_entries', {'job__in': ['180']},
231 [{u
'status': u
'Failed',
233 u
'host': {u
'status': u
'Repair Failed',
235 u
'hostname': u
'host0',
241 u
'job': {u
'control_file': u
"def run(machine):\n\thost = hosts.create_host(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',
245 u
'priority': u
'Medium',
247 u
'created_on': u
'2008-03-18 11:27:29',
252 out_words_ok
=['test_job0', 'host0', 'Failed',
257 def test_job_stat_list_unassigned_host(self
):
258 self
.run_cmd(argv
=['atest', 'job', 'stat', '6761',
259 '--list-hosts', '--ignore_site_file'],
260 rpcs
=[('get_jobs_summary', {'id__in': ['6761']}, True,
261 [{u
'status_counts': {u
'Queued': 1},
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',
266 u
'priority': u
'Medium',
268 u
'created_on': u
'2008-07-30 22:15:43',
272 ('get_host_queue_entries', {'job__in': ['6761']},
274 [{u
'status': u
'Queued',
279 u
'meta_host': u
'Xeon',
280 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\')',
281 u
'name': u
'test_on_meta_hosts',
282 u
'control_type': u
'Client',
284 u
'priority': u
'Medium',
286 u
'created_on': u
'2008-07-30 22:15:43',
292 err_words_ok
=['unassigned', 'meta-hosts'],
293 out_words_no
=['Xeon'])
296 def test_job_stat_list_hosts(self
):
297 self
.run_cmd(argv
=['atest', 'job', 'stat', '6761',
298 '--list-hosts', '--ignore_site_file'],
299 rpcs
=[('get_jobs_summary', {'id__in': ['6761']}, True,
300 [{u
'status_counts': {u
'Queued': 1},
301 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\')',
302 u
'name': u
'test_on_meta_hosts',
303 u
'control_type': u
'Client',
305 u
'priority': u
'Medium',
307 u
'created_on': u
'2008-07-30 22:15:43',
311 ('get_host_queue_entries', {'job__in': ['6761']},
313 [{u
'status': u
'Queued',
316 u
'host': {u
'status': u
'Running',
318 u
'hostname': u
'host41',
323 u
'protection': u
'Repair filesystem only',
326 u
'meta_host': u
'Xeon',
327 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\')',
328 u
'name': u
'test_on_meta_hosts',
329 u
'control_type': u
'Client',
331 u
'priority': u
'Medium',
333 u
'created_on': u
'2008-07-30 22:15:43',
339 {u
'status': u
'Running',
342 u
'host': {u
'status': u
'Running',
344 u
'hostname': u
'host42',
349 u
'protection': u
'Repair filesystem only',
352 u
'meta_host': u
'Xeon',
353 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\')',
354 u
'name': u
'test_on_meta_hosts',
355 u
'control_type': u
'Client',
357 u
'priority': u
'Medium',
359 u
'created_on': u
'2008-07-30 22:15:43',
365 out_words_ok
=['host41', 'host42'],
366 out_words_no
=['Xeon', 'Running', 'Queued'],
367 err_words_no
=['unassigned'])
370 def test_job_stat_list_hosts_status(self
):
371 self
.run_cmd(argv
=['atest', 'job', 'stat', '6761',
372 '--list-hosts-status', 'Running,Queued',
373 '--ignore_site_file'],
374 rpcs
=[('get_jobs_summary', {'id__in': ['6761']}, True,
375 [{u
'status_counts': {u
'Queued': 1, u
'Running': 1},
376 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\')',
378 u
'control_type': u
'Client',
380 u
'priority': u
'Medium',
382 u
'created_on': u
'2008-07-30 22:15:43',
386 ('get_host_queue_entries', {'job__in': ['6761']},
388 [{u
'status': u
'Queued',
391 u
'host': {u
'status': u
'Queued',
393 u
'hostname': u
'host41',
398 u
'protection': u
'Repair filesystem only',
402 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\')',
404 u
'control_type': u
'Client',
406 u
'priority': u
'Medium',
408 u
'created_on': u
'2008-07-30 22:15:43',
414 {u
'status': u
'Running',
417 u
'host': {u
'status': u
'Running',
419 u
'hostname': u
'host42',
424 u
'protection': u
'Repair filesystem only',
428 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\')',
430 u
'control_type': u
'Client',
432 u
'priority': u
'Medium',
434 u
'created_on': u
'2008-07-30 22:15:43',
440 out_words_ok
=['Queued', 'Running', 'host41', 'host42'],
441 out_words_no
=['Xeon'],
442 err_words_no
=['unassigned'])
445 def test_job_stat_job_multiple_hosts(self
):
446 self
.run_cmd(argv
=['atest', 'job', 'stat', '6761',
447 '--ignore_site_file'],
448 rpcs
=[('get_jobs_summary', {'id__in': ['6761']}, True,
449 [{u
'status_counts': {u
'Running': 1,
451 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\')',
452 u
'name': u
'test_on_meta_hosts',
453 u
'control_type': u
'Client',
455 u
'priority': u
'Medium',
457 u
'created_on': u
'2008-07-30 22:15:43',
461 ('get_host_queue_entries', {'job__in': ['6761']},
463 [{u
'status': u
'Queued',
468 u
'meta_host': u
'Xeon',
469 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\')',
470 u
'name': u
'test_on_meta_hosts',
471 u
'control_type': u
'Client',
473 u
'priority': u
'Medium',
475 u
'created_on': u
'2008-07-30 22:15:43',
481 {u
'status': u
'Queued',
486 u
'meta_host': u
'Xeon',
487 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\')',
488 u
'name': u
'test_on_meta_hosts',
489 u
'control_type': u
'Client',
491 u
'priority': u
'Medium',
493 u
'created_on': u
'2008-07-30 22:15:43',
499 {u
'status': u
'Queued',
504 u
'meta_host': u
'Athlon',
505 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\')',
506 u
'name': u
'test_on_meta_hosts',
507 u
'control_type': u
'Client',
509 u
'priority': u
'Medium',
511 u
'created_on': u
'2008-07-30 22:15:43',
517 {u
'status': u
'Queued',
522 u
'meta_host': u
'x286',
523 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\')',
524 u
'name': u
'test_on_meta_hosts',
525 u
'control_type': u
'Client',
527 u
'priority': u
'Medium',
529 u
'created_on': u
'2008-07-30 22:15:43',
535 {u
'status': u
'Running',
538 u
'host': {u
'status': u
'Running',
540 u
'hostname': u
'host42',
545 u
'protection': u
'Repair filesystem only',
548 u
'meta_host': u
'Athlon',
549 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\')',
550 u
'name': u
'test_on_meta_hosts',
551 u
'control_type': u
'Client',
553 u
'priority': u
'Medium',
555 u
'created_on': u
'2008-07-30 22:15:43',
561 out_words_ok
=['test_on_meta_hosts',
562 'host42', 'Queued', 'Running'],
563 out_words_no
=['Athlon', 'Xeon', 'x286'])
566 def test_job_stat_job_no_host_in_qes(self
):
567 results
= copy
.deepcopy(self
.results
)
568 self
.run_cmd(argv
=['atest', 'job', 'stat', '180',
569 '--ignore_site_file'],
570 rpcs
=[('get_jobs_summary', {'id__in': ['180']}, True,
572 ('get_host_queue_entries', {'job__in': ['180']},
574 [{u
'status': u
'Failed',
579 u
'job': {u
'control_file': u
"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
580 u
'name': u
'test_sleep',
581 u
'control_type': u
'Server',
582 u
'priority': u
'Medium',
584 u
'created_on': u
'2008-03-18 11:27:29',
589 err_words_ok
=['unassigned', 'meta-hosts'])
592 def test_job_stat_multi_jobs(self
):
593 results
= copy
.deepcopy(self
.results
)
594 self
.run_cmd(argv
=['atest', 'job', 'stat', '180', '338',
595 '--ignore_site_file'],
596 rpcs
=[('get_jobs_summary', {'id__in': ['180', '338']},
598 ('get_host_queue_entries',
599 {'job__in': ['180', '338']},
601 [{u
'status': u
'Failed',
603 u
'host': {u
'status': u
'Repair Failed',
605 u
'hostname': u
'host0',
611 u
'job': {u
'control_file': u
"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
612 u
'name': u
'test_sleep',
613 u
'control_type': u
'Server',
614 u
'priority': u
'Medium',
616 u
'created_on': u
'2008-03-18 11:27:29',
621 {u
'status': u
'Failed',
623 u
'host': {u
'status': u
'Repair Failed',
625 u
'hostname': u
'host10',
631 u
'job': {u
'control_file': u
"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
632 u
'name': u
'test_sleep',
633 u
'control_type': u
'Server',
634 u
'priority': u
'Medium',
636 u
'created_on': u
'2008-03-18 11:27:29',
641 out_words_ok
=['test_job0', 'test_job1'])
644 def test_job_stat_multi_jobs_name_id(self
):
645 self
.run_cmd(argv
=['atest', 'job', 'stat', 'mytest', '180',
646 '--ignore_site_file'],
647 rpcs
=[('get_jobs_summary', {'id__in': ['180']},
649 [{u
'status_counts': {u
'Aborted': 1},
651 u
"job.run_test('sleeptest')\n",
653 u
'control_type': u
'Server',
658 u
'2008-07-08 17:45:44',
661 ('get_jobs_summary', {'name__in': ['mytest']},
663 [{u
'status_counts': {u
'Queued': 1},
665 u
"job.run_test('sleeptest')\n",
667 u
'control_type': u
'Client',
671 u
'created_on': u
'2008-07-08 12:17:47',
674 ('get_host_queue_entries',
675 {'job__in': ['180']},
677 [{u
'status': u
'Failed',
679 u
'host': {u
'status': u
'Repair Failed',
681 u
'hostname': u
'host0',
687 u
'job': {u
'control_file': u
"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
688 u
'name': u
'test_sleep',
689 u
'control_type': u
'Server',
691 u
'priority': u
'Medium',
693 u
'created_on': u
'2008-03-18 11:27:29',
698 ('get_host_queue_entries',
699 {'job__name__in': ['mytest']},
701 [{u
'status': u
'Failed',
703 u
'host': {u
'status': u
'Repair Failed',
705 u
'hostname': u
'host10',
711 u
'job': {u
'control_file': u
"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",
712 u
'name': u
'test_sleep',
713 u
'control_type': u
'Server',
715 u
'priority': u
'Medium',
717 u
'created_on': u
'2008-03-18 11:27:29',
722 out_words_ok
=['job0', 'mytest', 'Aborted', 'Queued',
723 'Failed', 'Medium', 'High'])
726 class job_create_unittest(cli_mock
.cli_unittest
):
727 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)'
729 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)'
731 trivial_ctrl_file
= 'print "Hello"\n'
733 data
= {'priority': 'Medium', 'control_file': ctrl_file
, 'hosts': ['host0'],
734 'name': 'test_job0', 'control_type': 'Client', 'email_list': '',
735 'meta_hosts': [], 'synch_count': 1, 'dependencies': []}
738 def test_execute_create_job(self
):
739 self
.run_cmd(argv
=['atest', 'job', 'create', '-t', 'sleeptest',
740 'test_job0', '-m', 'host0', '--ignore_site_file'],
741 rpcs
=[('generate_control_file',
742 {'tests': ['sleeptest']},
744 {'control_file' : self
.ctrl_file
,
747 'dependencies' : []}),
748 ('create_job', self
.data
, True, 180)],
749 out_words_ok
=['test_job0', 'Created'],
750 out_words_no
=['Uploading', 'Done'])
753 def test_execute_create_job_with_atomic_group(self
):
754 data
= dict(self
.data
)
755 data
['atomic_group_name'] = 'my-atomic-group'
756 data
['control_type'] = 'Server'
757 mock_ctrl_file
= 'mock control file'
758 data
['control_file'] = mock_ctrl_file
759 data
['synch_count'] = 2
761 self
.run_cmd(argv
=['atest', 'job', 'create', '-t', 'mocktest',
762 'test_job0', '--ignore_site_file',
763 '-G', 'my-atomic-group'],
764 rpcs
=[('generate_control_file',
765 {'tests': ['mocktest']},
767 {'control_file' : mock_ctrl_file
,
770 'dependencies' : []}),
771 ('create_job', data
, True, 180)],
772 out_words_ok
=['test_job0', 'Created'],
773 out_words_no
=['Uploading', 'Done'])
776 def test_execute_create_job_with_control(self
):
777 file_temp
= cli_mock
.create_file(self
.ctrl_file
)
778 self
.run_cmd(argv
=['atest', 'job', 'create', '-f', file_temp
.name
,
779 'test_job0', '-m', 'host0', '--ignore_site_file'],
780 rpcs
=[('create_job', self
.data
, True, 42)],
781 out_words_ok
=['test_job0', 'Created'],
782 out_words_no
=['Uploading', 'Done'])
786 def test_execute_create_job_with_control_and_kernel(self
):
787 data
= self
.data
.copy()
788 data
['control_file'] = '# Made up control "file" for unittest.'
789 file_temp
= cli_mock
.create_file(self
.trivial_ctrl_file
)
790 self
.run_cmd(argv
=['atest', 'job', 'create', '-f', file_temp
.name
,
791 '-k', 'Kernel', 'test_job0', '-m', 'host0',
792 '--ignore_site_file'],
793 rpcs
=[('generate_control_file',
794 {'client_control_file': self
.trivial_ctrl_file
,
795 'kernel': [{'version': 'Kernel'}]},
797 {'control_file': data
['control_file'],
800 'dependencies': []}),
801 ('create_job', data
, True, 42)],
802 out_words_ok
=['test_job0', 'Created',
803 'Uploading', 'Done'])
807 def test_execute_create_job_with_control_and_email(self
):
808 data
= self
.data
.copy()
809 data
['email_list'] = 'em'
810 file_temp
= cli_mock
.create_file(self
.ctrl_file
)
811 self
.run_cmd(argv
=['atest', 'job', 'create', '-f', file_temp
.name
,
812 'test_job0', '-m', 'host0', '-e', 'em',
813 '--ignore_site_file'],
814 rpcs
=[('create_job', data
, True, 42)],
815 out_words_ok
=['test_job0', 'Created'],
816 out_words_no
=['Uploading', 'Done'])
820 def test_execute_create_job_with_control_and_dependencies(self
):
821 data
= self
.data
.copy()
822 data
['dependencies'] = ['dep1', 'dep2']
823 file_temp
= cli_mock
.create_file(self
.ctrl_file
)
824 self
.run_cmd(argv
=['atest', 'job', 'create', '-f', file_temp
.name
,
825 'test_job0', '-m', 'host0', '-d', 'dep1, dep2 ',
826 '--ignore_site_file'],
827 rpcs
=[('create_job', data
, True, 42)],
828 out_words_ok
=['test_job0', 'Created'],
829 out_words_no
=['Uploading', 'Done'])
833 def test_execute_create_job_with_control_and_comma_dependencies(self
):
834 data
= self
.data
.copy()
835 data
['dependencies'] = ['dep2,False', 'dep1,True']
836 file_temp
= cli_mock
.create_file(self
.ctrl_file
)
837 self
.run_cmd(argv
=['atest', 'job', 'create', '-f', file_temp
.name
,
838 'test_job0', '-m', 'host0', '-d',
839 'dep1\,True, dep2\,False ', '--ignore_site_file'],
840 rpcs
=[('create_job', data
, True, 42)],
841 out_words_ok
=['test_job0', 'Created'],
842 out_words_no
=['Uploading', 'Done'])
846 def test_execute_create_job_with_synch_count(self
):
847 data
= self
.data
.copy()
848 data
['synch_count'] = 2
849 file_temp
= cli_mock
.create_file(self
.ctrl_file
)
850 self
.run_cmd(argv
=['atest', 'job', 'create', '-f', file_temp
.name
,
851 'test_job0', '-m', 'host0', '-y', '2',
852 '--ignore_site_file'],
853 rpcs
=[('create_job', data
, True, 42)],
854 out_words_ok
=['test_job0', 'Created'],
855 out_words_no
=['Uploading', 'Done'])
859 def test_execute_create_job_with_test_and_dependencies(self
):
860 data
= self
.data
.copy()
861 data
['dependencies'] = ['dep1', 'dep2', 'dep3']
862 self
.run_cmd(argv
=['atest', 'job', 'create', '-t', 'sleeptest',
863 'test_job0', '-m', 'host0', '-d', 'dep1, dep2 ',
864 '--ignore_site_file'],
865 rpcs
=[('generate_control_file',
866 {'tests': ['sleeptest']},
868 {'control_file' : self
.ctrl_file
,
871 'dependencies' : ['dep3']}),
872 ('create_job', data
, True, 42)],
873 out_words_ok
=['test_job0', 'Created'],
874 out_words_no
=['Uploading', 'Done'])
877 def test_execute_create_job_with_test_and_comma_dependencies(self
):
878 data
= self
.data
.copy()
879 data
['dependencies'] = ['dep1,True', 'dep2,False', 'dep3,123']
880 self
.run_cmd(argv
=['atest', 'job', 'create', '-t', 'sleeptest',
881 'test_job0', '-m', 'host0', '-d',
882 'dep1\,True dep2\,False ', '--ignore_site_file'],
883 rpcs
=[('generate_control_file',
884 {'tests': ['sleeptest']},
886 {'control_file' : self
.ctrl_file
,
889 'dependencies' : ['dep3,123']}),
890 ('create_job', data
, True, 42)],
891 out_words_ok
=['test_job0', 'Created'],
892 out_words_no
=['Uploading', 'Done'])
895 def test_execute_create_job_with_kernel(self
):
896 data
= self
.data
.copy()
897 data
['control_file'] = self
.kernel_ctrl_file
898 self
.run_cmd(argv
=['atest', 'job', 'create', '-t', 'sleeptest',
899 '-k', 'kernel', 'test_job0', '-m', 'host0',
900 '--ignore_site_file'],
901 rpcs
=[('generate_control_file',
902 {'tests': ['sleeptest'],
903 'kernel': [{'version': 'kernel'}]
906 {'control_file' : self
.kernel_ctrl_file
,
909 'dependencies' : []}),
910 ('create_job', data
, True, 180)],
911 out_words_ok
=['test_job0', 'Created',
912 'Uploading', 'Done'])
915 def test_execute_create_job_with_kernels_and_cmdline(self
):
916 data
= self
.data
.copy()
917 data
['control_file'] = self
.kernel_ctrl_file
918 self
.run_cmd(argv
=['atest', 'job', 'create', '-t', 'sleeptest',
919 '-k', 'kernel1,kernel2', '--kernel-cmdline',
920 'arg1 arg2', 'test_job0', '-m', 'host0',
921 '--ignore_site_file'],
922 rpcs
=[('generate_control_file',
923 {'tests': ['sleeptest'],
924 'kernel': [{'version': 'kernel1',
925 'cmdline': 'arg1 arg2'},
926 {'version': 'kernel2',
927 'cmdline': 'arg1 arg2'}]
930 {'control_file' : self
.kernel_ctrl_file
,
933 'dependencies' : []}),
934 ('create_job', data
, True, 180)],
935 out_words_ok
=['test_job0', 'Created',
936 'Uploading', 'Done'])
939 def test_execute_create_job_with_kernel_spaces(self
):
940 data
= self
.data
.copy()
941 data
['control_file'] = self
.kernel_ctrl_file
942 data
['name'] = 'test job with spaces'
943 self
.run_cmd(argv
=['atest', 'job', 'create', '-t', 'sleeptest',
944 '-k', 'kernel', 'test job with spaces',
945 '-m', 'host0', '--ignore_site_file'],
946 rpcs
=[('generate_control_file',
947 {'tests': ['sleeptest'],
948 'kernel': [{'version': 'kernel'}]
951 {'control_file' : self
.kernel_ctrl_file
,
954 'dependencies' : []}),
955 ('create_job', data
, True, 180)],
956 # This is actually 7 spaces, the extra single quote that
957 # gets displayed before "test" causes the tab completion
958 # to move to the next 8 char boundary which is 7 characters
959 # away. Hence the 7 spaces in out_words_ok.
960 # The tab has been converted by print.
961 out_words_ok
=['test job with spaces', 'Created',
965 def test_execute_create_job_no_args(self
):
966 testjob
= job
.job_create()
967 sys
.argv
= ['atest', 'job', 'create', '--ignore_site_file']
969 (sys
.exit
.expect_call(mock
.anything_comparator())
970 .and_raises(cli_mock
.ExitException
))
971 self
.assertRaises(cli_mock
.ExitException
, testjob
.parse
)
973 self
.god
.check_playback()
976 def test_execute_create_job_no_hosts(self
):
977 testjob
= job
.job_create()
978 file_temp
= cli_mock
.create_file(self
.ctrl_file
)
979 sys
.argv
= ['atest', '-f', file_temp
.name
, 'test_job0',
980 '--ignore_site_file']
982 (sys
.exit
.expect_call(mock
.anything_comparator())
983 .and_raises(cli_mock
.ExitException
))
984 self
.assertRaises(cli_mock
.ExitException
, testjob
.parse
)
986 self
.god
.check_playback()
990 def test_execute_create_job_cfile_and_tests(self
):
991 testjob
= job
.job_create()
992 sys
.argv
= ['atest', 'job', 'create', '-t', 'sleeptest', '-f',
993 'control_file', 'test_job0', '-m', 'host0',
994 '--ignore_site_file']
996 (sys
.exit
.expect_call(mock
.anything_comparator())
997 .and_raises(cli_mock
.ExitException
))
998 self
.assertRaises(cli_mock
.ExitException
, testjob
.parse
)
1000 self
.god
.check_playback()
1003 def test_execute_create_job_cfile_and_kernel(self
):
1004 testjob
= job
.job_create()
1005 sys
.argv
= ['atest', 'job', 'create', '-f', 'control_file', '-k',
1006 'kernel', 'test_job0', '-m', 'host0', '--ignore_site_file']
1008 (sys
.exit
.expect_call(mock
.anything_comparator())
1009 .and_raises(cli_mock
.ExitException
))
1010 self
.assertRaises(cli_mock
.ExitException
, testjob
.parse
)
1011 self
.god
.unmock_io()
1012 self
.god
.check_playback()
1015 def test_execute_create_job_bad_cfile(self
):
1016 testjob
= job
.job_create()
1017 sys
.argv
= ['atest', 'job', 'create', '-f', 'control_file',
1018 'test_job0', '-m', 'host0', '--ignore_site_file']
1020 (sys
.exit
.expect_call(mock
.anything_comparator())
1021 .and_raises(IOError))
1022 self
.assertRaises(IOError, testjob
.parse
)
1023 self
.god
.unmock_io()
1026 def test_execute_create_job_bad_priority(self
):
1027 testjob
= job
.job_create()
1028 sys
.argv
= ['atest', 'job', 'create', '-t', 'sleeptest', '-p', 'Uber',
1029 '-m', 'host0', 'test_job0', '--ignore_site_file']
1031 (sys
.exit
.expect_call(mock
.anything_comparator())
1032 .and_raises(cli_mock
.ExitException
))
1033 self
.assertRaises(cli_mock
.ExitException
, testjob
.parse
)
1034 self
.god
.unmock_io()
1035 self
.god
.check_playback()
1038 def test_execute_create_job_with_mfile(self
):
1039 data
= self
.data
.copy()
1040 data
['hosts'] = ['host3', 'host2', 'host1', 'host0']
1041 ctemp
= cli_mock
.create_file(self
.ctrl_file
)
1042 file_temp
= cli_mock
.create_file('host0\nhost1\nhost2\nhost3')
1043 self
.run_cmd(argv
=['atest', 'job', 'create', '--mlist', file_temp
.name
,
1044 '-f', ctemp
.name
, 'test_job0', '--ignore_site_file'],
1045 rpcs
=[('create_job', data
, True, 42)],
1046 out_words_ok
=['test_job0', 'Created'])
1051 def test_execute_create_job_with_timeout(self
):
1052 data
= self
.data
.copy()
1053 data
['timeout'] = '222'
1054 file_temp
= cli_mock
.create_file(self
.ctrl_file
)
1055 self
.run_cmd(argv
=['atest', 'job', 'create', '-f', file_temp
.name
,
1056 'test_job0', '-m', 'host0', '-o', '222',
1057 '--ignore_site_file'],
1058 rpcs
=[('create_job', data
, True, 42)],
1059 out_words_ok
=['test_job0', 'Created'],)
1063 def test_execute_create_job_with_max_runtime(self
):
1064 data
= self
.data
.copy()
1065 data
['max_runtime_hrs'] = '222'
1066 file_temp
= cli_mock
.create_file(self
.ctrl_file
)
1067 self
.run_cmd(argv
=['atest', 'job', 'create', '-f', file_temp
.name
,
1068 'test_job0', '-m', 'host0', '--max_runtime', '222',
1069 '--ignore_site_file'],
1070 rpcs
=[('create_job', data
, True, 42)],
1071 out_words_ok
=['test_job0', 'Created'],)
1076 def test_execute_create_job_with_noverify(self
):
1077 data
= self
.data
.copy()
1078 data
['run_verify'] = False
1079 file_temp
= cli_mock
.create_file(self
.ctrl_file
)
1080 self
.run_cmd(argv
=['atest', 'job', 'create', '-f', file_temp
.name
,
1081 'test_job0', '-m', 'host0', '-n',
1082 '--ignore_site_file'],
1083 rpcs
=[('create_job', data
, True, 42)],
1084 out_words_ok
=['test_job0', 'Created'],)
1088 def test_execute_create_job_oth(self
):
1089 data
= self
.data
.copy()
1091 data
['one_time_hosts'] = ['host0']
1092 self
.run_cmd(argv
=['atest', 'job', 'create', '-t', 'sleeptest',
1093 'test_job0', '--one-time-hosts', 'host0'],
1094 rpcs
=[('generate_control_file',
1095 {'tests': ['sleeptest']},
1097 {'control_file' : self
.ctrl_file
,
1099 'is_server' : False,
1100 'dependencies' : []}),
1101 ('create_job', data
, True, 180)],
1102 out_words_ok
=['test_job0', 'Created'],
1103 out_words_no
=['Uploading', 'Done'])
1106 def test_execute_create_job_multi_oth(self
):
1107 data
= self
.data
.copy()
1109 data
['one_time_hosts'] = ['host1', 'host0']
1110 self
.run_cmd(argv
=['atest', 'job', 'create', '-t', 'sleeptest',
1111 'test_job0', '--one-time-hosts', 'host0,host1'],
1112 rpcs
=[('generate_control_file',
1113 {'tests': ['sleeptest']},
1115 {'control_file' : self
.ctrl_file
,
1117 'is_server' : False,
1118 'dependencies' : []}),
1119 ('create_job', data
, True, 180)],
1120 out_words_ok
=['test_job0', 'Created'],
1121 out_words_no
=['Uploading', 'Done'])
1124 def test_execute_create_job_oth_exists(self
):
1125 data
= self
.data
.copy()
1127 data
['one_time_hosts'] = ['host0']
1128 self
.run_cmd(argv
=['atest', 'job', 'create', '-t', 'sleeptest',
1129 'test_job0', '--one-time-hosts', 'host0'],
1130 rpcs
=[('generate_control_file',
1131 {'tests': ['sleeptest']},
1133 {'control_file' : self
.ctrl_file
,
1135 'is_server' : False,
1136 'dependencies' : []}),
1137 ('create_job', data
, False,
1138 '''ValidationError: {'hostname': 'host0 '''
1139 '''already exists in the autotest DB. '''
1140 '''Select it rather than entering it as '''
1141 '''a one time host.'}''')],
1142 out_words_no
=['test_job0', 'Created'],
1143 err_words_ok
=['failed', 'already exists'])
1146 def test_execute_create_job_with_control_and_labels(self
):
1147 data
= self
.data
.copy()
1148 data
['hosts'] = ['host0', 'host1', 'host2']
1149 file_temp
= cli_mock
.create_file(self
.ctrl_file
)
1150 self
.run_cmd(argv
=['atest', 'job', 'create', '-f', file_temp
.name
,
1151 'test_job0', '-m', 'host0', '-b', 'label1,label2',
1152 '--ignore_site_file'],
1153 rpcs
=[('get_hosts', {'multiple_labels': ['label1',
1155 [{u
'status': u
'Running', u
'lock_time': None,
1156 u
'hostname': u
'host1', u
'locked': False,
1157 u
'locked_by': None, u
'invalid': False, u
'id': 42,
1158 u
'labels': [u
'label1'], u
'platform':
1159 u
'Warp18_Diskfull', u
'protection':
1160 u
'Repair software only', u
'dirty':
1161 True, u
'synch_id': None},
1162 {u
'status': u
'Running', u
'lock_time': None,
1163 u
'hostname': u
'host2', u
'locked': False,
1164 u
'locked_by': None, u
'invalid': False, u
'id': 43,
1165 u
'labels': [u
'label2'], u
'platform':
1166 u
'Warp18_Diskfull', u
'protection':
1167 u
'Repair software only', u
'dirty': True,
1168 u
'synch_id': None}]),
1169 ('create_job', data
, True, 42)],
1170 out_words_ok
=['test_job0', 'Created'],
1171 out_words_no
=['Uploading', 'Done'])
1175 def test_execute_create_job_with_label_and_duplicate_hosts(self
):
1176 data
= self
.data
.copy()
1177 data
['hosts'] = ['host1', 'host0']
1178 file_temp
= cli_mock
.create_file(self
.ctrl_file
)
1179 self
.run_cmd(argv
=['atest', 'job', 'create', '-f', file_temp
.name
,
1180 'test_job0', '-m', 'host0,host1', '-b', 'label1',
1181 '--ignore_site_file'],
1182 rpcs
=[('get_hosts', {'multiple_labels': ['label1']}, True,
1183 [{u
'status': u
'Running', u
'lock_time': None,
1184 u
'hostname': u
'host1', u
'locked': False,
1185 u
'locked_by': None, u
'invalid': False, u
'id': 42,
1186 u
'labels': [u
'label1'], u
'platform':
1187 u
'Warp18_Diskfull', u
'protection':
1188 u
'Repair software only', u
'dirty':
1189 True, u
'synch_id': None}]),
1190 ('create_job', data
, True, 42)],
1191 out_words_ok
=['test_job0', 'Created'],
1192 out_words_no
=['Uploading', 'Done'])
1196 def test_execute_create_job_with_label_commas_and_duplicate_hosts(self
):
1197 data
= self
.data
.copy()
1198 data
['hosts'] = ['host1', 'host0']
1199 file_temp
= cli_mock
.create_file(self
.ctrl_file
)
1200 self
.run_cmd(argv
=['atest', 'job', 'create', '-f', file_temp
.name
,
1201 'test_job0', '-m', 'host0,host1', '-b',
1202 'label1,label\\,2', '--ignore_site_file'],
1203 rpcs
=[('get_hosts', {'multiple_labels': ['label1',
1205 [{u
'status': u
'Running', u
'lock_time': None,
1206 u
'hostname': u
'host1', u
'locked': False,
1207 u
'locked_by': None, u
'invalid': False, u
'id': 42,
1208 u
'labels': [u
'label1', u
'label,2'], u
'platform':
1209 u
'Warp18_Diskfull', u
'protection':
1210 u
'Repair software only', u
'dirty':
1211 True, u
'synch_id': None}]),
1212 ('create_job', data
, True, 42)],
1213 out_words_ok
=['test_job0', 'Created'],
1214 out_words_no
=['Uploading', 'Done'])
1218 def test_execute_create_job_with_label_escaping_and_duplicate_hosts(self
):
1219 data
= self
.data
.copy()
1220 data
['hosts'] = ['host1', 'host0']
1221 file_temp
= cli_mock
.create_file(self
.ctrl_file
)
1222 self
.run_cmd(argv
=['atest', 'job', 'create', '-f', file_temp
.name
,
1223 'test_job0', '-m', 'host0,host1', '-b',
1224 'label1,label\\,2\\\\,label3', '--ignore_site_file'],
1225 rpcs
=[('get_hosts', {'multiple_labels': ['label,2\\',
1226 'label1', 'label3']}, True,
1227 [{u
'status': u
'Running', u
'lock_time': None,
1228 u
'hostname': u
'host1', u
'locked': False,
1229 u
'locked_by': None, u
'invalid': False, u
'id': 42,
1230 u
'labels': [u
'label1', u
'label,2\\', u
'label3'],
1231 u
'platform': u
'Warp18_Diskfull', u
'protection':
1232 u
'Repair software only', u
'dirty':
1233 True, u
'synch_id': None}]),
1234 ('create_job', data
, True, 42)],
1235 out_words_ok
=['test_job0', 'Created'],
1236 out_words_no
=['Uploading', 'Done'])
1240 def _test_parse_hosts(self
, args
, exp_hosts
=[], exp_meta_hosts
=[]):
1241 testjob
= job
.job_create_or_clone()
1242 (hosts
, meta_hosts
) = testjob
._parse
_hosts
(args
)
1243 self
.assertEqualNoOrder(hosts
, exp_hosts
)
1244 self
.assertEqualNoOrder(meta_hosts
, exp_meta_hosts
)
1247 def test_parse_hosts_regular(self
):
1248 self
._test
_parse
_hosts
(['host0'], ['host0'])
1251 def test_parse_hosts_regulars(self
):
1252 self
._test
_parse
_hosts
(['host0', 'host1'], ['host0', 'host1'])
1255 def test_parse_hosts_meta_one(self
):
1256 self
._test
_parse
_hosts
(['*meta0'], [], ['meta0'])
1259 def test_parse_hosts_meta_five(self
):
1260 self
._test
_parse
_hosts
(['5*meta0'], [], ['meta0']*5)
1263 def test_parse_hosts_metas_five(self
):
1264 self
._test
_parse
_hosts
(['5*meta0', '2*meta1'], [],
1265 ['meta0']*5 + ['meta1']*2)
1268 def test_parse_hosts_mix(self
):
1269 self
._test
_parse
_hosts
(['5*meta0', 'host0', '2*meta1', 'host1',
1270 '*meta2'], ['host0', 'host1'],
1271 ['meta0']*5 + ['meta1']*2 + ['meta2'])
1274 class job_clone_unittest(cli_mock
.cli_unittest
):
1275 job_data
= {'control_file': u
'NAME = \'Server Sleeptest\'\nAUTHOR = \'mbligh@google.com (Martin Bligh)\'\nTIME = \'SHORT\'\nTEST_CLASS = \'Software\'\nTEST_CATEGORY = \'Functional\'\nTEST_TYPE = \'server\'\nEXPERIMENTAL = \'False\'\n\nDOC = """\nruns sleep for one second on the list of machines.\n"""\n\ndef run(machine):\n host = hosts.create_host(machine)\n job.run_test(\'sleeptest\')\n\njob.parallel_simple(run, machines)\n',
1276 'control_type': u
'Server',
1279 'max_runtime_hrs': 480,
1280 'parse_failed_repair': True,
1281 'priority': u
'Medium',
1282 'reboot_after': u
'Always',
1283 'reboot_before': u
'If dirty',
1288 local_hosts
= [{u
'acls': [u
'acl0'],
1289 u
'atomic_group': None,
1292 u
'hostname': u
'host0',
1295 u
'labels': [u
'label0', u
'label1'],
1299 u
'other_labels': u
'label0, label1',
1300 u
'platform': u
'plat0',
1301 u
'protection': u
'Repair software only',
1302 u
'status': u
'Ready',
1304 {u
'acls': [u
'acl0'],
1305 u
'atomic_group': None,
1308 u
'hostname': u
'host1',
1311 u
'labels': [u
'label0', u
'label1'],
1315 u
'other_labels': u
'label0, label1',
1316 u
'platform': u
'plat0',
1317 u
'protection': u
'Repair software only',
1318 u
'status': u
'Ready',
1323 super(job_clone_unittest
, self
).setUp()
1324 self
.job_data_clone_info
= copy
.deepcopy(self
.job_data
)
1325 self
.job_data_clone_info
['created_on'] = '2009-07-23 16:21:29'
1326 self
.job_data_clone_info
['name'] = 'testing_clone'
1327 self
.job_data_clone_info
['id'] = 42
1328 self
.job_data_clone_info
['owner'] = 'user0'
1330 self
.job_data_cloned
= copy
.deepcopy(self
.job_data
)
1331 self
.job_data_cloned
['name'] = 'cloned'
1332 self
.job_data_cloned
['hosts'] = [u
'host0']
1333 self
.job_data_cloned
['meta_hosts'] = []
1336 def test_backward_compat(self
):
1337 self
.run_cmd(argv
=['atest', 'job', 'create', '--clone', '42',
1339 rpcs
=[('get_info_for_clone', {'id': '42',
1340 'preserve_metahosts': True},
1342 {u
'atomic_group_name': None,
1343 u
'hosts': [{u
'acls': [u
'acl0'],
1344 u
'atomic_group': None,
1347 u
'hostname': u
'host0',
1350 u
'labels': [u
'label0', u
'label1'],
1354 u
'other_labels': u
'label0, label1',
1355 u
'platform': u
'plat0',
1356 u
'protection': u
'Repair software only',
1357 u
'status': u
'Ready',
1358 u
'synch_id': None}],
1359 u
'job': self
.job_data_clone_info
,
1360 u
'meta_host_counts': {}}),
1361 ('create_job', self
.job_data_cloned
, True, 43)],
1362 out_words_ok
=['Created job', '43'])
1365 def test_clone_reuse_hosts(self
):
1366 self
.job_data_cloned
['hosts'] = [u
'host0', 'host1']
1367 self
.run_cmd(argv
=['atest', 'job', 'clone', '--id', '42',
1369 rpcs
=[('get_info_for_clone', {'id': '42',
1370 'preserve_metahosts': True},
1372 {u
'atomic_group_name': None,
1373 u
'hosts': self
.local_hosts
,
1374 u
'job': self
.job_data_clone_info
,
1375 u
'meta_host_counts': {}}),
1376 ('create_job', self
.job_data_cloned
, True, 43)],
1377 out_words_ok
=['Created job', '43'])
1380 def test_clone_reuse_metahosts(self
):
1381 self
.job_data_cloned
['hosts'] = []
1382 self
.job_data_cloned
['meta_hosts'] = ['type1']*4 + ['type0']
1383 self
.run_cmd(argv
=['atest', 'job', 'clone', '--id', '42',
1385 rpcs
=[('get_info_for_clone', {'id': '42',
1386 'preserve_metahosts': True},
1388 {u
'atomic_group_name': None,
1390 u
'job': self
.job_data_clone_info
,
1391 u
'meta_host_counts': {u
'type0': 1,
1393 ('create_job', self
.job_data_cloned
, True, 43)],
1394 out_words_ok
=['Created job', '43'])
1397 def test_clone_reuse_both(self
):
1398 self
.job_data_cloned
['hosts'] = [u
'host0', 'host1']
1399 self
.job_data_cloned
['meta_hosts'] = ['type1']*4 + ['type0']
1400 self
.run_cmd(argv
=['atest', 'job', 'clone', '--id', '42',
1402 rpcs
=[('get_info_for_clone', {'id': '42',
1403 'preserve_metahosts': True},
1405 {u
'atomic_group_name': None,
1406 u
'hosts': self
.local_hosts
,
1407 u
'job': self
.job_data_clone_info
,
1408 u
'meta_host_counts': {u
'type0': 1,
1410 ('create_job', self
.job_data_cloned
, True, 43)],
1411 out_words_ok
=['Created job', '43'])
1414 def test_clone_no_hosts(self
):
1415 self
.run_cmd(argv
=['atest', 'job', 'clone', '--id', '42', 'cloned'],
1417 out_words_ok
=['usage'],
1418 err_words_ok
=['machine'])
1421 def test_clone_reuse_and_hosts(self
):
1422 self
.run_cmd(argv
=['atest', 'job', 'clone', '--id', '42',
1423 '-r', '-m', 'host5', 'cloned'],
1425 out_words_ok
=['usage'],
1426 err_words_ok
=['specify'])
1429 def test_clone_new_multiple_hosts(self
):
1430 self
.job_data_cloned
['hosts'] = [u
'host5', 'host4', 'host3']
1431 self
.run_cmd(argv
=['atest', 'job', 'clone', '--id', '42',
1432 '-m', 'host5,host4,host3', 'cloned'],
1433 rpcs
=[('get_info_for_clone', {'id': '42',
1434 'preserve_metahosts': False},
1436 {u
'atomic_group_name': None,
1437 u
'hosts': self
.local_hosts
,
1438 u
'job': self
.job_data_clone_info
,
1439 u
'meta_host_counts': {}}),
1440 ('create_job', self
.job_data_cloned
, True, 43)],
1441 out_words_ok
=['Created job', '43'])
1444 def test_clone_oth(self
):
1445 self
.job_data_cloned
['hosts'] = []
1446 self
.job_data_cloned
['one_time_hosts'] = [u
'host5']
1447 self
.run_cmd(argv
=['atest', 'job', 'clone', '--id', '42',
1448 '--one-time-hosts', 'host5', 'cloned'],
1449 rpcs
=[('get_info_for_clone', {'id': '42',
1450 'preserve_metahosts': False},
1452 {u
'atomic_group_name': None,
1453 u
'hosts': self
.local_hosts
,
1454 u
'job': self
.job_data_clone_info
,
1455 u
'meta_host_counts': {}}),
1456 ('create_job', self
.job_data_cloned
, True, 43)],
1457 out_words_ok
=['Created job', '43'])
1460 class job_abort_unittest(cli_mock
.cli_unittest
):
1461 results
= [{u
'status_counts': {u
'Aborted': 1}, u
'control_file':
1462 u
"job.run_test('sleeptest')\n", u
'name': u
'test_job0',
1463 u
'control_type': u
'Server', u
'priority':
1464 u
'Medium', u
'owner': u
'user0', u
'created_on':
1465 u
'2008-07-08 17:45:44', u
'synch_count': 2, u
'id': 180}]
1467 def test_execute_job_abort(self
):
1468 self
.run_cmd(argv
=['atest', 'job', 'abort', '180',
1469 '--ignore_site_file'],
1470 rpcs
=[('abort_host_queue_entries',
1471 {'job__id__in': ['180']}, True, None)],
1472 out_words_ok
=['Aborting', '180'])
1475 if __name__
== '__main__':