Skip only one host weight calculation
If there is only one host available, calculate the weight make no sense because whatever the weight it is, nova will use the host. Closes-Bug: 1448015 Change-Id: I38aed6a6e45d24dc0daf2e96c353f394f3ef5e3f
This commit is contained in:
@@ -16,7 +16,11 @@
|
||||
Tests For weights.
|
||||
"""
|
||||
|
||||
import mock
|
||||
|
||||
from nova.scheduler import weights as scheduler_weights
|
||||
from nova import test
|
||||
from nova.tests.unit.scheduler import fakes
|
||||
from nova import weights
|
||||
|
||||
|
||||
@@ -51,3 +55,19 @@ class TestWeigher(test.NoDBTestCase):
|
||||
for seq, result, minval, maxval in map_:
|
||||
ret = weights.normalize(seq, minval=minval, maxval=maxval)
|
||||
self.assertEqual(tuple(ret), result)
|
||||
|
||||
@mock.patch('nova.weights.BaseWeigher.weigh_objects')
|
||||
def test_only_one_host(self, mock_weigh):
|
||||
host_values = [
|
||||
('host1', 'node1', {'free_ram_mb': 512}),
|
||||
]
|
||||
hostinfo = [fakes.FakeHostState(host, node, values)
|
||||
for host, node, values in host_values]
|
||||
|
||||
weight_handler = scheduler_weights.HostWeightHandler()
|
||||
weighers = [scheduler_weights.ram.RAMWeigher()]
|
||||
weighed_host = weight_handler.get_weighed_objects(weighers,
|
||||
hostinfo, {})
|
||||
self.assertEqual(1, len(weighed_host))
|
||||
self.assertEqual('host1', weighed_host[0].obj.host)
|
||||
self.assertFalse(mock_weigh.called)
|
||||
|
||||
@@ -123,11 +123,11 @@ class BaseWeightHandler(loadables.BaseLoader):
|
||||
|
||||
def get_weighed_objects(self, weighers, obj_list, weighing_properties):
|
||||
"""Return a sorted (descending), normalized list of WeighedObjects."""
|
||||
|
||||
if not obj_list:
|
||||
return []
|
||||
|
||||
weighed_objs = [self.object_class(obj, 0.0) for obj in obj_list]
|
||||
|
||||
if len(weighed_objs) <= 1:
|
||||
return weighed_objs
|
||||
|
||||
for weigher in weighers:
|
||||
weights = weigher.weigh_objects(weighed_objs, weighing_properties)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user