diff --git a/swh/objstorage/cloud/objstorage_azure.py b/swh/objstorage/cloud/objstorage_azure.py --- a/swh/objstorage/cloud/objstorage_azure.py +++ b/swh/objstorage/cloud/objstorage_azure.py @@ -24,6 +24,16 @@ account_key=api_secret_key) self.container_name = container_name + def get_blob_service(self, hex_obj_id): + """Get the block_blob_service and container that contains the object with + internal id hex_obj_id + """ + return self.block_blob_service, self.container_name + + def get_all_blob_services(self): + """Get all active block_blob_services""" + yield self.block_blob_service, self.container_name + def _internal_id(self, obj_id): """Internal id is the hex version in objstorage. @@ -32,28 +42,32 @@ def check_config(self, *, check_write): """Check the configuration for this object storage""" - props = self.block_blob_service.get_container_properties( - self.container_name - ) + for service, container in self.get_all_blob_services(): + props = service.get_container_properties(container) - # FIXME: check_write is ignored here - return bool(props) + # FIXME: check_write is ignored here + if not props: + return False + + return True def __contains__(self, obj_id): """Does the storage contains the obj_id. """ hex_obj_id = self._internal_id(obj_id) - return self.block_blob_service.exists( - container_name=self.container_name, + service, container = self.get_blob_service(hex_obj_id) + return service.exists( + container_name=container, blob_name=hex_obj_id) def __iter__(self): """Iterate over the objects present in the storage. """ - for obj in self.block_blob_service.list_blobs(self.container_name): - yield hashutil.hash_to_bytes(obj.name) + for service, container in self.get_all_blob_services(): + for obj in service.list_blobs(container): + yield hashutil.hash_to_bytes(obj.name) def __len__(self): """Compute the number of objects in the current object storage. @@ -78,8 +92,9 @@ hex_obj_id = self._internal_id(obj_id) # Send the gzipped content - self.block_blob_service.create_blob_from_bytes( - container_name=self.container_name, + service, container = self.get_blob_service(hex_obj_id) + service.create_blob_from_bytes( + container_name=container, blob_name=hex_obj_id, blob=gzip.compress(content)) @@ -96,9 +111,10 @@ """ hex_obj_id = self._internal_id(obj_id) + service, container = self.get_blob_service(hex_obj_id) try: - blob = self.block_blob_service.get_blob_to_bytes( - container_name=self.container_name, + blob = service.get_blob_to_bytes( + container_name=container, blob_name=hex_obj_id) except AzureMissingResourceHttpError: raise ObjNotFoundError(obj_id) @@ -118,9 +134,10 @@ """Delete an object.""" super().delete(obj_id) # Check delete permission hex_obj_id = self._internal_id(obj_id) + service, container = self.get_blob_service(hex_obj_id) try: - self.block_blob_service.delete_blob( - container_name=self.container_name, + service.delete_blob( + container_name=container, blob_name=hex_obj_id) except AzureMissingResourceHttpError: raise ObjNotFoundError('Content {} not found!'.format(hex_obj_id))