blob: d0240e51b1dd6ba83149f72eb77182b1467c475b [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
mblighbe630eb2008-08-01 16:41:48 +000013
14
15class job_unittest(cli_mock.cli_unittest):
16 def setUp(self):
17 super(job_unittest, self).setUp()
mblighbe630eb2008-08-01 16:41:48 +000018 self.values = copy.deepcopy(self.values_template)
19
20 results = [{u'status_counts': {u'Aborted': 1},
21 u'control_file':
22 u"job.run_test('sleeptest')\n",
23 u'name': u'test_job0',
24 u'control_type': u'Server',
mblighbe630eb2008-08-01 16:41:48 +000025 u'priority':
26 u'Medium',
27 u'owner': u'user0',
28 u'created_on':
29 u'2008-07-08 17:45:44',
showard2bab8f42008-11-12 18:15:22 +000030 u'synch_count': 2,
mblighbe630eb2008-08-01 16:41:48 +000031 u'id': 180},
32 {u'status_counts': {u'Queued': 1},
33 u'control_file':
34 u"job.run_test('sleeptest')\n",
35 u'name': u'test_job1',
36 u'control_type': u'Client',
mblighbe630eb2008-08-01 16:41:48 +000037 u'priority':
38 u'High',
39 u'owner': u'user0',
40 u'created_on':
41 u'2008-07-08 12:17:47',
42 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +000043 u'id': 338}]
44
45
46 values_template = [{u'id': 180, # Valid job
47 u'priority': u'Low',
48 u'name': u'test_job0',
49 u'owner': u'Cringer',
mbligh0887d402009-01-30 00:50:29 +000050 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +000051 u'created_on': u'2008-07-02 13:02:40',
52 u'control_type': u'Server',
53 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000054 u'synch_count': 2},
mblighbe630eb2008-08-01 16:41:48 +000055 {u'id': 338, # Valid job
56 u'priority': 'High',
57 u'name': u'test_job1',
58 u'owner': u'Fisto',
mbligh0887d402009-01-30 00:50:29 +000059 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +000060 u'created_on': u'2008-07-06 14:05:33',
61 u'control_type': u'Client',
62 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000063 u'synch_count': 1},
mblighbe630eb2008-08-01 16:41:48 +000064 {u'id': 339, # Valid job
65 u'priority': 'Medium',
66 u'name': u'test_job2',
67 u'owner': u'Roboto',
mbligh0887d402009-01-30 00:50:29 +000068 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +000069 u'created_on': u'2008-07-07 15:33:18',
70 u'control_type': u'Server',
71 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000072 u'synch_count': 1},
mblighbe630eb2008-08-01 16:41:48 +000073 {u'id': 340, # Invalid job priority
74 u'priority': u'Uber',
75 u'name': u'test_job3',
76 u'owner': u'Panthor',
mbligh0887d402009-01-30 00:50:29 +000077 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +000078 u'created_on': u'2008-07-04 00:00:01',
79 u'control_type': u'Server',
80 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000081 u'synch_count': 2},
mblighbe630eb2008-08-01 16:41:48 +000082 {u'id': 350, # Invalid job created_on
83 u'priority': 'Medium',
84 u'name': u'test_job4',
85 u'owner': u'Icer',
mbligh0887d402009-01-30 00:50:29 +000086 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +000087 u'created_on': u'Today',
88 u'control_type': u'Client',
89 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000090 u'synch_count': 1},
mblighbe630eb2008-08-01 16:41:48 +000091 {u'id': 420, # Invalid job control_type
92 u'priority': 'Urgent',
93 u'name': u'test_job5',
94 u'owner': u'Spikor',
mbligh0887d402009-01-30 00:50:29 +000095 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +000096 u'created_on': u'2012-08-08 18:54:37',
97 u'control_type': u'Child',
98 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000099 u'synch_count': 2}]
mblighbe630eb2008-08-01 16:41:48 +0000100
101
102class job_list_unittest(job_unittest):
103 def test_job_list_jobs(self):
showardf4a68992010-02-03 20:29:59 +0000104 self.god.stub_function(getpass, 'getuser')
mblighbe630eb2008-08-01 16:41:48 +0000105 getpass.getuser.expect_call().and_return('user0')
mbligha212d712009-02-11 01:22:36 +0000106 self.run_cmd(argv=['atest', 'job', 'list', '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000107 rpcs=[('get_jobs_summary', {'owner': 'user0',
108 'running': None},
109 True, self.values)],
110 out_words_ok=['test_job0', 'test_job1', 'test_job2'],
111 out_words_no=['Uber', 'Today', 'Child'])
112
113
114 def test_job_list_jobs_only_user(self):
115 values = [item for item in self.values if item['owner'] == 'Cringer']
mbligha212d712009-02-11 01:22:36 +0000116 self.run_cmd(argv=['atest', 'job', 'list', '-u', 'Cringer',
117 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000118 rpcs=[('get_jobs_summary', {'owner': 'Cringer',
119 'running': None},
120 True, values)],
121 out_words_ok=['Cringer'],
122 out_words_no=['Fisto', 'Roboto', 'Panthor', 'Icer',
123 'Spikor'])
124
125
126 def test_job_list_jobs_all(self):
mbligha212d712009-02-11 01:22:36 +0000127 self.run_cmd(argv=['atest', 'job', 'list', '--all',
128 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000129 rpcs=[('get_jobs_summary', {'running': None},
130 True, self.values)],
131 out_words_ok=['Fisto', 'Roboto', 'Panthor',
132 'Icer', 'Spikor', 'Cringer'],
133 out_words_no=['Created', 'Priority'])
134
135
136 def test_job_list_jobs_id(self):
mbligha212d712009-02-11 01:22:36 +0000137 self.run_cmd(argv=['atest', 'job', 'list', '5964',
138 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000139 rpcs=[('get_jobs_summary', {'id__in': ['5964'],
140 'running': None},
141 True,
142 [{u'status_counts': {u'Completed': 1},
143 u'control_file': u'kernel = \'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\'\ndef step_init():\n job.next_step([step_test])\n testkernel = job.kernel(\'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\')\n \n testkernel.install()\n testkernel.boot(args=\'console_always_print=1\')\n\ndef step_test():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME = "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1 second by default. It\'s a good way to test\n profilers and double check that autotest is working.\n The seconds argument can also be modified to make the machine sleep for as\n long as needed.\n """\n \n job.run_test(\'sleeptest\', seconds = 1)',
144 u'name': u'mytest',
145 u'control_type': u'Client',
mblighbe630eb2008-08-01 16:41:48 +0000146 u'run_verify': 1,
147 u'priority': u'Medium',
148 u'owner': u'user0',
149 u'created_on': u'2008-07-28 12:42:52',
150 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000151 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000152 u'id': 5964}])],
153 out_words_ok=['user0', 'Completed', '1', '5964'],
154 out_words_no=['sleeptest', 'Priority', 'Client', '2008'])
155
156
157 def test_job_list_jobs_id_verbose(self):
mbligha212d712009-02-11 01:22:36 +0000158 self.run_cmd(argv=['atest', 'job', 'list', '5964', '-v',
159 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000160 rpcs=[('get_jobs_summary', {'id__in': ['5964'],
161 'running': None},
162 True,
163 [{u'status_counts': {u'Completed': 1},
164 u'control_file': u'kernel = \'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\'\ndef step_init():\n job.next_step([step_test])\n testkernel = job.kernel(\'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\')\n \n testkernel.install()\n testkernel.boot(args=\'console_always_print=1\')\n\ndef step_test():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME = "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1 second by default. It\'s a good way to test\n profilers and double check that autotest is working.\n The seconds argument can also be modified to make the machine sleep for as\n long as needed.\n """\n \n job.run_test(\'sleeptest\', seconds = 1)',
165 u'name': u'mytest',
166 u'control_type': u'Client',
mblighbe630eb2008-08-01 16:41:48 +0000167 u'run_verify': 1,
168 u'priority': u'Medium',
169 u'owner': u'user0',
170 u'created_on': u'2008-07-28 12:42:52',
171 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000172 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000173 u'id': 5964}])],
174 out_words_ok=['user0', 'Completed', '1', '5964',
175 'Client', '2008', 'Priority'],
176 out_words_no=['sleeptest'])
177
178
179 def test_job_list_jobs_name(self):
mbligha212d712009-02-11 01:22:36 +0000180 self.run_cmd(argv=['atest', 'job', 'list', 'myt*',
181 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000182 rpcs=[('get_jobs_summary', {'name__startswith': 'myt',
183 'running': None},
184 True,
185 [{u'status_counts': {u'Completed': 1},
186 u'control_file': u'kernel = \'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\'\ndef step_init():\n job.next_step([step_test])\n testkernel = job.kernel(\'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\')\n \n testkernel.install()\n testkernel.boot(args=\'console_always_print=1\')\n\ndef step_test():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME = "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1 second by default. It\'s a good way to test\n profilers and double check that autotest is working.\n The seconds argument can also be modified to make the machine sleep for as\n long as needed.\n """\n \n job.run_test(\'sleeptest\', seconds = 1)',
187 u'name': u'mytest',
188 u'control_type': u'Client',
mblighbe630eb2008-08-01 16:41:48 +0000189 u'run_verify': 1,
190 u'priority': u'Medium',
191 u'owner': u'user0',
192 u'created_on': u'2008-07-28 12:42:52',
193 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000194 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000195 u'id': 5964}])],
196 out_words_ok=['user0', 'Completed', '1', '5964'],
197 out_words_no=['sleeptest', 'Priority', 'Client', '2008'])
198
199
200 def test_job_list_jobs_all_verbose(self):
mbligha212d712009-02-11 01:22:36 +0000201 self.run_cmd(argv=['atest', 'job', 'list', '--all', '--verbose',
202 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000203 rpcs=[('get_jobs_summary', {'running': None},
204 True, self.values)],
205 out_words_ok=['Fisto', 'Spikor', 'Cringer', 'Priority',
206 'Created'])
207
208
showard53cb10c2009-05-01 00:09:36 +0000209class job_list_jobs_all_and_user_unittest(cli_mock.cli_unittest):
mblighbe630eb2008-08-01 16:41:48 +0000210 def test_job_list_jobs_all_and_user(self):
211 testjob = job.job_list()
mbligha212d712009-02-11 01:22:36 +0000212 sys.argv = ['atest', 'job', 'list', '-a', '-u', 'user0',
213 '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000214 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000215 (sys.exit.expect_call(mock.anything_comparator())
216 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000217 self.assertRaises(cli_mock.ExitException, testjob.parse)
218 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000219 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000220
221
222class job_stat_unittest(job_unittest):
223 def test_job_stat_job(self):
224 results = copy.deepcopy(self.results)
mbligha212d712009-02-11 01:22:36 +0000225 self.run_cmd(argv=['atest', 'job', 'stat', '180',
226 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000227 rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,
228 [results[0]]),
229 ('get_host_queue_entries', {'job__in': ['180']},
230 True,
231 [{u'status': u'Failed',
232 u'complete': 1,
233 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000234 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000235 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000236 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000237 u'id': 4432,
238 u'synch_id': None},
239 u'priority': 1,
240 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000241 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 +0000242 u'name': u'test_sleep',
243 u'control_type': u'Server',
244 u'synchronizing': 0,
245 u'priority': u'Medium',
246 u'owner': u'user0',
247 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000248 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000249 u'id': 180},
250 u'active': 0,
251 u'id': 101084}])],
252 out_words_ok=['test_job0', 'host0', 'Failed',
253 'Aborted'])
254
255
mblighfca5ed12009-11-06 02:59:56 +0000256
257 def test_job_stat_list_unassigned_host(self):
258 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
259 '--list-hosts', '--ignore_site_file'],
260 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
261 [{u'status_counts': {u'Queued': 1},
262 u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
263 u'name': u'test_on_meta_hosts',
264 u'control_type': u'Client',
265 u'run_verify': 1,
266 u'priority': u'Medium',
267 u'owner': u'user0',
268 u'created_on': u'2008-07-30 22:15:43',
269 u'timeout': 144,
270 u'synch_count': 1,
271 u'id': 6761}]),
272 ('get_host_queue_entries', {'job__in': ['6761']},
273 True,
274 [{u'status': u'Queued',
275 u'complete': 0,
276 u'deleted': 0,
277 u'host': None,
278 u'priority': 1,
279 u'meta_host': u'Xeon',
280 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
281 u'name': u'test_on_meta_hosts',
282 u'control_type': u'Client',
283 u'run_verify': 1,
284 u'priority': u'Medium',
285 u'owner': u'user0',
286 u'created_on': u'2008-07-30 22:15:43',
287 u'timeout': 144,
288 u'synch_count': 1,
289 u'id': 6761},
290 u'active': 0,
291 u'id': 193166} ])],
292 err_words_ok=['unassigned', 'meta-hosts'],
293 out_words_no=['Xeon'])
294
295
296 def test_job_stat_list_hosts(self):
297 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
298 '--list-hosts', '--ignore_site_file'],
299 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
300 [{u'status_counts': {u'Queued': 1},
301 u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
302 u'name': u'test_on_meta_hosts',
303 u'control_type': u'Client',
304 u'run_verify': 1,
305 u'priority': u'Medium',
306 u'owner': u'user0',
307 u'created_on': u'2008-07-30 22:15:43',
308 u'timeout': 144,
309 u'synch_count': 1,
310 u'id': 6761}]),
311 ('get_host_queue_entries', {'job__in': ['6761']},
312 True,
313 [{u'status': u'Queued',
314 u'complete': 0,
315 u'deleted': 0,
316 u'host': {u'status': u'Running',
317 u'lock_time': None,
318 u'hostname': u'host41',
319 u'locked': False,
320 u'locked_by': None,
321 u'invalid': False,
322 u'id': 4833,
323 u'protection': u'Repair filesystem only',
324 u'synch_id': None},
325 u'priority': 1,
326 u'meta_host': u'Xeon',
327 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
328 u'name': u'test_on_meta_hosts',
329 u'control_type': u'Client',
330 u'run_verify': 1,
331 u'priority': u'Medium',
332 u'owner': u'user0',
333 u'created_on': u'2008-07-30 22:15:43',
334 u'timeout': 144,
335 u'synch_count': 1,
336 u'id': 6761},
337 u'active': 0,
338 u'id': 193166},
339 {u'status': u'Running',
340 u'complete': 0,
341 u'deleted': 0,
342 u'host': {u'status': u'Running',
343 u'lock_time': None,
344 u'hostname': u'host42',
345 u'locked': False,
346 u'locked_by': None,
347 u'invalid': False,
348 u'id': 4833,
349 u'protection': u'Repair filesystem only',
350 u'synch_id': None},
351 u'priority': 1,
352 u'meta_host': u'Xeon',
353 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
354 u'name': u'test_on_meta_hosts',
355 u'control_type': u'Client',
356 u'run_verify': 1,
357 u'priority': u'Medium',
358 u'owner': u'user0',
359 u'created_on': u'2008-07-30 22:15:43',
360 u'timeout': 144,
361 u'synch_count': 1,
362 u'id': 6761},
363 u'active': 0,
364 u'id': 193166} ])],
365 out_words_ok=['host41', 'host42'],
366 out_words_no=['Xeon', 'Running', 'Queued'],
367 err_words_no=['unassigned'])
368
369
370 def test_job_stat_list_hosts_status(self):
371 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
372 '--list-hosts-status', 'Running,Queued',
373 '--ignore_site_file'],
374 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
375 [{u'status_counts': {u'Queued': 1, u'Running': 1},
376 u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
377 u'name': u'test',
378 u'control_type': u'Client',
379 u'run_verify': 1,
380 u'priority': u'Medium',
381 u'owner': u'user0',
382 u'created_on': u'2008-07-30 22:15:43',
383 u'timeout': 144,
384 u'synch_count': 1,
385 u'id': 6761}]),
386 ('get_host_queue_entries', {'job__in': ['6761']},
387 True,
388 [{u'status': u'Queued',
389 u'complete': 0,
390 u'deleted': 0,
391 u'host': {u'status': u'Queued',
392 u'lock_time': None,
393 u'hostname': u'host41',
394 u'locked': False,
395 u'locked_by': None,
396 u'invalid': False,
397 u'id': 4833,
398 u'protection': u'Repair filesystem only',
399 u'synch_id': None},
400 u'priority': 1,
401 u'meta_host': None,
402 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
403 u'name': u'test',
404 u'control_type': u'Client',
405 u'run_verify': 1,
406 u'priority': u'Medium',
407 u'owner': u'user0',
408 u'created_on': u'2008-07-30 22:15:43',
409 u'timeout': 144,
410 u'synch_count': 1,
411 u'id': 6761},
412 u'active': 0,
413 u'id': 193166},
414 {u'status': u'Running',
415 u'complete': 0,
416 u'deleted': 0,
417 u'host': {u'status': u'Running',
418 u'lock_time': None,
419 u'hostname': u'host42',
420 u'locked': False,
421 u'locked_by': None,
422 u'invalid': False,
423 u'id': 4833,
424 u'protection': u'Repair filesystem only',
425 u'synch_id': None},
426 u'priority': 1,
427 u'meta_host': None,
428 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
429 u'name': u'test',
430 u'control_type': u'Client',
431 u'run_verify': 1,
432 u'priority': u'Medium',
433 u'owner': u'user0',
434 u'created_on': u'2008-07-30 22:15:43',
435 u'timeout': 144,
436 u'synch_count': 1,
437 u'id': 6761},
438 u'active': 0,
439 u'id': 193166} ])],
440 out_words_ok=['Queued', 'Running', 'host41', 'host42'],
441 out_words_no=['Xeon'],
442 err_words_no=['unassigned'])
443
444
mblighbe630eb2008-08-01 16:41:48 +0000445 def test_job_stat_job_multiple_hosts(self):
mbligha212d712009-02-11 01:22:36 +0000446 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
447 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000448 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
449 [{u'status_counts': {u'Running': 1,
450 u'Queued': 4},
451 u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
452 u'name': u'test_on_meta_hosts',
453 u'control_type': u'Client',
mblighbe630eb2008-08-01 16:41:48 +0000454 u'run_verify': 1,
455 u'priority': u'Medium',
456 u'owner': u'user0',
457 u'created_on': u'2008-07-30 22:15:43',
458 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000459 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000460 u'id': 6761}]),
461 ('get_host_queue_entries', {'job__in': ['6761']},
462 True,
463 [{u'status': u'Queued',
464 u'complete': 0,
465 u'deleted': 0,
466 u'host': None,
467 u'priority': 1,
468 u'meta_host': u'Xeon',
469 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
470 u'name': u'test_on_meta_hosts',
471 u'control_type': u'Client',
mblighbe630eb2008-08-01 16:41:48 +0000472 u'run_verify': 1,
473 u'priority': u'Medium',
474 u'owner': u'user0',
475 u'created_on': u'2008-07-30 22:15:43',
476 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000477 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000478 u'id': 6761},
479 u'active': 0,
480 u'id': 193166},
481 {u'status': u'Queued',
482 u'complete': 0,
483 u'deleted': 0,
484 u'host': None,
485 u'priority': 1,
486 u'meta_host': u'Xeon',
487 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
488 u'name': u'test_on_meta_hosts',
489 u'control_type': u'Client',
mblighbe630eb2008-08-01 16:41:48 +0000490 u'run_verify': 1,
491 u'priority': u'Medium',
492 u'owner': u'user0',
493 u'created_on': u'2008-07-30 22:15:43',
494 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000495 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000496 u'id': 6761},
497 u'active': 0,
498 u'id': 193167},
499 {u'status': u'Queued',
500 u'complete': 0,
501 u'deleted': 0,
502 u'host': None,
503 u'priority': 1,
504 u'meta_host': u'Athlon',
505 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
506 u'name': u'test_on_meta_hosts',
507 u'control_type': u'Client',
mblighbe630eb2008-08-01 16:41:48 +0000508 u'run_verify': 1,
509 u'priority': u'Medium',
510 u'owner': u'user0',
511 u'created_on': u'2008-07-30 22:15:43',
512 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000513 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000514 u'id': 6761},
515 u'active': 0,
516 u'id': 193168},
517 {u'status': u'Queued',
518 u'complete': 0,
519 u'deleted': 0,
520 u'host': None,
521 u'priority': 1,
522 u'meta_host': u'x286',
523 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
524 u'name': u'test_on_meta_hosts',
525 u'control_type': u'Client',
mblighbe630eb2008-08-01 16:41:48 +0000526 u'run_verify': 1,
527 u'priority': u'Medium',
528 u'owner': u'user0',
529 u'created_on': u'2008-07-30 22:15:43',
530 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000531 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000532 u'id': 6761},
533 u'active': 0,
534 u'id': 193169},
535 {u'status': u'Running',
536 u'complete': 0,
537 u'deleted': 0,
538 u'host': {u'status': u'Running',
539 u'lock_time': None,
540 u'hostname': u'host42',
mbligh0887d402009-01-30 00:50:29 +0000541 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000542 u'locked_by': None,
mbligh0887d402009-01-30 00:50:29 +0000543 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000544 u'id': 4833,
545 u'protection': u'Repair filesystem only',
546 u'synch_id': None},
547 u'priority': 1,
548 u'meta_host': u'Athlon',
549 u'job': {u'control_file': u'def step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "mbligh@google.com (Martin Bligh)"\n NAME = "Kernbench"\n TIME = "SHORT"\n TEST_CLASS = "Kernel"\n TEST_CATEGORY = "Benchmark"\n TEST_TYPE = "client"\n \n DOC = """\n A standard CPU benchmark. Runs a kernel compile and measures the performance.\n """\n \n job.run_test(\'kernbench\')',
550 u'name': u'test_on_meta_hosts',
551 u'control_type': u'Client',
mblighbe630eb2008-08-01 16:41:48 +0000552 u'run_verify': 1,
553 u'priority': u'Medium',
554 u'owner': u'user0',
555 u'created_on': u'2008-07-30 22:15:43',
556 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000557 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000558 u'id': 6761},
559 u'active': 1,
560 u'id': 193170} ])],
561 out_words_ok=['test_on_meta_hosts',
562 'host42', 'Queued', 'Running'],
563 out_words_no=['Athlon', 'Xeon', 'x286'])
564
565
566 def test_job_stat_job_no_host_in_qes(self):
567 results = copy.deepcopy(self.results)
mbligha212d712009-02-11 01:22:36 +0000568 self.run_cmd(argv=['atest', 'job', 'stat', '180',
569 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000570 rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,
571 [results[0]]),
572 ('get_host_queue_entries', {'job__in': ['180']},
573 True,
574 [{u'status': u'Failed',
575 u'complete': 1,
576 u'host': None,
577 u'priority': 1,
578 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000579 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 +0000580 u'name': u'test_sleep',
581 u'control_type': u'Server',
mblighbe630eb2008-08-01 16:41:48 +0000582 u'priority': u'Medium',
583 u'owner': u'user0',
584 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000585 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000586 u'id': 180},
587 u'active': 0,
588 u'id': 101084}])],
mblighfca5ed12009-11-06 02:59:56 +0000589 err_words_ok=['unassigned', 'meta-hosts'])
mblighbe630eb2008-08-01 16:41:48 +0000590
591
592 def test_job_stat_multi_jobs(self):
593 results = copy.deepcopy(self.results)
mbligha212d712009-02-11 01:22:36 +0000594 self.run_cmd(argv=['atest', 'job', 'stat', '180', '338',
595 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000596 rpcs=[('get_jobs_summary', {'id__in': ['180', '338']},
597 True, results),
598 ('get_host_queue_entries',
599 {'job__in': ['180', '338']},
600 True,
601 [{u'status': u'Failed',
602 u'complete': 1,
603 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000604 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000605 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000606 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000607 u'id': 4432,
608 u'synch_id': None},
609 u'priority': 1,
610 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000611 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 +0000612 u'name': u'test_sleep',
613 u'control_type': u'Server',
mblighbe630eb2008-08-01 16:41:48 +0000614 u'priority': u'Medium',
615 u'owner': u'user0',
616 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000617 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000618 u'id': 180},
619 u'active': 0,
620 u'id': 101084},
621 {u'status': u'Failed',
622 u'complete': 1,
623 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000624 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000625 u'hostname': u'host10',
mbligh0887d402009-01-30 00:50:29 +0000626 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000627 u'id': 4432,
628 u'synch_id': None},
629 u'priority': 1,
630 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000631 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 +0000632 u'name': u'test_sleep',
633 u'control_type': u'Server',
mblighbe630eb2008-08-01 16:41:48 +0000634 u'priority': u'Medium',
635 u'owner': u'user0',
636 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000637 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000638 u'id': 338},
639 u'active': 0,
640 u'id': 101084}])],
641 out_words_ok=['test_job0', 'test_job1'])
642
643
644 def test_job_stat_multi_jobs_name_id(self):
mbligha212d712009-02-11 01:22:36 +0000645 self.run_cmd(argv=['atest', 'job', 'stat', 'mytest', '180',
646 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000647 rpcs=[('get_jobs_summary', {'id__in': ['180']},
648 True,
649 [{u'status_counts': {u'Aborted': 1},
650 u'control_file':
651 u"job.run_test('sleeptest')\n",
652 u'name': u'job0',
653 u'control_type': u'Server',
mblighbe630eb2008-08-01 16:41:48 +0000654 u'priority':
655 u'Medium',
656 u'owner': u'user0',
657 u'created_on':
658 u'2008-07-08 17:45:44',
showard2bab8f42008-11-12 18:15:22 +0000659 u'synch_count': 2,
mblighbe630eb2008-08-01 16:41:48 +0000660 u'id': 180}]),
661 ('get_jobs_summary', {'name__in': ['mytest']},
662 True,
663 [{u'status_counts': {u'Queued': 1},
664 u'control_file':
665 u"job.run_test('sleeptest')\n",
666 u'name': u'mytest',
667 u'control_type': u'Client',
mblighbe630eb2008-08-01 16:41:48 +0000668 u'priority':
669 u'High',
670 u'owner': u'user0',
671 u'created_on': u'2008-07-08 12:17:47',
672 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000673 u'id': 338}]),
674 ('get_host_queue_entries',
675 {'job__in': ['180']},
676 True,
677 [{u'status': u'Failed',
678 u'complete': 1,
679 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000680 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000681 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000682 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000683 u'id': 4432,
684 u'synch_id': None},
685 u'priority': 1,
686 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000687 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 +0000688 u'name': u'test_sleep',
689 u'control_type': u'Server',
690 u'synchronizing': 0,
691 u'priority': u'Medium',
692 u'owner': u'user0',
693 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000694 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000695 u'id': 180},
696 u'active': 0,
697 u'id': 101084}]),
698 ('get_host_queue_entries',
699 {'job__name__in': ['mytest']},
700 True,
701 [{u'status': u'Failed',
702 u'complete': 1,
703 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000704 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000705 u'hostname': u'host10',
mbligh0887d402009-01-30 00:50:29 +0000706 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000707 u'id': 4432,
708 u'synch_id': None},
709 u'priority': 1,
710 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000711 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 +0000712 u'name': u'test_sleep',
713 u'control_type': u'Server',
714 u'synchronizing': 0,
715 u'priority': u'Medium',
716 u'owner': u'user0',
717 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000718 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000719 u'id': 338},
720 u'active': 0,
721 u'id': 101084}])],
722 out_words_ok=['job0', 'mytest', 'Aborted', 'Queued',
723 'Failed', 'Medium', 'High'])
724
725
726class job_create_unittest(cli_mock.cli_unittest):
727 ctrl_file = '\ndef step_init():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME =\n "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1\n second by default. It\'s a good way to test\n profilers and double check\n that autotest is working.\n The seconds argument can also be modified to\n make the machine sleep for as\n long as needed.\n """\n \n\n job.run_test(\'sleeptest\', seconds = 1)'
728
729 kernel_ctrl_file = 'kernel = \'kernel\'\ndef step_init():\n job.next_step([step_test])\n testkernel = job.kernel(\'kernel\')\n \n testkernel.install()\n testkernel.boot(args=\'console_always_print=1\')\n\ndef step_test():\n job.next_step(\'step0\')\n\ndef step0():\n AUTHOR = "Autotest Team"\n NAME = "Sleeptest"\n TIME = "SHORT"\n TEST_CATEGORY = "Functional"\n TEST_CLASS = "General"\n TEST_TYPE = "client"\n \n DOC = """\n This test simply sleeps for 1 second by default. It\'s a good way to test\n profilers and double check that autotest is working.\n The seconds argument can also be modified to make the machine sleep for as\n long as needed.\n """\n \n job.run_test(\'sleeptest\', seconds = 1)'
730
mbligh120351e2009-01-24 01:40:45 +0000731 trivial_ctrl_file = 'print "Hello"\n'
732
mblighbe630eb2008-08-01 16:41:48 +0000733 data = {'priority': 'Medium', 'control_file': ctrl_file, 'hosts': ['host0'],
mbligh6fee7fd2008-10-10 15:44:39 +0000734 'name': 'test_job0', 'control_type': 'Client', 'email_list': '',
showard2bab8f42008-11-12 18:15:22 +0000735 'meta_hosts': [], 'synch_count': 1, 'dependencies': []}
mblighbe630eb2008-08-01 16:41:48 +0000736
737
738 def test_execute_create_job(self):
739 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
mbligha212d712009-02-11 01:22:36 +0000740 'test_job0', '-m', 'host0', '--ignore_site_file'],
showard989f25d2008-10-01 11:38:11 +0000741 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000742 {'tests': ['sleeptest']},
showard989f25d2008-10-01 11:38:11 +0000743 True,
744 {'control_file' : self.ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000745 'synch_count' : 1,
showard989f25d2008-10-01 11:38:11 +0000746 'is_server' : False,
747 'dependencies' : []}),
mblighbe630eb2008-08-01 16:41:48 +0000748 ('create_job', self.data, True, 180)],
749 out_words_ok=['test_job0', 'Created'],
750 out_words_no=['Uploading', 'Done'])
751
752
showard648a35c2009-05-01 00:08:42 +0000753 def test_execute_create_job_with_atomic_group(self):
754 data = dict(self.data)
755 data['atomic_group_name'] = 'my-atomic-group'
756 data['control_type'] = 'Server'
757 mock_ctrl_file = 'mock control file'
758 data['control_file'] = mock_ctrl_file
759 data['synch_count'] = 2
760 data['hosts'] = []
761 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'mocktest',
762 'test_job0', '--ignore_site_file',
763 '-G', 'my-atomic-group'],
764 rpcs=[('generate_control_file',
765 {'tests': ['mocktest']},
766 True,
767 {'control_file' : mock_ctrl_file,
768 'synch_count' : 2,
769 'is_server' : True,
770 'dependencies' : []}),
771 ('create_job', data, True, 180)],
772 out_words_ok=['test_job0', 'Created'],
773 out_words_no=['Uploading', 'Done'])
774
775
mblighbe630eb2008-08-01 16:41:48 +0000776 def test_execute_create_job_with_control(self):
mbligh41515392009-07-11 00:13:11 +0000777 file_temp = cli_mock.create_file(self.ctrl_file)
778 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000779 'test_job0', '-m', 'host0', '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000780 rpcs=[('create_job', self.data, True, 42)],
781 out_words_ok=['test_job0', 'Created'],
782 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000783 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000784
785
mbligh120351e2009-01-24 01:40:45 +0000786 def test_execute_create_job_with_control_and_kernel(self):
787 data = self.data.copy()
788 data['control_file'] = '# Made up control "file" for unittest.'
mbligh41515392009-07-11 00:13:11 +0000789 file_temp = cli_mock.create_file(self.trivial_ctrl_file)
790 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000791 '-k', 'Kernel', 'test_job0', '-m', 'host0',
792 '--ignore_site_file'],
mbligh120351e2009-01-24 01:40:45 +0000793 rpcs=[('generate_control_file',
794 {'client_control_file': self.trivial_ctrl_file,
795 'do_push_packages': True,
mbligha3c58d22009-08-24 22:01:51 +0000796 'kernel': [{'version': 'Kernel'}]},
mbligh120351e2009-01-24 01:40:45 +0000797 True,
798 {'control_file': data['control_file'],
799 'synch_count': 1,
800 'is_server': False,
801 'dependencies': []}),
802 ('create_job', data, True, 42)],
803 out_words_ok=['test_job0', 'Created',
804 'Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000805 file_temp.clean()
mbligh120351e2009-01-24 01:40:45 +0000806
807
mbligh0a669132008-10-10 20:02:32 +0000808 def test_execute_create_job_with_control_and_email(self):
809 data = self.data.copy()
810 data['email_list'] = 'em'
mbligh41515392009-07-11 00:13:11 +0000811 file_temp = cli_mock.create_file(self.ctrl_file)
812 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000813 'test_job0', '-m', 'host0', '-e', 'em',
814 '--ignore_site_file'],
mbligh0a669132008-10-10 20:02:32 +0000815 rpcs=[('create_job', data, True, 42)],
816 out_words_ok=['test_job0', 'Created'],
817 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000818 file_temp.clean()
mbligh0a669132008-10-10 20:02:32 +0000819
820
showardb27f4ad2009-05-01 00:08:26 +0000821 def test_execute_create_job_with_control_and_dependencies(self):
mbligh0a669132008-10-10 20:02:32 +0000822 data = self.data.copy()
823 data['dependencies'] = ['dep1', 'dep2']
mbligh41515392009-07-11 00:13:11 +0000824 file_temp = cli_mock.create_file(self.ctrl_file)
825 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
showardb27f4ad2009-05-01 00:08:26 +0000826 'test_job0', '-m', 'host0', '-d', 'dep1, dep2 ',
mbligha212d712009-02-11 01:22:36 +0000827 '--ignore_site_file'],
mbligh0a669132008-10-10 20:02:32 +0000828 rpcs=[('create_job', data, True, 42)],
829 out_words_ok=['test_job0', 'Created'],
830 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000831 file_temp.clean()
mbligh0a669132008-10-10 20:02:32 +0000832
833
showard7bce1022008-11-14 22:51:05 +0000834 def test_execute_create_job_with_synch_count(self):
835 data = self.data.copy()
836 data['synch_count'] = 2
mbligh41515392009-07-11 00:13:11 +0000837 file_temp = cli_mock.create_file(self.ctrl_file)
838 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000839 'test_job0', '-m', 'host0', '-y', '2',
840 '--ignore_site_file'],
showard7bce1022008-11-14 22:51:05 +0000841 rpcs=[('create_job', data, True, 42)],
842 out_words_ok=['test_job0', 'Created'],
843 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000844 file_temp.clean()
showard7bce1022008-11-14 22:51:05 +0000845
846
showardb27f4ad2009-05-01 00:08:26 +0000847 def test_execute_create_job_with_test_and_dependencies(self):
mblighb9a8b162008-10-29 16:47:29 +0000848 data = self.data.copy()
849 data['dependencies'] = ['dep1', 'dep2', 'dep3']
850 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
showardb27f4ad2009-05-01 00:08:26 +0000851 'test_job0', '-m', 'host0', '-d', 'dep1, dep2 ',
mbligha212d712009-02-11 01:22:36 +0000852 '--ignore_site_file'],
mblighb9a8b162008-10-29 16:47:29 +0000853 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000854 {'tests': ['sleeptest']},
mblighb9a8b162008-10-29 16:47:29 +0000855 True,
856 {'control_file' : self.ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000857 'synch_count' : 1,
mblighb9a8b162008-10-29 16:47:29 +0000858 'is_server' : False,
859 'dependencies' : ['dep3']}),
860 ('create_job', data, True, 42)],
861 out_words_ok=['test_job0', 'Created'],
862 out_words_no=['Uploading', 'Done'])
863
864
mblighbe630eb2008-08-01 16:41:48 +0000865 def test_execute_create_job_with_kernel(self):
866 data = self.data.copy()
867 data['control_file'] = self.kernel_ctrl_file
868 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
mbligha212d712009-02-11 01:22:36 +0000869 '-k', 'kernel', 'test_job0', '-m', 'host0',
870 '--ignore_site_file'],
showard989f25d2008-10-01 11:38:11 +0000871 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000872 {'tests': ['sleeptest'],
mbligha3c58d22009-08-24 22:01:51 +0000873 'kernel': [{'version': 'kernel'}],
874 'do_push_packages': True},
875 True,
876 {'control_file' : self.kernel_ctrl_file,
877 'synch_count' : 1,
878 'is_server' : False,
879 'dependencies' : []}),
880 ('create_job', data, True, 180)],
881 out_words_ok=['test_job0', 'Created',
882 'Uploading', 'Done'])
883
884
885 def test_execute_create_job_with_kernels_and_cmdline(self):
886 data = self.data.copy()
887 data['control_file'] = self.kernel_ctrl_file
888 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
889 '-k', 'kernel1,kernel2', '--kernel-cmdline',
890 'arg1 arg2', 'test_job0', '-m', 'host0',
891 '--ignore_site_file'],
892 rpcs=[('generate_control_file',
893 {'tests': ['sleeptest'],
894 'kernel': [{'version': 'kernel1',
895 'cmdline': 'arg1 arg2'},
896 {'version': 'kernel2',
897 'cmdline': 'arg1 arg2'}],
898 'do_push_packages': True},
showard989f25d2008-10-01 11:38:11 +0000899 True,
900 {'control_file' : self.kernel_ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000901 'synch_count' : 1,
showard989f25d2008-10-01 11:38:11 +0000902 'is_server' : False,
903 'dependencies' : []}),
mblighbe630eb2008-08-01 16:41:48 +0000904 ('create_job', data, True, 180)],
905 out_words_ok=['test_job0', 'Created',
906 'Uploading', 'Done'])
907
908
909 def test_execute_create_job_with_kernel_spaces(self):
910 data = self.data.copy()
911 data['control_file'] = self.kernel_ctrl_file
912 data['name'] = 'test job with spaces'
913 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
914 '-k', 'kernel', 'test job with spaces',
mbligha212d712009-02-11 01:22:36 +0000915 '-m', 'host0', '--ignore_site_file'],
showard989f25d2008-10-01 11:38:11 +0000916 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000917 {'tests': ['sleeptest'],
mbligha3c58d22009-08-24 22:01:51 +0000918 'kernel': [{'version': 'kernel'}],
919 'do_push_packages': True},
showard989f25d2008-10-01 11:38:11 +0000920 True,
921 {'control_file' : self.kernel_ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000922 'synch_count' : 1,
showard989f25d2008-10-01 11:38:11 +0000923 'is_server' : False,
924 'dependencies' : []}),
mblighbe630eb2008-08-01 16:41:48 +0000925 ('create_job', data, True, 180)],
mblighc6133172009-09-18 19:34:50 +0000926 # This is actually 7 spaces, the extra single quote that
927 # gets displayed before "test" causes the tab completion
928 # to move to the next 8 char boundary which is 7 characters
929 # away. Hence the 7 spaces in out_words_ok.
930 # The tab has been converted by print.
931 out_words_ok=['test job with spaces', 'Created',
932 'id', '180'])
mblighbe630eb2008-08-01 16:41:48 +0000933
934
935 def test_execute_create_job_no_args(self):
936 testjob = job.job_create()
mbligha212d712009-02-11 01:22:36 +0000937 sys.argv = ['atest', 'job', 'create', '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000938 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000939 (sys.exit.expect_call(mock.anything_comparator())
940 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000941 self.assertRaises(cli_mock.ExitException, testjob.parse)
942 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000943 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000944
945
946 def test_execute_create_job_no_hosts(self):
947 testjob = job.job_create()
mbligh41515392009-07-11 00:13:11 +0000948 file_temp = cli_mock.create_file(self.ctrl_file)
949 sys.argv = ['atest', '-f', file_temp.name, 'test_job0',
950 '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000951 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000952 (sys.exit.expect_call(mock.anything_comparator())
953 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000954 self.assertRaises(cli_mock.ExitException, testjob.parse)
955 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000956 self.god.check_playback()
mbligh41515392009-07-11 00:13:11 +0000957 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000958
959
960 def test_execute_create_job_cfile_and_tests(self):
961 testjob = job.job_create()
962 sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-f',
mbligha212d712009-02-11 01:22:36 +0000963 'control_file', 'test_job0', '-m', 'host0',
964 '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000965 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000966 (sys.exit.expect_call(mock.anything_comparator())
967 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000968 self.assertRaises(cli_mock.ExitException, testjob.parse)
969 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000970 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000971
972
973 def test_execute_create_job_cfile_and_kernel(self):
974 testjob = job.job_create()
975 sys.argv = ['atest', 'job', 'create', '-f', 'control_file', '-k',
mbligha212d712009-02-11 01:22:36 +0000976 'kernel', 'test_job0', '-m', 'host0', '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000977 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000978 (sys.exit.expect_call(mock.anything_comparator())
979 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000980 self.assertRaises(cli_mock.ExitException, testjob.parse)
981 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000982 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000983
984
985 def test_execute_create_job_bad_cfile(self):
986 testjob = job.job_create()
mbligha212d712009-02-11 01:22:36 +0000987 sys.argv = ['atest', 'job', 'create', '-f', 'control_file',
988 'test_job0', '-m', 'host0', '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000989 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000990 (sys.exit.expect_call(mock.anything_comparator())
991 .and_raises(IOError))
mblighbe630eb2008-08-01 16:41:48 +0000992 self.assertRaises(IOError, testjob.parse)
993 self.god.unmock_io()
994
995
996 def test_execute_create_job_bad_priority(self):
997 testjob = job.job_create()
998 sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-p', 'Uber',
mbligha212d712009-02-11 01:22:36 +0000999 '-m', 'host0', 'test_job0', '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +00001000 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +00001001 (sys.exit.expect_call(mock.anything_comparator())
1002 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +00001003 self.assertRaises(cli_mock.ExitException, testjob.parse)
1004 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +00001005 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +00001006
1007
1008 def test_execute_create_job_with_mfile(self):
1009 data = self.data.copy()
1010 data['hosts'] = ['host3', 'host2', 'host1', 'host0']
mbligh41515392009-07-11 00:13:11 +00001011 ctemp = cli_mock.create_file(self.ctrl_file)
1012 file_temp = cli_mock.create_file('host0\nhost1\nhost2\nhost3')
1013 self.run_cmd(argv=['atest', 'job', 'create', '--mlist', file_temp.name,
1014 '-f', ctemp.name, 'test_job0', '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +00001015 rpcs=[('create_job', data, True, 42)],
1016 out_words_ok=['test_job0', 'Created'])
mbligh41515392009-07-11 00:13:11 +00001017 ctemp.clean()
1018 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +00001019
1020
mbligh5d0b4b32008-12-22 14:43:01 +00001021 def test_execute_create_job_with_timeout(self):
1022 data = self.data.copy()
1023 data['timeout'] = '222'
mbligh41515392009-07-11 00:13:11 +00001024 file_temp = cli_mock.create_file(self.ctrl_file)
1025 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +00001026 'test_job0', '-m', 'host0', '-o', '222',
1027 '--ignore_site_file'],
mbligh5d0b4b32008-12-22 14:43:01 +00001028 rpcs=[('create_job', data, True, 42)],
1029 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +00001030 file_temp.clean()
mbligh5d0b4b32008-12-22 14:43:01 +00001031
1032
showard12f3e322009-05-13 21:27:42 +00001033 def test_execute_create_job_with_max_runtime(self):
1034 data = self.data.copy()
1035 data['max_runtime_hrs'] = '222'
mbligh41515392009-07-11 00:13:11 +00001036 file_temp = cli_mock.create_file(self.ctrl_file)
1037 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
showard12f3e322009-05-13 21:27:42 +00001038 'test_job0', '-m', 'host0', '--max_runtime', '222',
1039 '--ignore_site_file'],
1040 rpcs=[('create_job', data, True, 42)],
1041 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +00001042 file_temp.clean()
showard12f3e322009-05-13 21:27:42 +00001043
1044
1045
mbligh5d0b4b32008-12-22 14:43:01 +00001046 def test_execute_create_job_with_noverify(self):
1047 data = self.data.copy()
1048 data['run_verify'] = False
mbligh41515392009-07-11 00:13:11 +00001049 file_temp = cli_mock.create_file(self.ctrl_file)
1050 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +00001051 'test_job0', '-m', 'host0', '-n',
1052 '--ignore_site_file'],
mbligh5d0b4b32008-12-22 14:43:01 +00001053 rpcs=[('create_job', data, True, 42)],
1054 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +00001055 file_temp.clean()
mbligh5d0b4b32008-12-22 14:43:01 +00001056
1057
mblighce348642009-02-12 21:50:39 +00001058 def test_execute_create_job_oth(self):
1059 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +00001060 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +00001061 data['one_time_hosts'] = ['host0']
1062 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
1063 'test_job0', '--one-time-hosts', 'host0'],
1064 rpcs=[('generate_control_file',
1065 {'tests': ['sleeptest']},
1066 True,
1067 {'control_file' : self.ctrl_file,
1068 'synch_count' : 1,
1069 'is_server' : False,
1070 'dependencies' : []}),
1071 ('create_job', data, True, 180)],
1072 out_words_ok=['test_job0', 'Created'],
1073 out_words_no=['Uploading', 'Done'])
1074
1075
1076 def test_execute_create_job_multi_oth(self):
1077 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +00001078 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +00001079 data['one_time_hosts'] = ['host1', 'host0']
1080 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
1081 'test_job0', '--one-time-hosts', 'host0,host1'],
1082 rpcs=[('generate_control_file',
1083 {'tests': ['sleeptest']},
1084 True,
1085 {'control_file' : self.ctrl_file,
1086 'synch_count' : 1,
1087 'is_server' : False,
1088 'dependencies' : []}),
1089 ('create_job', data, True, 180)],
1090 out_words_ok=['test_job0', 'Created'],
1091 out_words_no=['Uploading', 'Done'])
1092
1093
1094 def test_execute_create_job_oth_exists(self):
1095 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +00001096 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +00001097 data['one_time_hosts'] = ['host0']
1098 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
1099 'test_job0', '--one-time-hosts', 'host0'],
1100 rpcs=[('generate_control_file',
1101 {'tests': ['sleeptest']},
1102 True,
1103 {'control_file' : self.ctrl_file,
1104 'synch_count' : 1,
1105 'is_server' : False,
1106 'dependencies' : []}),
1107 ('create_job', data, False,
1108 '''ValidationError: {'hostname': 'host0 '''
1109 '''already exists in the autotest DB. '''
1110 '''Select it rather than entering it as '''
1111 '''a one time host.'}''')],
1112 out_words_no=['test_job0', 'Created'],
1113 err_words_ok=['failed', 'already exists'])
1114
1115
showardb27f4ad2009-05-01 00:08:26 +00001116 def test_execute_create_job_with_control_and_labels(self):
1117 data = self.data.copy()
1118 data['hosts'] = ['host0', 'host1', 'host2']
mbligh41515392009-07-11 00:13:11 +00001119 file_temp = cli_mock.create_file(self.ctrl_file)
1120 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
showardb27f4ad2009-05-01 00:08:26 +00001121 'test_job0', '-m', 'host0', '-b', 'label1,label2',
1122 '--ignore_site_file'],
1123 rpcs=[('get_hosts', {'multiple_labels': ['label1',
1124 'label2']}, True,
1125 [{u'status': u'Running', u'lock_time': None,
1126 u'hostname': u'host1', u'locked': False,
1127 u'locked_by': None, u'invalid': False, u'id': 42,
1128 u'labels': [u'label1'], u'platform':
1129 u'Warp18_Diskfull', u'protection':
1130 u'Repair software only', u'dirty':
1131 True, u'synch_id': None},
1132 {u'status': u'Running', u'lock_time': None,
1133 u'hostname': u'host2', u'locked': False,
1134 u'locked_by': None, u'invalid': False, u'id': 43,
1135 u'labels': [u'label2'], u'platform':
1136 u'Warp18_Diskfull', u'protection':
1137 u'Repair software only', u'dirty': True,
1138 u'synch_id': None}]),
1139 ('create_job', data, True, 42)],
1140 out_words_ok=['test_job0', 'Created'],
1141 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +00001142 file_temp.clean()
showardb27f4ad2009-05-01 00:08:26 +00001143
1144
1145 def test_execute_create_job_with_label_and_duplicate_hosts(self):
1146 data = self.data.copy()
1147 data['hosts'] = ['host1', 'host0']
mbligh41515392009-07-11 00:13:11 +00001148 file_temp = cli_mock.create_file(self.ctrl_file)
1149 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
showardb27f4ad2009-05-01 00:08:26 +00001150 'test_job0', '-m', 'host0,host1', '-b', 'label1',
1151 '--ignore_site_file'],
1152 rpcs=[('get_hosts', {'multiple_labels': ['label1']}, True,
1153 [{u'status': u'Running', u'lock_time': None,
1154 u'hostname': u'host1', u'locked': False,
1155 u'locked_by': None, u'invalid': False, u'id': 42,
1156 u'labels': [u'label1'], u'platform':
1157 u'Warp18_Diskfull', u'protection':
1158 u'Repair software only', u'dirty':
1159 True, u'synch_id': None}]),
1160 ('create_job', data, True, 42)],
1161 out_words_ok=['test_job0', 'Created'],
1162 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +00001163 file_temp.clean()
showardb27f4ad2009-05-01 00:08:26 +00001164
1165
jamesrenc2863162010-07-12 21:20:51 +00001166 def test_execute_create_job_with_label_commas_and_duplicate_hosts(self):
1167 data = self.data.copy()
1168 data['hosts'] = ['host1', 'host0']
1169 file_temp = cli_mock.create_file(self.ctrl_file)
1170 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1171 'test_job0', '-m', 'host0,host1', '-b',
1172 'label1,label\\,2', '--ignore_site_file'],
1173 rpcs=[('get_hosts', {'multiple_labels': ['label1',
1174 'label,2']}, True,
1175 [{u'status': u'Running', u'lock_time': None,
1176 u'hostname': u'host1', u'locked': False,
1177 u'locked_by': None, u'invalid': False, u'id': 42,
1178 u'labels': [u'label1', u'label,2'], u'platform':
1179 u'Warp18_Diskfull', u'protection':
1180 u'Repair software only', u'dirty':
1181 True, u'synch_id': None}]),
1182 ('create_job', data, True, 42)],
1183 out_words_ok=['test_job0', 'Created'],
1184 out_words_no=['Uploading', 'Done'])
1185 file_temp.clean()
1186
1187
1188 def test_execute_create_job_with_label_escaping_and_duplicate_hosts(self):
1189 data = self.data.copy()
1190 data['hosts'] = ['host1', 'host0']
1191 file_temp = cli_mock.create_file(self.ctrl_file)
1192 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1193 'test_job0', '-m', 'host0,host1', '-b',
1194 'label1,label\\,2\\\\,label3', '--ignore_site_file'],
1195 rpcs=[('get_hosts', {'multiple_labels': ['label,2\\',
1196 'label1', 'label3']}, True,
1197 [{u'status': u'Running', u'lock_time': None,
1198 u'hostname': u'host1', u'locked': False,
1199 u'locked_by': None, u'invalid': False, u'id': 42,
1200 u'labels': [u'label1', u'label,2\\', u'label3'],
1201 u'platform': u'Warp18_Diskfull', u'protection':
1202 u'Repair software only', u'dirty':
1203 True, u'synch_id': None}]),
1204 ('create_job', data, True, 42)],
1205 out_words_ok=['test_job0', 'Created'],
1206 out_words_no=['Uploading', 'Done'])
1207 file_temp.clean()
1208
1209
mblighbe630eb2008-08-01 16:41:48 +00001210 def _test_parse_hosts(self, args, exp_hosts=[], exp_meta_hosts=[]):
mbligh56f1f4a2009-08-03 16:45:12 +00001211 testjob = job.job_create_or_clone()
1212 (hosts, meta_hosts) = testjob._parse_hosts(args)
mblighbe630eb2008-08-01 16:41:48 +00001213 self.assertEqualNoOrder(hosts, exp_hosts)
1214 self.assertEqualNoOrder(meta_hosts, exp_meta_hosts)
1215
1216
1217 def test_parse_hosts_regular(self):
1218 self._test_parse_hosts(['host0'], ['host0'])
1219
1220
1221 def test_parse_hosts_regulars(self):
1222 self._test_parse_hosts(['host0', 'host1'], ['host0', 'host1'])
1223
1224
1225 def test_parse_hosts_meta_one(self):
1226 self._test_parse_hosts(['*meta0'], [], ['meta0'])
1227
1228
1229 def test_parse_hosts_meta_five(self):
1230 self._test_parse_hosts(['5*meta0'], [], ['meta0']*5)
1231
1232
1233 def test_parse_hosts_metas_five(self):
1234 self._test_parse_hosts(['5*meta0', '2*meta1'], [],
1235 ['meta0']*5 + ['meta1']*2)
1236
1237
1238 def test_parse_hosts_mix(self):
1239 self._test_parse_hosts(['5*meta0', 'host0', '2*meta1', 'host1',
1240 '*meta2'], ['host0', 'host1'],
1241 ['meta0']*5 + ['meta1']*2 + ['meta2'])
1242
1243
mbligh5a496082009-08-03 16:44:54 +00001244class job_clone_unittest(cli_mock.cli_unittest):
1245 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',
1246 'control_type': u'Server',
1247 'dependencies': [],
1248 'email_list': u'',
1249 'max_runtime_hrs': 480,
1250 'parse_failed_repair': True,
1251 'priority': u'Medium',
1252 'reboot_after': u'Always',
1253 'reboot_before': u'If dirty',
1254 'run_verify': True,
1255 'synch_count': 1,
1256 'timeout': 480}
1257
mbligh56f1f4a2009-08-03 16:45:12 +00001258 local_hosts = [{u'acls': [u'acl0'],
1259 u'atomic_group': None,
1260 u'attributes': {},
1261 u'dirty': False,
1262 u'hostname': u'host0',
1263 u'id': 8,
1264 u'invalid': False,
1265 u'labels': [u'label0', u'label1'],
1266 u'lock_time': None,
1267 u'locked': False,
1268 u'locked_by': None,
1269 u'other_labels': u'label0, label1',
1270 u'platform': u'plat0',
1271 u'protection': u'Repair software only',
1272 u'status': u'Ready',
1273 u'synch_id': None},
1274 {u'acls': [u'acl0'],
1275 u'atomic_group': None,
1276 u'attributes': {},
1277 u'dirty': False,
1278 u'hostname': u'host1',
1279 u'id': 9,
1280 u'invalid': False,
1281 u'labels': [u'label0', u'label1'],
1282 u'lock_time': None,
1283 u'locked': False,
1284 u'locked_by': None,
1285 u'other_labels': u'label0, label1',
1286 u'platform': u'plat0',
1287 u'protection': u'Repair software only',
1288 u'status': u'Ready',
1289 u'synch_id': None}]
1290
1291
mbligh5a496082009-08-03 16:44:54 +00001292 def setUp(self):
1293 super(job_clone_unittest, self).setUp()
1294 self.job_data_clone_info = copy.deepcopy(self.job_data)
1295 self.job_data_clone_info['created_on'] = '2009-07-23 16:21:29'
1296 self.job_data_clone_info['name'] = 'testing_clone'
1297 self.job_data_clone_info['id'] = 42
1298 self.job_data_clone_info['owner'] = 'user0'
1299
1300 self.job_data_cloned = copy.deepcopy(self.job_data)
1301 self.job_data_cloned['name'] = 'cloned'
1302 self.job_data_cloned['hosts'] = [u'host0']
1303 self.job_data_cloned['meta_hosts'] = []
1304
1305
1306 def test_backward_compat(self):
1307 self.run_cmd(argv=['atest', 'job', 'create', '--clone', '42',
1308 '-r', 'cloned'],
1309 rpcs=[('get_info_for_clone', {'id': '42',
1310 'preserve_metahosts': True},
1311 True,
1312 {u'atomic_group_name': None,
1313 u'hosts': [{u'acls': [u'acl0'],
1314 u'atomic_group': None,
1315 u'attributes': {},
1316 u'dirty': False,
1317 u'hostname': u'host0',
1318 u'id': 4378,
1319 u'invalid': False,
1320 u'labels': [u'label0', u'label1'],
1321 u'lock_time': None,
1322 u'locked': False,
1323 u'locked_by': None,
1324 u'other_labels': u'label0, label1',
1325 u'platform': u'plat0',
1326 u'protection': u'Repair software only',
1327 u'status': u'Ready',
1328 u'synch_id': None}],
1329 u'job': self.job_data_clone_info,
1330 u'meta_host_counts': {}}),
1331 ('create_job', self.job_data_cloned, True, 43)],
1332 out_words_ok=['Created job', '43'])
1333
1334
1335 def test_clone_reuse_hosts(self):
mbligh56f1f4a2009-08-03 16:45:12 +00001336 self.job_data_cloned['hosts'] = [u'host0', 'host1']
mbligh5a496082009-08-03 16:44:54 +00001337 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1338 '-r', 'cloned'],
1339 rpcs=[('get_info_for_clone', {'id': '42',
1340 'preserve_metahosts': True},
1341 True,
1342 {u'atomic_group_name': None,
mbligh56f1f4a2009-08-03 16:45:12 +00001343 u'hosts': self.local_hosts,
mbligh5a496082009-08-03 16:44:54 +00001344 u'job': self.job_data_clone_info,
1345 u'meta_host_counts': {}}),
1346 ('create_job', self.job_data_cloned, True, 43)],
1347 out_words_ok=['Created job', '43'])
1348
1349
mbligh56f1f4a2009-08-03 16:45:12 +00001350 def test_clone_reuse_metahosts(self):
1351 self.job_data_cloned['hosts'] = []
1352 self.job_data_cloned['meta_hosts'] = ['type1']*4 + ['type0']
1353 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1354 '-r', 'cloned'],
1355 rpcs=[('get_info_for_clone', {'id': '42',
1356 'preserve_metahosts': True},
1357 True,
1358 {u'atomic_group_name': None,
1359 u'hosts': [],
1360 u'job': self.job_data_clone_info,
1361 u'meta_host_counts': {u'type0': 1,
1362 u'type1': 4}}),
1363 ('create_job', self.job_data_cloned, True, 43)],
1364 out_words_ok=['Created job', '43'])
1365
1366
1367 def test_clone_reuse_both(self):
1368 self.job_data_cloned['hosts'] = [u'host0', 'host1']
1369 self.job_data_cloned['meta_hosts'] = ['type1']*4 + ['type0']
1370 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1371 '-r', 'cloned'],
1372 rpcs=[('get_info_for_clone', {'id': '42',
1373 'preserve_metahosts': True},
1374 True,
1375 {u'atomic_group_name': None,
1376 u'hosts': self.local_hosts,
1377 u'job': self.job_data_clone_info,
1378 u'meta_host_counts': {u'type0': 1,
1379 u'type1': 4}}),
1380 ('create_job', self.job_data_cloned, True, 43)],
1381 out_words_ok=['Created job', '43'])
1382
1383
mbligh5a496082009-08-03 16:44:54 +00001384 def test_clone_no_hosts(self):
1385 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42', 'cloned'],
1386 exit_code=1,
1387 out_words_ok=['usage'],
1388 err_words_ok=['machine'])
1389
1390
mbligh56f1f4a2009-08-03 16:45:12 +00001391 def test_clone_reuse_and_hosts(self):
1392 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1393 '-r', '-m', 'host5', 'cloned'],
1394 exit_code=1,
1395 out_words_ok=['usage'],
1396 err_words_ok=['specify'])
1397
1398
1399 def test_clone_new_multiple_hosts(self):
1400 self.job_data_cloned['hosts'] = [u'host5', 'host4', 'host3']
1401 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1402 '-m', 'host5,host4,host3', 'cloned'],
1403 rpcs=[('get_info_for_clone', {'id': '42',
1404 'preserve_metahosts': False},
1405 True,
1406 {u'atomic_group_name': None,
1407 u'hosts': self.local_hosts,
1408 u'job': self.job_data_clone_info,
1409 u'meta_host_counts': {}}),
1410 ('create_job', self.job_data_cloned, True, 43)],
1411 out_words_ok=['Created job', '43'])
1412
1413
1414 def test_clone_oth(self):
1415 self.job_data_cloned['hosts'] = []
1416 self.job_data_cloned['one_time_hosts'] = [u'host5']
1417 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1418 '--one-time-hosts', 'host5', 'cloned'],
1419 rpcs=[('get_info_for_clone', {'id': '42',
1420 'preserve_metahosts': False},
1421 True,
1422 {u'atomic_group_name': None,
1423 u'hosts': self.local_hosts,
1424 u'job': self.job_data_clone_info,
1425 u'meta_host_counts': {}}),
1426 ('create_job', self.job_data_cloned, True, 43)],
1427 out_words_ok=['Created job', '43'])
mbligh5a496082009-08-03 16:44:54 +00001428
1429
mblighbe630eb2008-08-01 16:41:48 +00001430class job_abort_unittest(cli_mock.cli_unittest):
1431 results = [{u'status_counts': {u'Aborted': 1}, u'control_file':
1432 u"job.run_test('sleeptest')\n", u'name': u'test_job0',
showard2bab8f42008-11-12 18:15:22 +00001433 u'control_type': u'Server', u'priority':
mblighbe630eb2008-08-01 16:41:48 +00001434 u'Medium', u'owner': u'user0', u'created_on':
showard2bab8f42008-11-12 18:15:22 +00001435 u'2008-07-08 17:45:44', u'synch_count': 2, u'id': 180}]
mblighbe630eb2008-08-01 16:41:48 +00001436
1437 def test_execute_job_abort(self):
mbligha212d712009-02-11 01:22:36 +00001438 self.run_cmd(argv=['atest', 'job', 'abort', '180',
1439 '--ignore_site_file'],
mbligh206d50a2008-11-13 01:19:25 +00001440 rpcs=[('abort_host_queue_entries',
1441 {'job__id__in': ['180']}, True, None)],
1442 out_words_ok=['Aborting', '180'])
mblighbe630eb2008-08-01 16:41:48 +00001443
1444
1445if __name__ == '__main__':
1446 unittest.main()