'Tests the case that the build request is deleted before the instance
is created, so we do not create the instance.'

@mock.patch('nova.compute.rpcapi.ComputeAPI.build_and_run_instance')
@mock.patch('nova.scheduler.rpcapi.SchedulerAPI.select_destinations')
@mock.patch('nova.objects.BuildRequest.get_by_instance_uuid')
@mock.patch('nova.objects.BuildRequest.destroy')
@mock.patch('nova.conductor.manager.ComputeTaskManager._bury_in_cell0')
@mock.patch('nova.objects.Instance.create')
def test_schedule_and_build_delete_before_scheduling(self, inst_create, bury, br_destroy, br_get_by_inst, select_destinations, build_and_run):

    inst_uuid = self.params['build_requests'][0].instance.uuid
    br_get_by_inst.side_effect = exc.BuildRequestNotFound(uuid=inst_uuid)
    self.start_service('compute', host='fake-host')
    select_destinations.return_value = [{'host': 'fake-host', 'nodename': 'nodesarestupid', 'limits': None}]
    self.conductor.schedule_and_build_instances(**self.params)
    self.assertFalse(inst_create.called)
    self.assertFalse(build_and_run.called)
    self.assertFalse(bury.called)
    self.assertFalse(br_destroy.called)
