Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ Compute
(#2147)
[Miguel Caballer - @micafer]

Storage
~~~~~~~

- [Azure Blobs] Fix ``chunk_size`` argument being ignored by
``download_object_as_stream`` and ``download_object_range_as_stream``. The
requested chunk size is now forwarded to the underlying iterator instead of
always using ``AZURE_DOWNLOAD_CHUNK_SIZE``.
(GITHUB-1698)
[Sanjay Santhanam - @Sanjays2402]

Changes in Apache Libcloud 3.9.1
--------------------------------

Expand Down
4 changes: 2 additions & 2 deletions libcloud/storage/drivers/azure_blobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ def download_object_as_stream(self, obj, chunk_size=None):
"""
obj_path = self._get_object_path(obj.container, obj.name)
response = self.connection.request(obj_path, method="GET", stream=True, raw=True)
iterator = response.iter_content(AZURE_DOWNLOAD_CHUNK_SIZE)
iterator = response.iter_content(chunk_size or AZURE_DOWNLOAD_CHUNK_SIZE)

return self._get_object(
obj=obj,
Expand Down Expand Up @@ -848,7 +848,7 @@ def download_object_range_as_stream(self, obj, start_bytes, end_bytes=None, chun
response = self.connection.request(
obj_path, method="GET", headers=headers, stream=True, raw=True
)
iterator = response.iter_content(AZURE_DOWNLOAD_CHUNK_SIZE)
iterator = response.iter_content(chunk_size or AZURE_DOWNLOAD_CHUNK_SIZE)
success_status_codes = [httplib.OK, httplib.PARTIAL_CONTENT]

return self._get_object(
Expand Down
34 changes: 34 additions & 0 deletions libcloud/test/storage/test_azure_blobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,40 @@ def test_download_object_as_stream_success(self):
consumed_stream = "".join(chunk.decode("utf-8") for chunk in stream)
self.assertEqual(len(consumed_stream), obj.size)

def test_download_object_as_stream_uses_chunk_size(self):
container = Container(name="foo_bar_container", extra={}, driver=self.driver)

obj = Object(
name="foo_bar_object",
size=1000,
hash=None,
extra={},
container=container,
meta_data=None,
driver=self.driver_type,
)

used_chunk_sizes = []

def mock_get_object(
self, obj, callback, callback_kwargs, response, success_status_code=None
):
iterator = callback_kwargs["iterator"]
used_chunk_sizes.append(iterator.gi_frame.f_locals.get("chunk_size"))
return iterator

old_func = self.driver_type._get_object
self.driver_type._get_object = mock_get_object
try:
self.driver.download_object_as_stream(obj=obj, chunk_size=1234)
self.driver.download_object_range_as_stream(
obj=obj, start_bytes=0, end_bytes=10, chunk_size=4321
)
finally:
self.driver_type._get_object = old_func

self.assertEqual(used_chunk_sizes, [1234, 4321])

def test_download_object_range_success(self):
container = Container(name="foo_bar_container", extra={}, driver=self.driver)
obj = Object(
Expand Down