1#!/usr/bin/python -u
2#
3# Copyright 2008 Google Inc. All Rights Reserved.
4
5
6"""Tests for job."""
7
8import copy, getpass, unittest, sys, os
9
10import common
11from autotest_lib.cli import cli_mock, topic_common, job
12from autotest_lib.client.common_lib.test_utils import mock
13from autotest_lib.client.common_lib import control_data
14
15CLIENT = control_data.CONTROL_TYPE_NAMES.CLIENT
16SERVER = control_data.CONTROL_TYPE_NAMES.SERVER
17
18class job_unittest(cli_mock.cli_unittest):
19    def setUp(self):
20        super(job_unittest, self).setUp()
21        self.values = copy.deepcopy(self.values_template)
22
23    results = [{u'status_counts': {u'Aborted': 1},
24                u'control_file':
25                u"job.run_test('sleeptest')\n",
26                u'name': u'test_job0',
27                u'control_type': SERVER,
28                u'priority':
29                u'Medium',
30                u'owner': u'user0',
31                u'created_on':
32                u'2008-07-08 17:45:44',
33                u'synch_count': 2,
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': CLIENT,
40                u'priority':
41                u'High',
42                u'owner': u'user0',
43                u'created_on':
44                u'2008-07-08 12:17:47',
45                u'synch_count': 1,
46                u'id': 338}]
47
48
49    values_template = [{u'id': 180,          # Valid job
50                        u'priority': u'Low',
51                        u'name': u'test_job0',
52                        u'owner': u'Cringer',
53                        u'invalid': False,
54                        u'created_on': u'2008-07-02 13:02:40',
55                        u'control_type': SERVER,
56                        u'status_counts': {u'Queued': 1},
57                        u'synch_count': 2},
58                       {u'id': 338,          # Valid job
59                        u'priority': 'High',
60                        u'name': u'test_job1',
61                        u'owner': u'Fisto',
62                        u'invalid': False,
63                        u'created_on': u'2008-07-06 14:05:33',
64                        u'control_type': CLIENT,
65                        u'status_counts': {u'Queued': 1},
66                        u'synch_count': 1},
67                       {u'id': 339,          # Valid job
68                        u'priority': 'Medium',
69                        u'name': u'test_job2',
70                        u'owner': u'Roboto',
71                        u'invalid': False,
72                        u'created_on': u'2008-07-07 15:33:18',
73                        u'control_type': SERVER,
74                        u'status_counts': {u'Queued': 1},
75                        u'synch_count': 1},
76                       {u'id': 340,          # Invalid job priority
77                        u'priority': u'Uber',
78                        u'name': u'test_job3',
79                        u'owner': u'Panthor',
80                        u'invalid': True,
81                        u'created_on': u'2008-07-04 00:00:01',
82                        u'control_type': SERVER,
83                        u'status_counts': {u'Queued': 1},
84                        u'synch_count': 2},
85                       {u'id': 350,          # Invalid job created_on
86                        u'priority': 'Medium',
87                        u'name': u'test_job4',
88                        u'owner': u'Icer',
89                        u'invalid': True,
90                        u'created_on': u'Today',
91                        u'control_type': CLIENT,
92                        u'status_counts': {u'Queued': 1},
93                        u'synch_count': 1},
94                       {u'id': 420,          # Invalid job control_type
95                        u'priority': 'Urgent',
96                        u'name': u'test_job5',
97                        u'owner': u'Spikor',
98                        u'invalid': True,
99                        u'created_on': u'2012-08-08 18:54:37',
100                        u'control_type': u'Child',
101                        u'status_counts': {u'Queued': 1},
102                        u'synch_count': 2}]
103
104
105class job_list_unittest(job_unittest):
106    def test_job_list_jobs(self):
107        self.god.stub_function(getpass, 'getuser')
108        getpass.getuser.expect_call().and_return('user0')
109        self.run_cmd(argv=['atest', 'job', 'list', '--ignore_site_file'],
110                     rpcs=[('get_jobs_summary', {'owner': 'user0',
111                                                 'running': None},
112                            True, self.values)],
113                     out_words_ok=['test_job0', 'test_job1', 'test_job2'],
114                     out_words_no=['Uber', 'Today', 'Child'])
115
116
117    def test_job_list_jobs_only_user(self):
118        values = [item for item in self.values if item['owner'] == 'Cringer']
119        self.run_cmd(argv=['atest', 'job', 'list', '-u', 'Cringer',
120                           '--ignore_site_file'],
121                     rpcs=[('get_jobs_summary', {'owner': 'Cringer',
122                                                 'running': None},
123                            True, values)],
124                     out_words_ok=['Cringer'],
125                     out_words_no=['Fisto', 'Roboto', 'Panthor', 'Icer',
126                                   'Spikor'])
127
128
129    def test_job_list_jobs_all(self):
130        self.run_cmd(argv=['atest', 'job', 'list', '--all',
131                           '--ignore_site_file'],
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                           '--ignore_site_file'],
142                     rpcs=[('get_jobs_summary', {'id__in': ['5964'],
143                                                 'running': None},
144                            True,
145                            [{u'status_counts': {u'Completed': 1},
146                              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)',
147                              u'name': u'mytest',
148                              u'control_type': CLIENT,
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': 1,
155                              u'id': 5964}])],
156                     out_words_ok=['user0', 'Completed', '1', '5964'],
157                     out_words_no=['sleeptest', 'Priority', CLIENT, '2008'])
158
159
160    def test_job_list_jobs_id_verbose(self):
161        self.run_cmd(argv=['atest', 'job', 'list', '5964', '-v',
162                           '--ignore_site_file'],
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': CLIENT,
170                              u'run_verify': 1,
171                              u'priority': u'Medium',
172                              u'owner': u'user0',
173                              u'created_on': u'2008-07-28 12:42:52',
174                              u'timeout': 144,
175                              u'synch_count': 1,
176                              u'id': 5964}])],
177                     out_words_ok=['user0', 'Completed', '1', '5964',
178                                   CLIENT, '2008', 'Priority'],
179                     out_words_no=['sleeptest'])
180
181
182    def test_job_list_jobs_name(self):
183        self.run_cmd(argv=['atest', 'job', 'list', 'myt*',
184                           '--ignore_site_file'],
185                     rpcs=[('get_jobs_summary', {'name__startswith': 'myt',
186                                                 'running': None},
187                            True,
188                            [{u'status_counts': {u'Completed': 1},
189                              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)',
190                              u'name': u'mytest',
191                              u'control_type': CLIENT,
192                              u'run_verify': 1,
193                              u'priority': u'Medium',
194                              u'owner': u'user0',
195                              u'created_on': u'2008-07-28 12:42:52',
196                              u'timeout': 144,
197                              u'synch_count': 1,
198                              u'id': 5964}])],
199                     out_words_ok=['user0', 'Completed', '1', '5964'],
200                     out_words_no=['sleeptest', 'Priority', CLIENT, '2008'])
201
202
203    def test_job_list_jobs_all_verbose(self):
204        self.run_cmd(argv=['atest', 'job', 'list', '--all', '--verbose',
205                           '--ignore_site_file'],
206                     rpcs=[('get_jobs_summary', {'running': None},
207                            True, self.values)],
208                     out_words_ok=['Fisto', 'Spikor', 'Cringer', 'Priority',
209                                   'Created'])
210
211
212class job_list_jobs_all_and_user_unittest(cli_mock.cli_unittest):
213    def test_job_list_jobs_all_and_user(self):
214        testjob = job.job_list()
215        sys.argv = ['atest', 'job', 'list', '-a', '-u', 'user0',
216                    '--ignore_site_file']
217        self.god.mock_io()
218        (sys.exit.expect_call(mock.anything_comparator())
219         .and_raises(cli_mock.ExitException))
220        self.assertRaises(cli_mock.ExitException, testjob.parse)
221        self.god.unmock_io()
222        self.god.check_playback()
223
224
225class job_stat_unittest(job_unittest):
226    def test_job_stat_job(self):
227        results = copy.deepcopy(self.results)
228        self.run_cmd(argv=['atest', 'job', 'stat', '180',
229                           '--ignore_site_file'],
230                     rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,
231                            [results[0]]),
232                           ('get_host_queue_entries', {'job__in': ['180']},
233                            True,
234                            [{u'status': u'Failed',
235                              u'complete': 1,
236                              u'host': {u'status': u'Repair Failed',
237                                        u'locked': False,
238                                        u'hostname': u'host0',
239                                        u'invalid': True,
240                                        u'id': 4432,
241                                        u'synch_id': None},
242                              u'priority': 1,
243                              u'meta_host': None,
244                              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)",
245                                       u'name': u'test_sleep',
246                                       u'control_type': SERVER,
247                                       u'synchronizing': 0,
248                                       u'priority': u'Medium',
249                                       u'owner': u'user0',
250                                       u'created_on': u'2008-03-18 11:27:29',
251                                       u'synch_count': 1,
252                                       u'id': 180},
253                              u'active': 0,
254                              u'id': 101084}])],
255                     out_words_ok=['test_job0', 'host0', 'Failed',
256                                   'Aborted'])
257
258
259
260    def test_job_stat_list_unassigned_host(self):
261        self.run_cmd(argv=['atest', 'job', 'stat', '6761',
262                           '--list-hosts', '--ignore_site_file'],
263                     rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
264                            [{u'status_counts': {u'Queued': 1},
265                              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\')',
266                              u'name': u'test_on_meta_hosts',
267                              u'control_type': CLIENT,
268                              u'run_verify': 1,
269                              u'priority': u'Medium',
270                              u'owner': u'user0',
271                              u'created_on': u'2008-07-30 22:15:43',
272                              u'timeout': 144,
273                              u'synch_count': 1,
274                              u'id': 6761}]),
275                           ('get_host_queue_entries', {'job__in': ['6761']},
276                            True,
277                            [{u'status': u'Queued',
278                              u'complete': 0,
279                              u'deleted': 0,
280                              u'host': None,
281                              u'priority': 1,
282                              u'meta_host': u'Xeon',
283                              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\')',
284                                       u'name': u'test_on_meta_hosts',
285                                       u'control_type': CLIENT,
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': 1,
292                                       u'id': 6761},
293                              u'active': 0,
294                              u'id': 193166} ])],
295                     err_words_ok=['unassigned', 'meta-hosts'],
296                     out_words_no=['Xeon'])
297
298
299    def test_job_stat_list_hosts(self):
300        self.run_cmd(argv=['atest', 'job', 'stat', '6761',
301                           '--list-hosts', '--ignore_site_file'],
302                     rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
303                            [{u'status_counts': {u'Queued': 1},
304                              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\')',
305                              u'name': u'test_on_meta_hosts',
306                              u'control_type': CLIENT,
307                              u'run_verify': 1,
308                              u'priority': u'Medium',
309                              u'owner': u'user0',
310                              u'created_on': u'2008-07-30 22:15:43',
311                              u'timeout': 144,
312                              u'synch_count': 1,
313                              u'id': 6761}]),
314                           ('get_host_queue_entries', {'job__in': ['6761']},
315                            True,
316                            [{u'status': u'Queued',
317                              u'complete': 0,
318                              u'deleted': 0,
319                              u'host': {u'status': u'Running',
320                                        u'lock_time': None,
321                                        u'hostname': u'host41',
322                                        u'locked': False,
323                                        u'locked_by': None,
324                                        u'invalid': False,
325                                        u'id': 4833,
326                                        u'protection': u'Repair filesystem only',
327                                        u'synch_id': None},
328                              u'priority': 1,
329                              u'meta_host': u'Xeon',
330                              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\')',
331                                       u'name': u'test_on_meta_hosts',
332                                       u'control_type': CLIENT,
333                                       u'run_verify': 1,
334                                       u'priority': u'Medium',
335                                       u'owner': u'user0',
336                                       u'created_on': u'2008-07-30 22:15:43',
337                                       u'timeout': 144,
338                                       u'synch_count': 1,
339                                       u'id': 6761},
340                              u'active': 0,
341                              u'id': 193166},
342                            {u'status': u'Running',
343                              u'complete': 0,
344                              u'deleted': 0,
345                              u'host': {u'status': u'Running',
346                                        u'lock_time': None,
347                                        u'hostname': u'host42',
348                                        u'locked': False,
349                                        u'locked_by': None,
350                                        u'invalid': False,
351                                        u'id': 4833,
352                                        u'protection': u'Repair filesystem only',
353                                        u'synch_id': None},
354                              u'priority': 1,
355                              u'meta_host': u'Xeon',
356                              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\')',
357                                       u'name': u'test_on_meta_hosts',
358                                       u'control_type': CLIENT,
359                                       u'run_verify': 1,
360                                       u'priority': u'Medium',
361                                       u'owner': u'user0',
362                                       u'created_on': u'2008-07-30 22:15:43',
363                                       u'timeout': 144,
364                                       u'synch_count': 1,
365                                       u'id': 6761},
366                              u'active': 0,
367                              u'id': 193166} ])],
368                     out_words_ok=['host41', 'host42'],
369                     out_words_no=['Xeon', 'Running', 'Queued'],
370                     err_words_no=['unassigned'])
371
372
373    def test_job_stat_list_hosts_status(self):
374        self.run_cmd(argv=['atest', 'job', 'stat', '6761',
375                           '--list-hosts-status', 'Running,Queued',
376                           '--ignore_site_file'],
377                     rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
378                            [{u'status_counts': {u'Queued': 1, u'Running': 1},
379                              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\')',
380                              u'name': u'test',
381                              u'control_type': CLIENT,
382                              u'run_verify': 1,
383                              u'priority': u'Medium',
384                              u'owner': u'user0',
385                              u'created_on': u'2008-07-30 22:15:43',
386                              u'timeout': 144,
387                              u'synch_count': 1,
388                              u'id': 6761}]),
389                           ('get_host_queue_entries', {'job__in': ['6761']},
390                            True,
391                            [{u'status': u'Queued',
392                              u'complete': 0,
393                              u'deleted': 0,
394                              u'host': {u'status': u'Queued',
395                                        u'lock_time': None,
396                                        u'hostname': u'host41',
397                                        u'locked': False,
398                                        u'locked_by': None,
399                                        u'invalid': False,
400                                        u'id': 4833,
401                                        u'protection': u'Repair filesystem only',
402                                        u'synch_id': None},
403                              u'priority': 1,
404                              u'meta_host': None,
405                              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\')',
406                                       u'name': u'test',
407                                       u'control_type': CLIENT,
408                                       u'run_verify': 1,
409                                       u'priority': u'Medium',
410                                       u'owner': u'user0',
411                                       u'created_on': u'2008-07-30 22:15:43',
412                                       u'timeout': 144,
413                                       u'synch_count': 1,
414                                       u'id': 6761},
415                              u'active': 0,
416                              u'id': 193166},
417                            {u'status': u'Running',
418                              u'complete': 0,
419                              u'deleted': 0,
420                              u'host': {u'status': u'Running',
421                                        u'lock_time': None,
422                                        u'hostname': u'host42',
423                                        u'locked': False,
424                                        u'locked_by': None,
425                                        u'invalid': False,
426                                        u'id': 4833,
427                                        u'protection': u'Repair filesystem only',
428                                        u'synch_id': None},
429                              u'priority': 1,
430                              u'meta_host': None,
431                              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\')',
432                                       u'name': u'test',
433                                       u'control_type': CLIENT,
434                                       u'run_verify': 1,
435                                       u'priority': u'Medium',
436                                       u'owner': u'user0',
437                                       u'created_on': u'2008-07-30 22:15:43',
438                                       u'timeout': 144,
439                                       u'synch_count': 1,
440                                       u'id': 6761},
441                              u'active': 0,
442                              u'id': 193166} ])],
443                     out_words_ok=['Queued', 'Running', 'host41', 'host42'],
444                     out_words_no=['Xeon'],
445                     err_words_no=['unassigned'])
446
447
448    def test_job_stat_job_multiple_hosts(self):
449        self.run_cmd(argv=['atest', 'job', 'stat', '6761',
450                           '--ignore_site_file'],
451                     rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
452                            [{u'status_counts': {u'Running': 1,
453                                                 u'Queued': 4},
454                              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\')',
455                              u'name': u'test_on_meta_hosts',
456                              u'control_type': CLIENT,
457                              u'run_verify': 1,
458                              u'priority': u'Medium',
459                              u'owner': u'user0',
460                              u'created_on': u'2008-07-30 22:15:43',
461                              u'timeout': 144,
462                              u'synch_count': 1,
463                              u'id': 6761}]),
464                           ('get_host_queue_entries', {'job__in': ['6761']},
465                            True,
466                            [{u'status': u'Queued',
467                              u'complete': 0,
468                              u'deleted': 0,
469                              u'host': None,
470                              u'priority': 1,
471                              u'meta_host': u'Xeon',
472                              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\')',
473                                       u'name': u'test_on_meta_hosts',
474                                       u'control_type': CLIENT,
475                                       u'run_verify': 1,
476                                       u'priority': u'Medium',
477                                       u'owner': u'user0',
478                                       u'created_on': u'2008-07-30 22:15:43',
479                                       u'timeout': 144,
480                                       u'synch_count': 1,
481                                       u'id': 6761},
482                              u'active': 0,
483                              u'id': 193166},
484                             {u'status': u'Queued',
485                              u'complete': 0,
486                              u'deleted': 0,
487                              u'host': None,
488                              u'priority': 1,
489                              u'meta_host': u'Xeon',
490                              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\')',
491                                       u'name': u'test_on_meta_hosts',
492                                       u'control_type': CLIENT,
493                                       u'run_verify': 1,
494                                       u'priority': u'Medium',
495                                       u'owner': u'user0',
496                                       u'created_on': u'2008-07-30 22:15:43',
497                                       u'timeout': 144,
498                                       u'synch_count': 1,
499                                       u'id': 6761},
500                              u'active': 0,
501                              u'id': 193167},
502                             {u'status': u'Queued',
503                              u'complete': 0,
504                              u'deleted': 0,
505                              u'host': None,
506                              u'priority': 1,
507                              u'meta_host': u'Athlon',
508                              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\')',
509                                       u'name': u'test_on_meta_hosts',
510                                       u'control_type': CLIENT,
511                                       u'run_verify': 1,
512                                       u'priority': u'Medium',
513                                       u'owner': u'user0',
514                                       u'created_on': u'2008-07-30 22:15:43',
515                                       u'timeout': 144,
516                                       u'synch_count': 1,
517                                       u'id': 6761},
518                              u'active': 0,
519                              u'id': 193168},
520                             {u'status': u'Queued',
521                              u'complete': 0,
522                              u'deleted': 0,
523                              u'host': None,
524                              u'priority': 1,
525                              u'meta_host': u'x286',
526                              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\')',
527                                       u'name': u'test_on_meta_hosts',
528                                       u'control_type': CLIENT,
529                                       u'run_verify': 1,
530                                       u'priority': u'Medium',
531                                       u'owner': u'user0',
532                                       u'created_on': u'2008-07-30 22:15:43',
533                                       u'timeout': 144,
534                                       u'synch_count': 1,
535                                       u'id': 6761},
536                              u'active': 0,
537                              u'id': 193169},
538                             {u'status': u'Running',
539                              u'complete': 0,
540                              u'deleted': 0,
541                              u'host': {u'status': u'Running',
542                                        u'lock_time': None,
543                                        u'hostname': u'host42',
544                                        u'locked': False,
545                                        u'locked_by': None,
546                                        u'invalid': False,
547                                        u'id': 4833,
548                                        u'protection': u'Repair filesystem only',
549                                        u'synch_id': None},
550                              u'priority': 1,
551                              u'meta_host': u'Athlon',
552                              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\')',
553                                       u'name': u'test_on_meta_hosts',
554                                       u'control_type': CLIENT,
555                                       u'run_verify': 1,
556                                       u'priority': u'Medium',
557                                       u'owner': u'user0',
558                                       u'created_on': u'2008-07-30 22:15:43',
559                                       u'timeout': 144,
560                                       u'synch_count': 1,
561                                       u'id': 6761},
562                              u'active': 1,
563                              u'id': 193170} ])],
564                     out_words_ok=['test_on_meta_hosts',
565                                   'host42', 'Queued', 'Running'],
566                     out_words_no=['Athlon', 'Xeon', 'x286'])
567
568
569    def test_job_stat_job_no_host_in_qes(self):
570        results = copy.deepcopy(self.results)
571        self.run_cmd(argv=['atest', 'job', 'stat', '180',
572                           '--ignore_site_file'],
573                     rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,
574                            [results[0]]),
575                           ('get_host_queue_entries', {'job__in': ['180']},
576                            True,
577                            [{u'status': u'Failed',
578                              u'complete': 1,
579                              u'host': None,
580                              u'priority': 1,
581                              u'meta_host': None,
582                              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)",
583                                       u'name': u'test_sleep',
584                                       u'control_type': SERVER,
585                                       u'priority': u'Medium',
586                                       u'owner': u'user0',
587                                       u'created_on': u'2008-03-18 11:27:29',
588                                       u'synch_count': 1,
589                                       u'id': 180},
590                              u'active': 0,
591                              u'id': 101084}])],
592                     err_words_ok=['unassigned', 'meta-hosts'])
593
594
595    def test_job_stat_multi_jobs(self):
596        results = copy.deepcopy(self.results)
597        self.run_cmd(argv=['atest', 'job', 'stat', '180', '338',
598                           '--ignore_site_file'],
599                     rpcs=[('get_jobs_summary', {'id__in': ['180', '338']},
600                            True, results),
601                           ('get_host_queue_entries',
602                            {'job__in': ['180', '338']},
603                            True,
604                            [{u'status': u'Failed',
605                              u'complete': 1,
606                              u'host': {u'status': u'Repair Failed',
607                                        u'locked': False,
608                                        u'hostname': u'host0',
609                                        u'invalid': True,
610                                        u'id': 4432,
611                                        u'synch_id': None},
612                              u'priority': 1,
613                              u'meta_host': None,
614                              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)",
615                                       u'name': u'test_sleep',
616                                       u'control_type': SERVER,
617                                       u'priority': u'Medium',
618                                       u'owner': u'user0',
619                                       u'created_on': u'2008-03-18 11:27:29',
620                                       u'synch_count': 1,
621                                       u'id': 180},
622                              u'active': 0,
623                              u'id': 101084},
624                             {u'status': u'Failed',
625                              u'complete': 1,
626                              u'host': {u'status': u'Repair Failed',
627                                        u'locked': False,
628                                        u'hostname': u'host10',
629                                        u'invalid': True,
630                                        u'id': 4432,
631                                        u'synch_id': None},
632                              u'priority': 1,
633                              u'meta_host': None,
634                              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)",
635                                       u'name': u'test_sleep',
636                                       u'control_type': SERVER,
637                                       u'priority': u'Medium',
638                                       u'owner': u'user0',
639                                       u'created_on': u'2008-03-18 11:27:29',
640                                       u'synch_count': 1,
641                                       u'id': 338},
642                              u'active': 0,
643                              u'id': 101084}])],
644                     out_words_ok=['test_job0', 'test_job1'])
645
646
647    def test_job_stat_multi_jobs_name_id(self):
648        self.run_cmd(argv=['atest', 'job', 'stat', 'mytest', '180',
649                           '--ignore_site_file'],
650                     rpcs=[('get_jobs_summary', {'id__in': ['180']},
651                            True,
652                            [{u'status_counts': {u'Aborted': 1},
653                             u'control_file':
654                             u"job.run_test('sleeptest')\n",
655                             u'name': u'job0',
656                             u'control_type': SERVER,
657                             u'priority':
658                             u'Medium',
659                             u'owner': u'user0',
660                             u'created_on':
661                             u'2008-07-08 17:45:44',
662                             u'synch_count': 2,
663                             u'id': 180}]),
664                           ('get_jobs_summary', {'name__in': ['mytest']},
665                            True,
666                            [{u'status_counts': {u'Queued': 1},
667                             u'control_file':
668                             u"job.run_test('sleeptest')\n",
669                             u'name': u'mytest',
670                             u'control_type': CLIENT,
671                             u'priority':
672                             u'High',
673                             u'owner': u'user0',
674                             u'created_on': u'2008-07-08 12:17:47',
675                             u'synch_count': 1,
676                             u'id': 338}]),
677                           ('get_host_queue_entries',
678                            {'job__in': ['180']},
679                            True,
680                            [{u'status': u'Failed',
681                              u'complete': 1,
682                              u'host': {u'status': u'Repair Failed',
683                                        u'locked': False,
684                                        u'hostname': u'host0',
685                                        u'invalid': True,
686                                        u'id': 4432,
687                                        u'synch_id': None},
688                              u'priority': 1,
689                              u'meta_host': None,
690                              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)",
691                                       u'name': u'test_sleep',
692                                       u'control_type': SERVER,
693                                       u'synchronizing': 0,
694                                       u'priority': u'Medium',
695                                       u'owner': u'user0',
696                                       u'created_on': u'2008-03-18 11:27:29',
697                                       u'synch_count': 1,
698                                       u'id': 180},
699                              u'active': 0,
700                              u'id': 101084}]),
701                           ('get_host_queue_entries',
702                            {'job__name__in': ['mytest']},
703                            True,
704                            [{u'status': u'Failed',
705                              u'complete': 1,
706                              u'host': {u'status': u'Repair Failed',
707                                        u'locked': False,
708                                        u'hostname': u'host10',
709                                        u'invalid': True,
710                                        u'id': 4432,
711                                        u'synch_id': None},
712                              u'priority': 1,
713                              u'meta_host': None,
714                              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)",
715                                       u'name': u'test_sleep',
716                                       u'control_type': SERVER,
717                                       u'synchronizing': 0,
718                                       u'priority': u'Medium',
719                                       u'owner': u'user0',
720                                       u'created_on': u'2008-03-18 11:27:29',
721                                       u'synch_count': 1,
722                                       u'id': 338},
723                              u'active': 0,
724                              u'id': 101084}])],
725                     out_words_ok=['job0', 'mytest', 'Aborted', 'Queued',
726                                   'Failed', 'Medium', 'High'])
727
728
729class job_create_unittest(cli_mock.cli_unittest):
730    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)'
731
732    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)'
733
734    trivial_ctrl_file = 'print "Hello"\n'
735
736    data = {'priority': 'Medium', 'control_file': ctrl_file, 'hosts': ['host0'],
737            'name': 'test_job0', 'control_type': CLIENT, 'email_list': '',
738            'meta_hosts': [], 'synch_count': 1, 'dependencies': [],
739            'require_ssp': False}
740
741
742    def test_execute_create_job(self):
743        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
744                           'test_job0', '-m', 'host0', '--ignore_site_file'],
745                     rpcs=[('generate_control_file',
746                            {'tests': ['sleeptest']},
747                            True,
748                            {'control_file' : self.ctrl_file,
749                             'synch_count' : 1,
750                             'is_server' : False,
751                             'dependencies' : []}),
752                           ('create_job', self.data, True, 180)],
753                     out_words_ok=['test_job0', 'Created'],
754                     out_words_no=['Uploading', 'Done'])
755
756
757    def test_execute_create_job_with_atomic_group(self):
758        data = dict(self.data)
759        data['atomic_group_name'] = 'my-atomic-group'
760        data['control_type'] = SERVER
761        mock_ctrl_file = 'mock control file'
762        data['control_file'] = mock_ctrl_file
763        data['synch_count'] = 2
764        data['hosts'] = []
765        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'mocktest',
766                           'test_job0', '--ignore_site_file',
767                           '-G', 'my-atomic-group'],
768                     rpcs=[('generate_control_file',
769                            {'tests': ['mocktest']},
770                            True,
771                            {'control_file' : mock_ctrl_file,
772                             'synch_count' : 2,
773                             'is_server' : True,
774                             'dependencies' : []}),
775                           ('create_job', data, True, 180)],
776                     out_words_ok=['test_job0', 'Created'],
777                     out_words_no=['Uploading', 'Done'])
778
779
780    def test_execute_create_job_with_control(self):
781        file_temp = cli_mock.create_file(self.ctrl_file)
782        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
783                           'test_job0', '-m', 'host0', '--ignore_site_file'],
784                     rpcs=[('create_job', self.data, True, 42)],
785                     out_words_ok=['test_job0', 'Created'],
786                     out_words_no=['Uploading', 'Done'])
787        file_temp.clean()
788
789
790    def test_execute_create_job_with_control_and_kernel(self):
791        data = self.data.copy()
792        data['control_file'] = '# Made up control "file" for unittest.'
793        file_temp = cli_mock.create_file(self.trivial_ctrl_file)
794        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
795                           '-k', 'Kernel', 'test_job0', '-m', 'host0',
796                           '--ignore_site_file'],
797                     rpcs=[('generate_control_file',
798                            {'client_control_file': self.trivial_ctrl_file,
799                             'kernel': [{'version': 'Kernel'}]},
800                            True,
801                            {'control_file': data['control_file'],
802                             'synch_count': 1,
803                             'is_server': False,
804                             'dependencies': []}),
805                           ('create_job', data, True, 42)],
806                     out_words_ok=['test_job0', 'Created',
807                                   'Uploading', 'Done'])
808        file_temp.clean()
809
810
811    def test_execute_create_job_with_control_and_email(self):
812        data = self.data.copy()
813        data['email_list'] = 'em'
814        file_temp = cli_mock.create_file(self.ctrl_file)
815        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
816                           'test_job0', '-m', 'host0', '-e', 'em',
817                           '--ignore_site_file'],
818                     rpcs=[('create_job', data, True, 42)],
819                     out_words_ok=['test_job0', 'Created'],
820                     out_words_no=['Uploading', 'Done'])
821        file_temp.clean()
822
823
824    def test_execute_create_job_with_control_and_dependencies(self):
825        data = self.data.copy()
826        data['dependencies'] = ['dep1', 'dep2']
827        file_temp = cli_mock.create_file(self.ctrl_file)
828        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
829                           'test_job0', '-m', 'host0', '-d', 'dep1, dep2 ',
830                           '--ignore_site_file'],
831                     rpcs=[('create_job', data, True, 42)],
832                     out_words_ok=['test_job0', 'Created'],
833                     out_words_no=['Uploading', 'Done'])
834        file_temp.clean()
835
836
837    def test_execute_create_job_with_control_and_comma_dependencies(self):
838        data = self.data.copy()
839        data['dependencies'] = ['dep2,False', 'dep1,True']
840        file_temp = cli_mock.create_file(self.ctrl_file)
841        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
842                           'test_job0', '-m', 'host0', '-d',
843                           'dep1\,True, dep2\,False ', '--ignore_site_file'],
844                     rpcs=[('create_job', data, True, 42)],
845                     out_words_ok=['test_job0', 'Created'],
846                     out_words_no=['Uploading', 'Done'])
847        file_temp.clean()
848
849
850    def test_execute_create_job_with_synch_count(self):
851        data = self.data.copy()
852        data['synch_count'] = 2
853        file_temp = cli_mock.create_file(self.ctrl_file)
854        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
855                           'test_job0', '-m', 'host0', '-y', '2',
856                           '--ignore_site_file'],
857                     rpcs=[('create_job', data, True, 42)],
858                     out_words_ok=['test_job0', 'Created'],
859                     out_words_no=['Uploading', 'Done'])
860        file_temp.clean()
861
862
863    def test_execute_create_job_with_test_and_dependencies(self):
864        data = self.data.copy()
865        data['dependencies'] = ['dep1', 'dep2', 'dep3']
866        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
867                           'test_job0', '-m', 'host0', '-d', 'dep1, dep2 ',
868                           '--ignore_site_file'],
869                     rpcs=[('generate_control_file',
870                            {'tests': ['sleeptest']},
871                            True,
872                            {'control_file' : self.ctrl_file,
873                             'synch_count' : 1,
874                             'is_server' : False,
875                             'dependencies' : ['dep3']}),
876                           ('create_job', data, True, 42)],
877                     out_words_ok=['test_job0', 'Created'],
878                     out_words_no=['Uploading', 'Done'])
879
880
881    def test_execute_create_job_with_test_and_comma_dependencies(self):
882        data = self.data.copy()
883        data['dependencies'] = ['dep1,True', 'dep2,False', 'dep3,123']
884        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
885                           'test_job0', '-m', 'host0', '-d',
886                           'dep1\,True dep2\,False ', '--ignore_site_file'],
887                     rpcs=[('generate_control_file',
888                            {'tests': ['sleeptest']},
889                            True,
890                            {'control_file' : self.ctrl_file,
891                             'synch_count' : 1,
892                             'is_server' : False,
893                             'dependencies' : ['dep3,123']}),
894                           ('create_job', data, True, 42)],
895                     out_words_ok=['test_job0', 'Created'],
896                     out_words_no=['Uploading', 'Done'])
897
898
899    def test_execute_create_job_with_kernel(self):
900        data = self.data.copy()
901        data['control_file'] = self.kernel_ctrl_file
902        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
903                           '-k', 'kernel', 'test_job0', '-m', 'host0',
904                           '--ignore_site_file'],
905                     rpcs=[('generate_control_file',
906                            {'tests': ['sleeptest'],
907                             'kernel': [{'version': 'kernel'}]
908                             },
909                            True,
910                            {'control_file' : self.kernel_ctrl_file,
911                             'synch_count' : 1,
912                             'is_server' : False,
913                             'dependencies' : []}),
914                           ('create_job', data, True, 180)],
915                     out_words_ok=['test_job0', 'Created',
916                                   'Uploading', 'Done'])
917
918
919    def test_execute_create_job_with_kernels_and_cmdline(self):
920        data = self.data.copy()
921        data['control_file'] = self.kernel_ctrl_file
922        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
923                           '-k', 'kernel1,kernel2', '--kernel-cmdline',
924                           'arg1 arg2', 'test_job0', '-m', 'host0',
925                           '--ignore_site_file'],
926                     rpcs=[('generate_control_file',
927                            {'tests': ['sleeptest'],
928                             'kernel': [{'version': 'kernel1',
929                                         'cmdline': 'arg1 arg2'},
930                                        {'version': 'kernel2',
931                                         'cmdline': 'arg1 arg2'}]
932                             },
933                            True,
934                            {'control_file' : self.kernel_ctrl_file,
935                             'synch_count' : 1,
936                             'is_server' : False,
937                             'dependencies' : []}),
938                           ('create_job', data, True, 180)],
939                     out_words_ok=['test_job0', 'Created',
940                                   'Uploading', 'Done'])
941
942
943    def test_execute_create_job_with_kernel_spaces(self):
944        data = self.data.copy()
945        data['control_file'] = self.kernel_ctrl_file
946        data['name'] = 'test job	with  spaces'
947        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
948                           '-k', 'kernel', 'test job	with  spaces',
949                           '-m', 'host0', '--ignore_site_file'],
950                     rpcs=[('generate_control_file',
951                            {'tests': ['sleeptest'],
952                             'kernel': [{'version': 'kernel'}]
953                             },
954                            True,
955                            {'control_file' : self.kernel_ctrl_file,
956                             'synch_count' : 1,
957                             'is_server' : False,
958                             'dependencies' : []}),
959                           ('create_job', data, True, 180)],
960                     # This is actually 7 spaces, the extra single quote that
961                     # gets displayed before "test" causes the tab completion
962                     # to move to the next 8 char boundary which is 7 characters
963                     # away. Hence the 7 spaces in out_words_ok.
964                     # The tab has been converted by print.
965                     out_words_ok=['test job       with  spaces', 'Created',
966                                   'id', '180'])
967
968
969    def test_execute_create_job_no_args(self):
970        testjob = job.job_create()
971        sys.argv = ['atest', 'job', 'create', '--ignore_site_file']
972        self.god.mock_io()
973        (sys.exit.expect_call(mock.anything_comparator())
974         .and_raises(cli_mock.ExitException))
975        self.assertRaises(cli_mock.ExitException, testjob.parse)
976        self.god.unmock_io()
977        self.god.check_playback()
978
979
980    def test_execute_create_job_no_hosts(self):
981        testjob = job.job_create()
982        file_temp = cli_mock.create_file(self.ctrl_file)
983        sys.argv = ['atest', '-f', file_temp.name, 'test_job0',
984                    '--ignore_site_file']
985        self.god.mock_io()
986        (sys.exit.expect_call(mock.anything_comparator())
987         .and_raises(cli_mock.ExitException))
988        self.assertRaises(cli_mock.ExitException, testjob.parse)
989        self.god.unmock_io()
990        self.god.check_playback()
991        file_temp.clean()
992
993
994    def test_execute_create_job_cfile_and_tests(self):
995        testjob = job.job_create()
996        sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-f',
997                    'control_file', 'test_job0', '-m', 'host0',
998                    '--ignore_site_file']
999        self.god.mock_io()
1000        (sys.exit.expect_call(mock.anything_comparator())
1001         .and_raises(cli_mock.ExitException))
1002        self.assertRaises(cli_mock.ExitException, testjob.parse)
1003        self.god.unmock_io()
1004        self.god.check_playback()
1005
1006
1007    def test_execute_create_job_cfile_and_kernel(self):
1008        testjob = job.job_create()
1009        sys.argv = ['atest', 'job', 'create', '-f', 'control_file', '-k',
1010                    'kernel', 'test_job0', '-m', 'host0', '--ignore_site_file']
1011        self.god.mock_io()
1012        (sys.exit.expect_call(mock.anything_comparator())
1013         .and_raises(cli_mock.ExitException))
1014        self.assertRaises(cli_mock.ExitException, testjob.parse)
1015        self.god.unmock_io()
1016        self.god.check_playback()
1017
1018
1019    def test_execute_create_job_bad_cfile(self):
1020        testjob = job.job_create()
1021        sys.argv = ['atest', 'job', 'create', '-f', 'control_file',
1022                    'test_job0', '-m', 'host0', '--ignore_site_file']
1023        self.god.mock_io()
1024        (sys.exit.expect_call(mock.anything_comparator())
1025         .and_raises(IOError))
1026        self.assertRaises(IOError, testjob.parse)
1027        self.god.unmock_io()
1028
1029
1030    def test_execute_create_job_bad_priority(self):
1031        testjob = job.job_create()
1032        sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-p', 'Uber',
1033                    '-m', 'host0', 'test_job0', '--ignore_site_file']
1034        self.god.mock_io()
1035        (sys.exit.expect_call(mock.anything_comparator())
1036         .and_raises(cli_mock.ExitException))
1037        self.assertRaises(cli_mock.ExitException, testjob.parse)
1038        self.god.unmock_io()
1039        self.god.check_playback()
1040
1041
1042    def test_execute_create_job_with_mfile(self):
1043        data = self.data.copy()
1044        data['hosts'] = ['host3', 'host2', 'host1', 'host0']
1045        ctemp = cli_mock.create_file(self.ctrl_file)
1046        file_temp = cli_mock.create_file('host0\nhost1\nhost2\nhost3')
1047        self.run_cmd(argv=['atest', 'job', 'create', '--mlist', file_temp.name,
1048                           '-f', ctemp.name, 'test_job0', '--ignore_site_file'],
1049                     rpcs=[('create_job', data, True, 42)],
1050                     out_words_ok=['test_job0', 'Created'])
1051        ctemp.clean()
1052        file_temp.clean()
1053
1054
1055    def test_execute_create_job_with_timeout(self):
1056        data = self.data.copy()
1057        data['timeout_mins'] = '13320'
1058        file_temp = cli_mock.create_file(self.ctrl_file)
1059        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1060                           'test_job0', '-m', 'host0', '-o', '13320',
1061                           '--ignore_site_file'],
1062                     rpcs=[('create_job', data, True, 42)],
1063                     out_words_ok=['test_job0', 'Created'],)
1064        file_temp.clean()
1065
1066
1067    def test_execute_create_job_with_max_runtime(self):
1068        data = self.data.copy()
1069        data['max_runtime_mins'] = '13320'
1070        file_temp = cli_mock.create_file(self.ctrl_file)
1071        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1072                           'test_job0', '-m', 'host0', '--max_runtime',
1073                           '13320', '--ignore_site_file'],
1074                     rpcs=[('create_job', data, True, 42)],
1075                     out_words_ok=['test_job0', 'Created'],)
1076        file_temp.clean()
1077
1078
1079
1080    def test_execute_create_job_with_noverify(self):
1081        data = self.data.copy()
1082        data['run_verify'] = False
1083        file_temp = cli_mock.create_file(self.ctrl_file)
1084        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1085                           'test_job0', '-m', 'host0', '-n',
1086                           '--ignore_site_file'],
1087                     rpcs=[('create_job', data, True, 42)],
1088                     out_words_ok=['test_job0', 'Created'],)
1089        file_temp.clean()
1090
1091
1092    def test_execute_create_job_oth(self):
1093        data = self.data.copy()
1094        data['hosts'] = []
1095        data['one_time_hosts'] = ['host0']
1096        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
1097                           'test_job0', '--one-time-hosts', 'host0'],
1098                     rpcs=[('generate_control_file',
1099                            {'tests': ['sleeptest']},
1100                            True,
1101                            {'control_file' : self.ctrl_file,
1102                             'synch_count' : 1,
1103                             'is_server' : False,
1104                             'dependencies' : []}),
1105                           ('create_job', data, True, 180)],
1106                     out_words_ok=['test_job0', 'Created'],
1107                     out_words_no=['Uploading', 'Done'])
1108
1109
1110    def test_execute_create_job_multi_oth(self):
1111        data = self.data.copy()
1112        data['hosts'] = []
1113        data['one_time_hosts'] = ['host1', 'host0']
1114        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
1115                           'test_job0', '--one-time-hosts', 'host0,host1'],
1116                     rpcs=[('generate_control_file',
1117                            {'tests': ['sleeptest']},
1118                            True,
1119                            {'control_file' : self.ctrl_file,
1120                             'synch_count' : 1,
1121                             'is_server' : False,
1122                             'dependencies' : []}),
1123                           ('create_job', data, True, 180)],
1124                     out_words_ok=['test_job0', 'Created'],
1125                     out_words_no=['Uploading', 'Done'])
1126
1127
1128    def test_execute_create_job_oth_exists(self):
1129        data = self.data.copy()
1130        data['hosts'] = []
1131        data['one_time_hosts'] = ['host0']
1132        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
1133                           'test_job0', '--one-time-hosts', 'host0'],
1134                     rpcs=[('generate_control_file',
1135                            {'tests': ['sleeptest']},
1136                            True,
1137                            {'control_file' : self.ctrl_file,
1138                             'synch_count' : 1,
1139                             'is_server' : False,
1140                             'dependencies' : []}),
1141                           ('create_job', data, False,
1142                            '''ValidationError: {'hostname': 'host0 '''
1143                            '''already exists in the autotest DB.  '''
1144                            '''Select it rather than entering it as '''
1145                            '''a one time host.'}''')],
1146                     out_words_no=['test_job0', 'Created'],
1147                     err_words_ok=['failed', 'already exists'])
1148
1149
1150    def test_execute_create_job_with_control_and_labels(self):
1151        data = self.data.copy()
1152        data['hosts'] = ['host0', 'host1', 'host2']
1153        file_temp = cli_mock.create_file(self.ctrl_file)
1154        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1155                           'test_job0', '-m', 'host0', '-b', 'label1,label2',
1156                           '--ignore_site_file'],
1157                     rpcs=[('get_hosts', {'multiple_labels': ['label1',
1158                            'label2']}, True,
1159                            [{u'status': u'Running', u'lock_time': None,
1160                              u'hostname': u'host1', u'locked': False,
1161                              u'locked_by': None, u'invalid': False, u'id': 42,
1162                              u'labels': [u'label1'], u'platform':
1163                              u'Warp18_Diskfull', u'protection':
1164                              u'Repair software only', u'dirty':
1165                              True, u'synch_id': None},
1166                             {u'status': u'Running', u'lock_time': None,
1167                              u'hostname': u'host2', u'locked': False,
1168                              u'locked_by': None, u'invalid': False, u'id': 43,
1169                              u'labels': [u'label2'], u'platform':
1170                              u'Warp18_Diskfull', u'protection':
1171                              u'Repair software only', u'dirty': True,
1172                              u'synch_id': None}]),
1173                            ('create_job', data, True, 42)],
1174                     out_words_ok=['test_job0', 'Created'],
1175                     out_words_no=['Uploading', 'Done'])
1176        file_temp.clean()
1177
1178
1179    def test_execute_create_job_with_label_and_duplicate_hosts(self):
1180        data = self.data.copy()
1181        data['hosts'] = ['host1', 'host0']
1182        file_temp = cli_mock.create_file(self.ctrl_file)
1183        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1184                           'test_job0', '-m', 'host0,host1', '-b', 'label1',
1185                           '--ignore_site_file'],
1186                     rpcs=[('get_hosts', {'multiple_labels': ['label1']}, True,
1187                            [{u'status': u'Running', u'lock_time': None,
1188                              u'hostname': u'host1', u'locked': False,
1189                              u'locked_by': None, u'invalid': False, u'id': 42,
1190                              u'labels': [u'label1'], u'platform':
1191                              u'Warp18_Diskfull', u'protection':
1192                              u'Repair software only', u'dirty':
1193                              True, u'synch_id': None}]),
1194                            ('create_job', data, True, 42)],
1195                     out_words_ok=['test_job0', 'Created'],
1196                     out_words_no=['Uploading', 'Done'])
1197        file_temp.clean()
1198
1199
1200    def test_execute_create_job_with_label_commas_and_duplicate_hosts(self):
1201        data = self.data.copy()
1202        data['hosts'] = ['host1', 'host0']
1203        file_temp = cli_mock.create_file(self.ctrl_file)
1204        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1205                           'test_job0', '-m', 'host0,host1', '-b',
1206                           'label1,label\\,2', '--ignore_site_file'],
1207                     rpcs=[('get_hosts', {'multiple_labels': ['label1',
1208                            'label,2']}, True,
1209                            [{u'status': u'Running', u'lock_time': None,
1210                              u'hostname': u'host1', u'locked': False,
1211                              u'locked_by': None, u'invalid': False, u'id': 42,
1212                              u'labels': [u'label1', u'label,2'], u'platform':
1213                              u'Warp18_Diskfull', u'protection':
1214                              u'Repair software only', u'dirty':
1215                              True, u'synch_id': None}]),
1216                            ('create_job', data, True, 42)],
1217                     out_words_ok=['test_job0', 'Created'],
1218                     out_words_no=['Uploading', 'Done'])
1219        file_temp.clean()
1220
1221
1222    def test_execute_create_job_with_label_escaping_and_duplicate_hosts(self):
1223        data = self.data.copy()
1224        data['hosts'] = ['host1', 'host0']
1225        file_temp = cli_mock.create_file(self.ctrl_file)
1226        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1227                           'test_job0', '-m', 'host0,host1', '-b',
1228                           'label1,label\\,2\\\\,label3', '--ignore_site_file'],
1229                     rpcs=[('get_hosts', {'multiple_labels': ['label,2\\',
1230                            'label1', 'label3']}, True,
1231                            [{u'status': u'Running', u'lock_time': None,
1232                              u'hostname': u'host1', u'locked': False,
1233                              u'locked_by': None, u'invalid': False, u'id': 42,
1234                              u'labels': [u'label1', u'label,2\\', u'label3'],
1235                              u'platform': u'Warp18_Diskfull', u'protection':
1236                              u'Repair software only', u'dirty':
1237                              True, u'synch_id': None}]),
1238                            ('create_job', data, True, 42)],
1239                     out_words_ok=['test_job0', 'Created'],
1240                     out_words_no=['Uploading', 'Done'])
1241        file_temp.clean()
1242
1243
1244    def _test_parse_hosts(self, args, exp_hosts=[], exp_meta_hosts=[]):
1245        testjob = job.job_create_or_clone()
1246        (hosts, meta_hosts) = testjob._parse_hosts(args)
1247        self.assertEqualNoOrder(hosts, exp_hosts)
1248        self.assertEqualNoOrder(meta_hosts, exp_meta_hosts)
1249
1250
1251    def test_parse_hosts_regular(self):
1252        self._test_parse_hosts(['host0'], ['host0'])
1253
1254
1255    def test_parse_hosts_regulars(self):
1256        self._test_parse_hosts(['host0', 'host1'], ['host0', 'host1'])
1257
1258
1259    def test_parse_hosts_meta_one(self):
1260        self._test_parse_hosts(['*meta0'], [], ['meta0'])
1261
1262
1263    def test_parse_hosts_meta_five(self):
1264        self._test_parse_hosts(['5*meta0'], [], ['meta0']*5)
1265
1266
1267    def test_parse_hosts_metas_five(self):
1268        self._test_parse_hosts(['5*meta0', '2*meta1'], [],
1269                               ['meta0']*5 + ['meta1']*2)
1270
1271
1272    def test_parse_hosts_mix(self):
1273        self._test_parse_hosts(['5*meta0', 'host0', '2*meta1', 'host1',
1274                                '*meta2'], ['host0', 'host1'],
1275                               ['meta0']*5 + ['meta1']*2 + ['meta2'])
1276
1277
1278class job_clone_unittest(cli_mock.cli_unittest):
1279    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',
1280                    'control_type': SERVER,
1281                    'dependencies': [],
1282                    'email_list': u'',
1283                    'max_runtime_mins': 28800,
1284                    'parse_failed_repair': True,
1285                    'priority': u'Medium',
1286                    'reboot_after': u'Always',
1287                    'reboot_before': u'If dirty',
1288                    'run_verify': True,
1289                    'synch_count': 1,
1290                    'timeout_mins': 480}
1291
1292    local_hosts = [{u'acls': [u'acl0'],
1293                    u'atomic_group': None,
1294                    u'attributes': {},
1295                    u'dirty': False,
1296                    u'hostname': u'host0',
1297                    u'id': 8,
1298                    u'invalid': False,
1299                    u'labels': [u'label0', u'label1'],
1300                    u'lock_time': None,
1301                    u'locked': False,
1302                    u'locked_by': None,
1303                    u'other_labels': u'label0, label1',
1304                    u'platform': u'plat0',
1305                    u'protection': u'Repair software only',
1306                    u'status': u'Ready',
1307                    u'synch_id': None},
1308                   {u'acls': [u'acl0'],
1309                    u'atomic_group': None,
1310                    u'attributes': {},
1311                    u'dirty': False,
1312                    u'hostname': u'host1',
1313                    u'id': 9,
1314                    u'invalid': False,
1315                    u'labels': [u'label0', u'label1'],
1316                    u'lock_time': None,
1317                    u'locked': False,
1318                    u'locked_by': None,
1319                    u'other_labels': u'label0, label1',
1320                    u'platform': u'plat0',
1321                    u'protection': u'Repair software only',
1322                    u'status': u'Ready',
1323                    u'synch_id': None}]
1324
1325
1326    def setUp(self):
1327        super(job_clone_unittest, self).setUp()
1328        self.job_data_clone_info = copy.deepcopy(self.job_data)
1329        self.job_data_clone_info['created_on'] = '2009-07-23 16:21:29'
1330        self.job_data_clone_info['name'] = 'testing_clone'
1331        self.job_data_clone_info['id'] = 42
1332        self.job_data_clone_info['owner'] = 'user0'
1333
1334        self.job_data_cloned = copy.deepcopy(self.job_data)
1335        self.job_data_cloned['name'] = 'cloned'
1336        self.job_data_cloned['hosts'] = [u'host0']
1337        self.job_data_cloned['meta_hosts'] = []
1338
1339
1340    def test_backward_compat(self):
1341        self.run_cmd(argv=['atest', 'job', 'create', '--clone', '42',
1342                           '-r', 'cloned'],
1343                     rpcs=[('get_info_for_clone', {'id': '42',
1344                                                   'preserve_metahosts': True},
1345                            True,
1346                            {u'atomic_group_name': None,
1347                             u'hosts': [{u'acls': [u'acl0'],
1348                                         u'atomic_group': None,
1349                                         u'attributes': {},
1350                                         u'dirty': False,
1351                                         u'hostname': u'host0',
1352                                         u'id': 4378,
1353                                         u'invalid': False,
1354                                         u'labels': [u'label0', u'label1'],
1355                                         u'lock_time': None,
1356                                         u'locked': False,
1357                                         u'locked_by': None,
1358                                         u'other_labels': u'label0, label1',
1359                                         u'platform': u'plat0',
1360                                         u'protection': u'Repair software only',
1361                                         u'status': u'Ready',
1362                                         u'synch_id': None}],
1363                             u'job': self.job_data_clone_info,
1364                             u'meta_host_counts': {}}),
1365                           ('create_job', self.job_data_cloned, True, 43)],
1366                     out_words_ok=['Created job', '43'])
1367
1368
1369    def test_clone_reuse_hosts(self):
1370        self.job_data_cloned['hosts'] = [u'host0', 'host1']
1371        self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1372                           '-r', 'cloned'],
1373                     rpcs=[('get_info_for_clone', {'id': '42',
1374                                                   'preserve_metahosts': True},
1375                            True,
1376                            {u'atomic_group_name': None,
1377                             u'hosts': self.local_hosts,
1378                             u'job': self.job_data_clone_info,
1379                             u'meta_host_counts': {}}),
1380                           ('create_job', self.job_data_cloned, True, 43)],
1381                     out_words_ok=['Created job', '43'])
1382
1383
1384    def test_clone_reuse_metahosts(self):
1385        self.job_data_cloned['hosts'] = []
1386        self.job_data_cloned['meta_hosts'] = ['type1']*4 +  ['type0']
1387        self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1388                           '-r', 'cloned'],
1389                     rpcs=[('get_info_for_clone', {'id': '42',
1390                                                   'preserve_metahosts': True},
1391                            True,
1392                            {u'atomic_group_name': None,
1393                             u'hosts': [],
1394                             u'job': self.job_data_clone_info,
1395                             u'meta_host_counts': {u'type0': 1,
1396                                                   u'type1': 4}}),
1397                           ('create_job', self.job_data_cloned, True, 43)],
1398                     out_words_ok=['Created job', '43'])
1399
1400
1401    def test_clone_reuse_both(self):
1402        self.job_data_cloned['hosts'] = [u'host0', 'host1']
1403        self.job_data_cloned['meta_hosts'] = ['type1']*4 +  ['type0']
1404        self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1405                           '-r', 'cloned'],
1406                     rpcs=[('get_info_for_clone', {'id': '42',
1407                                                   'preserve_metahosts': True},
1408                            True,
1409                            {u'atomic_group_name': None,
1410                             u'hosts': self.local_hosts,
1411                             u'job': self.job_data_clone_info,
1412                             u'meta_host_counts': {u'type0': 1,
1413                                                   u'type1': 4}}),
1414                           ('create_job', self.job_data_cloned, True, 43)],
1415                     out_words_ok=['Created job', '43'])
1416
1417
1418    def test_clone_no_hosts(self):
1419        self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42', 'cloned'],
1420                     exit_code=1,
1421                     out_words_ok=['usage'],
1422                     err_words_ok=['machine'])
1423
1424
1425    def test_clone_reuse_and_hosts(self):
1426        self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1427                           '-r', '-m', 'host5', 'cloned'],
1428                     exit_code=1,
1429                     out_words_ok=['usage'],
1430                     err_words_ok=['specify'])
1431
1432
1433    def test_clone_new_multiple_hosts(self):
1434        self.job_data_cloned['hosts'] = [u'host5', 'host4', 'host3']
1435        self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1436                           '-m', 'host5,host4,host3', 'cloned'],
1437                     rpcs=[('get_info_for_clone', {'id': '42',
1438                                                   'preserve_metahosts': False},
1439                            True,
1440                            {u'atomic_group_name': None,
1441                             u'hosts': self.local_hosts,
1442                             u'job': self.job_data_clone_info,
1443                             u'meta_host_counts': {}}),
1444                           ('create_job', self.job_data_cloned, True, 43)],
1445                     out_words_ok=['Created job', '43'])
1446
1447
1448    def test_clone_oth(self):
1449        self.job_data_cloned['hosts'] = []
1450        self.job_data_cloned['one_time_hosts'] = [u'host5']
1451        self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1452                           '--one-time-hosts', 'host5', 'cloned'],
1453                     rpcs=[('get_info_for_clone', {'id': '42',
1454                                                   'preserve_metahosts': False},
1455                            True,
1456                            {u'atomic_group_name': None,
1457                             u'hosts': self.local_hosts,
1458                             u'job': self.job_data_clone_info,
1459                             u'meta_host_counts': {}}),
1460                           ('create_job', self.job_data_cloned, True, 43)],
1461                     out_words_ok=['Created job', '43'])
1462
1463
1464class job_abort_unittest(cli_mock.cli_unittest):
1465    results = [{u'status_counts': {u'Aborted': 1}, u'control_file':
1466                u"job.run_test('sleeptest')\n", u'name': u'test_job0',
1467                u'control_type': SERVER, u'priority':
1468                u'Medium', u'owner': u'user0', u'created_on':
1469                u'2008-07-08 17:45:44', u'synch_count': 2, u'id': 180}]
1470
1471    def test_execute_job_abort(self):
1472        self.run_cmd(argv=['atest', 'job', 'abort', '180',
1473                           '--ignore_site_file'],
1474                     rpcs=[('abort_host_queue_entries',
1475                            {'job__id__in': ['180']}, True, None)],
1476                     out_words_ok=['Aborting', '180'])
1477
1478
1479if __name__ == '__main__':
1480    unittest.main()
1481