blob: c69d48f29185d63970f99e3b4eaa0676a4d25f6e [file] [log] [blame]
jamesrenc44ae992010-02-19 00:12:54 +00001#!/usr/bin/python
Dan Shi76af8022013-10-19 01:59:49 -07002#pylint: disable-msg=C0111
jamesrenc44ae992010-02-19 00:12:54 +00003
4import datetime
Justin Giorgi67ad67d2016-06-29 14:41:04 -07005import unittest
6
jamesrenc44ae992010-02-19 00:12:54 +00007import common
8from autotest_lib.frontend import setup_django_environment
9from autotest_lib.frontend.afe import frontend_test_utils
Fang Deng51599032014-06-23 17:24:27 -070010from autotest_lib.client.common_lib import host_queue_entry_states
jamesrenc44ae992010-02-19 00:12:54 +000011from autotest_lib.client.common_lib.test_utils import mock
jamesrenc44ae992010-02-19 00:12:54 +000012from autotest_lib.database import database_connection
jamesrendd855242010-03-02 22:23:44 +000013from autotest_lib.frontend.afe import models, model_attributes
Dan Shi76af8022013-10-19 01:59:49 -070014from autotest_lib.scheduler import monitor_db
Prashanth B4ec98672014-05-15 10:44:54 -070015from autotest_lib.scheduler import scheduler_lib
jamesrenc44ae992010-02-19 00:12:54 +000016from autotest_lib.scheduler import scheduler_models
17
18_DEBUG = False
19
20
21class BaseSchedulerModelsTest(unittest.TestCase,
22 frontend_test_utils.FrontendTestMixin):
23 _config_section = 'AUTOTEST_WEB'
24
25 def _do_query(self, sql):
26 self._database.execute(sql)
27
28
29 def _set_monitor_stubs(self):
30 # Clear the instance cache as this is a brand new database.
31 scheduler_models.DBObject._clear_instance_cache()
32
33 self._database = (
34 database_connection.TranslatingDatabase.get_test_database(
Prashanth B4ec98672014-05-15 10:44:54 -070035 translators=scheduler_lib._DB_TRANSLATORS))
jamesrenc44ae992010-02-19 00:12:54 +000036 self._database.connect(db_type='django')
37 self._database.debug = _DEBUG
38
39 self.god.stub_with(scheduler_models, '_db', self._database)
40
41
42 def setUp(self):
43 self._frontend_common_setup()
44 self._set_monitor_stubs()
45
46
47 def tearDown(self):
48 self._database.disconnect()
49 self._frontend_common_teardown()
50
51
52 def _update_hqe(self, set, where=''):
53 query = 'UPDATE afe_host_queue_entries SET ' + set
54 if where:
55 query += ' WHERE ' + where
56 self._do_query(query)
57
58
59class DelayedCallTaskTest(unittest.TestCase):
60 def setUp(self):
61 self.god = mock.mock_god()
62
63
64 def tearDown(self):
65 self.god.unstub_all()
66
67
68 def test_delayed_call(self):
69 test_time = self.god.create_mock_function('time')
70 test_time.expect_call().and_return(33)
71 test_time.expect_call().and_return(34.01)
72 test_time.expect_call().and_return(34.99)
73 test_time.expect_call().and_return(35.01)
74 def test_callback():
75 test_callback.calls += 1
76 test_callback.calls = 0
77 delay_task = scheduler_models.DelayedCallTask(
78 delay_seconds=2, callback=test_callback,
79 now_func=test_time) # time 33
80 self.assertEqual(35, delay_task.end_time)
81 delay_task.poll() # activates the task and polls it once, time 34.01
82 self.assertEqual(0, test_callback.calls, "callback called early")
83 delay_task.poll() # time 34.99
84 self.assertEqual(0, test_callback.calls, "callback called early")
85 delay_task.poll() # time 35.01
86 self.assertEqual(1, test_callback.calls)
87 self.assert_(delay_task.is_done())
88 self.assert_(delay_task.success)
89 self.assert_(not delay_task.aborted)
90 self.god.check_playback()
91
92
93 def test_delayed_call_abort(self):
94 delay_task = scheduler_models.DelayedCallTask(
95 delay_seconds=987654, callback=lambda : None)
96 delay_task.abort()
97 self.assert_(delay_task.aborted)
98 self.assert_(delay_task.is_done())
99 self.assert_(not delay_task.success)
100 self.god.check_playback()
101
102
103class DBObjectTest(BaseSchedulerModelsTest):
104 def test_compare_fields_in_row(self):
105 host = scheduler_models.Host(id=1)
106 fields = list(host._fields)
107 row_data = [getattr(host, fieldname) for fieldname in fields]
108 self.assertEqual({}, host._compare_fields_in_row(row_data))
109 row_data[fields.index('hostname')] = 'spam'
110 self.assertEqual({'hostname': ('host1', 'spam')},
111 host._compare_fields_in_row(row_data))
112 row_data[fields.index('id')] = 23
113 self.assertEqual({'hostname': ('host1', 'spam'), 'id': (1, 23)},
114 host._compare_fields_in_row(row_data))
115
116
117 def test_compare_fields_in_row_datetime_ignores_microseconds(self):
118 datetime_with_us = datetime.datetime(2009, 10, 07, 12, 34, 56, 7890)
119 datetime_without_us = datetime.datetime(2009, 10, 07, 12, 34, 56, 0)
120 class TestTable(scheduler_models.DBObject):
121 _table_name = 'test_table'
122 _fields = ('id', 'test_datetime')
123 tt = TestTable(row=[1, datetime_without_us])
124 self.assertEqual({}, tt._compare_fields_in_row([1, datetime_with_us]))
125
126
127 def test_always_query(self):
128 host_a = scheduler_models.Host(id=2)
129 self.assertEqual(host_a.hostname, 'host2')
130 self._do_query('UPDATE afe_hosts SET hostname="host2-updated" '
131 'WHERE id=2')
132 host_b = scheduler_models.Host(id=2, always_query=True)
133 self.assert_(host_a is host_b, 'Cached instance not returned.')
134 self.assertEqual(host_a.hostname, 'host2-updated',
135 'Database was not re-queried')
136
137 # If either of these are called, a query was made when it shouldn't be.
138 host_a._compare_fields_in_row = lambda _: self.fail('eek! a query!')
139 host_a._update_fields_from_row = host_a._compare_fields_in_row
140 host_c = scheduler_models.Host(id=2, always_query=False)
141 self.assert_(host_a is host_c, 'Cached instance not returned')
142
143
144 def test_delete(self):
145 host = scheduler_models.Host(id=3)
146 host.delete()
147 host = self.assertRaises(scheduler_models.DBError, scheduler_models.Host, id=3,
148 always_query=False)
149 host = self.assertRaises(scheduler_models.DBError, scheduler_models.Host, id=3,
150 always_query=True)
151
152 def test_save(self):
153 # Dummy Job to avoid creating a one in the HostQueueEntry __init__.
154 class MockJob(object):
155 def __init__(self, id):
156 pass
157 def tag(self):
158 return 'MockJob'
159 self.god.stub_with(scheduler_models, 'Job', MockJob)
160 hqe = scheduler_models.HostQueueEntry(
161 new_record=True,
Fang Deng51599032014-06-23 17:24:27 -0700162 row=[0, 1, 2, 'Queued', None, 0, 0, 0, '.', None, False, None,
163 None])
jamesrenc44ae992010-02-19 00:12:54 +0000164 hqe.save()
165 new_id = hqe.id
166 # Force a re-query and verify that the correct data was stored.
167 scheduler_models.DBObject._clear_instance_cache()
168 hqe = scheduler_models.HostQueueEntry(id=new_id)
169 self.assertEqual(hqe.id, new_id)
170 self.assertEqual(hqe.job_id, 1)
171 self.assertEqual(hqe.host_id, 2)
172 self.assertEqual(hqe.status, 'Queued')
173 self.assertEqual(hqe.meta_host, None)
174 self.assertEqual(hqe.active, False)
175 self.assertEqual(hqe.complete, False)
176 self.assertEqual(hqe.deleted, False)
177 self.assertEqual(hqe.execution_subdir, '.')
178 self.assertEqual(hqe.atomic_group_id, None)
179 self.assertEqual(hqe.started_on, None)
Fang Deng51599032014-06-23 17:24:27 -0700180 self.assertEqual(hqe.finished_on, None)
jamesrenc44ae992010-02-19 00:12:54 +0000181
182
183class HostTest(BaseSchedulerModelsTest):
184 def test_cmp_for_sort(self):
185 expected_order = [
186 'alice', 'Host1', 'host2', 'host3', 'host09', 'HOST010',
187 'host10', 'host11', 'yolkfolk']
188 hostname_idx = list(scheduler_models.Host._fields).index('hostname')
189 row = [None] * len(scheduler_models.Host._fields)
190 hosts = []
191 for hostname in expected_order:
192 row[hostname_idx] = hostname
193 hosts.append(scheduler_models.Host(row=row, new_record=True))
194
195 host1 = hosts[expected_order.index('Host1')]
196 host010 = hosts[expected_order.index('HOST010')]
197 host10 = hosts[expected_order.index('host10')]
198 host3 = hosts[expected_order.index('host3')]
199 alice = hosts[expected_order.index('alice')]
200 self.assertEqual(0, scheduler_models.Host.cmp_for_sort(host10, host10))
201 self.assertEqual(1, scheduler_models.Host.cmp_for_sort(host10, host010))
202 self.assertEqual(-1, scheduler_models.Host.cmp_for_sort(host010, host10))
203 self.assertEqual(-1, scheduler_models.Host.cmp_for_sort(host1, host10))
204 self.assertEqual(-1, scheduler_models.Host.cmp_for_sort(host1, host010))
205 self.assertEqual(-1, scheduler_models.Host.cmp_for_sort(host3, host10))
206 self.assertEqual(-1, scheduler_models.Host.cmp_for_sort(host3, host010))
207 self.assertEqual(1, scheduler_models.Host.cmp_for_sort(host3, host1))
208 self.assertEqual(-1, scheduler_models.Host.cmp_for_sort(host1, host3))
209 self.assertEqual(-1, scheduler_models.Host.cmp_for_sort(alice, host3))
210 self.assertEqual(1, scheduler_models.Host.cmp_for_sort(host3, alice))
211 self.assertEqual(0, scheduler_models.Host.cmp_for_sort(alice, alice))
212
213 hosts.sort(cmp=scheduler_models.Host.cmp_for_sort)
214 self.assertEqual(expected_order, [h.hostname for h in hosts])
215
216 hosts.reverse()
217 hosts.sort(cmp=scheduler_models.Host.cmp_for_sort)
218 self.assertEqual(expected_order, [h.hostname for h in hosts])
219
220
221class HostQueueEntryTest(BaseSchedulerModelsTest):
222 def _create_hqe(self, dependency_labels=(), **create_job_kwargs):
223 job = self._create_job(**create_job_kwargs)
224 for label in dependency_labels:
225 job.dependency_labels.add(label)
226 hqes = list(scheduler_models.HostQueueEntry.fetch(where='job_id=%d' % job.id))
227 self.assertEqual(1, len(hqes))
228 return hqes[0]
229
230
231 def _check_hqe_labels(self, hqe, expected_labels):
232 expected_labels = set(expected_labels)
233 label_names = set(label.name for label in hqe.get_labels())
234 self.assertEqual(expected_labels, label_names)
235
236
237 def test_get_labels_empty(self):
238 hqe = self._create_hqe(hosts=[1])
239 labels = list(hqe.get_labels())
240 self.assertEqual([], labels)
241
242
243 def test_get_labels_metahost(self):
244 hqe = self._create_hqe(metahosts=[2])
245 self._check_hqe_labels(hqe, ['label2'])
246
247
248 def test_get_labels_dependancies(self):
249 hqe = self._create_hqe(dependency_labels=(self.label3, self.label4),
250 metahosts=[1])
251 self._check_hqe_labels(hqe, ['label1', 'label3', 'label4'])
252
253
Dan Shi76af8022013-10-19 01:59:49 -0700254 def setup_abort_test(self, agent_finished=True):
255 """Setup the variables for testing abort method.
256
257 @param agent_finished: True to mock agent is finished before aborting
258 the hqe.
259 @return hqe, dispatcher: Mock object of hqe and dispatcher to be used
260 to test abort method.
261 """
262 hqe = self._create_hqe(hosts=[1])
263 hqe.aborted = True
264 hqe.complete = False
265 hqe.status = models.HostQueueEntry.Status.STARTING
Fang Dengd44a1232014-08-18 14:40:28 -0700266 hqe.started_on = datetime.datetime.now()
Dan Shi76af8022013-10-19 01:59:49 -0700267
268 dispatcher = self.god.create_mock_class(monitor_db.BaseDispatcher,
269 'BaseDispatcher')
270 agent = self.god.create_mock_class(monitor_db.Agent, 'Agent')
271 dispatcher.get_agents_for_entry.expect_call(hqe).and_return([agent])
272 agent.is_done.expect_call().and_return(agent_finished)
273 return hqe, dispatcher
274
275
276 def test_abort_fail_with_unfinished_agent(self):
277 """abort should fail if the hqe still has agent not finished.
278 """
279 hqe, dispatcher = self.setup_abort_test(agent_finished=False)
Fang Deng51599032014-06-23 17:24:27 -0700280 self.assertIsNone(hqe.finished_on)
Dan Shi76af8022013-10-19 01:59:49 -0700281 with self.assertRaises(AssertionError):
282 hqe.abort(dispatcher)
283 self.god.check_playback()
Fang Deng51599032014-06-23 17:24:27 -0700284 # abort failed, finished_on should not be set
285 self.assertIsNone(hqe.finished_on)
Dan Shi76af8022013-10-19 01:59:49 -0700286
287
288 def test_abort_success(self):
289 """abort should succeed if all agents for the hqe are finished.
290 """
291 hqe, dispatcher = self.setup_abort_test(agent_finished=True)
Fang Deng51599032014-06-23 17:24:27 -0700292 self.assertIsNone(hqe.finished_on)
Dan Shi76af8022013-10-19 01:59:49 -0700293 hqe.abort(dispatcher)
294 self.god.check_playback()
Fang Deng51599032014-06-23 17:24:27 -0700295 self.assertIsNotNone(hqe.finished_on)
296
297
298 def test_set_finished_on(self):
299 """Test that finished_on is set when hqe completes."""
300 for status in host_queue_entry_states.Status.values:
301 hqe = self._create_hqe(hosts=[1])
Fang Dengd44a1232014-08-18 14:40:28 -0700302 hqe.started_on = datetime.datetime.now()
Jakob Juelich26ef4262014-09-17 15:24:15 -0700303 hqe.job.update_field('shard_id', 3)
Fang Deng51599032014-06-23 17:24:27 -0700304 self.assertIsNone(hqe.finished_on)
305 hqe.set_status(status)
306 if status in host_queue_entry_states.COMPLETE_STATUSES:
307 self.assertIsNotNone(hqe.finished_on)
Jakob Juelich26ef4262014-09-17 15:24:15 -0700308 self.assertIsNone(hqe.job.shard_id)
Fang Deng51599032014-06-23 17:24:27 -0700309 else:
310 self.assertIsNone(hqe.finished_on)
Jakob Juelich26ef4262014-09-17 15:24:15 -0700311 self.assertEquals(hqe.job.shard_id, 3)
Dan Shi76af8022013-10-19 01:59:49 -0700312
313
jamesrenc44ae992010-02-19 00:12:54 +0000314class JobTest(BaseSchedulerModelsTest):
315 def setUp(self):
316 super(JobTest, self).setUp()
317
318 def _mock_create(**kwargs):
319 task = models.SpecialTask(**kwargs)
320 task.save()
Alex Miller16e4d6c2013-06-27 14:04:13 -0700321 self._tasks.append(task)
jamesrenc44ae992010-02-19 00:12:54 +0000322 self.god.stub_with(models.SpecialTask.objects, 'create', _mock_create)
323
324
Dan Shi07e09af2013-04-12 09:31:29 -0700325 def _test_pre_job_tasks_helper(self,
326 reboot_before=model_attributes.RebootBefore.ALWAYS):
jamesrenc44ae992010-02-19 00:12:54 +0000327 """
328 Calls HQE._do_schedule_pre_job_tasks() and returns the created special
329 task
330 """
Alex Miller16e4d6c2013-06-27 14:04:13 -0700331 self._tasks = []
jamesrenc44ae992010-02-19 00:12:54 +0000332 queue_entry = scheduler_models.HostQueueEntry.fetch('id = 1')[0]
Dan Shi07e09af2013-04-12 09:31:29 -0700333 queue_entry.job.reboot_before = reboot_before
jamesrenc44ae992010-02-19 00:12:54 +0000334 queue_entry._do_schedule_pre_job_tasks()
Alex Miller16e4d6c2013-06-27 14:04:13 -0700335 return self._tasks
jamesrenc44ae992010-02-19 00:12:54 +0000336
337
338 def test_job_request_abort(self):
339 django_job = self._create_job(hosts=[5, 6], atomic_group=1)
340 job = scheduler_models.Job(django_job.id)
341 job.request_abort()
342 django_hqes = list(models.HostQueueEntry.objects.filter(job=job.id))
343 for hqe in django_hqes:
344 self.assertTrue(hqe.aborted)
345
346
347 def test__atomic_and_has_started__on_atomic(self):
348 self._create_job(hosts=[5, 6], atomic_group=1)
349 job = scheduler_models.Job.fetch('id = 1')[0]
350 self.assertFalse(job._atomic_and_has_started())
351
352 self._update_hqe("status='Pending'")
353 self.assertFalse(job._atomic_and_has_started())
354 self._update_hqe("status='Verifying'")
355 self.assertFalse(job._atomic_and_has_started())
356 self.assertFalse(job._atomic_and_has_started())
357 self._update_hqe("status='Failed'")
358 self.assertFalse(job._atomic_and_has_started())
359 self._update_hqe("status='Stopped'")
360 self.assertFalse(job._atomic_and_has_started())
361
362 self._update_hqe("status='Starting'")
363 self.assertTrue(job._atomic_and_has_started())
364 self._update_hqe("status='Completed'")
365 self.assertTrue(job._atomic_and_has_started())
366 self._update_hqe("status='Aborted'")
367
368
369 def test__atomic_and_has_started__not_atomic(self):
370 self._create_job(hosts=[1, 2])
371 job = scheduler_models.Job.fetch('id = 1')[0]
372 self.assertFalse(job._atomic_and_has_started())
373 self._update_hqe("status='Starting'")
374 self.assertFalse(job._atomic_and_has_started())
375
376
Alex Miller16e4d6c2013-06-27 14:04:13 -0700377 def _check_special_tasks(self, tasks, task_types):
378 self.assertEquals(len(tasks), len(task_types))
379 for task, (task_type, queue_entry_id) in zip(tasks, task_types):
380 self.assertEquals(task.task, task_type)
381 self.assertEquals(task.host.id, 1)
382 if queue_entry_id:
383 self.assertEquals(task.queue_entry.id, queue_entry_id)
jamesrenc44ae992010-02-19 00:12:54 +0000384
385
386 def test_run_asynchronous(self):
387 self._create_job(hosts=[1, 2])
388
Alex Miller16e4d6c2013-06-27 14:04:13 -0700389 tasks = self._test_pre_job_tasks_helper()
jamesrenc44ae992010-02-19 00:12:54 +0000390
Dan Shi07e09af2013-04-12 09:31:29 -0700391 self._check_special_tasks(tasks, [(models.SpecialTask.Task.RESET, 1)])
jamesrenc44ae992010-02-19 00:12:54 +0000392
393
394 def test_run_asynchronous_skip_verify(self):
395 job = self._create_job(hosts=[1, 2])
396 job.run_verify = False
397 job.save()
398
Alex Miller16e4d6c2013-06-27 14:04:13 -0700399 tasks = self._test_pre_job_tasks_helper()
jamesrenc44ae992010-02-19 00:12:54 +0000400
Dan Shi07e09af2013-04-12 09:31:29 -0700401 self._check_special_tasks(tasks, [(models.SpecialTask.Task.RESET, 1)])
jamesrenc44ae992010-02-19 00:12:54 +0000402
403
404 def test_run_synchronous_verify(self):
405 self._create_job(hosts=[1, 2], synchronous=True)
406
Alex Miller16e4d6c2013-06-27 14:04:13 -0700407 tasks = self._test_pre_job_tasks_helper()
jamesrenc44ae992010-02-19 00:12:54 +0000408
Dan Shi07e09af2013-04-12 09:31:29 -0700409 self._check_special_tasks(tasks, [(models.SpecialTask.Task.RESET, 1)])
jamesrenc44ae992010-02-19 00:12:54 +0000410
411
412 def test_run_synchronous_skip_verify(self):
413 job = self._create_job(hosts=[1, 2], synchronous=True)
414 job.run_verify = False
415 job.save()
416
Alex Miller16e4d6c2013-06-27 14:04:13 -0700417 tasks = self._test_pre_job_tasks_helper()
jamesrenc44ae992010-02-19 00:12:54 +0000418
Dan Shi07e09af2013-04-12 09:31:29 -0700419 self._check_special_tasks(tasks, [(models.SpecialTask.Task.RESET, 1)])
420
421
422 def test_run_asynchronous_do_not_reset(self):
423 job = self._create_job(hosts=[1, 2])
424 job.run_reset = False
425 job.run_verify = False
426 job.save()
427
428 tasks = self._test_pre_job_tasks_helper()
429
Alex Miller16e4d6c2013-06-27 14:04:13 -0700430 self.assertEquals(tasks, [])
jamesrenc44ae992010-02-19 00:12:54 +0000431
432
Dan Shi07e09af2013-04-12 09:31:29 -0700433 def test_run_synchronous_do_not_reset_no_RebootBefore(self):
434 job = self._create_job(hosts=[1, 2], synchronous=True)
435 job.reboot_before = model_attributes.RebootBefore.NEVER
436 job.save()
437
438 tasks = self._test_pre_job_tasks_helper(
439 reboot_before=model_attributes.RebootBefore.NEVER)
440
Alex Miller6ee996f2013-02-28 13:53:52 -0800441 self._check_special_tasks(tasks, [(models.SpecialTask.Task.VERIFY, 1)])
Dan Shi07e09af2013-04-12 09:31:29 -0700442
443
444 def test_run_asynchronous_do_not_reset(self):
445 job = self._create_job(hosts=[1, 2], synchronous=False)
446 job.reboot_before = model_attributes.RebootBefore.NEVER
447 job.save()
448
449 tasks = self._test_pre_job_tasks_helper(
450 reboot_before=model_attributes.RebootBefore.NEVER)
451
Alex Miller6ee996f2013-02-28 13:53:52 -0800452 self._check_special_tasks(tasks, [(models.SpecialTask.Task.VERIFY, 1)])
Dan Shi07e09af2013-04-12 09:31:29 -0700453
454
jamesrenc44ae992010-02-19 00:12:54 +0000455 def test_run_atomic_group_already_started(self):
456 self._create_job(hosts=[5, 6], atomic_group=1, synchronous=True)
457 self._update_hqe("status='Starting', execution_subdir=''")
458
459 job = scheduler_models.Job.fetch('id = 1')[0]
460 queue_entry = scheduler_models.HostQueueEntry.fetch('id = 1')[0]
461 assert queue_entry.job is job
462 self.assertEqual(None, job.run(queue_entry))
463
464 self.god.check_playback()
465
466
467 def test_reboot_before_always(self):
468 job = self._create_job(hosts=[1])
jamesrendd855242010-03-02 22:23:44 +0000469 job.reboot_before = model_attributes.RebootBefore.ALWAYS
jamesrenc44ae992010-02-19 00:12:54 +0000470 job.save()
471
Alex Miller16e4d6c2013-06-27 14:04:13 -0700472 tasks = self._test_pre_job_tasks_helper()
jamesrenc44ae992010-02-19 00:12:54 +0000473
Alex Miller16e4d6c2013-06-27 14:04:13 -0700474 self._check_special_tasks(tasks, [
Dan Shi07e09af2013-04-12 09:31:29 -0700475 (models.SpecialTask.Task.RESET, None)
Alex Miller16e4d6c2013-06-27 14:04:13 -0700476 ])
jamesrenc44ae992010-02-19 00:12:54 +0000477
478
Dan Shi07e09af2013-04-12 09:31:29 -0700479 def _test_reboot_before_if_dirty_helper(self):
jamesrenc44ae992010-02-19 00:12:54 +0000480 job = self._create_job(hosts=[1])
jamesrendd855242010-03-02 22:23:44 +0000481 job.reboot_before = model_attributes.RebootBefore.IF_DIRTY
jamesrenc44ae992010-02-19 00:12:54 +0000482 job.save()
483
Alex Miller16e4d6c2013-06-27 14:04:13 -0700484 tasks = self._test_pre_job_tasks_helper()
Dan Shi07e09af2013-04-12 09:31:29 -0700485 task_types = [(models.SpecialTask.Task.RESET, None)]
Alex Miller16e4d6c2013-06-27 14:04:13 -0700486
487 self._check_special_tasks(tasks, task_types)
jamesrenc44ae992010-02-19 00:12:54 +0000488
489
490 def test_reboot_before_if_dirty(self):
491 models.Host.smart_get(1).update_object(dirty=True)
Dan Shi07e09af2013-04-12 09:31:29 -0700492 self._test_reboot_before_if_dirty_helper()
jamesrenc44ae992010-02-19 00:12:54 +0000493
494
495 def test_reboot_before_not_dirty(self):
496 models.Host.smart_get(1).update_object(dirty=False)
Dan Shi07e09af2013-04-12 09:31:29 -0700497 self._test_reboot_before_if_dirty_helper()
jamesrenc44ae992010-02-19 00:12:54 +0000498
499
500 def test_next_group_name(self):
501 django_job = self._create_job(metahosts=[1])
502 job = scheduler_models.Job(id=django_job.id)
503 self.assertEqual('group0', job._next_group_name())
504
505 for hqe in django_job.hostqueueentry_set.filter():
506 hqe.execution_subdir = 'my_rack.group0'
507 hqe.save()
508 self.assertEqual('my_rack.group1', job._next_group_name('my/rack'))
509
510
511if __name__ == '__main__':
512 unittest.main()