5 from autotest_lib
.client
.common_lib
.test_utils
import mock
6 from autotest_lib
.frontend
import setup_django_environment
7 from autotest_lib
.frontend
import setup_test_environment
8 from autotest_lib
.scheduler
import metahost_scheduler
, scheduler_models
10 class LabelMetahostSchedulerTest(unittest
.TestCase
):
12 self
.god
= mock
.mock_god()
13 self
.scheduling_utility
= self
.god
.create_mock_class(
14 metahost_scheduler
.HostSchedulingUtility
, 'utility')
15 self
.metahost_scheduler
= metahost_scheduler
.LabelMetahostScheduler()
23 return self
.god
.create_mock_class(scheduler_models
.HostQueueEntry
,
27 def test_can_schedule_metahost(self
):
29 entry
.meta_host
= None
30 self
.assertFalse(self
.metahost_scheduler
.can_schedule_metahost(entry
))
33 self
.assert_(self
.metahost_scheduler
.can_schedule_metahost(entry
))
36 def test_schedule_metahost(self
):
41 self
.scheduling_utility
.hosts_in_label
.expect_call(1).and_return(
43 # 2 is in ineligible_hosts
44 (self
.scheduling_utility
.ineligible_hosts_for_entry
.expect_call(entry
)
46 self
.scheduling_utility
.is_host_usable
.expect_call(2).and_return(True)
48 self
.scheduling_utility
.is_host_usable
.expect_call(3).and_return(False)
49 self
.scheduling_utility
.remove_host_from_label
.expect_call(3, 1)
50 # 4 is ineligible for the job
51 self
.scheduling_utility
.is_host_usable
.expect_call(4).and_return(True)
52 (self
.scheduling_utility
.is_host_eligible_for_job
.expect_call(4, entry
)
55 self
.scheduling_utility
.is_host_usable
.expect_call(5).and_return(True)
56 (self
.scheduling_utility
.is_host_eligible_for_job
.expect_call(5, entry
)
58 self
.scheduling_utility
.remove_host_from_label
.expect_call(5, 1)
59 self
.scheduling_utility
.pop_host
.expect_call(5).and_return(host
)
60 entry
.set_host
.expect_call(host
)
62 self
.metahost_scheduler
.schedule_metahost(entry
,
63 self
.scheduling_utility
)
64 self
.god
.check_playback()
67 def test_no_hosts(self
):
71 self
.scheduling_utility
.hosts_in_label
.expect_call(1).and_return(())
72 (self
.scheduling_utility
.ineligible_hosts_for_entry
.expect_call(entry
)
75 self
.metahost_scheduler
.schedule_metahost(entry
,
76 self
.scheduling_utility
)
77 self
.god
.check_playback()
80 if __name__
== '__main__':