libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [libcloud] branch trunk updated: Fix Azure upload_object_via_stream used with iter
Date Tue, 28 May 2019 12:44:56 GMT
This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git


The following commit(s) were added to refs/heads/trunk by this push:
     new d949d76  Fix Azure upload_object_via_stream used with iter
     new f086aa6  Merge pull request #1287 from CatalystCode/1043_fix_azure_upload_object_via_stream_with_iterator
d949d76 is described below

commit d949d76b9bb24ca7b8f1839c45090db64689453a
Author: Clemens Wolff <clewolff@microsoft.com>
AuthorDate: Fri May 17 14:05:55 2019 -0400

    Fix Azure upload_object_via_stream used with iter
---
 libcloud/storage/drivers/azure_blobs.py   | 11 ++++++++++-
 libcloud/test/storage/test_azure_blobs.py | 18 ++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/libcloud/storage/drivers/azure_blobs.py b/libcloud/storage/drivers/azure_blobs.py
index ca63d3a..06c3184 100644
--- a/libcloud/storage/drivers/azure_blobs.py
+++ b/libcloud/storage/drivers/azure_blobs.py
@@ -18,6 +18,7 @@ from __future__ import with_statement
 import base64
 import os
 import binascii
+from io import BytesIO
 
 from libcloud.utils.py3 import ET
 from libcloud.utils.py3 import httplib
@@ -799,6 +800,9 @@ class AzureBlobsStorageDriver(StorageDriver):
         """
         @inherits: :class:`StorageDriver.upload_object_via_stream`
 
+        Note that if ``iterator`` does not support ``seek``, the
+        entire generator will be buffered in memory.
+
         :param ex_blob_type: Storage class
         :type ex_blob_type: ``str``
 
@@ -825,7 +829,12 @@ class AzureBlobsStorageDriver(StorageDriver):
         """
         self._check_values(ex_blob_type, ex_page_blob_size)
         if ex_blob_type == "BlockBlob":
-            iterator.seek(0, os.SEEK_END)
+            try:
+                iterator.seek(0, os.SEEK_END)
+            except AttributeError:
+                buffer = BytesIO()
+                buffer.writelines(iterator)
+                iterator = buffer
             blob_size = iterator.tell()
             iterator.seek(0)
         else:
diff --git a/libcloud/test/storage/test_azure_blobs.py b/libcloud/test/storage/test_azure_blobs.py
index aa09c66..cbd71e1 100644
--- a/libcloud/test/storage/test_azure_blobs.py
+++ b/libcloud/test/storage/test_azure_blobs.py
@@ -874,6 +874,24 @@ class AzureBlobsTests(unittest.TestCase):
         self.assertEqual(obj.size, 3)
         self.mock_response_klass.use_param = None
 
+    def test_upload_blob_object_via_stream_from_iterable(self):
+        self.mock_response_klass.use_param = 'comp'
+        container = Container(name='foo_bar_container', extra={},
+                              driver=self.driver)
+
+        object_name = 'foo_test_upload'
+        iterator = iter([b('34'), b('5')])
+        extra = {'content_type': 'text/plain'}
+        obj = self.driver.upload_object_via_stream(container=container,
+                                                   object_name=object_name,
+                                                   iterator=iterator,
+                                                   extra=extra,
+                                                   ex_blob_type='BlockBlob')
+
+        self.assertEqual(obj.name, object_name)
+        self.assertEqual(obj.size, 3)
+        self.mock_response_klass.use_param = None
+
     def test_upload_blob_object_via_stream_with_lease(self):
         self.mock_response_klass.use_param = 'comp'
         container = Container(name='foo_bar_container', extra={},


Mime
View raw message