'Test error handling.
Test error handling when attempting an import of a backup
record where the backup driver returns an exception.'

def test_import_record_with_verify_invalid_backup(self):

    vol_size = 1
    backup_id = uuid.uuid4()
    export = self._create_exported_record_entry(vol_size=vol_size, exported_id=backup_id)
    imported_record = self._create_export_record_db_entry(backup_id=backup_id)
    backup_hosts = []
    backup_driver = self.backup_mgr.service.get_backup_driver(self.ctxt)
    _mock_backup_verify_class = ('%s.%s.%s' % (backup_driver.__module__, backup_driver.__class__.__name__, 'verify'))
    with mock.patch(_mock_backup_verify_class) as _mock_record_verify:
        _mock_record_verify.side_effect = exception.InvalidBackup(reason='fake')
        self.assertRaises(exception.InvalidBackup, self.backup_mgr.import_record, self.ctxt, imported_record, export['backup_service'], export['backup_url'], backup_hosts)
        self.assertTrue(_mock_record_verify.called)
    backup = db.backup_get(self.ctxt, imported_record.id)
    self.assertEqual(fields.BackupStatus.ERROR, backup['status'])
