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 <mgolub@mirantis.com>
This commit is contained in:
Mykola Golub 2016-05-23 09:18:34 +03:00
parent d305eaad8d
commit b8b3a9757f
2 changed files with 45 additions and 17 deletions

View File

@ -462,7 +462,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.
@ -499,7 +499,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:
@ -509,8 +509,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,
@ -526,7 +528,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.
@ -569,8 +571,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,
@ -1259,8 +1262,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.
@ -1292,8 +1295,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,

View File

@ -753,19 +753,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