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:
@@ -28,6 +28,7 @@ from oslo.config import cfg
|
||||
from nova.compute import rpcapi as compute_rpcapi
|
||||
from nova import exception
|
||||
from nova.scheduler import driver
|
||||
from nova.scheduler import host_manager
|
||||
|
||||
CONF = cfg.CONF
|
||||
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):
|
||||
"""Selects random destinations."""
|
||||
num_instances = request_spec['num_instances']
|
||||
# NOTE(alaski): Returns a list of tuples for compatibility with
|
||||
# filter_scheduler
|
||||
dests = [(self._schedule(context, CONF.compute_topic, request_spec,
|
||||
filter_properties), None) for i in range(num_instances)]
|
||||
# NOTE(alaski): Returns a list of HostState objects for compatibility
|
||||
# with filter_scheduler
|
||||
dests = []
|
||||
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:
|
||||
raise exception.NoValidHost(reason='')
|
||||
return dests
|
||||
|
||||
@@ -172,9 +172,8 @@ class FilterScheduler(driver.Scheduler):
|
||||
if len(selected_hosts) < num_instances:
|
||||
raise exception.NoValidHost(reason='')
|
||||
|
||||
dests = []
|
||||
for host in selected_hosts:
|
||||
dests.append((host.obj.host, host.obj.nodename))
|
||||
# Returns HostState objects.
|
||||
dests = [host.obj for host in selected_hosts]
|
||||
return dests
|
||||
|
||||
def _provision_resource(self, context, weighed_host, request_spec,
|
||||
|
||||
@@ -220,10 +220,10 @@ class ChanceSchedulerTestCase(test_scheduler.SchedulerTestCase):
|
||||
self.mox.ReplayAll()
|
||||
dests = self.driver.select_destinations(ctxt, request_spec, {})
|
||||
self.assertEquals(2, len(dests))
|
||||
(host, node) = dests[0]
|
||||
(host, node) = (dests[0].host, dests[0].nodename)
|
||||
self.assertEquals('host3', host)
|
||||
self.assertEquals(None, node)
|
||||
(host, node) = dests[1]
|
||||
(host, node) = (dests[1].host, dests[1].nodename)
|
||||
self.assertEquals('host2', host)
|
||||
self.assertEquals(None, node)
|
||||
|
||||
|
||||
@@ -651,7 +651,7 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
|
||||
'num_instances': 1}
|
||||
self.mox.ReplayAll()
|
||||
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(node, selected_nodes[0])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user