Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: scheduler/monitor_db_cleanup_test.py

Issue 4823005: Merge remote branch 'cros/upstream' into tempbranch (Closed) Base URL: http://git.chromium.org/git/autotest.git@master
Patch Set: patch Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « scheduler/monitor_db_cleanup.py ('k') | scheduler/scheduler_config.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 import common 3 import common
4 import logging, unittest 4 import logging, unittest
5 from autotest_lib.frontend import setup_django_environment 5 from autotest_lib.frontend import setup_django_environment
6 from autotest_lib.database import database_connection 6 from autotest_lib.database import database_connection
7 from autotest_lib.frontend.afe import frontend_test_utils, models 7 from autotest_lib.frontend.afe import frontend_test_utils, models
8 from autotest_lib.scheduler import monitor_db_cleanup 8 from autotest_lib.scheduler import monitor_db_cleanup, scheduler_config
9 from autotest_lib.client.common_lib import host_protections 9 from autotest_lib.client.common_lib import host_protections
10 10
11 class UserCleanupTest(unittest.TestCase, frontend_test_utils.FrontendTestMixin): 11 class UserCleanupTest(unittest.TestCase, frontend_test_utils.FrontendTestMixin):
12 def setUp(self): 12 def setUp(self):
13 logging.basicConfig(level=logging.DEBUG) 13 logging.basicConfig(level=logging.DEBUG)
14 self._frontend_common_setup() 14 self._frontend_common_setup()
15 self._database = ( 15 self._database = (
16 database_connection.DatabaseConnection.get_test_database()) 16 database_connection.DatabaseConnection.get_test_database())
17 self._database.connect(db_type='django') 17 self._database.connect(db_type='django')
18 self.cleanup = monitor_db_cleanup.UserCleanup(self._database, 1) 18 self.cleanup = monitor_db_cleanup.UserCleanup(self._database, 1)
19 19
20 20
21 def tearDown(self): 21 def tearDown(self):
22 self._frontend_common_teardown() 22 self._frontend_common_teardown()
23 23
24 24
25 def test_reverify_dead_hosts(self): 25 def test_reverify_dead_hosts(self):
26 # unlimited reverifies
27 self.god.stub_with(scheduler_config.config,
28 'reverify_max_hosts_at_once', 0)
26 for i in (0, 1, 2): 29 for i in (0, 1, 2):
27 self.hosts[i].status = models.Host.Status.REPAIR_FAILED 30 self.hosts[i].status = models.Host.Status.REPAIR_FAILED
28 self.hosts[i].save() 31 self.hosts[i].save()
29 32
30 self.hosts[1].locked = True 33 self.hosts[1].locked = True
31 self.hosts[1].save() 34 self.hosts[1].save()
32 35
33 self.hosts[2].protection = host_protections.Protection.DO_NOT_VERIFY 36 self.hosts[2].protection = host_protections.Protection.DO_NOT_VERIFY
34 self.hosts[2].save() 37 self.hosts[2].save()
35 38
36 self.god.stub_with(self.cleanup, '_should_reverify_hosts_now', 39 self.god.stub_with(self.cleanup, '_should_reverify_hosts_now',
37 lambda : True) 40 lambda : True)
38 self.cleanup._reverify_dead_hosts() 41 self.cleanup._reverify_dead_hosts()
39 42
40 tasks = models.SpecialTask.objects.all() 43 tasks = models.SpecialTask.objects.all()
41 self.assertEquals(len(tasks), 1) 44 self.assertEquals(len(tasks), 1)
42 self.assertEquals(tasks[0].host.id, 1) 45 self.assertEquals(tasks[0].host.id, 1)
43 self.assertEquals(tasks[0].task, models.SpecialTask.Task.VERIFY) 46 self.assertEquals(tasks[0].task, models.SpecialTask.Task.VERIFY)
44 47
45 48
49 def test_reverify_dead_hosts_limits(self):
50 # limit the number of reverifies
51 self.assertTrue(hasattr(scheduler_config.config,
52 'reverify_max_hosts_at_once'))
53 self.god.stub_with(scheduler_config.config,
54 'reverify_max_hosts_at_once', 2)
55 for i in (0, 1, 2, 3, 4, 5):
56 self.hosts[i].status = models.Host.Status.REPAIR_FAILED
57 self.hosts[i].save()
58
59 self.hosts[1].locked = True
60 self.hosts[1].save()
61
62 self.hosts[2].protection = host_protections.Protection.DO_NOT_VERIFY
63 self.hosts[2].save()
64
65 self.god.stub_with(self.cleanup, '_should_reverify_hosts_now',
66 lambda : True)
67 self.cleanup._reverify_dead_hosts()
68
69 tasks = models.SpecialTask.objects.all()
70 # four hosts need reverifying but our max limit was set to 2
71 self.assertEquals(len(tasks), 2)
72 self.assertTrue(tasks[0].host.id in (1, 4, 5, 6))
73 self.assertTrue(tasks[1].host.id in (1, 4, 5, 6))
74 self.assertEquals(tasks[0].task, models.SpecialTask.Task.VERIFY)
75 self.assertEquals(tasks[1].task, models.SpecialTask.Task.VERIFY)
76
77
46 if __name__ == '__main__': 78 if __name__ == '__main__':
47 unittest.main() 79 unittest.main()
OLDNEW
« no previous file with comments | « scheduler/monitor_db_cleanup.py ('k') | scheduler/scheduler_config.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698