diff --git a/swh/objstorage/backends/libcloud.py b/swh/objstorage/backends/libcloud.py --- a/swh/objstorage/backends/libcloud.py +++ b/swh/objstorage/backends/libcloud.py @@ -171,6 +171,11 @@ obj = self._get_object(obj_id) return self.driver.delete_object(obj) + def _object_path(self, obj_id): + """Get the full path to an object""" + hex_obj_id = hashutil.hash_to_hex(obj_id) + return hex_obj_id + def _get_object(self, obj_id): """Get a Libcloud wrapper for an object pointer. @@ -178,10 +183,10 @@ directly. """ - hex_obj_id = hashutil.hash_to_hex(obj_id) + object_path = self._object_path(obj_id) try: - return self.driver.get_object(self.container_name, hex_obj_id) + return self.driver.get_object(self.container_name, object_path) except ObjectDoesNotExistError: raise ObjNotFoundError(obj_id) @@ -202,13 +207,13 @@ the given id. """ - hex_obj_id = hashutil.hash_to_hex(obj_id) + object_path = self._object_path(obj_id) if not isinstance(content, collections.Iterator): content = (content,) self.driver.upload_object_via_stream( self._compressor(content), - self.container, hex_obj_id) + self.container, object_path) class AwsCloudObjStorage(CloudObjStorage): diff --git a/swh/objstorage/tests/test_objstorage_cloud.py b/swh/objstorage/tests/test_objstorage_cloud.py --- a/swh/objstorage/tests/test_objstorage_cloud.py +++ b/swh/objstorage/tests/test_objstorage_cloud.py @@ -9,8 +9,6 @@ from libcloud.storage.types import (ContainerDoesNotExistError, ObjectDoesNotExistError) -from swh.model import hashutil - from swh.objstorage.objstorage import decompressors from swh.objstorage.exc import Error from swh.objstorage.backends.libcloud import CloudObjStorage @@ -107,9 +105,9 @@ def test_compression(self): content, obj_id = self.hash_content(b'add_get_w_id') self.storage.add(content, obj_id=obj_id) - data = self.storage.driver.containers[CONTAINER_NAME] - obj_id = hashutil.hash_to_hex(obj_id) - raw_content = b''.join(data[obj_id].content) + + libcloud_object = self.storage._get_object(obj_id) + raw_content = b''.join(libcloud_object.content) d = decompressors[self.compression]() assert d.decompress(raw_content) == content @@ -119,10 +117,8 @@ content, obj_id = self.hash_content(b'test content without garbage') self.storage.add(content, obj_id=obj_id) - data = self.storage.driver.containers[CONTAINER_NAME] - obj_id = hashutil.hash_to_hex(obj_id) - - data[obj_id].content.append(b'trailing garbage') + libcloud_object = self.storage._get_object(obj_id) + libcloud_object.content.append(b'trailing garbage') if self.compression == 'none': with self.assertRaises(Error) as e: