Enable skipped tests from test_capacity_weigher.py

Some tests from  test_capacity_weigher.py were skipped:

- test_capacity_weight_multiplier1
- test_capacity_weight_multiplier2
- test_default_of_spreading_first

because of assertion error when comparing weight of the winner host
with expected value.

Fix this assertions taking into account that weihts of the hosts
are normalised during weighing, so the weight of the winner host
will be 1.0 * weight_multiplier in case of positive weight_multiplier
and 0 in other case.

Make CapacityWeigher able to redefine weight_multiplier from
BaseWeigher.

Closes-Bug: #1329718

Change-Id: I504ae7d980aa063ffddb7f2676e91da4f790e0e4
This commit is contained in:
Julia Varlamova 2014-06-24 17:18:00 +04:00
parent 122c73af06
commit 7d1c88a3cf
2 changed files with 4 additions and 7 deletions

View File

@ -39,7 +39,7 @@ CONF.register_opts(capacity_weight_opts)
class CapacityWeigher(weights.BaseHostWeigher):
def _weight_multiplier(self):
def weight_multiplier(self):
"""Override the weight multiplier."""
return CONF.capacity_weight_multiplier

View File

@ -52,7 +52,6 @@ class CapacityWeigherTestCase(test.TestCase):
ctxt, CONF.share_topic)
return host_states
@testtools.skip("LP bug #1329718")
def test_default_of_spreading_first(self):
hostinfo_list = self._get_all_hosts()
@ -63,10 +62,9 @@ class CapacityWeigherTestCase(test.TestCase):
# so, host1 should win:
weighed_host = self._get_weighed_host(hostinfo_list)
self.assertEqual(weighed_host.weight, 921.0)
self.assertEqual(weighed_host.weight, 1.0)
self.assertEqual(weighed_host.obj.host, 'host1')
@testtools.skip("LP bug #1329718")
def test_capacity_weight_multiplier1(self):
self.flags(capacity_weight_multiplier=-1.0)
hostinfo_list = self._get_all_hosts()
@ -78,10 +76,9 @@ class CapacityWeigherTestCase(test.TestCase):
# so, host4 should win:
weighed_host = self._get_weighed_host(hostinfo_list)
self.assertEqual(weighed_host.weight, -190.0)
self.assertEqual(weighed_host.weight, 0.0)
self.assertEqual(weighed_host.obj.host, 'host4')
@testtools.skip("LP bug #1329718")
def test_capacity_weight_multiplier2(self):
self.flags(capacity_weight_multiplier=2.0)
hostinfo_list = self._get_all_hosts()
@ -93,5 +90,5 @@ class CapacityWeigherTestCase(test.TestCase):
# so, host1 should win:
weighed_host = self._get_weighed_host(hostinfo_list)
self.assertEqual(weighed_host.weight, 921.0 * 2)
self.assertEqual(weighed_host.weight, 2.0)
self.assertEqual(weighed_host.obj.host, 'host1')