Refactors select_destinations to return HostState objects

This is needed because we will need to pass 'limits'
(resource oversubscription values for the compute host)
attribute along with filter_properties to the compute manager.

Partially implements bp cold-migrations-to-conductor

Change-Id: Ide3a9781f66f961ff4aceadc00275de91c6c1030
This commit is contained in:
Tiago Mello
2013-07-02 15:53:49 -03:00
parent 0839fbbef4
commit db4f118988
4 changed files with 15 additions and 10 deletions

View File

@@ -28,6 +28,7 @@ from oslo.config import cfg
from nova.compute import rpcapi as compute_rpcapi from nova.compute import rpcapi as compute_rpcapi
from nova import exception from nova import exception
from nova.scheduler import driver from nova.scheduler import driver
from nova.scheduler import host_manager
CONF = cfg.CONF CONF = cfg.CONF
CONF.import_opt('compute_topic', 'nova.compute.rpcapi') CONF.import_opt('compute_topic', 'nova.compute.rpcapi')
@@ -75,10 +76,15 @@ class ChanceScheduler(driver.Scheduler):
def select_destinations(self, context, request_spec, filter_properties): def select_destinations(self, context, request_spec, filter_properties):
"""Selects random destinations.""" """Selects random destinations."""
num_instances = request_spec['num_instances'] num_instances = request_spec['num_instances']
# NOTE(alaski): Returns a list of tuples for compatibility with # NOTE(alaski): Returns a list of HostState objects for compatibility
# filter_scheduler # with filter_scheduler
dests = [(self._schedule(context, CONF.compute_topic, request_spec, dests = []
filter_properties), None) for i in range(num_instances)] for i in range(num_instances):
host = self._schedule(context, CONF.compute_topic,
request_spec, filter_properties)
host_state = host_manager.HostState(host, None)
dests.append(host_state)
if len(dests) < num_instances: if len(dests) < num_instances:
raise exception.NoValidHost(reason='') raise exception.NoValidHost(reason='')
return dests return dests

View File

@@ -172,9 +172,8 @@ class FilterScheduler(driver.Scheduler):
if len(selected_hosts) < num_instances: if len(selected_hosts) < num_instances:
raise exception.NoValidHost(reason='') raise exception.NoValidHost(reason='')
dests = [] # Returns HostState objects.
for host in selected_hosts: dests = [host.obj for host in selected_hosts]
dests.append((host.obj.host, host.obj.nodename))
return dests return dests
def _provision_resource(self, context, weighed_host, request_spec, def _provision_resource(self, context, weighed_host, request_spec,

View File

@@ -220,10 +220,10 @@ class ChanceSchedulerTestCase(test_scheduler.SchedulerTestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
dests = self.driver.select_destinations(ctxt, request_spec, {}) dests = self.driver.select_destinations(ctxt, request_spec, {})
self.assertEquals(2, len(dests)) self.assertEquals(2, len(dests))
(host, node) = dests[0] (host, node) = (dests[0].host, dests[0].nodename)
self.assertEquals('host3', host) self.assertEquals('host3', host)
self.assertEquals(None, node) self.assertEquals(None, node)
(host, node) = dests[1] (host, node) = (dests[1].host, dests[1].nodename)
self.assertEquals('host2', host) self.assertEquals('host2', host)
self.assertEquals(None, node) self.assertEquals(None, node)

View File

@@ -651,7 +651,7 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
'num_instances': 1} 'num_instances': 1}
self.mox.ReplayAll() self.mox.ReplayAll()
dests = sched.select_destinations(fake_context, request_spec, {}) dests = sched.select_destinations(fake_context, request_spec, {})
(host, node) = dests[0] (host, node) = (dests[0].host, dests[0].nodename)
self.assertEquals(host, selected_hosts[0]) self.assertEquals(host, selected_hosts[0])
self.assertEquals(node, selected_nodes[0]) self.assertEquals(node, selected_nodes[0])