]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test/pybind/test_rados.py: add WriteOp::rm_xattr() and test rm_xattr()
authorzhangjiao <zhangjiao@cmss.chinamobile.com>
Sat, 23 Nov 2019 09:38:44 +0000 (17:38 +0800)
committerzhangjiao <zhangjiao@cmss.chinamobile.com>
Wed, 18 Dec 2019 07:58:39 +0000 (15:58 +0800)
Signed-off-by: Zhang Jiao <zhangjiao@cmss.chinamobile.com>
src/pybind/rados/rados.pyx
src/test/pybind/test_rados.py

index 36f41aaf6cbce3b0fcbf92df4c6e755cf97bd1cb..87110da445e414a28842a57e6c7e0ef9aba77a63 100644 (file)
@@ -295,7 +295,8 @@ cdef extern from "rados/librados.h" nogil:
     void rados_write_op_omap_clear(rados_write_op_t write_op)
     void rados_write_op_set_flags(rados_write_op_t write_op, int flags)
     void rados_write_op_setxattr(rados_write_op_t write_op, const char *name, const char *value, size_t value_len)
-    
+    void rados_write_op_rmxattr(rados_write_op_t write_op, const char *name)
+
     void rados_write_op_create(rados_write_op_t write_op, int exclusive, const char *category)
     void rados_write_op_append(rados_write_op_t write_op, const char *buffer, size_t len)
     void rados_write_op_write_full(rados_write_op_t write_op, const char *buffer, size_t len)
@@ -2064,6 +2065,19 @@ cdef class WriteOp(object):
         with nogil:
             rados_write_op_setxattr(self.write_op, _xattr_name, _xattr_value, _xattr_value_len)
 
+    @requires(('xattr_name', str_type))
+    def rm_xattr(self, xattr_name):
+        """  
+        Removes an extended attribute on from an object.
+        :param xattr_name: name of the xattr to remove
+        :type xattr_name: str
+        """
+        xattr_name = cstr(xattr_name, 'xattr_name')
+        cdef:
+            char *_xattr_name = xattr_name
+        with nogil:
+            rados_write_op_rmxattr(self.write_op, _xattr_name)
+
     @requires(('to_write', bytes))
     def append(self, to_write):
         """
index 285d0a1a900ad3f3e8f507400032c1d13c621580..8ac70eac79268bdeb9220e4c97ffdf00d191805c 100644 (file)
@@ -3,7 +3,7 @@ from nose import SkipTest
 from nose.tools import eq_ as eq, ok_ as ok, assert_raises
 from rados import (Rados, Error, RadosStateError, Object, ObjectExists,
                    ObjectNotFound, ObjectBusy, requires, opt,
-                   LIBRADOS_ALL_NSPACES, WriteOpCtx, ReadOpCtx,
+                   LIBRADOS_ALL_NSPACES, WriteOpCtx, ReadOpCtx, LIBRADOS_CREATE_EXCLUSIVE,
                    LIBRADOS_SNAP_HEAD, LIBRADOS_OPERATION_BALANCE_READS, LIBRADOS_OPERATION_SKIPRWLOCKS, MonitorLog)
 import time
 import threading
@@ -583,6 +583,27 @@ class TestIoctx(object):
             self.ioctx.operate_read_op(read_op, "hw")
             eq(list(iter), [])
 
+    def test_xattrs_op(self):
+        xattrs = dict(a=b'1', b=b'2', c=b'3', d=b'a\0b', e=b'\0')
+        with WriteOpCtx() as write_op:
+            write_op.new(LIBRADOS_CREATE_EXCLUSIVE)
+            for key, value in xattrs.items():
+                write_op.set_xattr(key, value)
+                self.ioctx.operate_write_op(write_op, "abc")
+                eq(self.ioctx.get_xattr('abc', key), value)
+            stored_xattrs_1 = {}
+            for key, value in self.ioctx.get_xattrs('abc'):
+                stored_xattrs_1[key] = value
+            eq(stored_xattrs_1, xattrs)
+            for key in xattrs.keys():
+                write_op.rm_xattr(key)
+                self.ioctx.operate_write_op(write_op, "abc")
+            stored_xattrs_2 = {}
+            for key, value in self.ioctx.get_xattrs('abc'):
+                stored_xattrs_2[key] = value
+            eq(stored_xattrs_2, {})
+            write_op.remove()
+
     def test_locator(self):
         self.ioctx.set_locator_key("bar")
         self.ioctx.write('foo', b'contents1')