weigh_hosts() needs to return a list of hosts for the instances, not just a list of hosts
This commit is contained in:
@@ -55,5 +55,17 @@ class BaseScheduler(abstract_scheduler.AbstractScheduler):
|
|||||||
scheduling objectives
|
scheduling objectives
|
||||||
"""
|
"""
|
||||||
# NOTE(sirp): The default logic is the same as the NoopCostFunction
|
# NOTE(sirp): The default logic is the same as the NoopCostFunction
|
||||||
return [dict(weight=1, hostname=hostname, capabilities=capabilities)
|
hosts = [dict(weight=1, hostname=hostname, capabilities=capabilities)
|
||||||
for hostname, capabilities in hosts]
|
for hostname, capabilities in hosts]
|
||||||
|
|
||||||
|
# NOTE(Vek): What we actually need to return is enough hosts
|
||||||
|
# for all the instances!
|
||||||
|
num_instances = request_spec.get('num_instances', 1)
|
||||||
|
instances = []
|
||||||
|
while num_instances > len(hosts):
|
||||||
|
instances.extend(hosts)
|
||||||
|
num_instances -= len(hosts)
|
||||||
|
if num_instances > 0:
|
||||||
|
instances.extend(hosts[:num_instances])
|
||||||
|
|
||||||
|
return instances
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ class FakeAbstractScheduler(abstract_scheduler.AbstractScheduler):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class FakeBaseScheduler(base_scheduler.BaseScheduler):
|
||||||
|
# No need to stub anything at the moment
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class FakeZoneManager(zone_manager.ZoneManager):
|
class FakeZoneManager(zone_manager.ZoneManager):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.service_states = {
|
self.service_states = {
|
||||||
@@ -365,3 +370,30 @@ class AbstractSchedulerTestCase(test.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(fixture._decrypt_blob(test_data),
|
self.assertEqual(fixture._decrypt_blob(test_data),
|
||||||
json.dumps(test_data))
|
json.dumps(test_data))
|
||||||
|
|
||||||
|
|
||||||
|
class BaseSchedulerTestCase(test.TestCase):
|
||||||
|
"""Test case for Base Scheduler."""
|
||||||
|
|
||||||
|
def test_weigh_hosts(self):
|
||||||
|
"""
|
||||||
|
Try to weigh a short list of hosts and make sure enough
|
||||||
|
entries for a larger number instances are returned.
|
||||||
|
"""
|
||||||
|
|
||||||
|
sched = FakeBaseScheduler()
|
||||||
|
|
||||||
|
# Fake out a list of hosts
|
||||||
|
zm = FakeZoneManager()
|
||||||
|
hostlist = [(host, services['compute'])
|
||||||
|
for host, services in zm.service_states
|
||||||
|
if 'compute' in services]
|
||||||
|
|
||||||
|
# Call weigh_hosts()
|
||||||
|
num_instances = len(hostlist) * 2 + len(hostlist) / 2
|
||||||
|
instlist = sched.weigh_hosts('compute',
|
||||||
|
dict(num_instances=num_instances),
|
||||||
|
hostlist)
|
||||||
|
|
||||||
|
# Should be enough entries to cover all instances
|
||||||
|
self.assertEqual(len(instlist), num_instances)
|
||||||
|
|||||||
Reference in New Issue
Block a user