'Tests the call that returns a sorted list of hosts by calling the
host manager\'s filtering and weighing routines'

@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):

    self.flags(host_subset_size=2, group='filter_scheduler')
    hs1 = mock.Mock(spec=host_manager.HostState, host='host1')
    hs2 = mock.Mock(spec=host_manager.HostState, host='host2')
    all_host_states = [hs1, hs2]
    mock_weighed.return_value = [weights.WeighedHost(hs1, 1.0), weights.WeighedHost(hs2, 1.0)]
    results = self.driver._get_sorted_hosts(mock.sentinel.spec, all_host_states, mock.sentinel.index)
    mock_filt.assert_called_once_with(all_host_states, mock.sentinel.spec, mock.sentinel.index)
    mock_weighed.assert_called_once_with(mock_filt.return_value, mock.sentinel.spec)
    self.assertEqual([hs2, hs1], results)
