rbd: add error checking in RemoveImage()

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-06-10 10:38:56 +02:00 committed by John Mulligan
parent 9e7a1c444f
commit 3fc893bc0f
2 changed files with 13 additions and 0 deletions

View File

@ -1216,6 +1216,13 @@ func CreateImage(ioctx *rados.IOContext, name string, size uint64, rio *ImageOpt
// Implements:
// int rbd_remove(rados_ioctx_t io, const char *name);
func RemoveImage(ioctx *rados.IOContext, name string) error {
if ioctx == nil {
return ErrNoIOContext
}
if name == "" {
return ErrNoName
}
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
return getError(C.rbd_remove(cephIoctx(ioctx), c_name))

View File

@ -1300,6 +1300,12 @@ func TestRemoveImage(t *testing.T) {
ioctx, err := conn.OpenIOContext(poolname)
require.NoError(t, err)
// pass invalid parameters
err = RemoveImage(nil, "some-name")
require.Error(t, err)
err = RemoveImage(ioctx, "")
require.Error(t, err)
// trying to remove a non-existent image is an error
err = RemoveImage(ioctx, "bananarama")
require.Error(t, err)