Skip to content

Commit 61075e3

Browse files
committed
pybind/rbd: add ImageMemberOfGroup exception
EMLINK is returned by rbd_remove() if the image is a member of a group. Add a dedicated exception similar to ImageBusy or ImageHasSnapshots and a test for it. Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 1fd79d4 commit 61075e3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/pybind/rbd/rbd.pyx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ class ImageHasSnapshots(OSError):
270270
"RBD image has snapshots (%s)" % message, errno)
271271

272272

273+
class ImageMemberOfGroup(OSError):
274+
def __init__(self, message, errno=None):
275+
super(ImageMemberOfGroup, self).__init__(
276+
"RBD image is member of group (%s)" % message, errno)
277+
278+
273279
class FunctionNotSupported(OSError):
274280
def __init__(self, message, errno=None):
275281
super(FunctionNotSupported, self).__init__(
@@ -319,6 +325,7 @@ cdef errno_to_exception = {
319325
errno.EROFS : ReadOnlyImage,
320326
errno.EBUSY : ImageBusy,
321327
errno.ENOTEMPTY : ImageHasSnapshots,
328+
errno.EMLINK : ImageMemberOfGroup,
322329
errno.ENOSYS : FunctionNotSupported,
323330
errno.EDOM : ArgumentOutOfRange,
324331
errno.ESHUTDOWN : ConnectionShutdown,
@@ -338,6 +345,7 @@ cdef group_errno_to_exception = {
338345
errno.EROFS : ReadOnlyImage,
339346
errno.EBUSY : ImageBusy,
340347
errno.ENOTEMPTY : ImageHasSnapshots,
348+
errno.EMLINK : ImageMemberOfGroup,
341349
errno.ENOSYS : FunctionNotSupported,
342350
errno.EDOM : ArgumentOutOfRange,
343351
errno.ESHUTDOWN : ConnectionShutdown,

src/test/pybind/test_rbd.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
LIBRADOS_OP_FLAG_FADVISE_RANDOM)
2222
from rbd import (RBD, Group, Image, ImageNotFound, InvalidArgument, ImageExists,
2323
ImageBusy, ImageHasSnapshots, ReadOnlyImage, ObjectNotFound,
24-
FunctionNotSupported, ArgumentOutOfRange,
24+
FunctionNotSupported, ArgumentOutOfRange, ImageMemberOfGroup,
2525
ECANCELED, OperationCanceled,
2626
DiskQuotaExceeded, ConnectionShutdown, PermissionError,
2727
RBD_FEATURE_LAYERING, RBD_FEATURE_STRIPINGV2,
@@ -3077,6 +3077,15 @@ def test_group_image_list_move_to_trash(self):
30773077
eq([], list(self.group.list_images()))
30783078
RBD().trash_restore(ioctx, image_id, image_name)
30793079

3080+
def test_group_image_list_remove(self):
3081+
# need a closed image to get ImageMemberOfGroup instead of ImageBusy
3082+
self.image_names.append(create_image())
3083+
eq([], list(self.group.list_images()))
3084+
self.group.add_image(ioctx, image_name)
3085+
eq([image_name], [img['name'] for img in self.group.list_images()])
3086+
assert_raises(ImageMemberOfGroup, RBD().remove, ioctx, image_name)
3087+
eq([image_name], [img['name'] for img in self.group.list_images()])
3088+
30803089
def test_group_get_id(self):
30813090
id = self.group.id()
30823091
assert isinstance(id, str)

0 commit comments

Comments
 (0)