mirror of
https://github.com/ceph/ceph
synced 2024-12-28 22:43:29 +00:00
pybind/rbd: new OperationCanceled exception
This allows the error to be directly caught instead of attempting to parse the OSError.errno Signed-off-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
parent
6dc8249c7b
commit
2e85381665
@ -49,6 +49,10 @@ cdef extern from "time.h":
|
||||
time_t tv_sec
|
||||
long tv_nsec
|
||||
|
||||
cdef extern from "<errno.h>" nogil:
|
||||
enum:
|
||||
_ECANCELED "ECANCELED"
|
||||
|
||||
cdef extern from "rados/librados.h":
|
||||
enum:
|
||||
_LIBRADOS_SNAP_HEAD "LIBRADOS_SNAP_HEAD"
|
||||
@ -613,6 +617,8 @@ cdef extern from "rbd/librbd.h" nogil:
|
||||
int stat_option, uint64_t* stat_val)
|
||||
int rbd_pool_stats_get(rados_ioctx_t io, rbd_pool_stats_t stats)
|
||||
|
||||
ECANCELED = _ECANCELED
|
||||
|
||||
RBD_FEATURE_LAYERING = _RBD_FEATURE_LAYERING
|
||||
RBD_FEATURE_STRIPINGV2 = _RBD_FEATURE_STRIPINGV2
|
||||
RBD_FEATURE_EXCLUSIVE_LOCK = _RBD_FEATURE_EXCLUSIVE_LOCK
|
||||
@ -821,6 +827,10 @@ class DiskQuotaExceeded(OSError):
|
||||
super(DiskQuotaExceeded, self).__init__(
|
||||
"RBD disk quota exceeded (%s)" % message, errno)
|
||||
|
||||
class OperationCanceled(OSError):
|
||||
def __init__(self, message, errno=None):
|
||||
super(OperationCanceled, self).__init__(
|
||||
"RBD operation canceled (%s)" % message, errno)
|
||||
|
||||
cdef errno_to_exception = {
|
||||
errno.EPERM : PermissionError,
|
||||
@ -837,6 +847,7 @@ cdef errno_to_exception = {
|
||||
errno.ESHUTDOWN : ConnectionShutdown,
|
||||
errno.ETIMEDOUT : Timeout,
|
||||
errno.EDQUOT : DiskQuotaExceeded,
|
||||
ECANCELED : OperationCanceled,
|
||||
}
|
||||
|
||||
cdef group_errno_to_exception = {
|
||||
@ -854,6 +865,7 @@ cdef group_errno_to_exception = {
|
||||
errno.ESHUTDOWN : ConnectionShutdown,
|
||||
errno.ETIMEDOUT : Timeout,
|
||||
errno.EDQUOT : DiskQuotaExceeded,
|
||||
ECANCELED : OperationCanceled,
|
||||
}
|
||||
|
||||
cdef make_ex(ret, msg, exception_map=errno_to_exception):
|
||||
|
@ -16,6 +16,7 @@ from rados import (Rados,
|
||||
from rbd import (RBD, Group, Image, ImageNotFound, InvalidArgument, ImageExists,
|
||||
ImageBusy, ImageHasSnapshots, ReadOnlyImage,
|
||||
FunctionNotSupported, ArgumentOutOfRange,
|
||||
ECANCELED, OperationCanceled,
|
||||
DiskQuotaExceeded, ConnectionShutdown, PermissionError,
|
||||
RBD_FEATURE_LAYERING, RBD_FEATURE_STRIPINGV2,
|
||||
RBD_FEATURE_EXCLUSIVE_LOCK, RBD_FEATURE_JOURNALING,
|
||||
@ -338,9 +339,9 @@ def test_remove_with_progress():
|
||||
@with_setup(create_image)
|
||||
def test_remove_canceled():
|
||||
def progress_cb(current, total):
|
||||
return -errno.ESHUTDOWN
|
||||
return -ECANCELED
|
||||
|
||||
assert_raises(ConnectionShutdown, RBD().remove, ioctx, image_name,
|
||||
assert_raises(OperationCanceled, RBD().remove, ioctx, image_name,
|
||||
on_progress=progress_cb)
|
||||
|
||||
@with_setup(create_image, remove_image)
|
||||
|
Loading…
Reference in New Issue
Block a user