summaryrefslogtreecommitdiffstats
path: root/test/functional/libgfapi-python-tests.py
diff options
context:
space:
mode:
authorThiago da Silva <thiago@redhat.com>2014-02-21 18:23:29 -0500
committerGerrit Code Review <review@dev.gluster.org>2014-02-24 19:25:23 -0800
commit4185c26e9f6ff6f5395c326e4fb71f60b8d1656e (patch)
tree6785031207a1052fddf1b1a19ce41668e8ae6492 /test/functional/libgfapi-python-tests.py
parentf51edb0687dba2d6f6b07f8697c91f2df2f4cdda (diff)
changed write and read functions to support binary data
both functions were only supporting text data and needed to be changed to support binary data. The issue was found while testing libgfapi-python with smallfile (https://github.com/bengland2/smallfile). When calling gflfs_write, ctypes has no problem converting strings to the correct C data type, but is unable to handle bytearray: b = bytearray(1024) with vol.create(path, os.O_WRONLY | os.O_EXCL, 0644) as fd: fd.write(b) It would throw this error: exception: argument 2: <type 'exceptions.TypeError'>: Don't know how to convert parameter 2 reference: http://docs.python.org/2/library/ctypes.html#calling-functions-continued Change-Id: Ia2bb47343880cbf7121fed9510e4cfa085fe23bd Signed-off-by: Thiago da Silva <thiago@redhat.com>
Diffstat (limited to 'test/functional/libgfapi-python-tests.py')
-rw-r--r--test/functional/libgfapi-python-tests.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/test/functional/libgfapi-python-tests.py b/test/functional/libgfapi-python-tests.py
index d0703df..08742f3 100644
--- a/test/functional/libgfapi-python-tests.py
+++ b/test/functional/libgfapi-python-tests.py
@@ -7,6 +7,36 @@ from nose import SkipTest
from gluster import gfapi
+class BinFileOpsTest(unittest.TestCase):
+
+ vol = None
+ path = None
+ data = None
+
+ @classmethod
+ def setUpClass(cls):
+ cls.vol = gfapi.Volume("gfshost", "test")
+ cls.vol.set_logging("/dev/null", 7)
+ cls.vol.mount()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.vol = None
+
+ def setUp(self):
+ self.data = bytearray([(k % 128) for k in range(0, 1024)])
+ self.path = self._testMethodName + ".io"
+ with self.vol.creat(self.path, os.O_WRONLY | os.O_EXCL, 0644) as fd:
+ fd.write(self.data)
+
+ def test_bin_open_and_read(self):
+ with self.vol.open(self.path, os.O_RDONLY) as fd:
+ self.assertTrue(isinstance(fd, gfapi.File))
+ buf = fd.read(len(self.data))
+ self.assertFalse(isinstance(buf, types.IntType))
+ self.assertEqual(buf, self.data)
+
+
class FileOpsTest(unittest.TestCase):
vol = None
@@ -27,7 +57,7 @@ class FileOpsTest(unittest.TestCase):
self.data = loremipsum.get_sentence()
self.path = self._testMethodName + ".io"
with self.vol.creat(self.path, os.O_WRONLY | os.O_EXCL, 0644) as fd:
- rc = fd.write(self.data)
+ fd.write(self.data)
def tearDown(self):
self.path = None
@@ -38,7 +68,7 @@ class FileOpsTest(unittest.TestCase):
self.assertTrue(isinstance(fd, gfapi.File))
buf = fd.read(len(self.data))
self.assertFalse(isinstance(buf, types.IntType))
- self.assertEqual(buf, self.data)
+ self.assertEqual(buf.value, self.data)
def test_lstat(self):
sb = self.vol.lstat(self.path)