Fix WeightedHost
WeightedHosts don't have zone attributes. Let me know if I'm missing something and should be adding a hasattr check instead of removing the zone reference. Change-Id: If76f23fa46c965fc9004e35dd10da33e2bbb48dc
This commit is contained in:
@@ -63,8 +63,6 @@ class WeightedHost(object):
|
||||
x = dict(weight=self.weight)
|
||||
if self.host_state:
|
||||
x['host'] = self.host_state.host
|
||||
if self.zone:
|
||||
x['zone'] = self.zone
|
||||
return x
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
Tests For Least Cost functions.
|
||||
"""
|
||||
from nova import context
|
||||
from nova.scheduler import host_manager
|
||||
from nova.scheduler import least_cost
|
||||
from nova import test
|
||||
from nova.tests.scheduler import fakes
|
||||
@@ -89,3 +90,24 @@ class LeastCostTestCase(test.TestCase):
|
||||
options)
|
||||
self.assertEqual(weighted_host.weight, 10512)
|
||||
self.assertEqual(weighted_host.host_state.host, 'host1')
|
||||
|
||||
|
||||
class TestWeightedHost(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_dict_conversion_without_host_state(self):
|
||||
host = least_cost.WeightedHost('someweight')
|
||||
expected = {'weight': 'someweight'}
|
||||
self.assertDictMatch(host.to_dict(), expected)
|
||||
|
||||
def test_dict_conversion_with_host_state(self):
|
||||
host_state = host_manager.HostState('somehost', 'sometopic')
|
||||
host = least_cost.WeightedHost('someweight', host_state)
|
||||
expected = {'weight': 'someweight',
|
||||
'host': 'somehost'}
|
||||
self.assertDictMatch(host.to_dict(), expected)
|
||||
|
||||
Reference in New Issue
Block a user