| Index: scheduler/monitor_db_cleanup_test.py
|
| diff --git a/scheduler/monitor_db_cleanup_test.py b/scheduler/monitor_db_cleanup_test.py
|
| index 07573134e7c17b81ce8fa0ea36c8e9e3bd675181..6bf35c46738d16dd2a5ca57e8277700390969bd0 100755
|
| --- a/scheduler/monitor_db_cleanup_test.py
|
| +++ b/scheduler/monitor_db_cleanup_test.py
|
| @@ -5,7 +5,7 @@ import logging, unittest
|
| from autotest_lib.frontend import setup_django_environment
|
| from autotest_lib.database import database_connection
|
| from autotest_lib.frontend.afe import frontend_test_utils, models
|
| -from autotest_lib.scheduler import monitor_db_cleanup
|
| +from autotest_lib.scheduler import monitor_db_cleanup, scheduler_config
|
| from autotest_lib.client.common_lib import host_protections
|
|
|
| class UserCleanupTest(unittest.TestCase, frontend_test_utils.FrontendTestMixin):
|
| @@ -23,6 +23,9 @@ class UserCleanupTest(unittest.TestCase, frontend_test_utils.FrontendTestMixin):
|
|
|
|
|
| def test_reverify_dead_hosts(self):
|
| + # unlimited reverifies
|
| + self.god.stub_with(scheduler_config.config,
|
| + 'reverify_max_hosts_at_once', 0)
|
| for i in (0, 1, 2):
|
| self.hosts[i].status = models.Host.Status.REPAIR_FAILED
|
| self.hosts[i].save()
|
| @@ -43,5 +46,34 @@ class UserCleanupTest(unittest.TestCase, frontend_test_utils.FrontendTestMixin):
|
| self.assertEquals(tasks[0].task, models.SpecialTask.Task.VERIFY)
|
|
|
|
|
| + def test_reverify_dead_hosts_limits(self):
|
| + # limit the number of reverifies
|
| + self.assertTrue(hasattr(scheduler_config.config,
|
| + 'reverify_max_hosts_at_once'))
|
| + self.god.stub_with(scheduler_config.config,
|
| + 'reverify_max_hosts_at_once', 2)
|
| + for i in (0, 1, 2, 3, 4, 5):
|
| + self.hosts[i].status = models.Host.Status.REPAIR_FAILED
|
| + self.hosts[i].save()
|
| +
|
| + self.hosts[1].locked = True
|
| + self.hosts[1].save()
|
| +
|
| + self.hosts[2].protection = host_protections.Protection.DO_NOT_VERIFY
|
| + self.hosts[2].save()
|
| +
|
| + self.god.stub_with(self.cleanup, '_should_reverify_hosts_now',
|
| + lambda : True)
|
| + self.cleanup._reverify_dead_hosts()
|
| +
|
| + tasks = models.SpecialTask.objects.all()
|
| + # four hosts need reverifying but our max limit was set to 2
|
| + self.assertEquals(len(tasks), 2)
|
| + self.assertTrue(tasks[0].host.id in (1, 4, 5, 6))
|
| + self.assertTrue(tasks[1].host.id in (1, 4, 5, 6))
|
| + self.assertEquals(tasks[0].task, models.SpecialTask.Task.VERIFY)
|
| + self.assertEquals(tasks[1].task, models.SpecialTask.Task.VERIFY)
|
| +
|
| +
|
| if __name__ == '__main__':
|
| unittest.main()
|
|
|