blob: 652987ba05757a6aa27951e0b1cba478d711a14e [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
Richard Barnette41e617b2016-05-19 16:18:16 -07008# pylint: disable=missing-docstring
9
10import copy, getpass, unittest, sys
mblighbe630eb2008-08-01 16:41:48 +000011
12import common
Richard Barnette41e617b2016-05-19 16:18:16 -070013from autotest_lib.cli import cli_mock, job
showard53cb10c2009-05-01 00:09:36 +000014from autotest_lib.client.common_lib.test_utils import mock
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070015from autotest_lib.client.common_lib import control_data
Allen Li352b86a2016-12-14 12:11:27 -080016from autotest_lib.client.common_lib import priorities
mblighbe630eb2008-08-01 16:41:48 +000017
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070018CLIENT = control_data.CONTROL_TYPE_NAMES.CLIENT
19SERVER = control_data.CONTROL_TYPE_NAMES.SERVER
mblighbe630eb2008-08-01 16:41:48 +000020
21class job_unittest(cli_mock.cli_unittest):
22 def setUp(self):
23 super(job_unittest, self).setUp()
mblighbe630eb2008-08-01 16:41:48 +000024 self.values = copy.deepcopy(self.values_template)
25
26 results = [{u'status_counts': {u'Aborted': 1},
27 u'control_file':
28 u"job.run_test('sleeptest')\n",
29 u'name': u'test_job0',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070030 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +000031 u'priority':
Allen Li352b86a2016-12-14 12:11:27 -080032 priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +000033 u'owner': u'user0',
34 u'created_on':
35 u'2008-07-08 17:45:44',
showard2bab8f42008-11-12 18:15:22 +000036 u'synch_count': 2,
mblighbe630eb2008-08-01 16:41:48 +000037 u'id': 180},
38 {u'status_counts': {u'Queued': 1},
39 u'control_file':
40 u"job.run_test('sleeptest')\n",
41 u'name': u'test_job1',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070042 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +000043 u'priority':
Allen Li352b86a2016-12-14 12:11:27 -080044 priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +000045 u'owner': u'user0',
46 u'created_on':
47 u'2008-07-08 12:17:47',
48 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +000049 u'id': 338}]
50
51
52 values_template = [{u'id': 180, # Valid job
Allen Li352b86a2016-12-14 12:11:27 -080053 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +000054 u'name': u'test_job0',
55 u'owner': u'Cringer',
mbligh0887d402009-01-30 00:50:29 +000056 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +000057 u'created_on': u'2008-07-02 13:02:40',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070058 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +000059 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000060 u'synch_count': 2},
mblighbe630eb2008-08-01 16:41:48 +000061 {u'id': 338, # Valid job
Allen Li352b86a2016-12-14 12:11:27 -080062 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +000063 u'name': u'test_job1',
64 u'owner': u'Fisto',
mbligh0887d402009-01-30 00:50:29 +000065 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +000066 u'created_on': u'2008-07-06 14:05:33',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070067 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +000068 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000069 u'synch_count': 1},
mblighbe630eb2008-08-01 16:41:48 +000070 {u'id': 339, # Valid job
Allen Li352b86a2016-12-14 12:11:27 -080071 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +000072 u'name': u'test_job2',
73 u'owner': u'Roboto',
mbligh0887d402009-01-30 00:50:29 +000074 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +000075 u'created_on': u'2008-07-07 15:33:18',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070076 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +000077 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000078 u'synch_count': 1},
mblighbe630eb2008-08-01 16:41:48 +000079 {u'id': 340, # Invalid job priority
Allen Li352b86a2016-12-14 12:11:27 -080080 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +000081 u'name': u'test_job3',
82 u'owner': u'Panthor',
mbligh0887d402009-01-30 00:50:29 +000083 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +000084 u'created_on': u'2008-07-04 00:00:01',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070085 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +000086 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000087 u'synch_count': 2},
mblighbe630eb2008-08-01 16:41:48 +000088 {u'id': 350, # Invalid job created_on
Allen Li352b86a2016-12-14 12:11:27 -080089 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +000090 u'name': u'test_job4',
91 u'owner': u'Icer',
mbligh0887d402009-01-30 00:50:29 +000092 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +000093 u'created_on': u'Today',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -070094 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +000095 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +000096 u'synch_count': 1},
mblighbe630eb2008-08-01 16:41:48 +000097 {u'id': 420, # Invalid job control_type
98 u'priority': 'Urgent',
99 u'name': u'test_job5',
100 u'owner': u'Spikor',
mbligh0887d402009-01-30 00:50:29 +0000101 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000102 u'created_on': u'2012-08-08 18:54:37',
103 u'control_type': u'Child',
104 u'status_counts': {u'Queued': 1},
showard2bab8f42008-11-12 18:15:22 +0000105 u'synch_count': 2}]
mblighbe630eb2008-08-01 16:41:48 +0000106
107
108class job_list_unittest(job_unittest):
109 def test_job_list_jobs(self):
showardf4a68992010-02-03 20:29:59 +0000110 self.god.stub_function(getpass, 'getuser')
mblighbe630eb2008-08-01 16:41:48 +0000111 getpass.getuser.expect_call().and_return('user0')
mbligha212d712009-02-11 01:22:36 +0000112 self.run_cmd(argv=['atest', 'job', 'list', '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000113 rpcs=[('get_jobs_summary', {'owner': 'user0',
114 'running': None},
115 True, self.values)],
116 out_words_ok=['test_job0', 'test_job1', 'test_job2'],
117 out_words_no=['Uber', 'Today', 'Child'])
118
119
120 def test_job_list_jobs_only_user(self):
121 values = [item for item in self.values if item['owner'] == 'Cringer']
mbligha212d712009-02-11 01:22:36 +0000122 self.run_cmd(argv=['atest', 'job', 'list', '-u', 'Cringer',
123 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000124 rpcs=[('get_jobs_summary', {'owner': 'Cringer',
125 'running': None},
126 True, values)],
127 out_words_ok=['Cringer'],
128 out_words_no=['Fisto', 'Roboto', 'Panthor', 'Icer',
129 'Spikor'])
130
131
132 def test_job_list_jobs_all(self):
mbligha212d712009-02-11 01:22:36 +0000133 self.run_cmd(argv=['atest', 'job', 'list', '--all',
134 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000135 rpcs=[('get_jobs_summary', {'running': None},
136 True, self.values)],
137 out_words_ok=['Fisto', 'Roboto', 'Panthor',
138 'Icer', 'Spikor', 'Cringer'],
139 out_words_no=['Created', 'Priority'])
140
141
142 def test_job_list_jobs_id(self):
mbligha212d712009-02-11 01:22:36 +0000143 self.run_cmd(argv=['atest', 'job', 'list', '5964',
144 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000145 rpcs=[('get_jobs_summary', {'id__in': ['5964'],
146 'running': None},
147 True,
148 [{u'status_counts': {u'Completed': 1},
Richard Barnette41e617b2016-05-19 16:18:16 -0700149 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\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)',
mblighbe630eb2008-08-01 16:41:48 +0000150 u'name': u'mytest',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700151 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000152 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800153 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000154 u'owner': u'user0',
155 u'created_on': u'2008-07-28 12:42:52',
156 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000157 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000158 u'id': 5964}])],
159 out_words_ok=['user0', 'Completed', '1', '5964'],
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700160 out_words_no=['sleeptest', 'Priority', CLIENT, '2008'])
mblighbe630eb2008-08-01 16:41:48 +0000161
162
163 def test_job_list_jobs_id_verbose(self):
mbligha212d712009-02-11 01:22:36 +0000164 self.run_cmd(argv=['atest', 'job', 'list', '5964', '-v',
165 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000166 rpcs=[('get_jobs_summary', {'id__in': ['5964'],
167 'running': None},
168 True,
169 [{u'status_counts': {u'Completed': 1},
Richard Barnette41e617b2016-05-19 16:18:16 -0700170 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\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)',
mblighbe630eb2008-08-01 16:41:48 +0000171 u'name': u'mytest',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700172 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000173 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800174 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000175 u'owner': u'user0',
176 u'created_on': u'2008-07-28 12:42:52',
177 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000178 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000179 u'id': 5964}])],
180 out_words_ok=['user0', 'Completed', '1', '5964',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700181 CLIENT, '2008', 'Priority'],
mblighbe630eb2008-08-01 16:41:48 +0000182 out_words_no=['sleeptest'])
183
184
185 def test_job_list_jobs_name(self):
mbligha212d712009-02-11 01:22:36 +0000186 self.run_cmd(argv=['atest', 'job', 'list', 'myt*',
187 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000188 rpcs=[('get_jobs_summary', {'name__startswith': 'myt',
189 'running': None},
190 True,
191 [{u'status_counts': {u'Completed': 1},
Richard Barnette41e617b2016-05-19 16:18:16 -0700192 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\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)',
mblighbe630eb2008-08-01 16:41:48 +0000193 u'name': u'mytest',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700194 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000195 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800196 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000197 u'owner': u'user0',
198 u'created_on': u'2008-07-28 12:42:52',
199 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000200 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000201 u'id': 5964}])],
202 out_words_ok=['user0', 'Completed', '1', '5964'],
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700203 out_words_no=['sleeptest', 'Priority', CLIENT, '2008'])
mblighbe630eb2008-08-01 16:41:48 +0000204
205
206 def test_job_list_jobs_all_verbose(self):
mbligha212d712009-02-11 01:22:36 +0000207 self.run_cmd(argv=['atest', 'job', 'list', '--all', '--verbose',
208 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000209 rpcs=[('get_jobs_summary', {'running': None},
210 True, self.values)],
211 out_words_ok=['Fisto', 'Spikor', 'Cringer', 'Priority',
212 'Created'])
213
214
showard53cb10c2009-05-01 00:09:36 +0000215class job_list_jobs_all_and_user_unittest(cli_mock.cli_unittest):
mblighbe630eb2008-08-01 16:41:48 +0000216 def test_job_list_jobs_all_and_user(self):
217 testjob = job.job_list()
mbligha212d712009-02-11 01:22:36 +0000218 sys.argv = ['atest', 'job', 'list', '-a', '-u', 'user0',
219 '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000220 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000221 (sys.exit.expect_call(mock.anything_comparator())
222 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000223 self.assertRaises(cli_mock.ExitException, testjob.parse)
224 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000225 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000226
227
228class job_stat_unittest(job_unittest):
229 def test_job_stat_job(self):
230 results = copy.deepcopy(self.results)
mbligha212d712009-02-11 01:22:36 +0000231 self.run_cmd(argv=['atest', 'job', 'stat', '180',
232 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000233 rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,
234 [results[0]]),
235 ('get_host_queue_entries', {'job__in': ['180']},
236 True,
237 [{u'status': u'Failed',
238 u'complete': 1,
239 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000240 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000241 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000242 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000243 u'id': 4432,
244 u'synch_id': None},
245 u'priority': 1,
246 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000247 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 +0000248 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700249 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000250 u'synchronizing': 0,
Allen Li352b86a2016-12-14 12:11:27 -0800251 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000252 u'owner': u'user0',
253 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000254 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000255 u'id': 180},
256 u'active': 0,
257 u'id': 101084}])],
258 out_words_ok=['test_job0', 'host0', 'Failed',
259 'Aborted'])
260
261
mblighfca5ed12009-11-06 02:59:56 +0000262
263 def test_job_stat_list_unassigned_host(self):
264 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
265 '--list-hosts', '--ignore_site_file'],
266 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
267 [{u'status_counts': {u'Queued': 1},
268 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\')',
269 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700270 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000271 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800272 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000273 u'owner': u'user0',
274 u'created_on': u'2008-07-30 22:15:43',
275 u'timeout': 144,
276 u'synch_count': 1,
277 u'id': 6761}]),
278 ('get_host_queue_entries', {'job__in': ['6761']},
279 True,
280 [{u'status': u'Queued',
281 u'complete': 0,
282 u'deleted': 0,
283 u'host': None,
284 u'priority': 1,
285 u'meta_host': u'Xeon',
286 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\')',
287 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700288 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000289 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800290 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000291 u'owner': u'user0',
292 u'created_on': u'2008-07-30 22:15:43',
293 u'timeout': 144,
294 u'synch_count': 1,
295 u'id': 6761},
296 u'active': 0,
297 u'id': 193166} ])],
298 err_words_ok=['unassigned', 'meta-hosts'],
299 out_words_no=['Xeon'])
300
301
302 def test_job_stat_list_hosts(self):
303 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
304 '--list-hosts', '--ignore_site_file'],
305 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
306 [{u'status_counts': {u'Queued': 1},
307 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\')',
308 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700309 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000310 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800311 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000312 u'owner': u'user0',
313 u'created_on': u'2008-07-30 22:15:43',
314 u'timeout': 144,
315 u'synch_count': 1,
316 u'id': 6761}]),
317 ('get_host_queue_entries', {'job__in': ['6761']},
318 True,
319 [{u'status': u'Queued',
320 u'complete': 0,
321 u'deleted': 0,
322 u'host': {u'status': u'Running',
323 u'lock_time': None,
324 u'hostname': u'host41',
325 u'locked': False,
326 u'locked_by': None,
327 u'invalid': False,
328 u'id': 4833,
329 u'protection': u'Repair filesystem only',
330 u'synch_id': None},
331 u'priority': 1,
332 u'meta_host': u'Xeon',
333 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\')',
334 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700335 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000336 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800337 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000338 u'owner': u'user0',
339 u'created_on': u'2008-07-30 22:15:43',
340 u'timeout': 144,
341 u'synch_count': 1,
342 u'id': 6761},
343 u'active': 0,
344 u'id': 193166},
345 {u'status': u'Running',
346 u'complete': 0,
347 u'deleted': 0,
348 u'host': {u'status': u'Running',
349 u'lock_time': None,
350 u'hostname': u'host42',
351 u'locked': False,
352 u'locked_by': None,
353 u'invalid': False,
354 u'id': 4833,
355 u'protection': u'Repair filesystem only',
356 u'synch_id': None},
357 u'priority': 1,
358 u'meta_host': u'Xeon',
359 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\')',
360 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700361 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000362 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800363 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000364 u'owner': u'user0',
365 u'created_on': u'2008-07-30 22:15:43',
366 u'timeout': 144,
367 u'synch_count': 1,
368 u'id': 6761},
369 u'active': 0,
370 u'id': 193166} ])],
371 out_words_ok=['host41', 'host42'],
372 out_words_no=['Xeon', 'Running', 'Queued'],
373 err_words_no=['unassigned'])
374
375
376 def test_job_stat_list_hosts_status(self):
377 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
378 '--list-hosts-status', 'Running,Queued',
379 '--ignore_site_file'],
380 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
381 [{u'status_counts': {u'Queued': 1, u'Running': 1},
382 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\')',
383 u'name': u'test',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700384 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000385 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800386 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000387 u'owner': u'user0',
388 u'created_on': u'2008-07-30 22:15:43',
389 u'timeout': 144,
390 u'synch_count': 1,
391 u'id': 6761}]),
392 ('get_host_queue_entries', {'job__in': ['6761']},
393 True,
394 [{u'status': u'Queued',
395 u'complete': 0,
396 u'deleted': 0,
397 u'host': {u'status': u'Queued',
398 u'lock_time': None,
399 u'hostname': u'host41',
400 u'locked': False,
401 u'locked_by': None,
402 u'invalid': False,
403 u'id': 4833,
404 u'protection': u'Repair filesystem only',
405 u'synch_id': None},
406 u'priority': 1,
407 u'meta_host': None,
408 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\')',
409 u'name': u'test',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700410 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000411 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800412 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000413 u'owner': u'user0',
414 u'created_on': u'2008-07-30 22:15:43',
415 u'timeout': 144,
416 u'synch_count': 1,
417 u'id': 6761},
418 u'active': 0,
419 u'id': 193166},
420 {u'status': u'Running',
421 u'complete': 0,
422 u'deleted': 0,
423 u'host': {u'status': u'Running',
424 u'lock_time': None,
425 u'hostname': u'host42',
426 u'locked': False,
427 u'locked_by': None,
428 u'invalid': False,
429 u'id': 4833,
430 u'protection': u'Repair filesystem only',
431 u'synch_id': None},
432 u'priority': 1,
433 u'meta_host': None,
434 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\')',
435 u'name': u'test',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700436 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000437 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800438 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000439 u'owner': u'user0',
440 u'created_on': u'2008-07-30 22:15:43',
441 u'timeout': 144,
442 u'synch_count': 1,
443 u'id': 6761},
444 u'active': 0,
445 u'id': 193166} ])],
446 out_words_ok=['Queued', 'Running', 'host41', 'host42'],
447 out_words_no=['Xeon'],
448 err_words_no=['unassigned'])
449
450
mblighbe630eb2008-08-01 16:41:48 +0000451 def test_job_stat_job_multiple_hosts(self):
mbligha212d712009-02-11 01:22:36 +0000452 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
453 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000454 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
455 [{u'status_counts': {u'Running': 1,
456 u'Queued': 4},
457 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\')',
458 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700459 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000460 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800461 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000462 u'owner': u'user0',
463 u'created_on': u'2008-07-30 22:15:43',
464 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000465 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000466 u'id': 6761}]),
467 ('get_host_queue_entries', {'job__in': ['6761']},
468 True,
469 [{u'status': u'Queued',
470 u'complete': 0,
471 u'deleted': 0,
472 u'host': None,
473 u'priority': 1,
474 u'meta_host': u'Xeon',
475 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\')',
476 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700477 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000478 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800479 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000480 u'owner': u'user0',
481 u'created_on': u'2008-07-30 22:15:43',
482 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000483 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000484 u'id': 6761},
485 u'active': 0,
486 u'id': 193166},
487 {u'status': u'Queued',
488 u'complete': 0,
489 u'deleted': 0,
490 u'host': None,
491 u'priority': 1,
492 u'meta_host': u'Xeon',
493 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\')',
494 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700495 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000496 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800497 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000498 u'owner': u'user0',
499 u'created_on': u'2008-07-30 22:15:43',
500 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000501 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000502 u'id': 6761},
503 u'active': 0,
504 u'id': 193167},
505 {u'status': u'Queued',
506 u'complete': 0,
507 u'deleted': 0,
508 u'host': None,
509 u'priority': 1,
510 u'meta_host': u'Athlon',
511 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\')',
512 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700513 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000514 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800515 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000516 u'owner': u'user0',
517 u'created_on': u'2008-07-30 22:15:43',
518 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000519 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000520 u'id': 6761},
521 u'active': 0,
522 u'id': 193168},
523 {u'status': u'Queued',
524 u'complete': 0,
525 u'deleted': 0,
526 u'host': None,
527 u'priority': 1,
528 u'meta_host': u'x286',
529 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\')',
530 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700531 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000532 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800533 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000534 u'owner': u'user0',
535 u'created_on': u'2008-07-30 22:15:43',
536 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000537 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000538 u'id': 6761},
539 u'active': 0,
540 u'id': 193169},
541 {u'status': u'Running',
542 u'complete': 0,
543 u'deleted': 0,
544 u'host': {u'status': u'Running',
545 u'lock_time': None,
546 u'hostname': u'host42',
mbligh0887d402009-01-30 00:50:29 +0000547 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000548 u'locked_by': None,
mbligh0887d402009-01-30 00:50:29 +0000549 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000550 u'id': 4833,
551 u'protection': u'Repair filesystem only',
552 u'synch_id': None},
553 u'priority': 1,
554 u'meta_host': u'Athlon',
555 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\')',
556 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700557 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000558 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800559 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000560 u'owner': u'user0',
561 u'created_on': u'2008-07-30 22:15:43',
562 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000563 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000564 u'id': 6761},
565 u'active': 1,
566 u'id': 193170} ])],
567 out_words_ok=['test_on_meta_hosts',
568 'host42', 'Queued', 'Running'],
569 out_words_no=['Athlon', 'Xeon', 'x286'])
570
571
572 def test_job_stat_job_no_host_in_qes(self):
573 results = copy.deepcopy(self.results)
mbligha212d712009-02-11 01:22:36 +0000574 self.run_cmd(argv=['atest', 'job', 'stat', '180',
575 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000576 rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,
577 [results[0]]),
578 ('get_host_queue_entries', {'job__in': ['180']},
579 True,
580 [{u'status': u'Failed',
581 u'complete': 1,
582 u'host': None,
583 u'priority': 1,
584 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000585 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 +0000586 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700587 u'control_type': SERVER,
Allen Li352b86a2016-12-14 12:11:27 -0800588 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000589 u'owner': u'user0',
590 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000591 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000592 u'id': 180},
593 u'active': 0,
594 u'id': 101084}])],
mblighfca5ed12009-11-06 02:59:56 +0000595 err_words_ok=['unassigned', 'meta-hosts'])
mblighbe630eb2008-08-01 16:41:48 +0000596
597
598 def test_job_stat_multi_jobs(self):
599 results = copy.deepcopy(self.results)
mbligha212d712009-02-11 01:22:36 +0000600 self.run_cmd(argv=['atest', 'job', 'stat', '180', '338',
601 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000602 rpcs=[('get_jobs_summary', {'id__in': ['180', '338']},
603 True, results),
604 ('get_host_queue_entries',
605 {'job__in': ['180', '338']},
606 True,
607 [{u'status': u'Failed',
608 u'complete': 1,
609 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000610 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000611 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000612 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000613 u'id': 4432,
614 u'synch_id': None},
615 u'priority': 1,
616 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000617 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 +0000618 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700619 u'control_type': SERVER,
Allen Li352b86a2016-12-14 12:11:27 -0800620 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000621 u'owner': u'user0',
622 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000623 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000624 u'id': 180},
625 u'active': 0,
626 u'id': 101084},
627 {u'status': u'Failed',
628 u'complete': 1,
629 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000630 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000631 u'hostname': u'host10',
mbligh0887d402009-01-30 00:50:29 +0000632 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000633 u'id': 4432,
634 u'synch_id': None},
635 u'priority': 1,
636 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000637 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 +0000638 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700639 u'control_type': SERVER,
Allen Li352b86a2016-12-14 12:11:27 -0800640 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000641 u'owner': u'user0',
642 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000643 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000644 u'id': 338},
645 u'active': 0,
646 u'id': 101084}])],
647 out_words_ok=['test_job0', 'test_job1'])
648
649
650 def test_job_stat_multi_jobs_name_id(self):
mbligha212d712009-02-11 01:22:36 +0000651 self.run_cmd(argv=['atest', 'job', 'stat', 'mytest', '180',
652 '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000653 rpcs=[('get_jobs_summary', {'id__in': ['180']},
654 True,
655 [{u'status_counts': {u'Aborted': 1},
656 u'control_file':
657 u"job.run_test('sleeptest')\n",
658 u'name': u'job0',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700659 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000660 u'priority':
Allen Li352b86a2016-12-14 12:11:27 -0800661 priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000662 u'owner': u'user0',
663 u'created_on':
664 u'2008-07-08 17:45:44',
showard2bab8f42008-11-12 18:15:22 +0000665 u'synch_count': 2,
mblighbe630eb2008-08-01 16:41:48 +0000666 u'id': 180}]),
667 ('get_jobs_summary', {'name__in': ['mytest']},
668 True,
669 [{u'status_counts': {u'Queued': 1},
670 u'control_file':
671 u"job.run_test('sleeptest')\n",
672 u'name': u'mytest',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700673 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000674 u'priority':
Allen Li352b86a2016-12-14 12:11:27 -0800675 priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000676 u'owner': u'user0',
677 u'created_on': u'2008-07-08 12:17:47',
678 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000679 u'id': 338}]),
680 ('get_host_queue_entries',
681 {'job__in': ['180']},
682 True,
683 [{u'status': u'Failed',
684 u'complete': 1,
685 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000686 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000687 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000688 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000689 u'id': 4432,
690 u'synch_id': None},
691 u'priority': 1,
692 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000693 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 +0000694 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700695 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000696 u'synchronizing': 0,
Allen Li352b86a2016-12-14 12:11:27 -0800697 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000698 u'owner': u'user0',
699 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000700 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000701 u'id': 180},
702 u'active': 0,
703 u'id': 101084}]),
704 ('get_host_queue_entries',
705 {'job__name__in': ['mytest']},
706 True,
707 [{u'status': u'Failed',
708 u'complete': 1,
709 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000710 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000711 u'hostname': u'host10',
mbligh0887d402009-01-30 00:50:29 +0000712 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000713 u'id': 4432,
714 u'synch_id': None},
715 u'priority': 1,
716 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000717 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 +0000718 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700719 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000720 u'synchronizing': 0,
Allen Li352b86a2016-12-14 12:11:27 -0800721 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000722 u'owner': u'user0',
723 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000724 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000725 u'id': 338},
726 u'active': 0,
727 u'id': 101084}])],
728 out_words_ok=['job0', 'mytest', 'Aborted', 'Queued',
Allen Li352b86a2016-12-14 12:11:27 -0800729 'Failed', str(priorities.Priority.DEFAULT)])
mblighbe630eb2008-08-01 16:41:48 +0000730
731
732class job_create_unittest(cli_mock.cli_unittest):
733 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)'
734
Richard Barnette41e617b2016-05-19 16:18:16 -0700735 kernel_ctrl_file = 'kernel = \'kernel\'\ndef step_init():\n job.next_step([step_test])\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)'
mblighbe630eb2008-08-01 16:41:48 +0000736
mbligh120351e2009-01-24 01:40:45 +0000737 trivial_ctrl_file = 'print "Hello"\n'
738
Allen Li352b86a2016-12-14 12:11:27 -0800739 data = {'priority': priorities.Priority.DEFAULT, 'control_file': ctrl_file,
740 'hosts': ['host0'],
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700741 'name': 'test_job0', 'control_type': CLIENT, 'email_list': '',
Dan Shiec1d47d2015-02-13 11:38:13 -0800742 'meta_hosts': [], 'synch_count': 1, 'dependencies': [],
743 'require_ssp': False}
mblighbe630eb2008-08-01 16:41:48 +0000744
745
746 def test_execute_create_job(self):
747 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
mbligha212d712009-02-11 01:22:36 +0000748 'test_job0', '-m', 'host0', '--ignore_site_file'],
showard989f25d2008-10-01 11:38:11 +0000749 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000750 {'tests': ['sleeptest']},
showard989f25d2008-10-01 11:38:11 +0000751 True,
752 {'control_file' : self.ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000753 'synch_count' : 1,
showard989f25d2008-10-01 11:38:11 +0000754 'is_server' : False,
755 'dependencies' : []}),
mblighbe630eb2008-08-01 16:41:48 +0000756 ('create_job', self.data, True, 180)],
757 out_words_ok=['test_job0', 'Created'],
758 out_words_no=['Uploading', 'Done'])
759
760
showard648a35c2009-05-01 00:08:42 +0000761 def test_execute_create_job_with_atomic_group(self):
762 data = dict(self.data)
763 data['atomic_group_name'] = 'my-atomic-group'
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700764 data['control_type'] = SERVER
showard648a35c2009-05-01 00:08:42 +0000765 mock_ctrl_file = 'mock control file'
766 data['control_file'] = mock_ctrl_file
767 data['synch_count'] = 2
768 data['hosts'] = []
769 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'mocktest',
770 'test_job0', '--ignore_site_file',
771 '-G', 'my-atomic-group'],
772 rpcs=[('generate_control_file',
773 {'tests': ['mocktest']},
774 True,
775 {'control_file' : mock_ctrl_file,
776 'synch_count' : 2,
777 'is_server' : True,
778 'dependencies' : []}),
779 ('create_job', data, True, 180)],
780 out_words_ok=['test_job0', 'Created'],
781 out_words_no=['Uploading', 'Done'])
782
783
mblighbe630eb2008-08-01 16:41:48 +0000784 def test_execute_create_job_with_control(self):
mbligh41515392009-07-11 00:13:11 +0000785 file_temp = cli_mock.create_file(self.ctrl_file)
786 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000787 'test_job0', '-m', 'host0', '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000788 rpcs=[('create_job', self.data, True, 42)],
789 out_words_ok=['test_job0', 'Created'],
790 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000791 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000792
793
mbligh0a669132008-10-10 20:02:32 +0000794 def test_execute_create_job_with_control_and_email(self):
795 data = self.data.copy()
796 data['email_list'] = 'em'
mbligh41515392009-07-11 00:13:11 +0000797 file_temp = cli_mock.create_file(self.ctrl_file)
798 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000799 'test_job0', '-m', 'host0', '-e', 'em',
800 '--ignore_site_file'],
mbligh0a669132008-10-10 20:02:32 +0000801 rpcs=[('create_job', data, True, 42)],
802 out_words_ok=['test_job0', 'Created'],
803 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000804 file_temp.clean()
mbligh0a669132008-10-10 20:02:32 +0000805
806
showardb27f4ad2009-05-01 00:08:26 +0000807 def test_execute_create_job_with_control_and_dependencies(self):
mbligh0a669132008-10-10 20:02:32 +0000808 data = self.data.copy()
809 data['dependencies'] = ['dep1', 'dep2']
mbligh41515392009-07-11 00:13:11 +0000810 file_temp = cli_mock.create_file(self.ctrl_file)
811 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
showardb27f4ad2009-05-01 00:08:26 +0000812 'test_job0', '-m', 'host0', '-d', 'dep1, dep2 ',
mbligha212d712009-02-11 01:22:36 +0000813 '--ignore_site_file'],
mbligh0a669132008-10-10 20:02:32 +0000814 rpcs=[('create_job', data, True, 42)],
815 out_words_ok=['test_job0', 'Created'],
816 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000817 file_temp.clean()
mbligh0a669132008-10-10 20:02:32 +0000818
819
Eric Li8a12e802011-02-17 14:24:13 -0800820 def test_execute_create_job_with_control_and_comma_dependencies(self):
821 data = self.data.copy()
822 data['dependencies'] = ['dep2,False', 'dep1,True']
823 file_temp = cli_mock.create_file(self.ctrl_file)
824 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
825 'test_job0', '-m', 'host0', '-d',
826 'dep1\,True, dep2\,False ', '--ignore_site_file'],
827 rpcs=[('create_job', data, True, 42)],
828 out_words_ok=['test_job0', 'Created'],
829 out_words_no=['Uploading', 'Done'])
830 file_temp.clean()
831
832
showard7bce1022008-11-14 22:51:05 +0000833 def test_execute_create_job_with_synch_count(self):
834 data = self.data.copy()
835 data['synch_count'] = 2
mbligh41515392009-07-11 00:13:11 +0000836 file_temp = cli_mock.create_file(self.ctrl_file)
837 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000838 'test_job0', '-m', 'host0', '-y', '2',
839 '--ignore_site_file'],
showard7bce1022008-11-14 22:51:05 +0000840 rpcs=[('create_job', data, True, 42)],
841 out_words_ok=['test_job0', 'Created'],
842 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000843 file_temp.clean()
showard7bce1022008-11-14 22:51:05 +0000844
845
showardb27f4ad2009-05-01 00:08:26 +0000846 def test_execute_create_job_with_test_and_dependencies(self):
mblighb9a8b162008-10-29 16:47:29 +0000847 data = self.data.copy()
848 data['dependencies'] = ['dep1', 'dep2', 'dep3']
849 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
showardb27f4ad2009-05-01 00:08:26 +0000850 'test_job0', '-m', 'host0', '-d', 'dep1, dep2 ',
mbligha212d712009-02-11 01:22:36 +0000851 '--ignore_site_file'],
mblighb9a8b162008-10-29 16:47:29 +0000852 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000853 {'tests': ['sleeptest']},
mblighb9a8b162008-10-29 16:47:29 +0000854 True,
855 {'control_file' : self.ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000856 'synch_count' : 1,
mblighb9a8b162008-10-29 16:47:29 +0000857 'is_server' : False,
858 'dependencies' : ['dep3']}),
859 ('create_job', data, True, 42)],
860 out_words_ok=['test_job0', 'Created'],
861 out_words_no=['Uploading', 'Done'])
862
863
Eric Li8a12e802011-02-17 14:24:13 -0800864 def test_execute_create_job_with_test_and_comma_dependencies(self):
865 data = self.data.copy()
866 data['dependencies'] = ['dep1,True', 'dep2,False', 'dep3,123']
867 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
868 'test_job0', '-m', 'host0', '-d',
869 'dep1\,True dep2\,False ', '--ignore_site_file'],
870 rpcs=[('generate_control_file',
871 {'tests': ['sleeptest']},
872 True,
873 {'control_file' : self.ctrl_file,
874 'synch_count' : 1,
875 'is_server' : False,
876 'dependencies' : ['dep3,123']}),
877 ('create_job', data, True, 42)],
878 out_words_ok=['test_job0', 'Created'],
879 out_words_no=['Uploading', 'Done'])
880
881
mblighbe630eb2008-08-01 16:41:48 +0000882 def test_execute_create_job_no_args(self):
883 testjob = job.job_create()
mbligha212d712009-02-11 01:22:36 +0000884 sys.argv = ['atest', 'job', 'create', '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000885 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000886 (sys.exit.expect_call(mock.anything_comparator())
887 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000888 self.assertRaises(cli_mock.ExitException, testjob.parse)
889 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000890 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000891
892
893 def test_execute_create_job_no_hosts(self):
894 testjob = job.job_create()
mbligh41515392009-07-11 00:13:11 +0000895 file_temp = cli_mock.create_file(self.ctrl_file)
896 sys.argv = ['atest', '-f', file_temp.name, 'test_job0',
897 '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000898 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000899 (sys.exit.expect_call(mock.anything_comparator())
900 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000901 self.assertRaises(cli_mock.ExitException, testjob.parse)
902 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000903 self.god.check_playback()
mbligh41515392009-07-11 00:13:11 +0000904 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000905
906
907 def test_execute_create_job_cfile_and_tests(self):
908 testjob = job.job_create()
909 sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-f',
mbligha212d712009-02-11 01:22:36 +0000910 'control_file', 'test_job0', '-m', 'host0',
911 '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000912 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000913 (sys.exit.expect_call(mock.anything_comparator())
914 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000915 self.assertRaises(cli_mock.ExitException, testjob.parse)
916 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000917 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000918
919
mblighbe630eb2008-08-01 16:41:48 +0000920 def test_execute_create_job_bad_cfile(self):
921 testjob = job.job_create()
mbligha212d712009-02-11 01:22:36 +0000922 sys.argv = ['atest', 'job', 'create', '-f', 'control_file',
923 'test_job0', '-m', 'host0', '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000924 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000925 (sys.exit.expect_call(mock.anything_comparator())
926 .and_raises(IOError))
mblighbe630eb2008-08-01 16:41:48 +0000927 self.assertRaises(IOError, testjob.parse)
928 self.god.unmock_io()
929
930
931 def test_execute_create_job_bad_priority(self):
932 testjob = job.job_create()
933 sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-p', 'Uber',
mbligha212d712009-02-11 01:22:36 +0000934 '-m', 'host0', 'test_job0', '--ignore_site_file']
mblighbe630eb2008-08-01 16:41:48 +0000935 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000936 (sys.exit.expect_call(mock.anything_comparator())
937 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000938 self.assertRaises(cli_mock.ExitException, testjob.parse)
939 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000940 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000941
942
943 def test_execute_create_job_with_mfile(self):
944 data = self.data.copy()
945 data['hosts'] = ['host3', 'host2', 'host1', 'host0']
mbligh41515392009-07-11 00:13:11 +0000946 ctemp = cli_mock.create_file(self.ctrl_file)
947 file_temp = cli_mock.create_file('host0\nhost1\nhost2\nhost3')
948 self.run_cmd(argv=['atest', 'job', 'create', '--mlist', file_temp.name,
949 '-f', ctemp.name, 'test_job0', '--ignore_site_file'],
mblighbe630eb2008-08-01 16:41:48 +0000950 rpcs=[('create_job', data, True, 42)],
951 out_words_ok=['test_job0', 'Created'])
mbligh41515392009-07-11 00:13:11 +0000952 ctemp.clean()
953 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000954
955
mbligh5d0b4b32008-12-22 14:43:01 +0000956 def test_execute_create_job_with_timeout(self):
957 data = self.data.copy()
Simran Basi7e605742013-11-12 13:43:36 -0800958 data['timeout_mins'] = '13320'
mbligh41515392009-07-11 00:13:11 +0000959 file_temp = cli_mock.create_file(self.ctrl_file)
960 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Simran Basi7e605742013-11-12 13:43:36 -0800961 'test_job0', '-m', 'host0', '-o', '13320',
mbligha212d712009-02-11 01:22:36 +0000962 '--ignore_site_file'],
mbligh5d0b4b32008-12-22 14:43:01 +0000963 rpcs=[('create_job', data, True, 42)],
964 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +0000965 file_temp.clean()
mbligh5d0b4b32008-12-22 14:43:01 +0000966
967
showard12f3e322009-05-13 21:27:42 +0000968 def test_execute_create_job_with_max_runtime(self):
969 data = self.data.copy()
Simran Basi34217022012-11-06 13:43:15 -0800970 data['max_runtime_mins'] = '13320'
mbligh41515392009-07-11 00:13:11 +0000971 file_temp = cli_mock.create_file(self.ctrl_file)
972 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Simran Basi34217022012-11-06 13:43:15 -0800973 'test_job0', '-m', 'host0', '--max_runtime',
974 '13320', '--ignore_site_file'],
showard12f3e322009-05-13 21:27:42 +0000975 rpcs=[('create_job', data, True, 42)],
976 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +0000977 file_temp.clean()
showard12f3e322009-05-13 21:27:42 +0000978
979
980
mbligh5d0b4b32008-12-22 14:43:01 +0000981 def test_execute_create_job_with_noverify(self):
982 data = self.data.copy()
983 data['run_verify'] = False
mbligh41515392009-07-11 00:13:11 +0000984 file_temp = cli_mock.create_file(self.ctrl_file)
985 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
mbligha212d712009-02-11 01:22:36 +0000986 'test_job0', '-m', 'host0', '-n',
987 '--ignore_site_file'],
mbligh5d0b4b32008-12-22 14:43:01 +0000988 rpcs=[('create_job', data, True, 42)],
989 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +0000990 file_temp.clean()
mbligh5d0b4b32008-12-22 14:43:01 +0000991
992
mblighce348642009-02-12 21:50:39 +0000993 def test_execute_create_job_oth(self):
994 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +0000995 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +0000996 data['one_time_hosts'] = ['host0']
997 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
998 'test_job0', '--one-time-hosts', 'host0'],
999 rpcs=[('generate_control_file',
1000 {'tests': ['sleeptest']},
1001 True,
1002 {'control_file' : self.ctrl_file,
1003 'synch_count' : 1,
1004 'is_server' : False,
1005 'dependencies' : []}),
1006 ('create_job', data, True, 180)],
1007 out_words_ok=['test_job0', 'Created'],
1008 out_words_no=['Uploading', 'Done'])
1009
1010
1011 def test_execute_create_job_multi_oth(self):
1012 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +00001013 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +00001014 data['one_time_hosts'] = ['host1', 'host0']
1015 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
1016 'test_job0', '--one-time-hosts', 'host0,host1'],
1017 rpcs=[('generate_control_file',
1018 {'tests': ['sleeptest']},
1019 True,
1020 {'control_file' : self.ctrl_file,
1021 'synch_count' : 1,
1022 'is_server' : False,
1023 'dependencies' : []}),
1024 ('create_job', data, True, 180)],
1025 out_words_ok=['test_job0', 'Created'],
1026 out_words_no=['Uploading', 'Done'])
1027
1028
1029 def test_execute_create_job_oth_exists(self):
1030 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +00001031 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +00001032 data['one_time_hosts'] = ['host0']
1033 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
1034 'test_job0', '--one-time-hosts', 'host0'],
1035 rpcs=[('generate_control_file',
1036 {'tests': ['sleeptest']},
1037 True,
1038 {'control_file' : self.ctrl_file,
1039 'synch_count' : 1,
1040 'is_server' : False,
1041 'dependencies' : []}),
1042 ('create_job', data, False,
1043 '''ValidationError: {'hostname': 'host0 '''
1044 '''already exists in the autotest DB. '''
1045 '''Select it rather than entering it as '''
1046 '''a one time host.'}''')],
1047 out_words_no=['test_job0', 'Created'],
1048 err_words_ok=['failed', 'already exists'])
1049
1050
showardb27f4ad2009-05-01 00:08:26 +00001051 def test_execute_create_job_with_control_and_labels(self):
1052 data = self.data.copy()
1053 data['hosts'] = ['host0', 'host1', 'host2']
mbligh41515392009-07-11 00:13:11 +00001054 file_temp = cli_mock.create_file(self.ctrl_file)
1055 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
showardb27f4ad2009-05-01 00:08:26 +00001056 'test_job0', '-m', 'host0', '-b', 'label1,label2',
1057 '--ignore_site_file'],
1058 rpcs=[('get_hosts', {'multiple_labels': ['label1',
1059 'label2']}, True,
1060 [{u'status': u'Running', u'lock_time': None,
1061 u'hostname': u'host1', u'locked': False,
1062 u'locked_by': None, u'invalid': False, u'id': 42,
1063 u'labels': [u'label1'], u'platform':
1064 u'Warp18_Diskfull', u'protection':
1065 u'Repair software only', u'dirty':
1066 True, u'synch_id': None},
1067 {u'status': u'Running', u'lock_time': None,
1068 u'hostname': u'host2', u'locked': False,
1069 u'locked_by': None, u'invalid': False, u'id': 43,
1070 u'labels': [u'label2'], u'platform':
1071 u'Warp18_Diskfull', u'protection':
1072 u'Repair software only', u'dirty': True,
1073 u'synch_id': None}]),
1074 ('create_job', data, True, 42)],
1075 out_words_ok=['test_job0', 'Created'],
1076 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +00001077 file_temp.clean()
showardb27f4ad2009-05-01 00:08:26 +00001078
1079
1080 def test_execute_create_job_with_label_and_duplicate_hosts(self):
1081 data = self.data.copy()
1082 data['hosts'] = ['host1', 'host0']
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,
showardb27f4ad2009-05-01 00:08:26 +00001085 'test_job0', '-m', 'host0,host1', '-b', 'label1',
1086 '--ignore_site_file'],
1087 rpcs=[('get_hosts', {'multiple_labels': ['label1']}, True,
1088 [{u'status': u'Running', u'lock_time': None,
1089 u'hostname': u'host1', u'locked': False,
1090 u'locked_by': None, u'invalid': False, u'id': 42,
1091 u'labels': [u'label1'], u'platform':
1092 u'Warp18_Diskfull', u'protection':
1093 u'Repair software only', u'dirty':
1094 True, u'synch_id': None}]),
1095 ('create_job', data, True, 42)],
1096 out_words_ok=['test_job0', 'Created'],
1097 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +00001098 file_temp.clean()
showardb27f4ad2009-05-01 00:08:26 +00001099
1100
jamesrenc2863162010-07-12 21:20:51 +00001101 def test_execute_create_job_with_label_commas_and_duplicate_hosts(self):
1102 data = self.data.copy()
1103 data['hosts'] = ['host1', 'host0']
1104 file_temp = cli_mock.create_file(self.ctrl_file)
1105 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1106 'test_job0', '-m', 'host0,host1', '-b',
1107 'label1,label\\,2', '--ignore_site_file'],
1108 rpcs=[('get_hosts', {'multiple_labels': ['label1',
1109 'label,2']}, True,
1110 [{u'status': u'Running', u'lock_time': None,
1111 u'hostname': u'host1', u'locked': False,
1112 u'locked_by': None, u'invalid': False, u'id': 42,
1113 u'labels': [u'label1', u'label,2'], u'platform':
1114 u'Warp18_Diskfull', u'protection':
1115 u'Repair software only', u'dirty':
1116 True, u'synch_id': None}]),
1117 ('create_job', data, True, 42)],
1118 out_words_ok=['test_job0', 'Created'],
1119 out_words_no=['Uploading', 'Done'])
1120 file_temp.clean()
1121
1122
1123 def test_execute_create_job_with_label_escaping_and_duplicate_hosts(self):
1124 data = self.data.copy()
1125 data['hosts'] = ['host1', 'host0']
1126 file_temp = cli_mock.create_file(self.ctrl_file)
1127 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1128 'test_job0', '-m', 'host0,host1', '-b',
1129 'label1,label\\,2\\\\,label3', '--ignore_site_file'],
1130 rpcs=[('get_hosts', {'multiple_labels': ['label,2\\',
1131 'label1', 'label3']}, True,
1132 [{u'status': u'Running', u'lock_time': None,
1133 u'hostname': u'host1', u'locked': False,
1134 u'locked_by': None, u'invalid': False, u'id': 42,
1135 u'labels': [u'label1', u'label,2\\', u'label3'],
1136 u'platform': u'Warp18_Diskfull', u'protection':
1137 u'Repair software only', u'dirty':
1138 True, u'synch_id': None}]),
1139 ('create_job', data, True, 42)],
1140 out_words_ok=['test_job0', 'Created'],
1141 out_words_no=['Uploading', 'Done'])
1142 file_temp.clean()
1143
1144
mblighbe630eb2008-08-01 16:41:48 +00001145 def _test_parse_hosts(self, args, exp_hosts=[], exp_meta_hosts=[]):
mbligh56f1f4a2009-08-03 16:45:12 +00001146 testjob = job.job_create_or_clone()
1147 (hosts, meta_hosts) = testjob._parse_hosts(args)
mblighbe630eb2008-08-01 16:41:48 +00001148 self.assertEqualNoOrder(hosts, exp_hosts)
1149 self.assertEqualNoOrder(meta_hosts, exp_meta_hosts)
1150
1151
1152 def test_parse_hosts_regular(self):
1153 self._test_parse_hosts(['host0'], ['host0'])
1154
1155
1156 def test_parse_hosts_regulars(self):
1157 self._test_parse_hosts(['host0', 'host1'], ['host0', 'host1'])
1158
1159
1160 def test_parse_hosts_meta_one(self):
1161 self._test_parse_hosts(['*meta0'], [], ['meta0'])
1162
1163
1164 def test_parse_hosts_meta_five(self):
1165 self._test_parse_hosts(['5*meta0'], [], ['meta0']*5)
1166
1167
1168 def test_parse_hosts_metas_five(self):
1169 self._test_parse_hosts(['5*meta0', '2*meta1'], [],
1170 ['meta0']*5 + ['meta1']*2)
1171
1172
1173 def test_parse_hosts_mix(self):
1174 self._test_parse_hosts(['5*meta0', 'host0', '2*meta1', 'host1',
1175 '*meta2'], ['host0', 'host1'],
1176 ['meta0']*5 + ['meta1']*2 + ['meta2'])
1177
1178
mbligh5a496082009-08-03 16:44:54 +00001179class job_clone_unittest(cli_mock.cli_unittest):
1180 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 -07001181 'control_type': SERVER,
mbligh5a496082009-08-03 16:44:54 +00001182 'dependencies': [],
1183 'email_list': u'',
Simran Basi34217022012-11-06 13:43:15 -08001184 'max_runtime_mins': 28800,
mbligh5a496082009-08-03 16:44:54 +00001185 'parse_failed_repair': True,
Allen Li352b86a2016-12-14 12:11:27 -08001186 'priority': priorities.Priority.DEFAULT,
mbligh5a496082009-08-03 16:44:54 +00001187 'reboot_after': u'Always',
1188 'reboot_before': u'If dirty',
1189 'run_verify': True,
1190 'synch_count': 1,
Simran Basi7e605742013-11-12 13:43:36 -08001191 'timeout_mins': 480}
mbligh5a496082009-08-03 16:44:54 +00001192
mbligh56f1f4a2009-08-03 16:45:12 +00001193 local_hosts = [{u'acls': [u'acl0'],
1194 u'atomic_group': None,
1195 u'attributes': {},
1196 u'dirty': False,
1197 u'hostname': u'host0',
1198 u'id': 8,
1199 u'invalid': False,
1200 u'labels': [u'label0', u'label1'],
1201 u'lock_time': None,
1202 u'locked': False,
1203 u'locked_by': None,
1204 u'other_labels': u'label0, label1',
1205 u'platform': u'plat0',
1206 u'protection': u'Repair software only',
1207 u'status': u'Ready',
1208 u'synch_id': None},
1209 {u'acls': [u'acl0'],
1210 u'atomic_group': None,
1211 u'attributes': {},
1212 u'dirty': False,
1213 u'hostname': u'host1',
1214 u'id': 9,
1215 u'invalid': False,
1216 u'labels': [u'label0', u'label1'],
1217 u'lock_time': None,
1218 u'locked': False,
1219 u'locked_by': None,
1220 u'other_labels': u'label0, label1',
1221 u'platform': u'plat0',
1222 u'protection': u'Repair software only',
1223 u'status': u'Ready',
1224 u'synch_id': None}]
1225
1226
mbligh5a496082009-08-03 16:44:54 +00001227 def setUp(self):
1228 super(job_clone_unittest, self).setUp()
1229 self.job_data_clone_info = copy.deepcopy(self.job_data)
1230 self.job_data_clone_info['created_on'] = '2009-07-23 16:21:29'
1231 self.job_data_clone_info['name'] = 'testing_clone'
1232 self.job_data_clone_info['id'] = 42
1233 self.job_data_clone_info['owner'] = 'user0'
1234
1235 self.job_data_cloned = copy.deepcopy(self.job_data)
1236 self.job_data_cloned['name'] = 'cloned'
1237 self.job_data_cloned['hosts'] = [u'host0']
1238 self.job_data_cloned['meta_hosts'] = []
1239
1240
1241 def test_backward_compat(self):
1242 self.run_cmd(argv=['atest', 'job', 'create', '--clone', '42',
1243 '-r', 'cloned'],
1244 rpcs=[('get_info_for_clone', {'id': '42',
1245 'preserve_metahosts': True},
1246 True,
1247 {u'atomic_group_name': None,
1248 u'hosts': [{u'acls': [u'acl0'],
1249 u'atomic_group': None,
1250 u'attributes': {},
1251 u'dirty': False,
1252 u'hostname': u'host0',
1253 u'id': 4378,
1254 u'invalid': False,
1255 u'labels': [u'label0', u'label1'],
1256 u'lock_time': None,
1257 u'locked': False,
1258 u'locked_by': None,
1259 u'other_labels': u'label0, label1',
1260 u'platform': u'plat0',
1261 u'protection': u'Repair software only',
1262 u'status': u'Ready',
1263 u'synch_id': None}],
1264 u'job': self.job_data_clone_info,
1265 u'meta_host_counts': {}}),
1266 ('create_job', self.job_data_cloned, True, 43)],
1267 out_words_ok=['Created job', '43'])
1268
1269
1270 def test_clone_reuse_hosts(self):
mbligh56f1f4a2009-08-03 16:45:12 +00001271 self.job_data_cloned['hosts'] = [u'host0', 'host1']
mbligh5a496082009-08-03 16:44:54 +00001272 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1273 '-r', 'cloned'],
1274 rpcs=[('get_info_for_clone', {'id': '42',
1275 'preserve_metahosts': True},
1276 True,
1277 {u'atomic_group_name': None,
mbligh56f1f4a2009-08-03 16:45:12 +00001278 u'hosts': self.local_hosts,
mbligh5a496082009-08-03 16:44:54 +00001279 u'job': self.job_data_clone_info,
1280 u'meta_host_counts': {}}),
1281 ('create_job', self.job_data_cloned, True, 43)],
1282 out_words_ok=['Created job', '43'])
1283
1284
mbligh56f1f4a2009-08-03 16:45:12 +00001285 def test_clone_reuse_metahosts(self):
1286 self.job_data_cloned['hosts'] = []
1287 self.job_data_cloned['meta_hosts'] = ['type1']*4 + ['type0']
1288 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1289 '-r', 'cloned'],
1290 rpcs=[('get_info_for_clone', {'id': '42',
1291 'preserve_metahosts': True},
1292 True,
1293 {u'atomic_group_name': None,
1294 u'hosts': [],
1295 u'job': self.job_data_clone_info,
1296 u'meta_host_counts': {u'type0': 1,
1297 u'type1': 4}}),
1298 ('create_job', self.job_data_cloned, True, 43)],
1299 out_words_ok=['Created job', '43'])
1300
1301
1302 def test_clone_reuse_both(self):
1303 self.job_data_cloned['hosts'] = [u'host0', 'host1']
1304 self.job_data_cloned['meta_hosts'] = ['type1']*4 + ['type0']
1305 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1306 '-r', 'cloned'],
1307 rpcs=[('get_info_for_clone', {'id': '42',
1308 'preserve_metahosts': True},
1309 True,
1310 {u'atomic_group_name': None,
1311 u'hosts': self.local_hosts,
1312 u'job': self.job_data_clone_info,
1313 u'meta_host_counts': {u'type0': 1,
1314 u'type1': 4}}),
1315 ('create_job', self.job_data_cloned, True, 43)],
1316 out_words_ok=['Created job', '43'])
1317
1318
mbligh5a496082009-08-03 16:44:54 +00001319 def test_clone_no_hosts(self):
1320 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42', 'cloned'],
1321 exit_code=1,
1322 out_words_ok=['usage'],
1323 err_words_ok=['machine'])
1324
1325
mbligh56f1f4a2009-08-03 16:45:12 +00001326 def test_clone_reuse_and_hosts(self):
1327 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1328 '-r', '-m', 'host5', 'cloned'],
1329 exit_code=1,
1330 out_words_ok=['usage'],
1331 err_words_ok=['specify'])
1332
1333
1334 def test_clone_new_multiple_hosts(self):
1335 self.job_data_cloned['hosts'] = [u'host5', 'host4', 'host3']
1336 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1337 '-m', 'host5,host4,host3', 'cloned'],
1338 rpcs=[('get_info_for_clone', {'id': '42',
1339 'preserve_metahosts': False},
1340 True,
1341 {u'atomic_group_name': None,
1342 u'hosts': self.local_hosts,
1343 u'job': self.job_data_clone_info,
1344 u'meta_host_counts': {}}),
1345 ('create_job', self.job_data_cloned, True, 43)],
1346 out_words_ok=['Created job', '43'])
1347
1348
1349 def test_clone_oth(self):
1350 self.job_data_cloned['hosts'] = []
1351 self.job_data_cloned['one_time_hosts'] = [u'host5']
1352 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1353 '--one-time-hosts', 'host5', 'cloned'],
1354 rpcs=[('get_info_for_clone', {'id': '42',
1355 'preserve_metahosts': False},
1356 True,
1357 {u'atomic_group_name': None,
1358 u'hosts': self.local_hosts,
1359 u'job': self.job_data_clone_info,
1360 u'meta_host_counts': {}}),
1361 ('create_job', self.job_data_cloned, True, 43)],
1362 out_words_ok=['Created job', '43'])
mbligh5a496082009-08-03 16:44:54 +00001363
1364
mblighbe630eb2008-08-01 16:41:48 +00001365class job_abort_unittest(cli_mock.cli_unittest):
1366 results = [{u'status_counts': {u'Aborted': 1}, u'control_file':
1367 u"job.run_test('sleeptest')\n", u'name': u'test_job0',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001368 u'control_type': SERVER, u'priority':
Allen Li352b86a2016-12-14 12:11:27 -08001369 priorities.Priority.DEFAULT, u'owner': u'user0', u'created_on':
showard2bab8f42008-11-12 18:15:22 +00001370 u'2008-07-08 17:45:44', u'synch_count': 2, u'id': 180}]
mblighbe630eb2008-08-01 16:41:48 +00001371
1372 def test_execute_job_abort(self):
mbligha212d712009-02-11 01:22:36 +00001373 self.run_cmd(argv=['atest', 'job', 'abort', '180',
1374 '--ignore_site_file'],
mbligh206d50a2008-11-13 01:19:25 +00001375 rpcs=[('abort_host_queue_entries',
1376 {'job__id__in': ['180']}, True, None)],
1377 out_words_ok=['Aborting', '180'])
mblighbe630eb2008-08-01 16:41:48 +00001378
1379
1380if __name__ == '__main__':
1381 unittest.main()