]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/rbd: new OperationCanceled exception
authorJason Dillaman <dillaman@redhat.com>
Tue, 23 Jul 2019 16:50:59 +0000 (12:50 -0400)
committerJason Dillaman <dillaman@redhat.com>
Sun, 18 Aug 2019 20:47:10 +0000 (16:47 -0400)
This allows the error to be directly caught instead of attempting
to parse the OSError.errno

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit 2e85381665a28167cc01d3ef66a577502b79e7ed)

src/pybind/rbd/rbd.pyx
src/test/pybind/test_rbd.py

index 7db18d9d23c14e5dfcb6869e551852fbb154a921..5af51ee84546960b9fdce819a3b5809f95c54d69 100644 (file)
@@ -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
@@ -781,6 +787,10 @@ class Timeout(OSError):
 class DiskQuotaExceeded(OSError):
     pass
 
+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,
@@ -797,6 +807,7 @@ cdef errno_to_exception = {
     errno.ESHUTDOWN : ConnectionShutdown,
     errno.ETIMEDOUT : Timeout,
     errno.EDQUOT    : DiskQuotaExceeded,
+    ECANCELED       : OperationCanceled,
 }
 
 cdef group_errno_to_exception = {
@@ -814,6 +825,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):
index f18918a3f114a2858ab5ed2836d83ab0b5db36f3..0742ab8069c6f49dc285b7f764ce1a33ceaf6088 100644 (file)
@@ -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)