diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-02-19 07:13:50 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-02-19 07:13:50 +0000 |
| commit | b9e7da43f1dfe56b4fa7eff26ab4973b1381191b (patch) | |
| tree | 96a5cc2d2fb7a0ecf3a1aad02c7134b5e5a31a4c /nova/tests | |
| parent | 749d7a3a2f3595d629ac494fb71a3d060fff29c5 (diff) | |
| parent | 53a7538a84ea2612cd86e6e98887cab7723dcbb2 (diff) | |
Merge "Add select_hosts to scheduler manager rpc"
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/scheduler/test_chance_scheduler.py | 30 | ||||
| -rw-r--r-- | nova/tests/scheduler/test_filter_scheduler.py | 40 | ||||
| -rw-r--r-- | nova/tests/scheduler/test_rpcapi.py | 6 |
3 files changed, 76 insertions, 0 deletions
diff --git a/nova/tests/scheduler/test_chance_scheduler.py b/nova/tests/scheduler/test_chance_scheduler.py index dcbe86f75..0ee617044 100644 --- a/nova/tests/scheduler/test_chance_scheduler.py +++ b/nova/tests/scheduler/test_chance_scheduler.py @@ -165,3 +165,33 @@ class ChanceSchedulerTestCase(test_scheduler.SchedulerTestCase): self.driver.schedule_prep_resize(fake_context, {}, {}, {}, instance, {}, None) self.assertEqual(info['called'], 0) + + def test_select_hosts(self): + ctxt = context.RequestContext('fake', 'fake', False) + ctxt_elevated = 'fake-context-elevated' + fake_args = (1, 2, 3) + instance_opts = {'fake_opt1': 'meow', 'launch_index': -1} + instance1 = {'uuid': 'fake-uuid1'} + instance2 = {'uuid': 'fake-uuid2'} + request_spec = {'instance_uuids': ['fake-uuid1', 'fake-uuid2'], + 'instance_properties': instance_opts} + + self.mox.StubOutWithMock(ctxt, 'elevated') + self.mox.StubOutWithMock(self.driver, 'hosts_up') + self.mox.StubOutWithMock(random, 'random') + + ctxt.elevated().AndReturn(ctxt_elevated) + # instance 1 + self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn( + ['host1', 'host2', 'host3', 'host4']) + random.random().AndReturn(.5) + + # instance 2 + ctxt.elevated().AndReturn(ctxt_elevated) + self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn( + ['host1', 'host2', 'host3', 'host4']) + random.random().AndReturn(.2) + + self.mox.ReplayAll() + hosts = self.driver.select_hosts(ctxt, request_spec, {}) + self.assertEquals(['host3', 'host1'], hosts) diff --git a/nova/tests/scheduler/test_filter_scheduler.py b/nova/tests/scheduler/test_filter_scheduler.py index 4b07581fb..849f63f5d 100644 --- a/nova/tests/scheduler/test_filter_scheduler.py +++ b/nova/tests/scheduler/test_filter_scheduler.py @@ -656,3 +656,43 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): self.assertEquals(1, len(hosts)) self.assertEquals(50, hosts[0].weight) + + def test_select_hosts_happy_day(self): + """select_hosts is basically a wrapper around the _select() method. + Similar to the _select tests, this just does a happy path test to + ensure there is nothing glaringly wrong.""" + + self.next_weight = 1.0 + + selected_hosts = [] + + def _fake_weigh_objects(_self, functions, hosts, options): + self.next_weight += 2.0 + host_state = hosts[0] + selected_hosts.append(host_state.host) + return [weights.WeighedHost(host_state, self.next_weight)] + + sched = fakes.FakeFilterScheduler() + fake_context = context.RequestContext('user', 'project', + is_admin=True) + + self.stubs.Set(sched.host_manager, 'get_filtered_hosts', + fake_get_filtered_hosts) + self.stubs.Set(weights.HostWeightHandler, + 'get_weighed_objects', _fake_weigh_objects) + fakes.mox_host_manager_db_calls(self.mox, fake_context) + + request_spec = {'num_instances': 10, + 'instance_type': {'memory_mb': 512, 'root_gb': 512, + 'ephemeral_gb': 0, + 'vcpus': 1}, + 'instance_properties': {'project_id': 1, + 'root_gb': 512, + 'memory_mb': 512, + 'ephemeral_gb': 0, + 'vcpus': 1, + 'os_type': 'Linux'}} + self.mox.ReplayAll() + hosts = sched.select_hosts(fake_context, request_spec, {}) + self.assertEquals(len(hosts), 10) + self.assertEquals(hosts, selected_hosts) diff --git a/nova/tests/scheduler/test_rpcapi.py b/nova/tests/scheduler/test_rpcapi.py index e9a1680a8..af6a57ba6 100644 --- a/nova/tests/scheduler/test_rpcapi.py +++ b/nova/tests/scheduler/test_rpcapi.py @@ -90,3 +90,9 @@ class SchedulerRpcAPITestCase(test.TestCase): def test_get_backdoor_port(self): self._test_scheduler_api('get_backdoor_port', rpc_method='call', host='fake_host', version='2.5') + + def test_select_hosts(self): + self._test_scheduler_api('select_hosts', rpc_method='call', + request_spec='fake_request_spec', + filter_properties='fake_prop', + version='2.6') |
