'Ensure that delete_backup() is called if the metadata backup fails.
Also ensure that the exception is propagated to the caller.'

@common_mocks
def test_backup_metadata_error(self):

    with mock.patch.object(self.service, '_backup_metadata') as mock_backup_metadata:
        mock_backup_metadata.side_effect = exception.BackupOperationError
        with mock.patch.object(self.service, '_get_volume_size_gb'):
            with mock.patch.object(self.service, '_file_is_rbd', return_value=False):
                with mock.patch.object(self.service, '_full_backup'):
                    with mock.patch.object(self.service, 'delete_backup') as mock_delete:
                        self.assertRaises(exception.BackupOperationError, self.service.backup, self.backup, mock.Mock(), backup_metadata=True)
                        self.assertTrue(mock_delete.called)
