ganesha: read and store non-ASCII data in exports

For py27, allow reading and storing non-ASCII data in exports
stored as Ceph RADOS objects (This is possible with py3).
Do this by decoding binary data and encoding text data with 'utf-8'
when reading and writing RADOS export objects.

TrivialFix

Change-Id: Idcf8b1c1ed1a65e2cce19726997694d993879c14
This commit is contained in:
Ramana Raja 2018-01-02 16:37:03 +05:30
parent 098546fbf4
commit 15727cd157
2 changed files with 8 additions and 6 deletions

View File

@ -518,14 +518,14 @@ class GaneshaManager(object):
def _get_rados_object(self, obj_name):
"""Get data stored in Ceph RADOS object as a text string."""
return self.ceph_vol_client.get_object(
self.ganesha_rados_store_pool_name, obj_name).decode()
self.ganesha_rados_store_pool_name, obj_name).decode('utf-8')
def _put_rados_object(self, obj_name, data):
"""Put data as a byte string in a Ceph RADOS object."""
return self.ceph_vol_client.put_object(
self.ganesha_rados_store_pool_name,
obj_name,
data.encode())
data.encode('utf-8'))
def _delete_rados_object(self, obj_name):
return self.ceph_vol_client.delete_object(

View File

@ -1021,24 +1021,26 @@ class GaneshaManagerTestCase(test.TestCase):
self._manager._remove_rados_object_url_from_index.called)
def test_get_rados_object(self):
fakebin = six.unichr(246).encode('utf-8')
self.mock_object(self._ceph_vol_client, 'get_object',
mock.Mock(return_value=b'fakedata'))
mock.Mock(return_value=fakebin))
ret = self._manager_with_rados_store._get_rados_object('fakeobj')
self._ceph_vol_client.get_object.assert_called_once_with(
'fakepool', 'fakeobj')
self.assertEqual(b'fakedata'.decode(), ret)
self.assertEqual(fakebin.decode('utf-8'), ret)
def test_put_rados_object(self):
faketext = six.unichr(246)
self.mock_object(self._ceph_vol_client, 'put_object',
mock.Mock(return_value=None))
ret = self._manager_with_rados_store._put_rados_object(
'fakeobj', 'fakedata')
'fakeobj', faketext)
self._ceph_vol_client.put_object.assert_called_once_with(
'fakepool', 'fakeobj', 'fakedata'.encode())
'fakepool', 'fakeobj', faketext.encode('utf-8'))
self.assertIsNone(ret)
def test_delete_rados_object(self):