From: David Zafman Date: Tue, 8 Apr 2014 17:44:47 +0000 (-0700) Subject: pybind, test: Add python binding for append and add to test X-Git-Tag: v0.80-rc1~59^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=39bf68c3ceee3f62960d0866f35835325cca5660;p=ceph.git pybind, test: Add python binding for append and add to test Signed-off-by: David Zafman --- diff --git a/src/pybind/rados.py b/src/pybind/rados.py index 34411e665bfb..6d02d38581dd 100644 --- a/src/pybind/rados.py +++ b/src/pybind/rados.py @@ -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 diff --git a/src/test/pybind/test_rados.py b/src/test/pybind/test_rados.py index 7d5aa3bd9628..7efed7dfc967 100644 --- a/src/test/pybind/test_rados.py +++ b/src/test/pybind/test_rados.py @@ -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')