blob: 7d368d63e8ed33f2aabe18e74f07a3061472efec [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,
Allen Lie4c08272017-02-01 16:40:53 -0800235 u'id': 4432},
mblighbe630eb2008-08-01 16:41:48 +0000236 u'priority': 1,
237 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000238 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 +0000239 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700240 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000241 u'synchronizing': 0,
Allen Li352b86a2016-12-14 12:11:27 -0800242 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000243 u'owner': u'user0',
244 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000245 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000246 u'id': 180},
247 u'active': 0,
248 u'id': 101084}])],
249 out_words_ok=['test_job0', 'host0', 'Failed',
250 'Aborted'])
251
252
mblighfca5ed12009-11-06 02:59:56 +0000253
254 def test_job_stat_list_unassigned_host(self):
255 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
Allen Lib774aa22017-02-01 17:42:15 -0800256 '--list-hosts'],
mblighfca5ed12009-11-06 02:59:56 +0000257 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
258 [{u'status_counts': {u'Queued': 1},
259 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\')',
260 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700261 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000262 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800263 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000264 u'owner': u'user0',
265 u'created_on': u'2008-07-30 22:15:43',
266 u'timeout': 144,
267 u'synch_count': 1,
268 u'id': 6761}]),
269 ('get_host_queue_entries', {'job__in': ['6761']},
270 True,
271 [{u'status': u'Queued',
272 u'complete': 0,
273 u'deleted': 0,
274 u'host': None,
275 u'priority': 1,
276 u'meta_host': u'Xeon',
277 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\')',
278 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700279 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000280 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800281 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000282 u'owner': u'user0',
283 u'created_on': u'2008-07-30 22:15:43',
284 u'timeout': 144,
285 u'synch_count': 1,
286 u'id': 6761},
287 u'active': 0,
288 u'id': 193166} ])],
289 err_words_ok=['unassigned', 'meta-hosts'],
290 out_words_no=['Xeon'])
291
292
293 def test_job_stat_list_hosts(self):
294 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
Allen Lib774aa22017-02-01 17:42:15 -0800295 '--list-hosts'],
mblighfca5ed12009-11-06 02:59:56 +0000296 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
297 [{u'status_counts': {u'Queued': 1},
298 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\')',
299 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700300 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000301 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800302 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000303 u'owner': u'user0',
304 u'created_on': u'2008-07-30 22:15:43',
305 u'timeout': 144,
306 u'synch_count': 1,
307 u'id': 6761}]),
308 ('get_host_queue_entries', {'job__in': ['6761']},
309 True,
310 [{u'status': u'Queued',
311 u'complete': 0,
312 u'deleted': 0,
313 u'host': {u'status': u'Running',
314 u'lock_time': None,
315 u'hostname': u'host41',
316 u'locked': False,
317 u'locked_by': None,
318 u'invalid': False,
319 u'id': 4833,
Allen Lie4c08272017-02-01 16:40:53 -0800320 u'protection': u'Repair filesystem only'},
mblighfca5ed12009-11-06 02:59:56 +0000321 u'priority': 1,
322 u'meta_host': u'Xeon',
323 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\')',
324 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700325 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000326 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800327 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000328 u'owner': u'user0',
329 u'created_on': u'2008-07-30 22:15:43',
330 u'timeout': 144,
331 u'synch_count': 1,
332 u'id': 6761},
333 u'active': 0,
334 u'id': 193166},
335 {u'status': u'Running',
336 u'complete': 0,
337 u'deleted': 0,
338 u'host': {u'status': u'Running',
339 u'lock_time': None,
340 u'hostname': u'host42',
341 u'locked': False,
342 u'locked_by': None,
343 u'invalid': False,
344 u'id': 4833,
Allen Lie4c08272017-02-01 16:40:53 -0800345 u'protection': u'Repair filesystem only'},
mblighfca5ed12009-11-06 02:59:56 +0000346 u'priority': 1,
347 u'meta_host': u'Xeon',
348 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\')',
349 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700350 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000351 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800352 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000353 u'owner': u'user0',
354 u'created_on': u'2008-07-30 22:15:43',
355 u'timeout': 144,
356 u'synch_count': 1,
357 u'id': 6761},
358 u'active': 0,
359 u'id': 193166} ])],
360 out_words_ok=['host41', 'host42'],
361 out_words_no=['Xeon', 'Running', 'Queued'],
362 err_words_no=['unassigned'])
363
364
365 def test_job_stat_list_hosts_status(self):
366 self.run_cmd(argv=['atest', 'job', 'stat', '6761',
Allen Lib774aa22017-02-01 17:42:15 -0800367 '--list-hosts-status', 'Running,Queued'],
mblighfca5ed12009-11-06 02:59:56 +0000368 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
369 [{u'status_counts': {u'Queued': 1, u'Running': 1},
370 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\')',
371 u'name': u'test',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700372 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000373 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800374 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000375 u'owner': u'user0',
376 u'created_on': u'2008-07-30 22:15:43',
377 u'timeout': 144,
378 u'synch_count': 1,
379 u'id': 6761}]),
380 ('get_host_queue_entries', {'job__in': ['6761']},
381 True,
382 [{u'status': u'Queued',
383 u'complete': 0,
384 u'deleted': 0,
385 u'host': {u'status': u'Queued',
386 u'lock_time': None,
387 u'hostname': u'host41',
388 u'locked': False,
389 u'locked_by': None,
390 u'invalid': False,
391 u'id': 4833,
Allen Lie4c08272017-02-01 16:40:53 -0800392 u'protection': u'Repair filesystem only'},
mblighfca5ed12009-11-06 02:59:56 +0000393 u'priority': 1,
394 u'meta_host': None,
395 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\')',
396 u'name': u'test',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700397 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000398 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800399 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000400 u'owner': u'user0',
401 u'created_on': u'2008-07-30 22:15:43',
402 u'timeout': 144,
403 u'synch_count': 1,
404 u'id': 6761},
405 u'active': 0,
406 u'id': 193166},
407 {u'status': u'Running',
408 u'complete': 0,
409 u'deleted': 0,
410 u'host': {u'status': u'Running',
411 u'lock_time': None,
412 u'hostname': u'host42',
413 u'locked': False,
414 u'locked_by': None,
415 u'invalid': False,
416 u'id': 4833,
Allen Lie4c08272017-02-01 16:40:53 -0800417 u'protection': u'Repair filesystem only'},
mblighfca5ed12009-11-06 02:59:56 +0000418 u'priority': 1,
419 u'meta_host': None,
420 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\')',
421 u'name': u'test',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700422 u'control_type': CLIENT,
mblighfca5ed12009-11-06 02:59:56 +0000423 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800424 u'priority': priorities.Priority.DEFAULT,
mblighfca5ed12009-11-06 02:59:56 +0000425 u'owner': u'user0',
426 u'created_on': u'2008-07-30 22:15:43',
427 u'timeout': 144,
428 u'synch_count': 1,
429 u'id': 6761},
430 u'active': 0,
431 u'id': 193166} ])],
432 out_words_ok=['Queued', 'Running', 'host41', 'host42'],
433 out_words_no=['Xeon'],
434 err_words_no=['unassigned'])
435
436
mblighbe630eb2008-08-01 16:41:48 +0000437 def test_job_stat_job_multiple_hosts(self):
Allen Lib774aa22017-02-01 17:42:15 -0800438 self.run_cmd(argv=['atest', 'job', 'stat', '6761'],
mblighbe630eb2008-08-01 16:41:48 +0000439 rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,
440 [{u'status_counts': {u'Running': 1,
441 u'Queued': 4},
442 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\')',
443 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700444 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000445 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800446 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000447 u'owner': u'user0',
448 u'created_on': u'2008-07-30 22:15:43',
449 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000450 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000451 u'id': 6761}]),
452 ('get_host_queue_entries', {'job__in': ['6761']},
453 True,
454 [{u'status': u'Queued',
455 u'complete': 0,
456 u'deleted': 0,
457 u'host': None,
458 u'priority': 1,
459 u'meta_host': u'Xeon',
460 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\')',
461 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700462 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000463 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800464 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000465 u'owner': u'user0',
466 u'created_on': u'2008-07-30 22:15:43',
467 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000468 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000469 u'id': 6761},
470 u'active': 0,
471 u'id': 193166},
472 {u'status': u'Queued',
473 u'complete': 0,
474 u'deleted': 0,
475 u'host': None,
476 u'priority': 1,
477 u'meta_host': u'Xeon',
478 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\')',
479 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700480 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000481 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800482 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000483 u'owner': u'user0',
484 u'created_on': u'2008-07-30 22:15:43',
485 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000486 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000487 u'id': 6761},
488 u'active': 0,
489 u'id': 193167},
490 {u'status': u'Queued',
491 u'complete': 0,
492 u'deleted': 0,
493 u'host': None,
494 u'priority': 1,
495 u'meta_host': u'Athlon',
496 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\')',
497 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700498 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000499 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800500 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000501 u'owner': u'user0',
502 u'created_on': u'2008-07-30 22:15:43',
503 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000504 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000505 u'id': 6761},
506 u'active': 0,
507 u'id': 193168},
508 {u'status': u'Queued',
509 u'complete': 0,
510 u'deleted': 0,
511 u'host': None,
512 u'priority': 1,
513 u'meta_host': u'x286',
514 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\')',
515 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700516 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000517 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800518 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000519 u'owner': u'user0',
520 u'created_on': u'2008-07-30 22:15:43',
521 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000522 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000523 u'id': 6761},
524 u'active': 0,
525 u'id': 193169},
526 {u'status': u'Running',
527 u'complete': 0,
528 u'deleted': 0,
529 u'host': {u'status': u'Running',
530 u'lock_time': None,
531 u'hostname': u'host42',
mbligh0887d402009-01-30 00:50:29 +0000532 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000533 u'locked_by': None,
mbligh0887d402009-01-30 00:50:29 +0000534 u'invalid': False,
mblighbe630eb2008-08-01 16:41:48 +0000535 u'id': 4833,
Allen Lie4c08272017-02-01 16:40:53 -0800536 u'protection': u'Repair filesystem only'},
mblighbe630eb2008-08-01 16:41:48 +0000537 u'priority': 1,
538 u'meta_host': u'Athlon',
539 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\')',
540 u'name': u'test_on_meta_hosts',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700541 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000542 u'run_verify': 1,
Allen Li352b86a2016-12-14 12:11:27 -0800543 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000544 u'owner': u'user0',
545 u'created_on': u'2008-07-30 22:15:43',
546 u'timeout': 144,
showard2bab8f42008-11-12 18:15:22 +0000547 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000548 u'id': 6761},
549 u'active': 1,
550 u'id': 193170} ])],
551 out_words_ok=['test_on_meta_hosts',
552 'host42', 'Queued', 'Running'],
553 out_words_no=['Athlon', 'Xeon', 'x286'])
554
555
556 def test_job_stat_job_no_host_in_qes(self):
557 results = copy.deepcopy(self.results)
Allen Lib774aa22017-02-01 17:42:15 -0800558 self.run_cmd(argv=['atest', 'job', 'stat', '180'],
mblighbe630eb2008-08-01 16:41:48 +0000559 rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,
560 [results[0]]),
561 ('get_host_queue_entries', {'job__in': ['180']},
562 True,
563 [{u'status': u'Failed',
564 u'complete': 1,
565 u'host': None,
566 u'priority': 1,
567 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000568 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 +0000569 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700570 u'control_type': SERVER,
Allen Li352b86a2016-12-14 12:11:27 -0800571 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000572 u'owner': u'user0',
573 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000574 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000575 u'id': 180},
576 u'active': 0,
577 u'id': 101084}])],
mblighfca5ed12009-11-06 02:59:56 +0000578 err_words_ok=['unassigned', 'meta-hosts'])
mblighbe630eb2008-08-01 16:41:48 +0000579
580
581 def test_job_stat_multi_jobs(self):
582 results = copy.deepcopy(self.results)
Allen Lib774aa22017-02-01 17:42:15 -0800583 self.run_cmd(argv=['atest', 'job', 'stat', '180', '338'],
mblighbe630eb2008-08-01 16:41:48 +0000584 rpcs=[('get_jobs_summary', {'id__in': ['180', '338']},
585 True, results),
586 ('get_host_queue_entries',
587 {'job__in': ['180', '338']},
588 True,
589 [{u'status': u'Failed',
590 u'complete': 1,
591 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000592 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000593 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000594 u'invalid': True,
Allen Lie4c08272017-02-01 16:40:53 -0800595 u'id': 4432},
mblighbe630eb2008-08-01 16:41:48 +0000596 u'priority': 1,
597 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000598 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 +0000599 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700600 u'control_type': SERVER,
Allen Li352b86a2016-12-14 12:11:27 -0800601 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000602 u'owner': u'user0',
603 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000604 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000605 u'id': 180},
606 u'active': 0,
607 u'id': 101084},
608 {u'status': u'Failed',
609 u'complete': 1,
610 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000611 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000612 u'hostname': u'host10',
mbligh0887d402009-01-30 00:50:29 +0000613 u'invalid': True,
Allen Lie4c08272017-02-01 16:40:53 -0800614 u'id': 4432},
mblighbe630eb2008-08-01 16:41:48 +0000615 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': 338},
625 u'active': 0,
626 u'id': 101084}])],
627 out_words_ok=['test_job0', 'test_job1'])
628
629
630 def test_job_stat_multi_jobs_name_id(self):
Allen Lib774aa22017-02-01 17:42:15 -0800631 self.run_cmd(argv=['atest', 'job', 'stat', 'mytest', '180'],
mblighbe630eb2008-08-01 16:41:48 +0000632 rpcs=[('get_jobs_summary', {'id__in': ['180']},
633 True,
634 [{u'status_counts': {u'Aborted': 1},
635 u'control_file':
636 u"job.run_test('sleeptest')\n",
637 u'name': u'job0',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700638 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000639 u'priority':
Allen Li352b86a2016-12-14 12:11:27 -0800640 priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000641 u'owner': u'user0',
642 u'created_on':
643 u'2008-07-08 17:45:44',
showard2bab8f42008-11-12 18:15:22 +0000644 u'synch_count': 2,
mblighbe630eb2008-08-01 16:41:48 +0000645 u'id': 180}]),
646 ('get_jobs_summary', {'name__in': ['mytest']},
647 True,
648 [{u'status_counts': {u'Queued': 1},
649 u'control_file':
650 u"job.run_test('sleeptest')\n",
651 u'name': u'mytest',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700652 u'control_type': CLIENT,
mblighbe630eb2008-08-01 16:41:48 +0000653 u'priority':
Allen Li352b86a2016-12-14 12:11:27 -0800654 priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000655 u'owner': u'user0',
656 u'created_on': u'2008-07-08 12:17:47',
657 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000658 u'id': 338}]),
659 ('get_host_queue_entries',
660 {'job__in': ['180']},
661 True,
662 [{u'status': u'Failed',
663 u'complete': 1,
664 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000665 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000666 u'hostname': u'host0',
mbligh0887d402009-01-30 00:50:29 +0000667 u'invalid': True,
Allen Lie4c08272017-02-01 16:40:53 -0800668 u'id': 4432},
mblighbe630eb2008-08-01 16:41:48 +0000669 u'priority': 1,
670 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000671 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 +0000672 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700673 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000674 u'synchronizing': 0,
Allen Li352b86a2016-12-14 12:11:27 -0800675 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000676 u'owner': u'user0',
677 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000678 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000679 u'id': 180},
680 u'active': 0,
681 u'id': 101084}]),
682 ('get_host_queue_entries',
683 {'job__name__in': ['mytest']},
684 True,
685 [{u'status': u'Failed',
686 u'complete': 1,
687 u'host': {u'status': u'Repair Failed',
mbligh0887d402009-01-30 00:50:29 +0000688 u'locked': False,
mblighbe630eb2008-08-01 16:41:48 +0000689 u'hostname': u'host10',
mbligh0887d402009-01-30 00:50:29 +0000690 u'invalid': True,
Allen Lie4c08272017-02-01 16:40:53 -0800691 u'id': 4432},
mblighbe630eb2008-08-01 16:41:48 +0000692 u'priority': 1,
693 u'meta_host': None,
jadmanski8d631c92008-08-18 21:12:40 +0000694 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 +0000695 u'name': u'test_sleep',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700696 u'control_type': SERVER,
mblighbe630eb2008-08-01 16:41:48 +0000697 u'synchronizing': 0,
Allen Li352b86a2016-12-14 12:11:27 -0800698 u'priority': priorities.Priority.DEFAULT,
mblighbe630eb2008-08-01 16:41:48 +0000699 u'owner': u'user0',
700 u'created_on': u'2008-03-18 11:27:29',
showard2bab8f42008-11-12 18:15:22 +0000701 u'synch_count': 1,
mblighbe630eb2008-08-01 16:41:48 +0000702 u'id': 338},
703 u'active': 0,
704 u'id': 101084}])],
705 out_words_ok=['job0', 'mytest', 'Aborted', 'Queued',
Allen Li352b86a2016-12-14 12:11:27 -0800706 'Failed', str(priorities.Priority.DEFAULT)])
mblighbe630eb2008-08-01 16:41:48 +0000707
708
709class job_create_unittest(cli_mock.cli_unittest):
710 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)'
711
Richard Barnette41e617b2016-05-19 16:18:16 -0700712 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 +0000713
mbligh120351e2009-01-24 01:40:45 +0000714 trivial_ctrl_file = 'print "Hello"\n'
715
Allen Li352b86a2016-12-14 12:11:27 -0800716 data = {'priority': priorities.Priority.DEFAULT, 'control_file': ctrl_file,
717 'hosts': ['host0'],
Aviv Keshet3dd8beb2013-05-13 17:36:04 -0700718 'name': 'test_job0', 'control_type': CLIENT, 'email_list': '',
Dan Shiec1d47d2015-02-13 11:38:13 -0800719 'meta_hosts': [], 'synch_count': 1, 'dependencies': [],
720 'require_ssp': False}
mblighbe630eb2008-08-01 16:41:48 +0000721
722
723 def test_execute_create_job(self):
724 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
Allen Lib774aa22017-02-01 17:42:15 -0800725 'test_job0', '-m', 'host0'],
showard989f25d2008-10-01 11:38:11 +0000726 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000727 {'tests': ['sleeptest']},
showard989f25d2008-10-01 11:38:11 +0000728 True,
729 {'control_file' : self.ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000730 'synch_count' : 1,
showard989f25d2008-10-01 11:38:11 +0000731 'is_server' : False,
732 'dependencies' : []}),
mblighbe630eb2008-08-01 16:41:48 +0000733 ('create_job', self.data, True, 180)],
734 out_words_ok=['test_job0', 'Created'],
735 out_words_no=['Uploading', 'Done'])
736
737
738 def test_execute_create_job_with_control(self):
mbligh41515392009-07-11 00:13:11 +0000739 file_temp = cli_mock.create_file(self.ctrl_file)
740 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -0800741 'test_job0', '-m', 'host0'],
mblighbe630eb2008-08-01 16:41:48 +0000742 rpcs=[('create_job', self.data, True, 42)],
743 out_words_ok=['test_job0', 'Created'],
744 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000745 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000746
747
mbligh0a669132008-10-10 20:02:32 +0000748 def test_execute_create_job_with_control_and_email(self):
749 data = self.data.copy()
750 data['email_list'] = 'em'
mbligh41515392009-07-11 00:13:11 +0000751 file_temp = cli_mock.create_file(self.ctrl_file)
752 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -0800753 'test_job0', '-m', 'host0', '-e', 'em'],
mbligh0a669132008-10-10 20:02:32 +0000754 rpcs=[('create_job', data, True, 42)],
755 out_words_ok=['test_job0', 'Created'],
756 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000757 file_temp.clean()
mbligh0a669132008-10-10 20:02:32 +0000758
759
showardb27f4ad2009-05-01 00:08:26 +0000760 def test_execute_create_job_with_control_and_dependencies(self):
mbligh0a669132008-10-10 20:02:32 +0000761 data = self.data.copy()
762 data['dependencies'] = ['dep1', 'dep2']
mbligh41515392009-07-11 00:13:11 +0000763 file_temp = cli_mock.create_file(self.ctrl_file)
764 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -0800765 'test_job0', '-m', 'host0', '-d', 'dep1, dep2 '],
mbligh0a669132008-10-10 20:02:32 +0000766 rpcs=[('create_job', data, True, 42)],
767 out_words_ok=['test_job0', 'Created'],
768 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000769 file_temp.clean()
mbligh0a669132008-10-10 20:02:32 +0000770
771
Eric Li8a12e802011-02-17 14:24:13 -0800772 def test_execute_create_job_with_control_and_comma_dependencies(self):
773 data = self.data.copy()
774 data['dependencies'] = ['dep2,False', 'dep1,True']
775 file_temp = cli_mock.create_file(self.ctrl_file)
776 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
777 'test_job0', '-m', 'host0', '-d',
Allen Lib774aa22017-02-01 17:42:15 -0800778 'dep1\,True, dep2\,False '],
Eric Li8a12e802011-02-17 14:24:13 -0800779 rpcs=[('create_job', data, True, 42)],
780 out_words_ok=['test_job0', 'Created'],
781 out_words_no=['Uploading', 'Done'])
782 file_temp.clean()
783
784
showard7bce1022008-11-14 22:51:05 +0000785 def test_execute_create_job_with_synch_count(self):
786 data = self.data.copy()
787 data['synch_count'] = 2
mbligh41515392009-07-11 00:13:11 +0000788 file_temp = cli_mock.create_file(self.ctrl_file)
789 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -0800790 'test_job0', '-m', 'host0', '-y', '2'],
showard7bce1022008-11-14 22:51:05 +0000791 rpcs=[('create_job', data, True, 42)],
792 out_words_ok=['test_job0', 'Created'],
793 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +0000794 file_temp.clean()
showard7bce1022008-11-14 22:51:05 +0000795
796
showardb27f4ad2009-05-01 00:08:26 +0000797 def test_execute_create_job_with_test_and_dependencies(self):
mblighb9a8b162008-10-29 16:47:29 +0000798 data = self.data.copy()
799 data['dependencies'] = ['dep1', 'dep2', 'dep3']
800 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
Allen Lib774aa22017-02-01 17:42:15 -0800801 'test_job0', '-m', 'host0', '-d', 'dep1, dep2 '],
mblighb9a8b162008-10-29 16:47:29 +0000802 rpcs=[('generate_control_file',
mbligh120351e2009-01-24 01:40:45 +0000803 {'tests': ['sleeptest']},
mblighb9a8b162008-10-29 16:47:29 +0000804 True,
805 {'control_file' : self.ctrl_file,
showard2bab8f42008-11-12 18:15:22 +0000806 'synch_count' : 1,
mblighb9a8b162008-10-29 16:47:29 +0000807 'is_server' : False,
808 'dependencies' : ['dep3']}),
809 ('create_job', data, True, 42)],
810 out_words_ok=['test_job0', 'Created'],
811 out_words_no=['Uploading', 'Done'])
812
813
Eric Li8a12e802011-02-17 14:24:13 -0800814 def test_execute_create_job_with_test_and_comma_dependencies(self):
815 data = self.data.copy()
816 data['dependencies'] = ['dep1,True', 'dep2,False', 'dep3,123']
817 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
818 'test_job0', '-m', 'host0', '-d',
Allen Lib774aa22017-02-01 17:42:15 -0800819 'dep1\,True dep2\,False '],
Eric Li8a12e802011-02-17 14:24:13 -0800820 rpcs=[('generate_control_file',
821 {'tests': ['sleeptest']},
822 True,
823 {'control_file' : self.ctrl_file,
824 'synch_count' : 1,
825 'is_server' : False,
826 'dependencies' : ['dep3,123']}),
827 ('create_job', data, True, 42)],
828 out_words_ok=['test_job0', 'Created'],
829 out_words_no=['Uploading', 'Done'])
830
831
mblighbe630eb2008-08-01 16:41:48 +0000832 def test_execute_create_job_no_args(self):
833 testjob = job.job_create()
Allen Lib774aa22017-02-01 17:42:15 -0800834 sys.argv = ['atest', 'job', 'create']
mblighbe630eb2008-08-01 16:41:48 +0000835 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000836 (sys.exit.expect_call(mock.anything_comparator())
837 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000838 self.assertRaises(cli_mock.ExitException, testjob.parse)
839 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000840 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000841
842
843 def test_execute_create_job_no_hosts(self):
844 testjob = job.job_create()
mbligh41515392009-07-11 00:13:11 +0000845 file_temp = cli_mock.create_file(self.ctrl_file)
Allen Lib774aa22017-02-01 17:42:15 -0800846 sys.argv = ['atest', '-f', file_temp.name, 'test_job0']
mblighbe630eb2008-08-01 16:41:48 +0000847 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000848 (sys.exit.expect_call(mock.anything_comparator())
849 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000850 self.assertRaises(cli_mock.ExitException, testjob.parse)
851 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000852 self.god.check_playback()
mbligh41515392009-07-11 00:13:11 +0000853 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000854
855
856 def test_execute_create_job_cfile_and_tests(self):
857 testjob = job.job_create()
858 sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-f',
Allen Lib774aa22017-02-01 17:42:15 -0800859 'control_file', 'test_job0', '-m', 'host0']
mblighbe630eb2008-08-01 16:41:48 +0000860 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000861 (sys.exit.expect_call(mock.anything_comparator())
862 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000863 self.assertRaises(cli_mock.ExitException, testjob.parse)
864 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000865 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000866
867
mblighbe630eb2008-08-01 16:41:48 +0000868 def test_execute_create_job_bad_cfile(self):
869 testjob = job.job_create()
mbligha212d712009-02-11 01:22:36 +0000870 sys.argv = ['atest', 'job', 'create', '-f', 'control_file',
Allen Lib774aa22017-02-01 17:42:15 -0800871 'test_job0', '-m', 'host0']
mblighbe630eb2008-08-01 16:41:48 +0000872 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000873 (sys.exit.expect_call(mock.anything_comparator())
874 .and_raises(IOError))
mblighbe630eb2008-08-01 16:41:48 +0000875 self.assertRaises(IOError, testjob.parse)
876 self.god.unmock_io()
877
878
879 def test_execute_create_job_bad_priority(self):
880 testjob = job.job_create()
881 sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-p', 'Uber',
Allen Lib774aa22017-02-01 17:42:15 -0800882 '-m', 'host0', 'test_job0']
mblighbe630eb2008-08-01 16:41:48 +0000883 self.god.mock_io()
showard53cb10c2009-05-01 00:09:36 +0000884 (sys.exit.expect_call(mock.anything_comparator())
885 .and_raises(cli_mock.ExitException))
mblighbe630eb2008-08-01 16:41:48 +0000886 self.assertRaises(cli_mock.ExitException, testjob.parse)
887 self.god.unmock_io()
showard53cb10c2009-05-01 00:09:36 +0000888 self.god.check_playback()
mblighbe630eb2008-08-01 16:41:48 +0000889
890
891 def test_execute_create_job_with_mfile(self):
892 data = self.data.copy()
893 data['hosts'] = ['host3', 'host2', 'host1', 'host0']
mbligh41515392009-07-11 00:13:11 +0000894 ctemp = cli_mock.create_file(self.ctrl_file)
895 file_temp = cli_mock.create_file('host0\nhost1\nhost2\nhost3')
896 self.run_cmd(argv=['atest', 'job', 'create', '--mlist', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -0800897 '-f', ctemp.name, 'test_job0'],
mblighbe630eb2008-08-01 16:41:48 +0000898 rpcs=[('create_job', data, True, 42)],
899 out_words_ok=['test_job0', 'Created'])
mbligh41515392009-07-11 00:13:11 +0000900 ctemp.clean()
901 file_temp.clean()
mblighbe630eb2008-08-01 16:41:48 +0000902
903
mbligh5d0b4b32008-12-22 14:43:01 +0000904 def test_execute_create_job_with_timeout(self):
905 data = self.data.copy()
Simran Basi7e605742013-11-12 13:43:36 -0800906 data['timeout_mins'] = '13320'
mbligh41515392009-07-11 00:13:11 +0000907 file_temp = cli_mock.create_file(self.ctrl_file)
908 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -0800909 'test_job0', '-m', 'host0', '-o', '13320'],
mbligh5d0b4b32008-12-22 14:43:01 +0000910 rpcs=[('create_job', data, True, 42)],
911 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +0000912 file_temp.clean()
mbligh5d0b4b32008-12-22 14:43:01 +0000913
914
showard12f3e322009-05-13 21:27:42 +0000915 def test_execute_create_job_with_max_runtime(self):
916 data = self.data.copy()
Simran Basi34217022012-11-06 13:43:15 -0800917 data['max_runtime_mins'] = '13320'
mbligh41515392009-07-11 00:13:11 +0000918 file_temp = cli_mock.create_file(self.ctrl_file)
919 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Simran Basi34217022012-11-06 13:43:15 -0800920 'test_job0', '-m', 'host0', '--max_runtime',
Allen Lib774aa22017-02-01 17:42:15 -0800921 '13320'],
showard12f3e322009-05-13 21:27:42 +0000922 rpcs=[('create_job', data, True, 42)],
923 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +0000924 file_temp.clean()
showard12f3e322009-05-13 21:27:42 +0000925
926
927
mbligh5d0b4b32008-12-22 14:43:01 +0000928 def test_execute_create_job_with_noverify(self):
929 data = self.data.copy()
930 data['run_verify'] = False
mbligh41515392009-07-11 00:13:11 +0000931 file_temp = cli_mock.create_file(self.ctrl_file)
932 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -0800933 'test_job0', '-m', 'host0', '-n'],
mbligh5d0b4b32008-12-22 14:43:01 +0000934 rpcs=[('create_job', data, True, 42)],
935 out_words_ok=['test_job0', 'Created'],)
mbligh41515392009-07-11 00:13:11 +0000936 file_temp.clean()
mbligh5d0b4b32008-12-22 14:43:01 +0000937
938
mblighce348642009-02-12 21:50:39 +0000939 def test_execute_create_job_oth(self):
940 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +0000941 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +0000942 data['one_time_hosts'] = ['host0']
943 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
944 'test_job0', '--one-time-hosts', 'host0'],
945 rpcs=[('generate_control_file',
946 {'tests': ['sleeptest']},
947 True,
948 {'control_file' : self.ctrl_file,
949 'synch_count' : 1,
950 'is_server' : False,
951 'dependencies' : []}),
952 ('create_job', data, True, 180)],
953 out_words_ok=['test_job0', 'Created'],
954 out_words_no=['Uploading', 'Done'])
955
956
957 def test_execute_create_job_multi_oth(self):
958 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +0000959 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +0000960 data['one_time_hosts'] = ['host1', 'host0']
961 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
962 'test_job0', '--one-time-hosts', 'host0,host1'],
963 rpcs=[('generate_control_file',
964 {'tests': ['sleeptest']},
965 True,
966 {'control_file' : self.ctrl_file,
967 'synch_count' : 1,
968 'is_server' : False,
969 'dependencies' : []}),
970 ('create_job', data, True, 180)],
971 out_words_ok=['test_job0', 'Created'],
972 out_words_no=['Uploading', 'Done'])
973
974
975 def test_execute_create_job_oth_exists(self):
976 data = self.data.copy()
mblighad575162010-03-24 22:14:18 +0000977 data['hosts'] = []
mblighce348642009-02-12 21:50:39 +0000978 data['one_time_hosts'] = ['host0']
979 self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',
980 'test_job0', '--one-time-hosts', 'host0'],
981 rpcs=[('generate_control_file',
982 {'tests': ['sleeptest']},
983 True,
984 {'control_file' : self.ctrl_file,
985 'synch_count' : 1,
986 'is_server' : False,
987 'dependencies' : []}),
988 ('create_job', data, False,
989 '''ValidationError: {'hostname': 'host0 '''
990 '''already exists in the autotest DB. '''
991 '''Select it rather than entering it as '''
992 '''a one time host.'}''')],
993 out_words_no=['test_job0', 'Created'],
994 err_words_ok=['failed', 'already exists'])
995
996
showardb27f4ad2009-05-01 00:08:26 +0000997 def test_execute_create_job_with_control_and_labels(self):
998 data = self.data.copy()
999 data['hosts'] = ['host0', 'host1', 'host2']
mbligh41515392009-07-11 00:13:11 +00001000 file_temp = cli_mock.create_file(self.ctrl_file)
1001 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -08001002 'test_job0', '-m', 'host0', '-b', 'label1,label2'],
showardb27f4ad2009-05-01 00:08:26 +00001003 rpcs=[('get_hosts', {'multiple_labels': ['label1',
1004 'label2']}, True,
1005 [{u'status': u'Running', u'lock_time': None,
1006 u'hostname': u'host1', u'locked': False,
1007 u'locked_by': None, u'invalid': False, u'id': 42,
1008 u'labels': [u'label1'], u'platform':
1009 u'Warp18_Diskfull', u'protection':
Allen Lie4c08272017-02-01 16:40:53 -08001010 u'Repair software only', u'dirty': True},
showardb27f4ad2009-05-01 00:08:26 +00001011 {u'status': u'Running', u'lock_time': None,
1012 u'hostname': u'host2', u'locked': False,
1013 u'locked_by': None, u'invalid': False, u'id': 43,
1014 u'labels': [u'label2'], u'platform':
1015 u'Warp18_Diskfull', u'protection':
Allen Lie4c08272017-02-01 16:40:53 -08001016 u'Repair software only', u'dirty': True}]),
showardb27f4ad2009-05-01 00:08:26 +00001017 ('create_job', data, True, 42)],
1018 out_words_ok=['test_job0', 'Created'],
1019 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +00001020 file_temp.clean()
showardb27f4ad2009-05-01 00:08:26 +00001021
1022
1023 def test_execute_create_job_with_label_and_duplicate_hosts(self):
1024 data = self.data.copy()
1025 data['hosts'] = ['host1', 'host0']
mbligh41515392009-07-11 00:13:11 +00001026 file_temp = cli_mock.create_file(self.ctrl_file)
1027 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
Allen Lib774aa22017-02-01 17:42:15 -08001028 'test_job0', '-m', 'host0,host1', '-b', 'label1'],
showardb27f4ad2009-05-01 00:08:26 +00001029 rpcs=[('get_hosts', {'multiple_labels': ['label1']}, True,
1030 [{u'status': u'Running', u'lock_time': None,
1031 u'hostname': u'host1', u'locked': False,
1032 u'locked_by': None, u'invalid': False, u'id': 42,
1033 u'labels': [u'label1'], u'platform':
1034 u'Warp18_Diskfull', u'protection':
Allen Lie4c08272017-02-01 16:40:53 -08001035 u'Repair software only', u'dirty': True}]),
showardb27f4ad2009-05-01 00:08:26 +00001036 ('create_job', data, True, 42)],
1037 out_words_ok=['test_job0', 'Created'],
1038 out_words_no=['Uploading', 'Done'])
mbligh41515392009-07-11 00:13:11 +00001039 file_temp.clean()
showardb27f4ad2009-05-01 00:08:26 +00001040
1041
jamesrenc2863162010-07-12 21:20:51 +00001042 def test_execute_create_job_with_label_commas_and_duplicate_hosts(self):
1043 data = self.data.copy()
1044 data['hosts'] = ['host1', 'host0']
1045 file_temp = cli_mock.create_file(self.ctrl_file)
1046 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1047 'test_job0', '-m', 'host0,host1', '-b',
Allen Lib774aa22017-02-01 17:42:15 -08001048 'label1,label\\,2'],
jamesrenc2863162010-07-12 21:20:51 +00001049 rpcs=[('get_hosts', {'multiple_labels': ['label1',
1050 'label,2']}, True,
1051 [{u'status': u'Running', u'lock_time': None,
1052 u'hostname': u'host1', u'locked': False,
1053 u'locked_by': None, u'invalid': False, u'id': 42,
1054 u'labels': [u'label1', u'label,2'], u'platform':
1055 u'Warp18_Diskfull', u'protection':
Allen Lie4c08272017-02-01 16:40:53 -08001056 u'Repair software only', u'dirty': True}]),
jamesrenc2863162010-07-12 21:20:51 +00001057 ('create_job', data, True, 42)],
1058 out_words_ok=['test_job0', 'Created'],
1059 out_words_no=['Uploading', 'Done'])
1060 file_temp.clean()
1061
1062
1063 def test_execute_create_job_with_label_escaping_and_duplicate_hosts(self):
1064 data = self.data.copy()
1065 data['hosts'] = ['host1', 'host0']
1066 file_temp = cli_mock.create_file(self.ctrl_file)
1067 self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
1068 'test_job0', '-m', 'host0,host1', '-b',
Allen Lib774aa22017-02-01 17:42:15 -08001069 'label1,label\\,2\\\\,label3'],
jamesrenc2863162010-07-12 21:20:51 +00001070 rpcs=[('get_hosts', {'multiple_labels': ['label,2\\',
1071 'label1', 'label3']}, True,
1072 [{u'status': u'Running', u'lock_time': None,
1073 u'hostname': u'host1', u'locked': False,
1074 u'locked_by': None, u'invalid': False, u'id': 42,
1075 u'labels': [u'label1', u'label,2\\', u'label3'],
1076 u'platform': u'Warp18_Diskfull', u'protection':
Allen Lie4c08272017-02-01 16:40:53 -08001077 u'Repair software only', u'dirty': True}]),
jamesrenc2863162010-07-12 21:20:51 +00001078 ('create_job', data, True, 42)],
1079 out_words_ok=['test_job0', 'Created'],
1080 out_words_no=['Uploading', 'Done'])
1081 file_temp.clean()
1082
1083
mblighbe630eb2008-08-01 16:41:48 +00001084 def _test_parse_hosts(self, args, exp_hosts=[], exp_meta_hosts=[]):
mbligh56f1f4a2009-08-03 16:45:12 +00001085 testjob = job.job_create_or_clone()
1086 (hosts, meta_hosts) = testjob._parse_hosts(args)
mblighbe630eb2008-08-01 16:41:48 +00001087 self.assertEqualNoOrder(hosts, exp_hosts)
1088 self.assertEqualNoOrder(meta_hosts, exp_meta_hosts)
1089
1090
1091 def test_parse_hosts_regular(self):
1092 self._test_parse_hosts(['host0'], ['host0'])
1093
1094
1095 def test_parse_hosts_regulars(self):
1096 self._test_parse_hosts(['host0', 'host1'], ['host0', 'host1'])
1097
1098
1099 def test_parse_hosts_meta_one(self):
1100 self._test_parse_hosts(['*meta0'], [], ['meta0'])
1101
1102
1103 def test_parse_hosts_meta_five(self):
1104 self._test_parse_hosts(['5*meta0'], [], ['meta0']*5)
1105
1106
1107 def test_parse_hosts_metas_five(self):
1108 self._test_parse_hosts(['5*meta0', '2*meta1'], [],
1109 ['meta0']*5 + ['meta1']*2)
1110
1111
1112 def test_parse_hosts_mix(self):
1113 self._test_parse_hosts(['5*meta0', 'host0', '2*meta1', 'host1',
1114 '*meta2'], ['host0', 'host1'],
1115 ['meta0']*5 + ['meta1']*2 + ['meta2'])
1116
1117
mbligh5a496082009-08-03 16:44:54 +00001118class job_clone_unittest(cli_mock.cli_unittest):
1119 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 -07001120 'control_type': SERVER,
mbligh5a496082009-08-03 16:44:54 +00001121 'dependencies': [],
1122 'email_list': u'',
Simran Basi34217022012-11-06 13:43:15 -08001123 'max_runtime_mins': 28800,
mbligh5a496082009-08-03 16:44:54 +00001124 'parse_failed_repair': True,
Allen Li352b86a2016-12-14 12:11:27 -08001125 'priority': priorities.Priority.DEFAULT,
mbligh5a496082009-08-03 16:44:54 +00001126 'reboot_after': u'Always',
1127 'reboot_before': u'If dirty',
1128 'run_verify': True,
1129 'synch_count': 1,
Simran Basi7e605742013-11-12 13:43:36 -08001130 'timeout_mins': 480}
mbligh5a496082009-08-03 16:44:54 +00001131
mbligh56f1f4a2009-08-03 16:45:12 +00001132 local_hosts = [{u'acls': [u'acl0'],
mbligh56f1f4a2009-08-03 16:45:12 +00001133 u'attributes': {},
1134 u'dirty': False,
1135 u'hostname': u'host0',
1136 u'id': 8,
1137 u'invalid': False,
1138 u'labels': [u'label0', u'label1'],
1139 u'lock_time': None,
1140 u'locked': False,
1141 u'locked_by': None,
1142 u'other_labels': u'label0, label1',
1143 u'platform': u'plat0',
1144 u'protection': u'Repair software only',
Allen Lie4c08272017-02-01 16:40:53 -08001145 u'status': u'Ready'},
mbligh56f1f4a2009-08-03 16:45:12 +00001146 {u'acls': [u'acl0'],
mbligh56f1f4a2009-08-03 16:45:12 +00001147 u'attributes': {},
1148 u'dirty': False,
1149 u'hostname': u'host1',
1150 u'id': 9,
1151 u'invalid': False,
1152 u'labels': [u'label0', u'label1'],
1153 u'lock_time': None,
1154 u'locked': False,
1155 u'locked_by': None,
1156 u'other_labels': u'label0, label1',
1157 u'platform': u'plat0',
1158 u'protection': u'Repair software only',
Allen Lie4c08272017-02-01 16:40:53 -08001159 u'status': u'Ready'}]
mbligh56f1f4a2009-08-03 16:45:12 +00001160
1161
mbligh5a496082009-08-03 16:44:54 +00001162 def setUp(self):
1163 super(job_clone_unittest, self).setUp()
1164 self.job_data_clone_info = copy.deepcopy(self.job_data)
1165 self.job_data_clone_info['created_on'] = '2009-07-23 16:21:29'
1166 self.job_data_clone_info['name'] = 'testing_clone'
1167 self.job_data_clone_info['id'] = 42
1168 self.job_data_clone_info['owner'] = 'user0'
1169
1170 self.job_data_cloned = copy.deepcopy(self.job_data)
1171 self.job_data_cloned['name'] = 'cloned'
1172 self.job_data_cloned['hosts'] = [u'host0']
1173 self.job_data_cloned['meta_hosts'] = []
1174
1175
1176 def test_backward_compat(self):
1177 self.run_cmd(argv=['atest', 'job', 'create', '--clone', '42',
1178 '-r', 'cloned'],
1179 rpcs=[('get_info_for_clone', {'id': '42',
1180 'preserve_metahosts': True},
1181 True,
Allen Li335f2162017-02-01 14:47:01 -08001182 {u'hosts': [{u'acls': [u'acl0'],
mbligh5a496082009-08-03 16:44:54 +00001183 u'attributes': {},
1184 u'dirty': False,
1185 u'hostname': u'host0',
1186 u'id': 4378,
1187 u'invalid': False,
1188 u'labels': [u'label0', u'label1'],
1189 u'lock_time': None,
1190 u'locked': False,
1191 u'locked_by': None,
1192 u'other_labels': u'label0, label1',
1193 u'platform': u'plat0',
1194 u'protection': u'Repair software only',
Allen Lie4c08272017-02-01 16:40:53 -08001195 u'status': u'Ready'}],
mbligh5a496082009-08-03 16:44:54 +00001196 u'job': self.job_data_clone_info,
1197 u'meta_host_counts': {}}),
1198 ('create_job', self.job_data_cloned, True, 43)],
1199 out_words_ok=['Created job', '43'])
1200
1201
1202 def test_clone_reuse_hosts(self):
mbligh56f1f4a2009-08-03 16:45:12 +00001203 self.job_data_cloned['hosts'] = [u'host0', 'host1']
mbligh5a496082009-08-03 16:44:54 +00001204 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1205 '-r', 'cloned'],
1206 rpcs=[('get_info_for_clone', {'id': '42',
1207 'preserve_metahosts': True},
1208 True,
Allen Li335f2162017-02-01 14:47:01 -08001209 {u'hosts': self.local_hosts,
mbligh5a496082009-08-03 16:44:54 +00001210 u'job': self.job_data_clone_info,
1211 u'meta_host_counts': {}}),
1212 ('create_job', self.job_data_cloned, True, 43)],
1213 out_words_ok=['Created job', '43'])
1214
1215
mbligh56f1f4a2009-08-03 16:45:12 +00001216 def test_clone_reuse_metahosts(self):
1217 self.job_data_cloned['hosts'] = []
1218 self.job_data_cloned['meta_hosts'] = ['type1']*4 + ['type0']
1219 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1220 '-r', 'cloned'],
1221 rpcs=[('get_info_for_clone', {'id': '42',
1222 'preserve_metahosts': True},
1223 True,
Allen Li335f2162017-02-01 14:47:01 -08001224 {u'hosts': [],
mbligh56f1f4a2009-08-03 16:45:12 +00001225 u'job': self.job_data_clone_info,
1226 u'meta_host_counts': {u'type0': 1,
1227 u'type1': 4}}),
1228 ('create_job', self.job_data_cloned, True, 43)],
1229 out_words_ok=['Created job', '43'])
1230
1231
1232 def test_clone_reuse_both(self):
1233 self.job_data_cloned['hosts'] = [u'host0', 'host1']
1234 self.job_data_cloned['meta_hosts'] = ['type1']*4 + ['type0']
1235 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1236 '-r', 'cloned'],
1237 rpcs=[('get_info_for_clone', {'id': '42',
1238 'preserve_metahosts': True},
1239 True,
Allen Li335f2162017-02-01 14:47:01 -08001240 {
mbligh56f1f4a2009-08-03 16:45:12 +00001241 u'hosts': self.local_hosts,
1242 u'job': self.job_data_clone_info,
1243 u'meta_host_counts': {u'type0': 1,
1244 u'type1': 4}}),
1245 ('create_job', self.job_data_cloned, True, 43)],
1246 out_words_ok=['Created job', '43'])
1247
1248
mbligh5a496082009-08-03 16:44:54 +00001249 def test_clone_no_hosts(self):
1250 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42', 'cloned'],
1251 exit_code=1,
1252 out_words_ok=['usage'],
1253 err_words_ok=['machine'])
1254
1255
mbligh56f1f4a2009-08-03 16:45:12 +00001256 def test_clone_reuse_and_hosts(self):
1257 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1258 '-r', '-m', 'host5', 'cloned'],
1259 exit_code=1,
1260 out_words_ok=['usage'],
1261 err_words_ok=['specify'])
1262
1263
1264 def test_clone_new_multiple_hosts(self):
1265 self.job_data_cloned['hosts'] = [u'host5', 'host4', 'host3']
1266 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1267 '-m', 'host5,host4,host3', 'cloned'],
1268 rpcs=[('get_info_for_clone', {'id': '42',
1269 'preserve_metahosts': False},
1270 True,
Allen Li335f2162017-02-01 14:47:01 -08001271 {u'hosts': self.local_hosts,
mbligh56f1f4a2009-08-03 16:45:12 +00001272 u'job': self.job_data_clone_info,
1273 u'meta_host_counts': {}}),
1274 ('create_job', self.job_data_cloned, True, 43)],
1275 out_words_ok=['Created job', '43'])
1276
1277
1278 def test_clone_oth(self):
1279 self.job_data_cloned['hosts'] = []
1280 self.job_data_cloned['one_time_hosts'] = [u'host5']
1281 self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',
1282 '--one-time-hosts', 'host5', 'cloned'],
1283 rpcs=[('get_info_for_clone', {'id': '42',
1284 'preserve_metahosts': False},
1285 True,
Allen Li335f2162017-02-01 14:47:01 -08001286 {u'hosts': self.local_hosts,
mbligh56f1f4a2009-08-03 16:45:12 +00001287 u'job': self.job_data_clone_info,
1288 u'meta_host_counts': {}}),
1289 ('create_job', self.job_data_cloned, True, 43)],
1290 out_words_ok=['Created job', '43'])
mbligh5a496082009-08-03 16:44:54 +00001291
1292
mblighbe630eb2008-08-01 16:41:48 +00001293class job_abort_unittest(cli_mock.cli_unittest):
1294 results = [{u'status_counts': {u'Aborted': 1}, u'control_file':
1295 u"job.run_test('sleeptest')\n", u'name': u'test_job0',
Aviv Keshet3dd8beb2013-05-13 17:36:04 -07001296 u'control_type': SERVER, u'priority':
Allen Li352b86a2016-12-14 12:11:27 -08001297 priorities.Priority.DEFAULT, u'owner': u'user0', u'created_on':
showard2bab8f42008-11-12 18:15:22 +00001298 u'2008-07-08 17:45:44', u'synch_count': 2, u'id': 180}]
mblighbe630eb2008-08-01 16:41:48 +00001299
1300 def test_execute_job_abort(self):
Allen Lib774aa22017-02-01 17:42:15 -08001301 self.run_cmd(argv=['atest', 'job', 'abort', '180'],
mbligh206d50a2008-11-13 01:19:25 +00001302 rpcs=[('abort_host_queue_entries',
1303 {'job__id__in': ['180']}, True, None)],
1304 out_words_ok=['Aborting', '180'])
mblighbe630eb2008-08-01 16:41:48 +00001305
1306
1307if __name__ == '__main__':
1308 unittest.main()