From e15bfff2e822e15e0a34d09825e04cee381d8737 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Mon, 23 May 2016 09:18:34 +0300 Subject: [PATCH] pybind/rbd: create/clone/copy: default to None for features param If None is specified don't set the features so that the defaults is used. Fixes: http://tracker.ceph.com/issues/15982 Signed-off-by: Mykola Golub (cherry picked from commit b8b3a9757f7d517210a91f2893b0961b6b35afab) --- src/pybind/rbd/rbd.pyx | 26 +++++++++++++++----------- src/test/pybind/test_rbd.py | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/pybind/rbd/rbd.pyx b/src/pybind/rbd/rbd.pyx index 23a9895cfcb8..1d40f94e9795 100644 --- a/src/pybind/rbd/rbd.pyx +++ b/src/pybind/rbd/rbd.pyx @@ -368,7 +368,7 @@ class RBD(object): return (major, minor, extra) def create(self, ioctx, name, size, order=None, old_format=True, - features=0, stripe_unit=0, stripe_count=0): + features=None, stripe_unit=0, stripe_count=0): """ Create an rbd image. @@ -405,7 +405,7 @@ class RBD(object): if order is not None: _order = order if old_format: - if features != 0 or stripe_unit != 0 or stripe_count != 0: + if features or stripe_unit != 0 or stripe_count != 0: raise InvalidArgument('format 1 images do not support feature' ' masks or non-default striping') with nogil: @@ -415,8 +415,10 @@ class RBD(object): try: rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_FORMAT, 1 if old_format else 2) - rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_FEATURES, - features) + if features is not None: + rbd_image_options_set_uint64(opts, + RBD_IMAGE_OPTION_FEATURES, + features) rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_ORDER, _order) rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_STRIPE_UNIT, @@ -432,7 +434,7 @@ class RBD(object): raise make_ex(ret, 'error creating image') def clone(self, p_ioctx, p_name, p_snapname, c_ioctx, c_name, - features=0, order=None, stripe_unit=0, stripe_count=0): + features=None, order=None, stripe_unit=0, stripe_count=0): """ Clone a parent rbd snapshot into a COW sparse child. @@ -475,8 +477,9 @@ class RBD(object): rbd_image_options_create(&opts) try: - rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_FEATURES, - features) + if features is not None: + rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_FEATURES, + features) rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_ORDER, order) rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_STRIPE_UNIT, @@ -857,8 +860,8 @@ cdef class Image(object): raise make_ex(ret, 'error getting lock status for image' % (self.name)) return owner == 1 - def copy(self, dest_ioctx, dest_name, features=0, order=None, stripe_unit=0, - stripe_count=0): + def copy(self, dest_ioctx, dest_name, features=None, order=None, + stripe_unit=0, stripe_count=0): """ Copy the image to another location. @@ -890,8 +893,9 @@ cdef class Image(object): rbd_image_options_create(&opts) try: - rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_FEATURES, - features) + if features is not None: + rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_FEATURES, + features) rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_ORDER, order) rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_STRIPE_UNIT, diff --git a/src/test/pybind/test_rbd.py b/src/test/pybind/test_rbd.py index 04a3a3820da9..aae7fd021038 100644 --- a/src/test/pybind/test_rbd.py +++ b/src/test/pybind/test_rbd.py @@ -750,19 +750,43 @@ class TestClone(object): self.image.close() remove_image() - @require_features([RBD_FEATURE_STRIPINGV2]) - def test_with_params(self): - global features + def _test_with_params(self, features=None, order=None, stripe_unit=None, + stripe_count=None): self.image.create_snap('snap2') self.image.protect_snap('snap2') clone_name2 = get_temp_image_name() - self.rbd.clone(ioctx, image_name, 'snap2', ioctx, clone_name2, - features, self.image.stat()['order'], - self.image.stripe_unit(), self.image.stripe_count()) + if features is None: + self.rbd.clone(ioctx, image_name, 'snap2', ioctx, clone_name2) + elif order is None: + self.rbd.clone(ioctx, image_name, 'snap2', ioctx, clone_name2, + features) + elif stripe_unit is None: + self.rbd.clone(ioctx, image_name, 'snap2', ioctx, clone_name2, + features, order) + elif stripe_count is None: + self.rbd.clone(ioctx, image_name, 'snap2', ioctx, clone_name2, + features, order, stripe_unit) + else: + self.rbd.clone(ioctx, image_name, 'snap2', ioctx, clone_name2, + features, order, stripe_unit, stripe_count) self.rbd.remove(ioctx, clone_name2) self.image.unprotect_snap('snap2') self.image.remove_snap('snap2') + def test_with_params(self): + self._test_with_params() + + def test_with_params2(self): + global features + self._test_with_params(features, self.image.stat()['order']) + + @require_features([RBD_FEATURE_STRIPINGV2]) + def test_with_params3(self): + global features + self._test_with_params(features, self.image.stat()['order'], + self.image.stripe_unit(), + self.image.stripe_count()) + def test_unprotected(self): self.image.create_snap('snap2') global features -- 2.47.3