blob: f0b5e1e76d2b23e048a1f7c79714f5181577aed5 [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')
Allen Lib774aa22017-02-01 17:42:15 -0800112 self.run_cmd(argv=['atest', 'job', 'list'],
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']
Allen Lib774aa22017-02-01 17:42:15 -0800122 self.run_cmd(argv=['atest', 'job', 'list', '-u', 'Cringer'],
mblighbe630eb2008-08-01 16:41:48 +0000123 rpcs=[('get_jobs_summary', {'owner': 'Cringer',
124 'running': None},
125 True, values)],
126 out_words_ok=['Cringer'],
127 out_words_no=['Fisto', 'Roboto', 'Panthor', 'Icer',
128 'Spikor'])
129
130
131 def test_job_list_jobs_all(self):
Allen Lib774aa22017-02-01 17:42:15 -0800132 self.run_cmd(argv=['atest', 'job', 'list', '--all'],
mblighbe630eb2008-08-01 16:41:48 +0000133 rpcs=[('get_jobs_summary', {'running': None},
134 True, self.values)],
135 out_words_ok=['Fisto', 'Roboto', 'Panthor',
136 'Icer', 'Spikor', 'Cringer'],
137 out_words_no=['Created', 'Priority'])
138
139
140 def test_job_list_jobs_id(self):
Allen Lib774aa22017-02-01 17:42:15 -0800141 self.run_cmd(argv=['atest', 'job', 'list', '5964'],
mblighbe630eb2008-08-01 16:41:48 +0000142 rpcs=[('get_jobs_summary', {'id__in': ['5964'],
143 'running': None},
144 True,
145 [{u'status_counts': {u'Completed': 1},
Richard Barnette41e617b2016-05-19 16:18:16 -0700146 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 +0000147 u'name': u'mytest',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700148 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000149 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800150 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000151 u'owner': u'user0',
152 u'created_on': u'2008-07-28 12:42:52',
153 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000154 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000155 u'id': 5964}])],
156 out_words_ok=['user0', 'Completed', '1', '5964'],
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700157 out_words_no=['sleeptest', 'Priority', CLIENT, '2008'])
mblighbe630eb2008-08-01 16:41:48 +0000158
159
160 def test_job_list_jobs_id_verbose(self):
Allen Lib774aa22017-02-01 17:42:15 -0800161 self.run_cmd(argv=['atest', 'job', 'list', '5964', '-v'],
mblighbe630eb2008-08-01 16:41:48 +0000162 rpcs=[('get_jobs_summary', {'id__in': ['5964'],
163 'running': None},
164 True,
165 [{u'status_counts': {u'Completed': 1},
Richard Barnette41e617b2016-05-19 16:18:16 -0700166 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 +0000167 u'name': u'mytest',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700168 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000169 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800170 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000171 u'owner': u'user0',
172 u'created_on': u'2008-07-28 12:42:52',
173 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000174 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000175 u'id': 5964}])],
176 out_words_ok=['user0', 'Completed', '1', '5964',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700177 CLIENT, '2008', 'Priority'],
mblighbe630eb2008-08-01 16:41:48 +0000178 out_words_no=['sleeptest'])
179
180
181 def test_job_list_jobs_name(self):
Allen Lib774aa22017-02-01 17:42:15 -0800182 self.run_cmd(argv=['atest', 'job', 'list', 'myt*'],
mblighbe630eb2008-08-01 16:41:48 +0000183 rpcs=[('get_jobs_summary', {'name__startswith': 'myt',
184 'running': None},
185 True,
186 [{u'status_counts': {u'Completed': 1},
Richard Barnette41e617b2016-05-19 16:18:16 -0700187 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 +0000188 u'name': u'mytest',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700189 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000190 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800191 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000192 u'owner': u'user0',
193 u'created_on': u'2008-07-28 12:42:52',
194 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000195 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000196 u'id': 5964}])],
197 out_words_ok=['user0', 'Completed', '1', '5964'],
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700198 out_words_no=['sleeptest', 'Priority', CLIENT, '2008'])
mblighbe630eb2008-08-01 16:41:48 +0000199
200
201 def test_job_list_jobs_all_verbose(self):
Allen Lib774aa22017-02-01 17:42:15 -0800202 self.run_cmd(argv=['atest', 'job', 'list', '--all', '--verbose'],
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()
Allen Lib774aa22017-02-01 17:42:15 -0800212 sys.argv = ['atest', 'job', 'list', '-a', '-u', 'user0']
mblighbe630eb2008-08-01 16:41:48 +0000213 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000214 (sys.exit.expect_call(mock.anything_comparator())
215 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000216 self.assertRaises(cli_mock.ExitException, testjob.parse)
217 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000218 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000219
220
221class job_stat_unittest(job_unittest):
222 def test_job_stat_job(self):
223 results = copy.deepcopy(self.results)
Allen Lib774aa22017-02-01 17:42:15 -0800224 self.run_cmd(argv=['atest', 'job', 'stat', '180'],
mblighbe630eb2008-08-01 16:41:48 +0000225 rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,
226 [results[0]]),
227 ('get_host_queue_entries', {'job__in': ['180']},
228 True,
229 [{u'status': u'Failed',
230 u'complete': 1,
231 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000232 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000233 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000234 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000235 u'id': 4432,
236 u'synch_id': None},
237 u'priority': 1,
238 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000239 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 +0000240 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700241 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000242 u'synchronizing': 0,
Allen Li352b86a2016-12-14 12:11:27 -0800243 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000244 u'owner': u'user0',
245 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000246 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000247 u'id': 180},
248 u'active': 0,
249 u'id': 101084}])],
250 out_words_ok=['test_job0', 'host0', 'Failed',
251 'Aborted'])
252
253
mblighfca5ed12009-11-06 02:59:56 +0000254
255 def test_job_stat_list_unassigned_host(self):
256 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
Allen Lib774aa22017-02-01 17:42:15 -0800257 '--list-hosts'],
mblighfca5ed12009-11-06 02:59:56 +0000258 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
259 [{u'status_counts': {u'Queued': 1},
260 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\')',
261 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700262 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000263 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800264 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000265 u'owner': u'user0',
266 u'created_on': u'2008-07-30 22:15:43',
267 u'timeout': 144,
268 u'synch_count': 1,
269 u'id': 6761}]),
270 ('get_host_queue_entries', {'job__in': ['6761']},
271 True,
272 [{u'status': u'Queued',
273 u'complete': 0,
274 u'deleted': 0,
275 u'host': None,
276 u'priority': 1,
277 u'meta_host': u'Xeon',
278 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\')',
279 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700280 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000281 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800282 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000283 u'owner': u'user0',
284 u'created_on': u'2008-07-30 22:15:43',
285 u'timeout': 144,
286 u'synch_count': 1,
287 u'id': 6761},
288 u'active': 0,
289 u'id': 193166} ])],
290 err_words_ok=['unassigned', 'meta-hosts'],
291 out_words_no=['Xeon'])
292
293
294 def test_job_stat_list_hosts(self):
295 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
Allen Lib774aa22017-02-01 17:42:15 -0800296 '--list-hosts'],
mblighfca5ed12009-11-06 02:59:56 +0000297 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
298 [{u'status_counts': {u'Queued': 1},
299 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\')',
300 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700301 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000302 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800303 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000304 u'owner': u'user0',
305 u'created_on': u'2008-07-30 22:15:43',
306 u'timeout': 144,
307 u'synch_count': 1,
308 u'id': 6761}]),
309 ('get_host_queue_entries', {'job__in': ['6761']},
310 True,
311 [{u'status': u'Queued',
312 u'complete': 0,
313 u'deleted': 0,
314 u'host': {u'status': u'Running',
315 u'lock_time': None,
316 u'hostname': u'host41',
317 u'locked': False,
318 u'locked_by': None,
319 u'invalid': False,
320 u'id': 4833,
321 u'protection': u'Repair filesystem only',
322 u'synch_id': None},
323 u'priority': 1,
324 u'meta_host': u'Xeon',
325 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\')',
326 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700327 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000328 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800329 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000330 u'owner': u'user0',
331 u'created_on': u'2008-07-30 22:15:43',
332 u'timeout': 144,
333 u'synch_count': 1,
334 u'id': 6761},
335 u'active': 0,
336 u'id': 193166},
337 {u'status': u'Running',
338 u'complete': 0,
339 u'deleted': 0,
340 u'host': {u'status': u'Running',
341 u'lock_time': None,
342 u'hostname': u'host42',
343 u'locked': False,
344 u'locked_by': None,
345 u'invalid': False,
346 u'id': 4833,
347 u'protection': u'Repair filesystem only',
348 u'synch_id': None},
349 u'priority': 1,
350 u'meta_host': u'Xeon',
351 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\')',
352 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700353 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000354 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800355 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000356 u'owner': u'user0',
357 u'created_on': u'2008-07-30 22:15:43',
358 u'timeout': 144,
359 u'synch_count': 1,
360 u'id': 6761},
361 u'active': 0,
362 u'id': 193166} ])],
363 out_words_ok=['host41', 'host42'],
364 out_words_no=['Xeon', 'Running', 'Queued'],
365 err_words_no=['unassigned'])
366
367
368 def test_job_stat_list_hosts_status(self):
369 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
Allen Lib774aa22017-02-01 17:42:15 -0800370 '--list-hosts-status', 'Running,Queued'],
mblighfca5ed12009-11-06 02:59:56 +0000371 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
372 [{u'status_counts': {u'Queued': 1, u'Running': 1},
373 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\')',
374 u'name': u'test',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700375 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000376 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800377 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000378 u'owner': u'user0',
379 u'created_on': u'2008-07-30 22:15:43',
380 u'timeout': 144,
381 u'synch_count': 1,
382 u'id': 6761}]),
383 ('get_host_queue_entries', {'job__in': ['6761']},
384 True,
385 [{u'status': u'Queued',
386 u'complete': 0,
387 u'deleted': 0,
388 u'host': {u'status': u'Queued',
389 u'lock_time': None,
390 u'hostname': u'host41',
391 u'locked': False,
392 u'locked_by': None,
393 u'invalid': False,
394 u'id': 4833,
395 u'protection': u'Repair filesystem only',
396 u'synch_id': None},
397 u'priority': 1,
398 u'meta_host': None,
399 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\')',
400 u'name': u'test',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700401 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000402 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800403 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000404 u'owner': u'user0',
405 u'created_on': u'2008-07-30 22:15:43',
406 u'timeout': 144,
407 u'synch_count': 1,
408 u'id': 6761},
409 u'active': 0,
410 u'id': 193166},
411 {u'status': u'Running',
412 u'complete': 0,
413 u'deleted': 0,
414 u'host': {u'status': u'Running',
415 u'lock_time': None,
416 u'hostname': u'host42',
417 u'locked': False,
418 u'locked_by': None,
419 u'invalid': False,
420 u'id': 4833,
421 u'protection': u'Repair filesystem only',
422 u'synch_id': None},
423 u'priority': 1,
424 u'meta_host': None,
425 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\')',
426 u'name': u'test',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700427 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000428 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800429 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000430 u'owner': u'user0',
431 u'created_on': u'2008-07-30 22:15:43',
432 u'timeout': 144,
433 u'synch_count': 1,
434 u'id': 6761},
435 u'active': 0,
436 u'id': 193166} ])],
437 out_words_ok=['Queued', 'Running', 'host41', 'host42'],
438 out_words_no=['Xeon'],
439 err_words_no=['unassigned'])
440
441
mblighbe630eb2008-08-01 16:41:48 +0000442 def test_job_stat_job_multiple_hosts(self):
Allen Lib774aa22017-02-01 17:42:15 -0800443 self.run_cmd(argv=['atest', 'job', 'stat', '6761'],
mblighbe630eb2008-08-01 16:41:48 +0000444 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
445 [{u'status_counts': {u'Running': 1,
446 u'Queued': 4},
447 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\')',
448 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700449 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000450 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800451 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000452 u'owner': u'user0',
453 u'created_on': u'2008-07-30 22:15:43',
454 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000455 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000456 u'id': 6761}]),
457 ('get_host_queue_entries', {'job__in': ['6761']},
458 True,
459 [{u'status': u'Queued',
460 u'complete': 0,
461 u'deleted': 0,
462 u'host': None,
463 u'priority': 1,
464 u'meta_host': u'Xeon',
465 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\')',
466 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700467 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000468 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800469 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000470 u'owner': u'user0',
471 u'created_on': u'2008-07-30 22:15:43',
472 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000473 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000474 u'id': 6761},
475 u'active': 0,
476 u'id': 193166},
477 {u'status': u'Queued',
478 u'complete': 0,
479 u'deleted': 0,
480 u'host': None,
481 u'priority': 1,
482 u'meta_host': u'Xeon',
483 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\')',
484 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700485 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000486 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800487 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000488 u'owner': u'user0',
489 u'created_on': u'2008-07-30 22:15:43',
490 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000491 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000492 u'id': 6761},
493 u'active': 0,
494 u'id': 193167},
495 {u'status': u'Queued',
496 u'complete': 0,
497 u'deleted': 0,
498 u'host': None,
499 u'priority': 1,
500 u'meta_host': u'Athlon',
501 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\')',
502 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700503 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000504 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800505 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000506 u'owner': u'user0',
507 u'created_on': u'2008-07-30 22:15:43',
508 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000509 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000510 u'id': 6761},
511 u'active': 0,
512 u'id': 193168},
513 {u'status': u'Queued',
514 u'complete': 0,
515 u'deleted': 0,
516 u'host': None,
517 u'priority': 1,
518 u'meta_host': u'x286',
519 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\')',
520 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700521 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000522 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800523 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000524 u'owner': u'user0',
525 u'created_on': u'2008-07-30 22:15:43',
526 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000527 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000528 u'id': 6761},
529 u'active': 0,
530 u'id': 193169},
531 {u'status': u'Running',
532 u'complete': 0,
533 u'deleted': 0,
534 u'host': {u'status': u'Running',
535 u'lock_time': None,
536 u'hostname': u'host42',
mbligh0887d402009-01-30 00:50:29 +0000537 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000538 u'locked_by': None,
mbligh0887d402009-01-30 00:50:29 +0000539 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000540 u'id': 4833,
541 u'protection': u'Repair filesystem only',
542 u'synch_id': None},
543 u'priority': 1,
544 u'meta_host': u'Athlon',
545 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\')',
546 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700547 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000548 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800549 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000550 u'owner': u'user0',
551 u'created_on': u'2008-07-30 22:15:43',
552 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000553 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000554 u'id': 6761},
555 u'active': 1,
556 u'id': 193170} ])],
557 out_words_ok=['test_on_meta_hosts',
558 'host42', 'Queued', 'Running'],
559 out_words_no=['Athlon', 'Xeon', 'x286'])
560
561
562 def test_job_stat_job_no_host_in_qes(self):
563 results = copy.deepcopy(self.results)
Allen Lib774aa22017-02-01 17:42:15 -0800564 self.run_cmd(argv=['atest', 'job', 'stat', '180'],
mblighbe630eb2008-08-01 16:41:48 +0000565 rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,
566 [results[0]]),
567 ('get_host_queue_entries', {'job__in': ['180']},
568 True,
569 [{u'status': u'Failed',
570 u'complete': 1,
571 u'host': None,
572 u'priority': 1,
573 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000574 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 +0000575 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700576 u'control_type': SERVER,
Allen Li352b86a2016-12-14 12:11:27 -0800577 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000578 u'owner': u'user0',
579 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000580 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000581 u'id': 180},
582 u'active': 0,
583 u'id': 101084}])],
mblighfca5ed12009-11-06 02:59:56 +0000584 err_words_ok=['unassigned', 'meta-hosts'])
mblighbe630eb2008-08-01 16:41:48 +0000585
586
587 def test_job_stat_multi_jobs(self):
588 results = copy.deepcopy(self.results)
Allen Lib774aa22017-02-01 17:42:15 -0800589 self.run_cmd(argv=['atest', 'job', 'stat', '180', '338'],
mblighbe630eb2008-08-01 16:41:48 +0000590 rpcs=[('get_jobs_summary', {'id__in': ['180', '338']},
591 True, results),
592 ('get_host_queue_entries',
593 {'job__in': ['180', '338']},
594 True,
595 [{u'status': u'Failed',
596 u'complete': 1,
597 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000598 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000599 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000600 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000601 u'id': 4432,
602 u'synch_id': None},
603 u'priority': 1,
604 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000605 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 +0000606 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700607 u'control_type': SERVER,
Allen Li352b86a2016-12-14 12:11:27 -0800608 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000609 u'owner': u'user0',
610 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000611 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000612 u'id': 180},
613 u'active': 0,
614 u'id': 101084},
615 {u'status': u'Failed',
616 u'complete': 1,
617 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000618 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000619 u'hostname': u'host10',
mbligh0887d402009-01-30 00:50:29 +0000620 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000621 u'id': 4432,
622 u'synch_id': None},
623 u'priority': 1,
624 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000625 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 +0000626 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700627 u'control_type': SERVER,
Allen Li352b86a2016-12-14 12:11:27 -0800628 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000629 u'owner': u'user0',
630 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000631 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000632 u'id': 338},
633 u'active': 0,
634 u'id': 101084}])],
635 out_words_ok=['test_job0', 'test_job1'])
636
637
638 def test_job_stat_multi_jobs_name_id(self):
Allen Lib774aa22017-02-01 17:42:15 -0800639 self.run_cmd(argv=['atest', 'job', 'stat', 'mytest', '180'],
mblighbe630eb2008-08-01 16:41:48 +0000640 rpcs=[('get_jobs_summary', {'id__in': ['180']},
641 True,
642 [{u'status_counts': {u'Aborted': 1},
643 u'control_file':
644 u"job.run_test('sleeptest')\n",
645 u'name': u'job0',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700646 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000647 u'priority':
Allen Li352b86a2016-12-14 12:11:27 -0800648 priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000649 u'owner': u'user0',
650 u'created_on':
651 u'2008-07-08 17:45:44',
showard2bab8f42008-11-12 18:15:22 +0000652 u'synch_count': 2,
mblighbe630eb2008-08-01 16:41:48 +0000653 u'id': 180}]),
654 ('get_jobs_summary', {'name__in': ['mytest']},
655 True,
656 [{u'status_counts': {u'Queued': 1},
657 u'control_file':
658 u"job.run_test('sleeptest')\n",
659 u'name': u'mytest',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700660 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000661 u'priority':
Allen Li352b86a2016-12-14 12:11:27 -0800662 priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000663 u'owner': u'user0',
664 u'created_on': u'2008-07-08 12:17:47',
665 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000666 u'id': 338}]),
667 ('get_host_queue_entries',
668 {'job__in': ['180']},
669 True,
670 [{u'status': u'Failed',
671 u'complete': 1,
672 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000673 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000674 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000675 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000676 u'id': 4432,
677 u'synch_id': None},
678 u'priority': 1,
679 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000680 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 +0000681 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700682 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000683 u'synchronizing': 0,
Allen Li352b86a2016-12-14 12:11:27 -0800684 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000685 u'owner': u'user0',
686 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000687 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000688 u'id': 180},
689 u'active': 0,
690 u'id': 101084}]),
691 ('get_host_queue_entries',
692 {'job__name__in': ['mytest']},
693 True,
694 [{u'status': u'Failed',
695 u'complete': 1,
696 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000697 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000698 u'hostname': u'host10',
mbligh0887d402009-01-30 00:50:29 +0000699 u'invalid': True,
mblighbe630eb2008-08-01 16:41:48 +0000700 u'id': 4432,
701 u'synch_id': None},
702 u'priority': 1,
703 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000704 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 +0000705 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700706 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000707 u'synchronizing': 0,
Allen Li352b86a2016-12-14 12:11:27 -0800708 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000709 u'owner': u'user0',
710 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000711 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000712 u'id': 338},
713 u'active': 0,
714 u'id': 101084}])],
715 out_words_ok=['job0', 'mytest', 'Aborted', 'Queued',
Allen Li352b86a2016-12-14 12:11:27 -0800716 'Failed', str(priorities.Priority.DEFAULT)])
mblighbe630eb2008-08-01 16:41:48 +0000717
718
719class job_create_unittest(cli_mock.cli_unittest):
720 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)'
721
Richard Barnette41e617b2016-05-19 16:18:16 -0700722 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 +0000723
mbligh120351e2009-01-24 01:40:45 +0000724 trivial_ctrl_file = 'print "Hello"\n'
725
Allen Li352b86a2016-12-14 12:11:27 -0800726 data = {'priority': priorities.Priority.DEFAULT, 'control_file': ctrl_file,
727 'hosts': ['host0'],
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700728 'name': 'test_job0', 'control_type': CLIENT, 'email_list': '',
Dan Shiec1d47d2015-02-13 11:38:13 -0800729 'meta_hosts': [], 'synch_count': 1, 'dependencies': [],
730 'require_ssp': False}
mblighbe630eb2008-08-01 16:41:48 +0000731
732
733 def test_execute_create_job(self):
734 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
Allen Lib774aa22017-02-01 17:42:15 -0800735 'test_job0', '-m', 'host0'],
showard989f25d2008-10-01 11:38:11 +0000736 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000737 {'tests': ['sleeptest']},
showard989f25d2008-10-01 11:38:11 +0000738 True,
739 {'control_file' : self.ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000740 'synch_count' : 1,
showard989f25d2008-10-01 11:38:11 +0000741 'is_server' : False,
742 'dependencies' : []}),
mblighbe630eb2008-08-01 16:41:48 +0000743 ('create_job', self.data, True, 180)],
744 out_words_ok=['test_job0', 'Created'],
745 out_words_no=['Uploading', 'Done'])
746
747
748 def test_execute_create_job_with_control(self):
mbligh41515392009-07-11 00:13:11 +0000749 file_temp = cli_mock.create_file(self.ctrl_file)
750 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -0800751 'test_job0', '-m', 'host0'],
mblighbe630eb2008-08-01 16:41:48 +0000752 rpcs=[('create_job', self.data, True, 42)],
753 out_words_ok=['test_job0', 'Created'],
754 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000755 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000756
757
mbligh0a669132008-10-10 20:02:32 +0000758 def test_execute_create_job_with_control_and_email(self):
759 data = self.data.copy()
760 data['email_list'] = 'em'
mbligh41515392009-07-11 00:13:11 +0000761 file_temp = cli_mock.create_file(self.ctrl_file)
762 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -0800763 'test_job0', '-m', 'host0', '-e', 'em'],
mbligh0a669132008-10-10 20:02:32 +0000764 rpcs=[('create_job', data, True, 42)],
765 out_words_ok=['test_job0', 'Created'],
766 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000767 file_temp.clean()
mbligh0a669132008-10-10 20:02:32 +0000768
769
showardb27f4ad2009-05-01 00:08:26 +0000770 def test_execute_create_job_with_control_and_dependencies(self):
mbligh0a669132008-10-10 20:02:32 +0000771 data = self.data.copy()
772 data['dependencies'] = ['dep1', 'dep2']
mbligh41515392009-07-11 00:13:11 +0000773 file_temp = cli_mock.create_file(self.ctrl_file)
774 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -0800775 'test_job0', '-m', 'host0', '-d', 'dep1, dep2 '],
mbligh0a669132008-10-10 20:02:32 +0000776 rpcs=[('create_job', data, True, 42)],
777 out_words_ok=['test_job0', 'Created'],
778 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000779 file_temp.clean()
mbligh0a669132008-10-10 20:02:32 +0000780
781
Eric Li8a12e802011-02-17 14:24:13 -0800782 def test_execute_create_job_with_control_and_comma_dependencies(self):
783 data = self.data.copy()
784 data['dependencies'] = ['dep2,False', 'dep1,True']
785 file_temp = cli_mock.create_file(self.ctrl_file)
786 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
787 'test_job0', '-m', 'host0', '-d',
Allen Lib774aa22017-02-01 17:42:15 -0800788 'dep1\,True, dep2\,False '],
Eric Li8a12e802011-02-17 14:24:13 -0800789 rpcs=[('create_job', data, True, 42)],
790 out_words_ok=['test_job0', 'Created'],
791 out_words_no=['Uploading', 'Done'])
792 file_temp.clean()
793
794
showard7bce1022008-11-14 22:51:05 +0000795 def test_execute_create_job_with_synch_count(self):
796 data = self.data.copy()
797 data['synch_count'] = 2
mbligh41515392009-07-11 00:13:11 +0000798 file_temp = cli_mock.create_file(self.ctrl_file)
799 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -0800800 'test_job0', '-m', 'host0', '-y', '2'],
showard7bce1022008-11-14 22:51:05 +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()
showard7bce1022008-11-14 22:51:05 +0000805
806
showardb27f4ad2009-05-01 00:08:26 +0000807 def test_execute_create_job_with_test_and_dependencies(self):
mblighb9a8b162008-10-29 16:47:29 +0000808 data = self.data.copy()
809 data['dependencies'] = ['dep1', 'dep2', 'dep3']
810 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
Allen Lib774aa22017-02-01 17:42:15 -0800811 'test_job0', '-m', 'host0', '-d', 'dep1, dep2 '],
mblighb9a8b162008-10-29 16:47:29 +0000812 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000813 {'tests': ['sleeptest']},
mblighb9a8b162008-10-29 16:47:29 +0000814 True,
815 {'control_file' : self.ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000816 'synch_count' : 1,
mblighb9a8b162008-10-29 16:47:29 +0000817 'is_server' : False,
818 'dependencies' : ['dep3']}),
819 ('create_job', data, True, 42)],
820 out_words_ok=['test_job0', 'Created'],
821 out_words_no=['Uploading', 'Done'])
822
823
Eric Li8a12e802011-02-17 14:24:13 -0800824 def test_execute_create_job_with_test_and_comma_dependencies(self):
825 data = self.data.copy()
826 data['dependencies'] = ['dep1,True', 'dep2,False', 'dep3,123']
827 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
828 'test_job0', '-m', 'host0', '-d',
Allen Lib774aa22017-02-01 17:42:15 -0800829 'dep1\,True dep2\,False '],
Eric Li8a12e802011-02-17 14:24:13 -0800830 rpcs=[('generate_control_file',
831 {'tests': ['sleeptest']},
832 True,
833 {'control_file' : self.ctrl_file,
834 'synch_count' : 1,
835 'is_server' : False,
836 'dependencies' : ['dep3,123']}),
837 ('create_job', data, True, 42)],
838 out_words_ok=['test_job0', 'Created'],
839 out_words_no=['Uploading', 'Done'])
840
841
mblighbe630eb2008-08-01 16:41:48 +0000842 def test_execute_create_job_no_args(self):
843 testjob = job.job_create()
Allen Lib774aa22017-02-01 17:42:15 -0800844 sys.argv = ['atest', 'job', 'create']
mblighbe630eb2008-08-01 16:41:48 +0000845 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000846 (sys.exit.expect_call(mock.anything_comparator())
847 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000848 self.assertRaises(cli_mock.ExitException, testjob.parse)
849 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000850 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000851
852
853 def test_execute_create_job_no_hosts(self):
854 testjob = job.job_create()
mbligh41515392009-07-11 00:13:11 +0000855 file_temp = cli_mock.create_file(self.ctrl_file)
Allen Lib774aa22017-02-01 17:42:15 -0800856 sys.argv = ['atest', '-f', file_temp.name, 'test_job0']
mblighbe630eb2008-08-01 16:41:48 +0000857 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000858 (sys.exit.expect_call(mock.anything_comparator())
859 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000860 self.assertRaises(cli_mock.ExitException, testjob.parse)
861 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000862 self.god.check_playback()
mbligh41515392009-07-11 00:13:11 +0000863 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000864
865
866 def test_execute_create_job_cfile_and_tests(self):
867 testjob = job.job_create()
868 sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-f',
Allen Lib774aa22017-02-01 17:42:15 -0800869 'control_file', 'test_job0', '-m', 'host0']
mblighbe630eb2008-08-01 16:41:48 +0000870 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000871 (sys.exit.expect_call(mock.anything_comparator())
872 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000873 self.assertRaises(cli_mock.ExitException, testjob.parse)
874 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000875 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000876
877
mblighbe630eb2008-08-01 16:41:48 +0000878 def test_execute_create_job_bad_cfile(self):
879 testjob = job.job_create()
mbligha212d712009-02-11 01:22:36 +0000880 sys.argv = ['atest', 'job', 'create', '-f', 'control_file',
Allen Lib774aa22017-02-01 17:42:15 -0800881 'test_job0', '-m', 'host0']
mblighbe630eb2008-08-01 16:41:48 +0000882 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000883 (sys.exit.expect_call(mock.anything_comparator())
884 .and_raises(IOError))
mblighbe630eb2008-08-01 16:41:48 +0000885 self.assertRaises(IOError, testjob.parse)
886 self.god.unmock_io()
887
888
889 def test_execute_create_job_bad_priority(self):
890 testjob = job.job_create()
891 sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-p', 'Uber',
Allen Lib774aa22017-02-01 17:42:15 -0800892 '-m', 'host0', 'test_job0']
mblighbe630eb2008-08-01 16:41:48 +0000893 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000894 (sys.exit.expect_call(mock.anything_comparator())
895 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000896 self.assertRaises(cli_mock.ExitException, testjob.parse)
897 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000898 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000899
900
901 def test_execute_create_job_with_mfile(self):
902 data = self.data.copy()
903 data['hosts'] = ['host3', 'host2', 'host1', 'host0']
mbligh41515392009-07-11 00:13:11 +0000904 ctemp = cli_mock.create_file(self.ctrl_file)
905 file_temp = cli_mock.create_file('host0\nhost1\nhost2\nhost3')
906 self.run_cmd(argv=['atest', 'job', 'create', '--mlist', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -0800907 '-f', ctemp.name, 'test_job0'],
mblighbe630eb2008-08-01 16:41:48 +0000908 rpcs=[('create_job', data, True, 42)],
909 out_words_ok=['test_job0', 'Created'])
mbligh41515392009-07-11 00:13:11 +0000910 ctemp.clean()
911 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000912
913
mbligh5d0b4b32008-12-22 14:43:01 +0000914 def test_execute_create_job_with_timeout(self):
915 data = self.data.copy()
Simran Basi7e605742013-11-12 13:43:36 -0800916 data['timeout_mins'] = '13320'
mbligh41515392009-07-11 00:13:11 +0000917 file_temp = cli_mock.create_file(self.ctrl_file)
918 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -0800919 'test_job0', '-m', 'host0', '-o', '13320'],
mbligh5d0b4b32008-12-22 14:43:01 +0000920 rpcs=[('create_job', data, True, 42)],
921 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +0000922 file_temp.clean()
mbligh5d0b4b32008-12-22 14:43:01 +0000923
924
showard12f3e322009-05-13 21:27:42 +0000925 def test_execute_create_job_with_max_runtime(self):
926 data = self.data.copy()
Simran Basi34217022012-11-06 13:43:15 -0800927 data['max_runtime_mins'] = '13320'
mbligh41515392009-07-11 00:13:11 +0000928 file_temp = cli_mock.create_file(self.ctrl_file)
929 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Simran Basi34217022012-11-06 13:43:15 -0800930 'test_job0', '-m', 'host0', '--max_runtime',
Allen Lib774aa22017-02-01 17:42:15 -0800931 '13320'],
showard12f3e322009-05-13 21:27:42 +0000932 rpcs=[('create_job', data, True, 42)],
933 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +0000934 file_temp.clean()
showard12f3e322009-05-13 21:27:42 +0000935
936
937
mbligh5d0b4b32008-12-22 14:43:01 +0000938 def test_execute_create_job_with_noverify(self):
939 data = self.data.copy()
940 data['run_verify'] = False
mbligh41515392009-07-11 00:13:11 +0000941 file_temp = cli_mock.create_file(self.ctrl_file)
942 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -0800943 'test_job0', '-m', 'host0', '-n'],
mbligh5d0b4b32008-12-22 14:43:01 +0000944 rpcs=[('create_job', data, True, 42)],
945 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +0000946 file_temp.clean()
mbligh5d0b4b32008-12-22 14:43:01 +0000947
948
mblighce348642009-02-12 21:50:39 +0000949 def test_execute_create_job_oth(self):
950 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +0000951 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +0000952 data['one_time_hosts'] = ['host0']
953 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
954 'test_job0', '--one-time-hosts', 'host0'],
955 rpcs=[('generate_control_file',
956 {'tests': ['sleeptest']},
957 True,
958 {'control_file' : self.ctrl_file,
959 'synch_count' : 1,
960 'is_server' : False,
961 'dependencies' : []}),
962 ('create_job', data, True, 180)],
963 out_words_ok=['test_job0', 'Created'],
964 out_words_no=['Uploading', 'Done'])
965
966
967 def test_execute_create_job_multi_oth(self):
968 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +0000969 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +0000970 data['one_time_hosts'] = ['host1', 'host0']
971 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
972 'test_job0', '--one-time-hosts', 'host0,host1'],
973 rpcs=[('generate_control_file',
974 {'tests': ['sleeptest']},
975 True,
976 {'control_file' : self.ctrl_file,
977 'synch_count' : 1,
978 'is_server' : False,
979 'dependencies' : []}),
980 ('create_job', data, True, 180)],
981 out_words_ok=['test_job0', 'Created'],
982 out_words_no=['Uploading', 'Done'])
983
984
985 def test_execute_create_job_oth_exists(self):
986 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +0000987 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +0000988 data['one_time_hosts'] = ['host0']
989 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
990 'test_job0', '--one-time-hosts', 'host0'],
991 rpcs=[('generate_control_file',
992 {'tests': ['sleeptest']},
993 True,
994 {'control_file' : self.ctrl_file,
995 'synch_count' : 1,
996 'is_server' : False,
997 'dependencies' : []}),
998 ('create_job', data, False,
999 '''ValidationError: {'hostname': 'host0 '''
1000 '''already exists in the autotest DB. '''
1001 '''Select it rather than entering it as '''
1002 '''a one time host.'}''')],
1003 out_words_no=['test_job0', 'Created'],
1004 err_words_ok=['failed', 'already exists'])
1005
1006
showardb27f4ad2009-05-01 00:08:26 +00001007 def test_execute_create_job_with_control_and_labels(self):
1008 data = self.data.copy()
1009 data['hosts'] = ['host0', 'host1', 'host2']
mbligh41515392009-07-11 00:13:11 +00001010 file_temp = cli_mock.create_file(self.ctrl_file)
1011 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -08001012 'test_job0', '-m', 'host0', '-b', 'label1,label2'],
showardb27f4ad2009-05-01 00:08:26 +00001013 rpcs=[('get_hosts', {'multiple_labels': ['label1',
1014 'label2']}, True,
1015 [{u'status': u'Running', u'lock_time': None,
1016 u'hostname': u'host1', u'locked': False,
1017 u'locked_by': None, u'invalid': False, u'id': 42,
1018 u'labels': [u'label1'], u'platform':
1019 u'Warp18_Diskfull', u'protection':
1020 u'Repair software only', u'dirty':
1021 True, u'synch_id': None},
1022 {u'status': u'Running', u'lock_time': None,
1023 u'hostname': u'host2', u'locked': False,
1024 u'locked_by': None, u'invalid': False, u'id': 43,
1025 u'labels': [u'label2'], u'platform':
1026 u'Warp18_Diskfull', u'protection':
1027 u'Repair software only', u'dirty': True,
1028 u'synch_id': None}]),
1029 ('create_job', data, True, 42)],
1030 out_words_ok=['test_job0', 'Created'],
1031 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +00001032 file_temp.clean()
showardb27f4ad2009-05-01 00:08:26 +00001033
1034
1035 def test_execute_create_job_with_label_and_duplicate_hosts(self):
1036 data = self.data.copy()
1037 data['hosts'] = ['host1', 'host0']
mbligh41515392009-07-11 00:13:11 +00001038 file_temp = cli_mock.create_file(self.ctrl_file)
1039 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -08001040 'test_job0', '-m', 'host0,host1', '-b', 'label1'],
showardb27f4ad2009-05-01 00:08:26 +00001041 rpcs=[('get_hosts', {'multiple_labels': ['label1']}, True,
1042 [{u'status': u'Running', u'lock_time': None,
1043 u'hostname': u'host1', u'locked': False,
1044 u'locked_by': None, u'invalid': False, u'id': 42,
1045 u'labels': [u'label1'], u'platform':
1046 u'Warp18_Diskfull', u'protection':
1047 u'Repair software only', u'dirty':
1048 True, u'synch_id': None}]),
1049 ('create_job', data, True, 42)],
1050 out_words_ok=['test_job0', 'Created'],
1051 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +00001052 file_temp.clean()
showardb27f4ad2009-05-01 00:08:26 +00001053
1054
jamesrenc2863162010-07-12 21:20:51 +00001055 def test_execute_create_job_with_label_commas_and_duplicate_hosts(self):
1056 data = self.data.copy()
1057 data['hosts'] = ['host1', 'host0']
1058 file_temp = cli_mock.create_file(self.ctrl_file)
1059 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1060 'test_job0', '-m', 'host0,host1', '-b',
Allen Lib774aa22017-02-01 17:42:15 -08001061 'label1,label\\,2'],
jamesrenc2863162010-07-12 21:20:51 +00001062 rpcs=[('get_hosts', {'multiple_labels': ['label1',
1063 'label,2']}, True,
1064 [{u'status': u'Running', u'lock_time': None,
1065 u'hostname': u'host1', u'locked': False,
1066 u'locked_by': None, u'invalid': False, u'id': 42,
1067 u'labels': [u'label1', u'label,2'], u'platform':
1068 u'Warp18_Diskfull', u'protection':
1069 u'Repair software only', u'dirty':
1070 True, u'synch_id': None}]),
1071 ('create_job', data, True, 42)],
1072 out_words_ok=['test_job0', 'Created'],
1073 out_words_no=['Uploading', 'Done'])
1074 file_temp.clean()
1075
1076
1077 def test_execute_create_job_with_label_escaping_and_duplicate_hosts(self):
1078 data = self.data.copy()
1079 data['hosts'] = ['host1', 'host0']
1080 file_temp = cli_mock.create_file(self.ctrl_file)
1081 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1082 'test_job0', '-m', 'host0,host1', '-b',
Allen Lib774aa22017-02-01 17:42:15 -08001083 'label1,label\\,2\\\\,label3'],
jamesrenc2863162010-07-12 21:20:51 +00001084 rpcs=[('get_hosts', {'multiple_labels': ['label,2\\',
1085 'label1', 'label3']}, True,
1086 [{u'status': u'Running', u'lock_time': None,
1087 u'hostname': u'host1', u'locked': False,
1088 u'locked_by': None, u'invalid': False, u'id': 42,
1089 u'labels': [u'label1', u'label,2\\', u'label3'],
1090 u'platform': u'Warp18_Diskfull', u'protection':
1091 u'Repair software only', u'dirty':
1092 True, u'synch_id': None}]),
1093 ('create_job', data, True, 42)],
1094 out_words_ok=['test_job0', 'Created'],
1095 out_words_no=['Uploading', 'Done'])
1096 file_temp.clean()
1097
1098
mblighbe630eb2008-08-01 16:41:48 +00001099 def _test_parse_hosts(self, args, exp_hosts=[], exp_meta_hosts=[]):
mbligh56f1f4a2009-08-03 16:45:12 +00001100 testjob = job.job_create_or_clone()
1101 (hosts, meta_hosts) = testjob._parse_hosts(args)
mblighbe630eb2008-08-01 16:41:48 +00001102 self.assertEqualNoOrder(hosts, exp_hosts)
1103 self.assertEqualNoOrder(meta_hosts, exp_meta_hosts)
1104
1105
1106 def test_parse_hosts_regular(self):
1107 self._test_parse_hosts(['host0'], ['host0'])
1108
1109
1110 def test_parse_hosts_regulars(self):
1111 self._test_parse_hosts(['host0', 'host1'], ['host0', 'host1'])
1112
1113
1114 def test_parse_hosts_meta_one(self):
1115 self._test_parse_hosts(['*meta0'], [], ['meta0'])
1116
1117
1118 def test_parse_hosts_meta_five(self):
1119 self._test_parse_hosts(['5*meta0'], [], ['meta0']*5)
1120
1121
1122 def test_parse_hosts_metas_five(self):
1123 self._test_parse_hosts(['5*meta0', '2*meta1'], [],
1124 ['meta0']*5 + ['meta1']*2)
1125
1126
1127 def test_parse_hosts_mix(self):
1128 self._test_parse_hosts(['5*meta0', 'host0', '2*meta1', 'host1',
1129 '*meta2'], ['host0', 'host1'],
1130 ['meta0']*5 + ['meta1']*2 + ['meta2'])
1131
1132
mbligh5a496082009-08-03 16:44:54 +00001133class job_clone_unittest(cli_mock.cli_unittest):
1134 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 -07001135 'control_type': SERVER,
mbligh5a496082009-08-03 16:44:54 +00001136 'dependencies': [],
1137 'email_list': u'',
Simran Basi34217022012-11-06 13:43:15 -08001138 'max_runtime_mins': 28800,
mbligh5a496082009-08-03 16:44:54 +00001139 'parse_failed_repair': True,
Allen Li352b86a2016-12-14 12:11:27 -08001140 'priority': priorities.Priority.DEFAULT,
mbligh5a496082009-08-03 16:44:54 +00001141 'reboot_after': u'Always',
1142 'reboot_before': u'If dirty',
1143 'run_verify': True,
1144 'synch_count': 1,
Simran Basi7e605742013-11-12 13:43:36 -08001145 'timeout_mins': 480}
mbligh5a496082009-08-03 16:44:54 +00001146
mbligh56f1f4a2009-08-03 16:45:12 +00001147 local_hosts = [{u'acls': [u'acl0'],
mbligh56f1f4a2009-08-03 16:45:12 +00001148 u'attributes': {},
1149 u'dirty': False,
1150 u'hostname': u'host0',
1151 u'id': 8,
1152 u'invalid': False,
1153 u'labels': [u'label0', u'label1'],
1154 u'lock_time': None,
1155 u'locked': False,
1156 u'locked_by': None,
1157 u'other_labels': u'label0, label1',
1158 u'platform': u'plat0',
1159 u'protection': u'Repair software only',
1160 u'status': u'Ready',
1161 u'synch_id': None},
1162 {u'acls': [u'acl0'],
mbligh56f1f4a2009-08-03 16:45:12 +00001163 u'attributes': {},
1164 u'dirty': False,
1165 u'hostname': u'host1',
1166 u'id': 9,
1167 u'invalid': False,
1168 u'labels': [u'label0', u'label1'],
1169 u'lock_time': None,
1170 u'locked': False,
1171 u'locked_by': None,
1172 u'other_labels': u'label0, label1',
1173 u'platform': u'plat0',
1174 u'protection': u'Repair software only',
1175 u'status': u'Ready',
1176 u'synch_id': None}]
1177
1178
mbligh5a496082009-08-03 16:44:54 +00001179 def setUp(self):
1180 super(job_clone_unittest, self).setUp()
1181 self.job_data_clone_info = copy.deepcopy(self.job_data)
1182 self.job_data_clone_info['created_on'] = '2009-07-23 16:21:29'
1183 self.job_data_clone_info['name'] = 'testing_clone'
1184 self.job_data_clone_info['id'] = 42
1185 self.job_data_clone_info['owner'] = 'user0'
1186
1187 self.job_data_cloned = copy.deepcopy(self.job_data)
1188 self.job_data_cloned['name'] = 'cloned'
1189 self.job_data_cloned['hosts'] = [u'host0']
1190 self.job_data_cloned['meta_hosts'] = []
1191
1192
1193 def test_backward_compat(self):
1194 self.run_cmd(argv=['atest', 'job', 'create', '--clone', '42',
1195 '-r', 'cloned'],
1196 rpcs=[('get_info_for_clone', {'id': '42',
1197 'preserve_metahosts': True},
1198 True,
Allen Li335f2162017-02-01 14:47:01 -08001199 {u'hosts': [{u'acls': [u'acl0'],
mbligh5a496082009-08-03 16:44:54 +00001200 u'attributes': {},
1201 u'dirty': False,
1202 u'hostname': u'host0',
1203 u'id': 4378,
1204 u'invalid': False,
1205 u'labels': [u'label0', u'label1'],
1206 u'lock_time': None,
1207 u'locked': False,
1208 u'locked_by': None,
1209 u'other_labels': u'label0, label1',
1210 u'platform': u'plat0',
1211 u'protection': u'Repair software only',
1212 u'status': u'Ready',
1213 u'synch_id': None}],
1214 u'job': self.job_data_clone_info,
1215 u'meta_host_counts': {}}),
1216 ('create_job', self.job_data_cloned, True, 43)],
1217 out_words_ok=['Created job', '43'])
1218
1219
1220 def test_clone_reuse_hosts(self):
mbligh56f1f4a2009-08-03 16:45:12 +00001221 self.job_data_cloned['hosts'] = [u'host0', 'host1']
mbligh5a496082009-08-03 16:44:54 +00001222 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1223 '-r', 'cloned'],
1224 rpcs=[('get_info_for_clone', {'id': '42',
1225 'preserve_metahosts': True},
1226 True,
Allen Li335f2162017-02-01 14:47:01 -08001227 {u'hosts': self.local_hosts,
mbligh5a496082009-08-03 16:44:54 +00001228 u'job': self.job_data_clone_info,
1229 u'meta_host_counts': {}}),
1230 ('create_job', self.job_data_cloned, True, 43)],
1231 out_words_ok=['Created job', '43'])
1232
1233
mbligh56f1f4a2009-08-03 16:45:12 +00001234 def test_clone_reuse_metahosts(self):
1235 self.job_data_cloned['hosts'] = []
1236 self.job_data_cloned['meta_hosts'] = ['type1']*4 + ['type0']
1237 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1238 '-r', 'cloned'],
1239 rpcs=[('get_info_for_clone', {'id': '42',
1240 'preserve_metahosts': True},
1241 True,
Allen Li335f2162017-02-01 14:47:01 -08001242 {u'hosts': [],
mbligh56f1f4a2009-08-03 16:45:12 +00001243 u'job': self.job_data_clone_info,
1244 u'meta_host_counts': {u'type0': 1,
1245 u'type1': 4}}),
1246 ('create_job', self.job_data_cloned, True, 43)],
1247 out_words_ok=['Created job', '43'])
1248
1249
1250 def test_clone_reuse_both(self):
1251 self.job_data_cloned['hosts'] = [u'host0', 'host1']
1252 self.job_data_cloned['meta_hosts'] = ['type1']*4 + ['type0']
1253 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1254 '-r', 'cloned'],
1255 rpcs=[('get_info_for_clone', {'id': '42',
1256 'preserve_metahosts': True},
1257 True,
Allen Li335f2162017-02-01 14:47:01 -08001258 {
mbligh56f1f4a2009-08-03 16:45:12 +00001259 u'hosts': self.local_hosts,
1260 u'job': self.job_data_clone_info,
1261 u'meta_host_counts': {u'type0': 1,
1262 u'type1': 4}}),
1263 ('create_job', self.job_data_cloned, True, 43)],
1264 out_words_ok=['Created job', '43'])
1265
1266
mbligh5a496082009-08-03 16:44:54 +00001267 def test_clone_no_hosts(self):
1268 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42', 'cloned'],
1269 exit_code=1,
1270 out_words_ok=['usage'],
1271 err_words_ok=['machine'])
1272
1273
mbligh56f1f4a2009-08-03 16:45:12 +00001274 def test_clone_reuse_and_hosts(self):
1275 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1276 '-r', '-m', 'host5', 'cloned'],
1277 exit_code=1,
1278 out_words_ok=['usage'],
1279 err_words_ok=['specify'])
1280
1281
1282 def test_clone_new_multiple_hosts(self):
1283 self.job_data_cloned['hosts'] = [u'host5', 'host4', 'host3']
1284 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1285 '-m', 'host5,host4,host3', 'cloned'],
1286 rpcs=[('get_info_for_clone', {'id': '42',
1287 'preserve_metahosts': False},
1288 True,
Allen Li335f2162017-02-01 14:47:01 -08001289 {u'hosts': self.local_hosts,
mbligh56f1f4a2009-08-03 16:45:12 +00001290 u'job': self.job_data_clone_info,
1291 u'meta_host_counts': {}}),
1292 ('create_job', self.job_data_cloned, True, 43)],
1293 out_words_ok=['Created job', '43'])
1294
1295
1296 def test_clone_oth(self):
1297 self.job_data_cloned['hosts'] = []
1298 self.job_data_cloned['one_time_hosts'] = [u'host5']
1299 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1300 '--one-time-hosts', 'host5', 'cloned'],
1301 rpcs=[('get_info_for_clone', {'id': '42',
1302 'preserve_metahosts': False},
1303 True,
Allen Li335f2162017-02-01 14:47:01 -08001304 {u'hosts': self.local_hosts,
mbligh56f1f4a2009-08-03 16:45:12 +00001305 u'job': self.job_data_clone_info,
1306 u'meta_host_counts': {}}),
1307 ('create_job', self.job_data_cloned, True, 43)],
1308 out_words_ok=['Created job', '43'])
mbligh5a496082009-08-03 16:44:54 +00001309
1310
mblighbe630eb2008-08-01 16:41:48 +00001311class job_abort_unittest(cli_mock.cli_unittest):
1312 results = [{u'status_counts': {u'Aborted': 1}, u'control_file':
1313 u"job.run_test('sleeptest')\n", u'name': u'test_job0',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001314 u'control_type': SERVER, u'priority':
Allen Li352b86a2016-12-14 12:11:27 -08001315 priorities.Priority.DEFAULT, u'owner': u'user0', u'created_on':
showard2bab8f42008-11-12 18:15:22 +00001316 u'2008-07-08 17:45:44', u'synch_count': 2, u'id': 180}]
mblighbe630eb2008-08-01 16:41:48 +00001317
1318 def test_execute_job_abort(self):
Allen Lib774aa22017-02-01 17:42:15 -08001319 self.run_cmd(argv=['atest', 'job', 'abort', '180'],
mbligh206d50a2008-11-13 01:19:25 +00001320 rpcs=[('abort_host_queue_entries',
1321 {'job__id__in': ['180']}, True, None)],
1322 out_words_ok=['Aborting', '180'])
mblighbe630eb2008-08-01 16:41:48 +00001323
1324
1325if __name__ == '__main__':
1326 unittest.main()