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
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')
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')