'This test simulates a spawn failure on the last retry attempt.
If driver spawn raises an exception on the last retry attempt, the
instance fault message should not contain a traceback for the
last exception. The fault message field is limited in size and a long
message with a traceback displaces the original error message.'

def test_instance_fault_message_no_traceback_with_retry(self):

    self.flags(max_attempts=3, group='scheduler')
    flavor = objects.Flavor(id=1, name='flavor1', memory_mb=256, vcpus=1, root_gb=1, ephemeral_gb=1, flavorid='1', swap=0, rxtx_factor=1.0, vcpu_weight=1, disabled=False, is_public=True, extra_specs={}, projects=[])
    instance = objects.Instance(self.context, flavor=flavor, vcpus=1, memory_mb=256, root_gb=0, ephemeral_gb=0, project_id='fake')
    instance.create()
    @mock.patch.object(self.conductor.manager.compute_task_mgr, '_cleanup_allocated_networks')
    @mock.patch.object(self.compute.manager.network_api, 'cleanup_instance_network_on_host')
    @mock.patch('nova.compute.utils.notify_about_instance_usage')
    @mock.patch.object(self.compute.manager, '_get_resource_tracker')
    @mock.patch.object(self.compute.manager.driver, 'spawn')
    def _test(mock_spawn, mock_grt, mock_notify, mock_cinoh, mock_can):
        mock_spawn.side_effect = test.TestingException('Preserve    this')
        filter_properties = {'retry': {'num_attempts': 3}}
        self.compute.manager.build_and_run_instance(self.context, instance, {}, {}, filter_properties, block_device_mapping=[])
    _test()
    self.assertIn('Preserve    this', instance.fault.message)
