diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-07-01 17:30:40 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-07-01 17:30:40 +0000 |
commit | dcece3c8e41f757a33251c5969f47fa36455c57e (patch) | |
tree | 02f08397c3235e931a1d7b11840361b4c0f1a289 /nova/tests | |
parent | 3e232c84991edf15b2bcdb42885dcaff27b72206 (diff) | |
parent | 4f3c5411d92d488b78f06212912fc7ae6d225b79 (diff) | |
download | nova-dcece3c8e41f757a33251c5969f47fa36455c57e.tar.gz nova-dcece3c8e41f757a33251c5969f47fa36455c57e.tar.xz nova-dcece3c8e41f757a33251c5969f47fa36455c57e.zip |
Merge "New select_destinations scheduler call"
Diffstat (limited to 'nova/tests')
-rw-r--r-- | nova/tests/conductor/test_conductor.py | 3 | ||||
-rw-r--r-- | nova/tests/scheduler/test_chance_scheduler.py | 45 | ||||
-rw-r--r-- | nova/tests/scheduler/test_filter_scheduler.py | 55 | ||||
-rw-r--r-- | nova/tests/scheduler/test_rpcapi.py | 6 | ||||
-rw-r--r-- | nova/tests/scheduler/test_scheduler.py | 4 |
5 files changed, 112 insertions, 1 deletions
diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py index 609c2164c..9d8725f66 100644 --- a/nova/tests/conductor/test_conductor.py +++ b/nova/tests/conductor/test_conductor.py @@ -1251,7 +1251,8 @@ class _BaseTaskTestCase(object): 'instance_type': expected_instance_type, 'instance_uuids': ['fakeuuid', 'fakeuuid2'], 'block_device_mapping': 'block_device_mapping', - 'security_group': 'security_groups'}, + 'security_group': 'security_groups', + 'num_instances': 2}, admin_password='admin_password', injected_files='injected_files', requested_networks='requested_networks', is_first_time=True, diff --git a/nova/tests/scheduler/test_chance_scheduler.py b/nova/tests/scheduler/test_chance_scheduler.py index ba1701e93..4e52464ec 100644 --- a/nova/tests/scheduler/test_chance_scheduler.py +++ b/nova/tests/scheduler/test_chance_scheduler.py @@ -197,3 +197,48 @@ class ChanceSchedulerTestCase(test_scheduler.SchedulerTestCase): self.stubs.Set(self.driver, '_schedule', _return_no_host) self.assertRaises(exception.NoValidHost, self.driver.select_hosts, self.context, {}, {}) + + def test_select_destinations(self): + ctxt = context.RequestContext('fake', 'fake', False) + ctxt_elevated = 'fake-context-elevated' + request_spec = {'num_instances': 2} + + self.mox.StubOutWithMock(ctxt, 'elevated') + self.mox.StubOutWithMock(self.driver, 'hosts_up') + self.mox.StubOutWithMock(random, 'choice') + + hosts_full = ['host1', 'host2', 'host3', 'host4'] + + ctxt.elevated().AndReturn(ctxt_elevated) + self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn(hosts_full) + random.choice(hosts_full).AndReturn('host3') + + ctxt.elevated().AndReturn(ctxt_elevated) + self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn(hosts_full) + random.choice(hosts_full).AndReturn('host2') + + self.mox.ReplayAll() + dests = self.driver.select_destinations(ctxt, request_spec, {}) + self.assertEquals(2, len(dests)) + (host, node) = dests[0] + self.assertEquals('host3', host) + self.assertEquals(None, node) + (host, node) = dests[1] + self.assertEquals('host2', host) + self.assertEquals(None, node) + + def test_select_destinations_no_valid_host(self): + + def _return_no_host(*args, **kwargs): + return [] + + self.mox.StubOutWithMock(self.driver, 'hosts_up') + self.driver.hosts_up(mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([1, 2]) + self.stubs.Set(self.driver, '_filter_hosts', _return_no_host) + self.mox.ReplayAll() + + request_spec = {'num_instances': 1} + self.assertRaises(exception.NoValidHost, + self.driver.select_destinations, self.context, + request_spec, {}) diff --git a/nova/tests/scheduler/test_filter_scheduler.py b/nova/tests/scheduler/test_filter_scheduler.py index ac2e73ec7..1aeab0408 100644 --- a/nova/tests/scheduler/test_filter_scheduler.py +++ b/nova/tests/scheduler/test_filter_scheduler.py @@ -609,3 +609,58 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): self.stubs.Set(self.driver, '_schedule', _return_no_host) self.assertRaises(exception.NoValidHost, self.driver.select_hosts, self.context, {}, {}) + + def test_select_destinations(self): + """select_destinations is basically a wrapper around _schedule(). + + Similar to the _schedule tests, this just does a happy path test to + ensure there is nothing glaringly wrong. + """ + + self.next_weight = 1.0 + + selected_hosts = [] + selected_nodes = [] + + def _fake_weigh_objects(_self, functions, hosts, options): + self.next_weight += 2.0 + host_state = hosts[0] + selected_hosts.append(host_state.host) + selected_nodes.append(host_state.nodename) + 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 = {'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'}, + 'num_instances': 1} + self.mox.ReplayAll() + dests = sched.select_destinations(fake_context, request_spec, {}) + (host, node) = dests[0] + self.assertEquals(host, selected_hosts[0]) + self.assertEquals(node, selected_nodes[0]) + + def test_select_destinations_no_valid_host(self): + + def _return_no_host(*args, **kwargs): + return [] + + self.stubs.Set(self.driver, '_schedule', _return_no_host) + self.assertRaises(exception.NoValidHost, + self.driver.select_destinations, self.context, + {'num_instances': 1}, {}) diff --git a/nova/tests/scheduler/test_rpcapi.py b/nova/tests/scheduler/test_rpcapi.py index cecc55f20..7d61ecf97 100644 --- a/nova/tests/scheduler/test_rpcapi.py +++ b/nova/tests/scheduler/test_rpcapi.py @@ -86,3 +86,9 @@ class SchedulerRpcAPITestCase(test.NoDBTestCase): request_spec='fake_request_spec', filter_properties='fake_prop', version='2.6') + + def test_select_destinations(self): + self._test_scheduler_api('select_destinations', rpc_method='call', + request_spec='fake_request_spec', + filter_properties='fake_prop', + version='2.7') diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py index 149c6d3c8..e2778a94b 100644 --- a/nova/tests/scheduler/test_scheduler.py +++ b/nova/tests/scheduler/test_scheduler.py @@ -527,6 +527,10 @@ class SchedulerDriverBaseTestCase(SchedulerTestCase): self.assertRaises(NotImplementedError, self.driver.select_hosts, self.context, {}, {}) + def test_unimplemented_select_destinations(self): + self.assertRaises(NotImplementedError, + self.driver.select_destinations, self.context, {}, {}) + class SchedulerDriverModuleTestCase(test.NoDBTestCase): """Test case for scheduler driver module methods.""" |