'If there was a problem communicating with the Placement service,
alloc_reqs_by_rp_uuid will be None and we need to avoid trying to claim
in the Placement API.'

@mock.patch('nova.scheduler.filter_scheduler.FilterScheduler._claim_resources')
@mock.patch('nova.scheduler.filter_scheduler.FilterScheduler._get_all_host_states')
@mock.patch('nova.scheduler.filter_scheduler.FilterScheduler._get_sorted_hosts')
def test_schedule_placement_bad_comms(self, mock_get_hosts, mock_get_all_states, mock_claim):

    spec_obj = objects.RequestSpec(num_instances=1, flavor=objects.Flavor(memory_mb=512, root_gb=512, ephemeral_gb=0, swap=0, vcpus=1), project_id=uuids.project_id, instance_group=None)
    host_state = mock.Mock(spec=host_manager.HostState, host=mock.sentinel.host, uuid=uuids.cn1)
    all_host_states = [host_state]
    mock_get_all_states.return_value = all_host_states
    mock_get_hosts.return_value = all_host_states
    instance_uuids = None
    ctx = mock.Mock()
    selected_hosts = self.driver._schedule(ctx, spec_obj, instance_uuids, None, mock.sentinel.provider_summaries)
    mock_get_all_states.assert_called_once_with(ctx.elevated.return_value, spec_obj, mock.sentinel.provider_summaries)
    mock_get_hosts.assert_called_once_with(spec_obj, all_host_states, 0)
    self.assertEqual(len(selected_hosts), 1)
    self.assertEqual([host_state], selected_hosts)
    host_state.consume_from_request.assert_called_once_with(spec_obj)
    self.assertFalse(mock_claim.called)
