'Test of when an exception occurs in an exception handler.
In _backup_rbd(), after an exception.BackupRBDOperationFailed
occurs in self._rbd_diff_transfer(), we want to check the
process when the second exception occurs in
self._try_delete_base_image().'

@common_mocks
@mock.patch('fcntl.fcntl', spec=True)
@mock.patch('subprocess.Popen', spec=True)
def test_backup_volume_from_rbd_fail(self, mock_popen, mock_fnctl):

    backup_name = self.service._get_backup_base_name(self.backup_id, diff_format=True)
    def mock_write_data():
        self.volume_file.seek(0)
        data = self.volume_file.read(self.data_length)
        self.callstack.append('write')
        checksum.update(data)
        test_file.write(data)
    def mock_read_data():
        self.callstack.append('read')
        return self.volume_file.read(self.data_length)
    self._setup_mock_popen(mock_popen, ['out', 'err'], p1hook=mock_read_data, p2hook=mock_write_data)
    self.mock_rbd.RBD.list = mock.Mock()
    self.mock_rbd.RBD.list.return_value = [backup_name]
    with mock.patch.object(self.service, 'get_backup_snaps'):
        with mock.patch.object(self.service, '_rbd_diff_transfer') as mock_rbd_diff_transfer:
            def mock_rbd_diff_transfer_side_effect(src_name, src_pool, dest_name, dest_pool, src_user, src_conf, dest_user, dest_conf, src_snap, from_snap):
                raise exception.BackupRBDOperationFailed(_('mock'))
            mock_rbd_diff_transfer.side_effect = mock_rbd_diff_transfer_side_effect
            with mock.patch.object(self.service, '_full_backup'):
                with mock.patch.object(self.service, '_try_delete_base_image') as mock_try_delete_base_image:
                    def mock_try_delete_base_image_side_effect(backup_id, base_name):
                        raise self.service.rbd.ImageNotFound(_('mock'))
                    mock_try_delete_base_image.side_effect = mock_try_delete_base_image_side_effect
                    with mock.patch.object(self.service, '_backup_metadata'):
                        with tempfile.NamedTemporaryFile() as test_file:
                            checksum = hashlib.sha256()
                            image = self.service.rbd.Image()
                            meta = linuxrbd.RBDImageMetadata(image, 'pool_foo', 'user_foo', 'conf_foo')
                            rbdio = linuxrbd.RBDVolumeIOWrapper(meta)
                            self.assertRaises(self.service.rbd.ImageNotFound, self.service.backup, self.backup, rbdio)
