]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind, test: Add python binding for append and add to test
authorDavid Zafman <david.zafman@inktank.com>
Tue, 8 Apr 2014 17:44:47 +0000 (10:44 -0700)
committerDavid Zafman <david.zafman@inktank.com>
Fri, 11 Apr 2014 00:22:29 +0000 (17:22 -0700)
Signed-off-by: David Zafman <david.zafman@inktank.com>
src/pybind/rados.py
src/test/pybind/test_rados.py

index 34411e665bfbdece9cbb82b05af452b1e3dc62fd..6d02d38581dd905b000a8dee692c05ffe44419a2 100644 (file)
@@ -1260,6 +1260,37 @@ returned %d, but should return zero on success." % (self.name, ret))
             raise LogicError("Ioctx.write_full(%s): rados_write_full \
 returned %d, but should return zero on success." % (self.name, ret))
 
+    def append(self, key, data):
+        """
+        Append data to an object synchronously
+
+        :param key: name of the object
+        :type key: str
+        :param data: data to write
+        :type data: str
+
+        :raises: :class:`TypeError`
+        :raises: :class:`LogicError`
+        :returns: int - number of bytes written
+        """
+        self.require_ioctx_open()
+        if not isinstance(key, str):
+            raise TypeError('key must be a string')
+        if not isinstance(data, str):
+            raise TypeError('data must be a string')
+        length = len(data)
+        ret = run_in_thread(self.librados.rados_append,
+                            (self.io, c_char_p(key), c_char_p(data),
+                            c_size_t(length)))
+        if ret == 0:
+            return ret
+        elif ret < 0:
+            raise make_ex(ret, "Ioctx.append(%s): failed to append %s" % \
+                (self.name, key))
+        else:
+            raise LogicError("Ioctx.append(%s): rados_append \
+returned %d, but should return zero on success." % (self.name, ret))
+
     def read(self, key, length=8192, offset=0):
         """
         Read data from an object synchronously
index 7d5aa3bd9628d6be37ca6bcf2e2cc86276f4c23f..7efed7dfc967c102f2be0cbd96baae88f7f56449 100644 (file)
@@ -118,6 +118,12 @@ class TestIoctx(object):
         self.ioctx.write_full('abc', 'd')
         eq(self.ioctx.read('abc'), 'd')
 
+    def test_append(self):
+        self.ioctx.write('abc', 'a')
+        self.ioctx.append('abc', 'b')
+        self.ioctx.append('abc', 'c')
+        eq(self.ioctx.read('abc'), 'abc')
+
     def test_write_zeros(self):
         self.ioctx.write('abc', 'a\0b\0c')
         eq(self.ioctx.read('abc'), 'a\0b\0c')
@@ -136,8 +142,9 @@ class TestIoctx(object):
         self.ioctx.write('a', '')
         self.ioctx.write('b', 'foo')
         self.ioctx.write_full('c', 'bar')
+        self.ioctx.append('d', 'jazz')
         object_names = [obj.key for obj in self.ioctx.list_objects()]
-        eq(sorted(object_names), ['a', 'b', 'c'])
+        eq(sorted(object_names), ['a', 'b', 'c', 'd'])
 
     def test_xattrs(self):
         xattrs = dict(a='1', b='2', c='3', d='a\0b', e='\0')