diff options
author | Russell Bryant <rbryant@redhat.com> | 2013-04-10 01:39:16 +0200 |
---|---|---|
committer | Russell Bryant <rbryant@redhat.com> | 2013-04-10 09:07:32 -0400 |
commit | 2afb205d515a906a0df28f2376e9b3042a43daf1 (patch) | |
tree | e324753ded65c1194bafa56bf2f97655c942bc86 /nova/tests/scheduler | |
parent | a993b2b969bad0785aad02dc2a6f04ac0c675f8d (diff) | |
download | nova-2afb205d515a906a0df28f2376e9b3042a43daf1.tar.gz nova-2afb205d515a906a0df28f2376e9b3042a43daf1.tar.xz nova-2afb205d515a906a0df28f2376e9b3042a43daf1.zip |
Simplify random host choice.
The random Python module provides a handy funcion for choosing a random
element from a sequence. Use that instead of a more manual method of
accomplishing the same thing.
Change-Id: I1908bd5e79b6c21d0dcf7e540143e9b8de478d24
Diffstat (limited to 'nova/tests/scheduler')
-rw-r--r-- | nova/tests/scheduler/test_chance_scheduler.py | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/nova/tests/scheduler/test_chance_scheduler.py b/nova/tests/scheduler/test_chance_scheduler.py index d2de055b5..a589000cd 100644 --- a/nova/tests/scheduler/test_chance_scheduler.py +++ b/nova/tests/scheduler/test_chance_scheduler.py @@ -82,15 +82,15 @@ class ChanceSchedulerTestCase(test_scheduler.SchedulerTestCase): self.mox.StubOutWithMock(ctxt, 'elevated') self.mox.StubOutWithMock(self.driver, 'hosts_up') - self.mox.StubOutWithMock(random, 'random') + self.mox.StubOutWithMock(random, 'choice') self.mox.StubOutWithMock(driver, 'instance_update_db') self.mox.StubOutWithMock(compute_rpcapi.ComputeAPI, 'run_instance') ctxt.elevated().AndReturn(ctxt_elevated) # instance 1 - self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn( - ['host1', 'host2', 'host3', 'host4']) - random.random().AndReturn(.5) + hosts_full = ['host1', 'host2', 'host3', 'host4'] + self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn(hosts_full) + random.choice(hosts_full).AndReturn('host3') driver.instance_update_db(ctxt, instance1['uuid']).WithSideEffects( inc_launch_index).AndReturn(instance1) compute_rpcapi.ComputeAPI.run_instance(ctxt, host='host3', @@ -100,9 +100,8 @@ class ChanceSchedulerTestCase(test_scheduler.SchedulerTestCase): # instance 2 ctxt.elevated().AndReturn(ctxt_elevated) - self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn( - ['host1', 'host2', 'host3', 'host4']) - random.random().AndReturn(.2) + self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn(hosts_full) + random.choice(hosts_full).AndReturn('host1') driver.instance_update_db(ctxt, instance2['uuid']).WithSideEffects( inc_launch_index).AndReturn(instance2) compute_rpcapi.ComputeAPI.run_instance(ctxt, host='host1', @@ -178,19 +177,19 @@ class ChanceSchedulerTestCase(test_scheduler.SchedulerTestCase): self.mox.StubOutWithMock(ctxt, 'elevated') self.mox.StubOutWithMock(self.driver, 'hosts_up') - self.mox.StubOutWithMock(random, 'random') + self.mox.StubOutWithMock(random, 'choice') ctxt.elevated().AndReturn(ctxt_elevated) + # instance 1 - self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn( - ['host1', 'host2', 'host3', 'host4']) - random.random().AndReturn(.5) + hosts_full = ['host1', 'host2', 'host3', 'host4'] + self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn(hosts_full) + random.choice(hosts_full).AndReturn('host3') # instance 2 ctxt.elevated().AndReturn(ctxt_elevated) - self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn( - ['host1', 'host2', 'host3', 'host4']) - random.random().AndReturn(.2) + self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn(hosts_full) + random.choice(hosts_full).AndReturn('host1') self.mox.ReplayAll() hosts = self.driver.select_hosts(ctxt, request_spec, {}) |