blob: bac0ceb3a5a1f7b2084ae7db9787e48f548cf982 [file] [log] [blame]
mbligh0a669132008-10-10 20:02:32 +00001#!/usr/bin/python -u
mblighbe630eb2008-08-01 16:41:48 +00002#
3# Copyright 2008 Google Inc. All Rights Reserved.
4
mblighfb8f0ab2008-11-13 01:11:48 +00005
mblighbe630eb2008-08-01 16:41:48 +00006"""Tests for job."""
7
8import copy, getpass, unittest, sys, os
9
10import common
11from autotest_lib.cli import cli_mock, topic_common, job
showard53cb10c2009-05-01 00:09:36 +000012from autotest_lib.client.common_lib.test_utils import mock
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070013from autotest_lib.client.common_lib import control_data
mblighbe630eb2008-08-01 16:41:48 +000014
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070015CLIENT = control_data.CONTROL_TYPE_NAMES.CLIENT
16SERVER = control_data.CONTROL_TYPE_NAMES.SERVER
mblighbe630eb2008-08-01 16:41:48 +000017
18class job_unittest(cli_mock.cli_unittest):
19 def setUp(self):
20 super(job_unittest, self).setUp()
mblighbe630eb2008-08-01 16:41:48 +000021 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070027 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +000028 u'priority':
29 u'Medium',
30 u'owner': u'user0',
31 u'created_on':
32 u'2008-07-08 17:45:44',
showard2bab8f42008-11-12 18:15:22 +000033 u'synch_count': 2,
mblighbe630eb2008-08-01 16:41:48 +000034 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070039 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +000040 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,
mblighbe630eb2008-08-01 16:41:48 +000046 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',
mbligh0887d402009-01-30 00:50:29 +000053 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +000054 u'created_on': u'2008-07-02 13:02:40',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070055 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +000056 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000057 u'synch_count': 2},
mblighbe630eb2008-08-01 16:41:48 +000058 {u'id': 338, # Valid job
59 u'priority': 'High',
60 u'name': u'test_job1',
61 u'owner': u'Fisto',
mbligh0887d402009-01-30 00:50:29 +000062 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +000063 u'created_on': u'2008-07-06 14:05:33',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070064 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +000065 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000066 u'synch_count': 1},
mblighbe630eb2008-08-01 16:41:48 +000067 {u'id': 339, # Valid job
68 u'priority': 'Medium',
69 u'name': u'test_job2',
70 u'owner': u'Roboto',
mbligh0887d402009-01-30 00:50:29 +000071 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +000072 u'created_on': u'2008-07-07 15:33:18',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070073 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +000074 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000075 u'synch_count': 1},
mblighbe630eb2008-08-01 16:41:48 +000076 {u'id': 340, # Invalid job priority
77 u'priority': u'Uber',
78 u'name': u'test_job3',
79 u'owner': u'Panthor',
mbligh0887d402009-01-30 00:50:29 +000080 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +000081 u'created_on': u'2008-07-04 00:00:01',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070082 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +000083 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000084 u'synch_count': 2},
mblighbe630eb2008-08-01 16:41:48 +000085 {u'id': 350, # Invalid job created_on
86 u'priority': 'Medium',
87 u'name': u'test_job4',
88 u'owner': u'Icer',
mbligh0887d402009-01-30 00:50:29 +000089 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +000090 u'created_on': u'Today',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070091 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +000092 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000093 u'synch_count': 1},
mblighbe630eb2008-08-01 16:41:48 +000094 {u'id': 420, # Invalid job control_type
95 u'priority': 'Urgent',
96 u'name': u'test_job5',
97 u'owner': u'Spikor',
mbligh0887d402009-01-30 00:50:29 +000098 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +000099 u'created_on': u'2012-08-08 18:54:37',
100 u'control_type': u'Child',
101 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +0000102 u'synch_count': 2}]
mblighbe630eb2008-08-01 16:41:48 +0000103
104
105class job_list_unittest(job_unittest):
106 def test_job_list_jobs(self):
showardf4a68992010-02-03 20:29:59 +0000107 self.god.stub_function(getpass, 'getuser')
mblighbe630eb2008-08-01 16:41:48 +0000108 getpass.getuser.expect_call().and_return('user0')
mbligha212d712009-02-11 01:22:36 +0000109 self.run_cmd(argv=['atest', 'job', 'list', '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000110 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']
mbligha212d712009-02-11 01:22:36 +0000119 self.run_cmd(argv=['atest', 'job', 'list', '-u', 'Cringer',
120 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000121 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):
mbligha212d712009-02-11 01:22:36 +0000130 self.run_cmd(argv=['atest', 'job', 'list', '--all',
131 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000132 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):
mbligha212d712009-02-11 01:22:36 +0000140 self.run_cmd(argv=['atest', 'job', 'list', '5964',
141 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000142 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700148 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000149 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,
showard2bab8f42008-11-12 18:15:22 +0000154 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000155 u'id': 5964}])],
156 out_words_ok=['user0', 'Completed', '1', '5964'],
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700157 out_words_no=['sleeptest', 'Priority', CLIENT, '2008'])
mblighbe630eb2008-08-01 16:41:48 +0000158
159
160 def test_job_list_jobs_id_verbose(self):
mbligha212d712009-02-11 01:22:36 +0000161 self.run_cmd(argv=['atest', 'job', 'list', '5964', '-v',
162 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000163 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700169 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000170 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,
showard2bab8f42008-11-12 18:15:22 +0000175 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000176 u'id': 5964}])],
177 out_words_ok=['user0', 'Completed', '1', '5964',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700178 CLIENT, '2008', 'Priority'],
mblighbe630eb2008-08-01 16:41:48 +0000179 out_words_no=['sleeptest'])
180
181
182 def test_job_list_jobs_name(self):
mbligha212d712009-02-11 01:22:36 +0000183 self.run_cmd(argv=['atest', 'job', 'list', 'myt*',
184 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000185 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700191 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000192 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,
showard2bab8f42008-11-12 18:15:22 +0000197 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000198 u'id': 5964}])],
199 out_words_ok=['user0', 'Completed', '1', '5964'],
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700200 out_words_no=['sleeptest', 'Priority', CLIENT, '2008'])
mblighbe630eb2008-08-01 16:41:48 +0000201
202
203 def test_job_list_jobs_all_verbose(self):
mbligha212d712009-02-11 01:22:36 +0000204 self.run_cmd(argv=['atest', 'job', 'list', '--all', '--verbose',
205 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000206 rpcs=[('get_jobs_summary', {'running': None},
207 True, self.values)],
208 out_words_ok=['Fisto', 'Spikor', 'Cringer', 'Priority',
209 'Created'])
210
211
showard53cb10c2009-05-01 00:09:36 +0000212class job_list_jobs_all_and_user_unittest(cli_mock.cli_unittest):
mblighbe630eb2008-08-01 16:41:48 +0000213 def test_job_list_jobs_all_and_user(self):
214 testjob = job.job_list()
mbligha212d712009-02-11 01:22:36 +0000215 sys.argv = ['atest', 'job', 'list', '-a', '-u', 'user0',
216 '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000217 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000218 (sys.exit.expect_call(mock.anything_comparator())
219 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000220 self.assertRaises(cli_mock.ExitException, testjob.parse)
221 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000222 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000223
224
225class job_stat_unittest(job_unittest):
226 def test_job_stat_job(self):
227 results = copy.deepcopy(self.results)
mbligha212d712009-02-11 01:22:36 +0000228 self.run_cmd(argv=['atest', 'job', 'stat', '180',
229 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000230 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',
mbligh0887d402009-01-30 00:50:29 +0000237 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000238 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000239 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000240 u'id': 4432,
241 u'synch_id': None},
242 u'priority': 1,
243 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000244 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)",
mblighbe630eb2008-08-01 16:41:48 +0000245 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700246 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000247 u'synchronizing': 0,
248 u'priority': u'Medium',
249 u'owner': u'user0',
250 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000251 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000252 u'id': 180},
253 u'active': 0,
254 u'id': 101084}])],
255 out_words_ok=['test_job0', 'host0', 'Failed',
256 'Aborted'])
257
258
mblighfca5ed12009-11-06 02:59:56 +0000259
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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700267 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000268 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700285 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000286 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700306 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000307 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700332 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000333 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700358 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000359 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700381 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000382 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700407 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000408 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700433 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000434 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
mblighbe630eb2008-08-01 16:41:48 +0000448 def test_job_stat_job_multiple_hosts(self):
mbligha212d712009-02-11 01:22:36 +0000449 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
450 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000451 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700456 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000457 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,
showard2bab8f42008-11-12 18:15:22 +0000462 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000463 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700474 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000475 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,
showard2bab8f42008-11-12 18:15:22 +0000480 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000481 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700492 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000493 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,
showard2bab8f42008-11-12 18:15:22 +0000498 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000499 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700510 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000511 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,
showard2bab8f42008-11-12 18:15:22 +0000516 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000517 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700528 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000529 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,
showard2bab8f42008-11-12 18:15:22 +0000534 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000535 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',
mbligh0887d402009-01-30 00:50:29 +0000544 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000545 u'locked_by': None,
mbligh0887d402009-01-30 00:50:29 +0000546 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000547 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700554 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000555 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,
showard2bab8f42008-11-12 18:15:22 +0000560 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000561 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)
mbligha212d712009-02-11 01:22:36 +0000571 self.run_cmd(argv=['atest', 'job', 'stat', '180',
572 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000573 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,
jadmanski8d631c92008-08-18 21:12:40 +0000582 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)",
mblighbe630eb2008-08-01 16:41:48 +0000583 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700584 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000585 u'priority': u'Medium',
586 u'owner': u'user0',
587 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000588 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000589 u'id': 180},
590 u'active': 0,
591 u'id': 101084}])],
mblighfca5ed12009-11-06 02:59:56 +0000592 err_words_ok=['unassigned', 'meta-hosts'])
mblighbe630eb2008-08-01 16:41:48 +0000593
594
595 def test_job_stat_multi_jobs(self):
596 results = copy.deepcopy(self.results)
mbligha212d712009-02-11 01:22:36 +0000597 self.run_cmd(argv=['atest', 'job', 'stat', '180', '338',
598 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000599 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',
mbligh0887d402009-01-30 00:50:29 +0000607 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000608 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000609 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000610 u'id': 4432,
611 u'synch_id': None},
612 u'priority': 1,
613 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000614 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)",
mblighbe630eb2008-08-01 16:41:48 +0000615 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700616 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000617 u'priority': u'Medium',
618 u'owner': u'user0',
619 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000620 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000621 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',
mbligh0887d402009-01-30 00:50:29 +0000627 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000628 u'hostname': u'host10',
mbligh0887d402009-01-30 00:50:29 +0000629 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000630 u'id': 4432,
631 u'synch_id': None},
632 u'priority': 1,
633 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000634 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)",
mblighbe630eb2008-08-01 16:41:48 +0000635 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700636 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000637 u'priority': u'Medium',
638 u'owner': u'user0',
639 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000640 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000641 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):
mbligha212d712009-02-11 01:22:36 +0000648 self.run_cmd(argv=['atest', 'job', 'stat', 'mytest', '180',
649 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000650 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700656 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000657 u'priority':
658 u'Medium',
659 u'owner': u'user0',
660 u'created_on':
661 u'2008-07-08 17:45:44',
showard2bab8f42008-11-12 18:15:22 +0000662 u'synch_count': 2,
mblighbe630eb2008-08-01 16:41:48 +0000663 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700670 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000671 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,
mblighbe630eb2008-08-01 16:41:48 +0000676 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',
mbligh0887d402009-01-30 00:50:29 +0000683 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000684 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000685 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000686 u'id': 4432,
687 u'synch_id': None},
688 u'priority': 1,
689 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000690 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)",
mblighbe630eb2008-08-01 16:41:48 +0000691 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700692 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000693 u'synchronizing': 0,
694 u'priority': u'Medium',
695 u'owner': u'user0',
696 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000697 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000698 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',
mbligh0887d402009-01-30 00:50:29 +0000707 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000708 u'hostname': u'host10',
mbligh0887d402009-01-30 00:50:29 +0000709 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000710 u'id': 4432,
711 u'synch_id': None},
712 u'priority': 1,
713 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000714 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)",
mblighbe630eb2008-08-01 16:41:48 +0000715 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700716 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000717 u'synchronizing': 0,
718 u'priority': u'Medium',
719 u'owner': u'user0',
720 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000721 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000722 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
mbligh120351e2009-01-24 01:40:45 +0000734 trivial_ctrl_file = 'print "Hello"\n'
735
mblighbe630eb2008-08-01 16:41:48 +0000736 data = {'priority': 'Medium', 'control_file': ctrl_file, 'hosts': ['host0'],
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700737 'name': 'test_job0', 'control_type': CLIENT, 'email_list': '',
Dan Shiec1d47d2015-02-13 11:38:13 -0800738 'meta_hosts': [], 'synch_count': 1, 'dependencies': [],
739 'require_ssp': False}
mblighbe630eb2008-08-01 16:41:48 +0000740
741
742 def test_execute_create_job(self):
743 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
mbligha212d712009-02-11 01:22:36 +0000744 'test_job0', '-m', 'host0', '--ignore_site_file'],
showard989f25d2008-10-01 11:38:11 +0000745 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000746 {'tests': ['sleeptest']},
showard989f25d2008-10-01 11:38:11 +0000747 True,
748 {'control_file' : self.ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000749 'synch_count' : 1,
showard989f25d2008-10-01 11:38:11 +0000750 'is_server' : False,
751 'dependencies' : []}),
mblighbe630eb2008-08-01 16:41:48 +0000752 ('create_job', self.data, True, 180)],
753 out_words_ok=['test_job0', 'Created'],
754 out_words_no=['Uploading', 'Done'])
755
756
showard648a35c2009-05-01 00:08:42 +0000757 def test_execute_create_job_with_atomic_group(self):
758 data = dict(self.data)
759 data['atomic_group_name'] = 'my-atomic-group'
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700760 data['control_type'] = SERVER
showard648a35c2009-05-01 00:08:42 +0000761 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
mblighbe630eb2008-08-01 16:41:48 +0000780 def test_execute_create_job_with_control(self):
mbligh41515392009-07-11 00:13:11 +0000781 file_temp = cli_mock.create_file(self.ctrl_file)
782 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000783 'test_job0', '-m', 'host0', '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000784 rpcs=[('create_job', self.data, True, 42)],
785 out_words_ok=['test_job0', 'Created'],
786 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000787 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000788
789
mbligh120351e2009-01-24 01:40:45 +0000790 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.'
mbligh41515392009-07-11 00:13:11 +0000793 file_temp = cli_mock.create_file(self.trivial_ctrl_file)
794 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000795 '-k', 'Kernel', 'test_job0', '-m', 'host0',
796 '--ignore_site_file'],
mbligh120351e2009-01-24 01:40:45 +0000797 rpcs=[('generate_control_file',
798 {'client_control_file': self.trivial_ctrl_file,
mbligha3c58d22009-08-24 22:01:51 +0000799 'kernel': [{'version': 'Kernel'}]},
mbligh120351e2009-01-24 01:40:45 +0000800 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'])
mbligh41515392009-07-11 00:13:11 +0000808 file_temp.clean()
mbligh120351e2009-01-24 01:40:45 +0000809
810
mbligh0a669132008-10-10 20:02:32 +0000811 def test_execute_create_job_with_control_and_email(self):
812 data = self.data.copy()
813 data['email_list'] = 'em'
mbligh41515392009-07-11 00:13:11 +0000814 file_temp = cli_mock.create_file(self.ctrl_file)
815 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000816 'test_job0', '-m', 'host0', '-e', 'em',
817 '--ignore_site_file'],
mbligh0a669132008-10-10 20:02:32 +0000818 rpcs=[('create_job', data, True, 42)],
819 out_words_ok=['test_job0', 'Created'],
820 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000821 file_temp.clean()
mbligh0a669132008-10-10 20:02:32 +0000822
823
showardb27f4ad2009-05-01 00:08:26 +0000824 def test_execute_create_job_with_control_and_dependencies(self):
mbligh0a669132008-10-10 20:02:32 +0000825 data = self.data.copy()
826 data['dependencies'] = ['dep1', 'dep2']
mbligh41515392009-07-11 00:13:11 +0000827 file_temp = cli_mock.create_file(self.ctrl_file)
828 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
showardb27f4ad2009-05-01 00:08:26 +0000829 'test_job0', '-m', 'host0', '-d', 'dep1, dep2 ',
mbligha212d712009-02-11 01:22:36 +0000830 '--ignore_site_file'],
mbligh0a669132008-10-10 20:02:32 +0000831 rpcs=[('create_job', data, True, 42)],
832 out_words_ok=['test_job0', 'Created'],
833 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000834 file_temp.clean()
mbligh0a669132008-10-10 20:02:32 +0000835
836
Eric Li8a12e802011-02-17 14:24:13 -0800837 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
showard7bce1022008-11-14 22:51:05 +0000850 def test_execute_create_job_with_synch_count(self):
851 data = self.data.copy()
852 data['synch_count'] = 2
mbligh41515392009-07-11 00:13:11 +0000853 file_temp = cli_mock.create_file(self.ctrl_file)
854 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000855 'test_job0', '-m', 'host0', '-y', '2',
856 '--ignore_site_file'],
showard7bce1022008-11-14 22:51:05 +0000857 rpcs=[('create_job', data, True, 42)],
858 out_words_ok=['test_job0', 'Created'],
859 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000860 file_temp.clean()
showard7bce1022008-11-14 22:51:05 +0000861
862
showardb27f4ad2009-05-01 00:08:26 +0000863 def test_execute_create_job_with_test_and_dependencies(self):
mblighb9a8b162008-10-29 16:47:29 +0000864 data = self.data.copy()
865 data['dependencies'] = ['dep1', 'dep2', 'dep3']
866 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
showardb27f4ad2009-05-01 00:08:26 +0000867 'test_job0', '-m', 'host0', '-d', 'dep1, dep2 ',
mbligha212d712009-02-11 01:22:36 +0000868 '--ignore_site_file'],
mblighb9a8b162008-10-29 16:47:29 +0000869 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000870 {'tests': ['sleeptest']},
mblighb9a8b162008-10-29 16:47:29 +0000871 True,
872 {'control_file' : self.ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000873 'synch_count' : 1,
mblighb9a8b162008-10-29 16:47:29 +0000874 '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
Eric Li8a12e802011-02-17 14:24:13 -0800881 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
mblighbe630eb2008-08-01 16:41:48 +0000899 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',
mbligha212d712009-02-11 01:22:36 +0000903 '-k', 'kernel', 'test_job0', '-m', 'host0',
904 '--ignore_site_file'],
showard989f25d2008-10-01 11:38:11 +0000905 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000906 {'tests': ['sleeptest'],
Dale Curtis74a314b2011-06-23 14:55:46 -0700907 'kernel': [{'version': 'kernel'}]
908 },
mbligha3c58d22009-08-24 22:01:51 +0000909 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',
Dale Curtis74a314b2011-06-23 14:55:46 -0700931 'cmdline': 'arg1 arg2'}]
932 },
showard989f25d2008-10-01 11:38:11 +0000933 True,
934 {'control_file' : self.kernel_ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000935 'synch_count' : 1,
showard989f25d2008-10-01 11:38:11 +0000936 'is_server' : False,
937 'dependencies' : []}),
mblighbe630eb2008-08-01 16:41:48 +0000938 ('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',
mbligha212d712009-02-11 01:22:36 +0000949 '-m', 'host0', '--ignore_site_file'],
showard989f25d2008-10-01 11:38:11 +0000950 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000951 {'tests': ['sleeptest'],
Dale Curtis74a314b2011-06-23 14:55:46 -0700952 'kernel': [{'version': 'kernel'}]
953 },
showard989f25d2008-10-01 11:38:11 +0000954 True,
955 {'control_file' : self.kernel_ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000956 'synch_count' : 1,
showard989f25d2008-10-01 11:38:11 +0000957 'is_server' : False,
958 'dependencies' : []}),
mblighbe630eb2008-08-01 16:41:48 +0000959 ('create_job', data, True, 180)],
mblighc6133172009-09-18 19:34:50 +0000960 # 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'])
mblighbe630eb2008-08-01 16:41:48 +0000967
968
969 def test_execute_create_job_no_args(self):
970 testjob = job.job_create()
mbligha212d712009-02-11 01:22:36 +0000971 sys.argv = ['atest', 'job', 'create', '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000972 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000973 (sys.exit.expect_call(mock.anything_comparator())
974 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000975 self.assertRaises(cli_mock.ExitException, testjob.parse)
976 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000977 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000978
979
980 def test_execute_create_job_no_hosts(self):
981 testjob = job.job_create()
mbligh41515392009-07-11 00:13:11 +0000982 file_temp = cli_mock.create_file(self.ctrl_file)
983 sys.argv = ['atest', '-f', file_temp.name, 'test_job0',
984 '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000985 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000986 (sys.exit.expect_call(mock.anything_comparator())
987 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000988 self.assertRaises(cli_mock.ExitException, testjob.parse)
989 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000990 self.god.check_playback()
mbligh41515392009-07-11 00:13:11 +0000991 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000992
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',
mbligha212d712009-02-11 01:22:36 +0000997 'control_file', 'test_job0', '-m', 'host0',
998 '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000999 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +00001000 (sys.exit.expect_call(mock.anything_comparator())
1001 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +00001002 self.assertRaises(cli_mock.ExitException, testjob.parse)
1003 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +00001004 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +00001005
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',
mbligha212d712009-02-11 01:22:36 +00001010 'kernel', 'test_job0', '-m', 'host0', '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +00001011 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +00001012 (sys.exit.expect_call(mock.anything_comparator())
1013 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +00001014 self.assertRaises(cli_mock.ExitException, testjob.parse)
1015 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +00001016 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +00001017
1018
1019 def test_execute_create_job_bad_cfile(self):
1020 testjob = job.job_create()
mbligha212d712009-02-11 01:22:36 +00001021 sys.argv = ['atest', 'job', 'create', '-f', 'control_file',
1022 'test_job0', '-m', 'host0', '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +00001023 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +00001024 (sys.exit.expect_call(mock.anything_comparator())
1025 .and_raises(IOError))
mblighbe630eb2008-08-01 16:41:48 +00001026 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',
mbligha212d712009-02-11 01:22:36 +00001033 '-m', 'host0', 'test_job0', '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +00001034 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +00001035 (sys.exit.expect_call(mock.anything_comparator())
1036 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +00001037 self.assertRaises(cli_mock.ExitException, testjob.parse)
1038 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +00001039 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +00001040
1041
1042 def test_execute_create_job_with_mfile(self):
1043 data = self.data.copy()
1044 data['hosts'] = ['host3', 'host2', 'host1', 'host0']
mbligh41515392009-07-11 00:13:11 +00001045 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'],
mblighbe630eb2008-08-01 16:41:48 +00001049 rpcs=[('create_job', data, True, 42)],
1050 out_words_ok=['test_job0', 'Created'])
mbligh41515392009-07-11 00:13:11 +00001051 ctemp.clean()
1052 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +00001053
1054
mbligh5d0b4b32008-12-22 14:43:01 +00001055 def test_execute_create_job_with_timeout(self):
1056 data = self.data.copy()
Simran Basi7e605742013-11-12 13:43:36 -08001057 data['timeout_mins'] = '13320'
mbligh41515392009-07-11 00:13:11 +00001058 file_temp = cli_mock.create_file(self.ctrl_file)
1059 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Simran Basi7e605742013-11-12 13:43:36 -08001060 'test_job0', '-m', 'host0', '-o', '13320',
mbligha212d712009-02-11 01:22:36 +00001061 '--ignore_site_file'],
mbligh5d0b4b32008-12-22 14:43:01 +00001062 rpcs=[('create_job', data, True, 42)],
1063 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +00001064 file_temp.clean()
mbligh5d0b4b32008-12-22 14:43:01 +00001065
1066
showard12f3e322009-05-13 21:27:42 +00001067 def test_execute_create_job_with_max_runtime(self):
1068 data = self.data.copy()
Simran Basi34217022012-11-06 13:43:15 -08001069 data['max_runtime_mins'] = '13320'
mbligh41515392009-07-11 00:13:11 +00001070 file_temp = cli_mock.create_file(self.ctrl_file)
1071 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Simran Basi34217022012-11-06 13:43:15 -08001072 'test_job0', '-m', 'host0', '--max_runtime',
1073 '13320', '--ignore_site_file'],
showard12f3e322009-05-13 21:27:42 +00001074 rpcs=[('create_job', data, True, 42)],
1075 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +00001076 file_temp.clean()
showard12f3e322009-05-13 21:27:42 +00001077
1078
1079
mbligh5d0b4b32008-12-22 14:43:01 +00001080 def test_execute_create_job_with_noverify(self):
1081 data = self.data.copy()
1082 data['run_verify'] = False
mbligh41515392009-07-11 00:13:11 +00001083 file_temp = cli_mock.create_file(self.ctrl_file)
1084 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +00001085 'test_job0', '-m', 'host0', '-n',
1086 '--ignore_site_file'],
mbligh5d0b4b32008-12-22 14:43:01 +00001087 rpcs=[('create_job', data, True, 42)],
1088 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +00001089 file_temp.clean()
mbligh5d0b4b32008-12-22 14:43:01 +00001090
1091
mblighce348642009-02-12 21:50:39 +00001092 def test_execute_create_job_oth(self):
1093 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +00001094 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +00001095 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()
mblighad575162010-03-24 22:14:18 +00001112 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +00001113 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()
mblighad575162010-03-24 22:14:18 +00001130 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +00001131 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
showardb27f4ad2009-05-01 00:08:26 +00001150 def test_execute_create_job_with_control_and_labels(self):
1151 data = self.data.copy()
1152 data['hosts'] = ['host0', 'host1', 'host2']
mbligh41515392009-07-11 00:13:11 +00001153 file_temp = cli_mock.create_file(self.ctrl_file)
1154 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
showardb27f4ad2009-05-01 00:08:26 +00001155 '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'])
mbligh41515392009-07-11 00:13:11 +00001176 file_temp.clean()
showardb27f4ad2009-05-01 00:08:26 +00001177
1178
1179 def test_execute_create_job_with_label_and_duplicate_hosts(self):
1180 data = self.data.copy()
1181 data['hosts'] = ['host1', 'host0']
mbligh41515392009-07-11 00:13:11 +00001182 file_temp = cli_mock.create_file(self.ctrl_file)
1183 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
showardb27f4ad2009-05-01 00:08:26 +00001184 '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'])
mbligh41515392009-07-11 00:13:11 +00001197 file_temp.clean()
showardb27f4ad2009-05-01 00:08:26 +00001198
1199
jamesrenc2863162010-07-12 21:20:51 +00001200 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
mblighbe630eb2008-08-01 16:41:48 +00001244 def _test_parse_hosts(self, args, exp_hosts=[], exp_meta_hosts=[]):
mbligh56f1f4a2009-08-03 16:45:12 +00001245 testjob = job.job_create_or_clone()
1246 (hosts, meta_hosts) = testjob._parse_hosts(args)
mblighbe630eb2008-08-01 16:41:48 +00001247 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
mbligh5a496082009-08-03 16:44:54 +00001278class 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001280 'control_type': SERVER,
mbligh5a496082009-08-03 16:44:54 +00001281 'dependencies': [],
1282 'email_list': u'',
Simran Basi34217022012-11-06 13:43:15 -08001283 'max_runtime_mins': 28800,
mbligh5a496082009-08-03 16:44:54 +00001284 '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,
Simran Basi7e605742013-11-12 13:43:36 -08001290 'timeout_mins': 480}
mbligh5a496082009-08-03 16:44:54 +00001291
mbligh56f1f4a2009-08-03 16:45:12 +00001292 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
mbligh5a496082009-08-03 16:44:54 +00001326 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):
mbligh56f1f4a2009-08-03 16:45:12 +00001370 self.job_data_cloned['hosts'] = [u'host0', 'host1']
mbligh5a496082009-08-03 16:44:54 +00001371 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,
mbligh56f1f4a2009-08-03 16:45:12 +00001377 u'hosts': self.local_hosts,
mbligh5a496082009-08-03 16:44:54 +00001378 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
mbligh56f1f4a2009-08-03 16:45:12 +00001384 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
mbligh5a496082009-08-03 16:44:54 +00001418 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
mbligh56f1f4a2009-08-03 16:45:12 +00001425 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'])
mbligh5a496082009-08-03 16:44:54 +00001462
1463
mblighbe630eb2008-08-01 16:41:48 +00001464class 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',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001467 u'control_type': SERVER, u'priority':
mblighbe630eb2008-08-01 16:41:48 +00001468 u'Medium', u'owner': u'user0', u'created_on':
showard2bab8f42008-11-12 18:15:22 +00001469 u'2008-07-08 17:45:44', u'synch_count': 2, u'id': 180}]
mblighbe630eb2008-08-01 16:41:48 +00001470
1471 def test_execute_job_abort(self):
mbligha212d712009-02-11 01:22:36 +00001472 self.run_cmd(argv=['atest', 'job', 'abort', '180',
1473 '--ignore_site_file'],
mbligh206d50a2008-11-13 01:19:25 +00001474 rpcs=[('abort_host_queue_entries',
1475 {'job__id__in': ['180']}, True, None)],
1476 out_words_ok=['Aborting', '180'])
mblighbe630eb2008-08-01 16:41:48 +00001477
1478
1479if __name__ == '__main__':
1480 unittest.main()