Merge "Fix WeighedHost logging regression" into stable/queens
This commit is contained in:
commit
a2a08b86b1
|
@ -418,11 +418,12 @@ class FilterScheduler(driver.Scheduler):
|
|||
if w.weight == weighed_hosts[0].weight]
|
||||
random.shuffle(best_hosts)
|
||||
weighed_hosts = best_hosts + weighed_hosts[len(best_hosts):]
|
||||
# Log the weighed hosts before stripping off the wrapper class so that
|
||||
# the weight value gets logged.
|
||||
LOG.debug("Weighed %(hosts)s", {'hosts': weighed_hosts})
|
||||
# Strip off the WeighedHost wrapper class...
|
||||
weighed_hosts = [h.obj for h in weighed_hosts]
|
||||
|
||||
LOG.debug("Weighed %(hosts)s", {'hosts': weighed_hosts})
|
||||
|
||||
# We randomize the first element in the returned list to alleviate
|
||||
# congestion where the same host is consistently selected among
|
||||
# numerous potential hosts for similar request specs.
|
||||
|
|
|
@ -539,10 +539,11 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
|
|||
self.assertEqual(['host2', 'host1'], ig.hosts)
|
||||
self.assertEqual({}, ig.obj_get_changes())
|
||||
|
||||
@mock.patch('nova.scheduler.filter_scheduler.LOG.debug')
|
||||
@mock.patch('random.choice', side_effect=lambda x: x[1])
|
||||
@mock.patch('nova.scheduler.host_manager.HostManager.get_weighed_hosts')
|
||||
@mock.patch('nova.scheduler.host_manager.HostManager.get_filtered_hosts')
|
||||
def test_get_sorted_hosts(self, mock_filt, mock_weighed, mock_rand):
|
||||
def test_get_sorted_hosts(self, mock_filt, mock_weighed, mock_rand, debug):
|
||||
"""Tests the call that returns a sorted list of hosts by calling the
|
||||
host manager's filtering and weighing routines
|
||||
"""
|
||||
|
@ -557,8 +558,18 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
|
|||
weights.WeighedHost(hs1, 1.0), weights.WeighedHost(hs2, 1.0),
|
||||
]
|
||||
|
||||
# Make sure that when logging the weighed hosts we are logging them
|
||||
# with the WeighedHost wrapper class rather than the HostState objects.
|
||||
def fake_debug(message, *args, **kwargs):
|
||||
if message.startswith('Weighed'):
|
||||
self.assertEqual(1, len(args))
|
||||
for weighed_host in args[0]['hosts']:
|
||||
self.assertIsInstance(weighed_host, weights.WeighedHost)
|
||||
debug.side_effect = fake_debug
|
||||
|
||||
results = self.driver._get_sorted_hosts(mock.sentinel.spec,
|
||||
all_host_states, mock.sentinel.index)
|
||||
debug.assert_called()
|
||||
|
||||
mock_filt.assert_called_once_with(all_host_states, mock.sentinel.spec,
|
||||
mock.sentinel.index)
|
||||
|
|
Loading…
Reference in New Issue