libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [38/51] [abbrv] libcloud git commit: fixes to the azure blob driver
Date Mon, 09 Jan 2017 04:52:58 GMT
fixes to the azure blob driver


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/6e0040d8
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/6e0040d8
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/6e0040d8

Branch: refs/heads/trunk
Commit: 6e0040d8904cacb5dbe88309e9051be08cdc59f9
Parents: 109ecad
Author: Anthony Shaw <anthonyshaw@apache.org>
Authored: Fri Jan 6 20:14:40 2017 +1100
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Fri Jan 6 20:14:40 2017 +1100

----------------------------------------------------------------------
 libcloud/storage/drivers/azure_blobs.py   | 27 ++++++++------------------
 libcloud/test/__init__.py                 |  5 +++--
 libcloud/test/storage/test_azure_blobs.py | 10 ++++++----
 3 files changed, 17 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/6e0040d8/libcloud/storage/drivers/azure_blobs.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/azure_blobs.py b/libcloud/storage/drivers/azure_blobs.py
index 793746b..b30d624 100644
--- a/libcloud/storage/drivers/azure_blobs.py
+++ b/libcloud/storage/drivers/azure_blobs.py
@@ -785,8 +785,6 @@ class AzureBlobsStorageDriver(StorageDriver):
             return self._put_object(container=container,
                                     object_name=object_name,
                                     object_size=object_size,
-                                    upload_func=upload_func,
-                                    upload_func_kwargs=upload_func_kwargs,
                                     file_path=file_path, extra=extra,
                                     verify_hash=verify_hash,
                                     blob_type=ex_blob_type,
@@ -817,20 +815,13 @@ class AzureBlobsStorageDriver(StorageDriver):
 
         object_path = self._get_object_path(container, object_name)
 
-        upload_func = self._upload_in_chunks
-        upload_func_kwargs = {'iterator': iterator,
-                              'object_path': object_path,
-                              'blob_type': ex_blob_type,
-                              'lease': None}
-
         return self._put_object(container=container,
                                 object_name=object_name,
                                 object_size=ex_page_blob_size,
-                                upload_func=upload_func,
-                                upload_func_kwargs=upload_func_kwargs,
                                 extra=extra, verify_hash=verify_hash,
                                 blob_type=ex_blob_type,
-                                use_lease=ex_use_lease)
+                                use_lease=ex_use_lease,
+                                stream=iterator)
 
     def delete_object(self, obj):
         """
@@ -900,9 +891,10 @@ class AzureBlobsStorageDriver(StorageDriver):
 
         return headers
 
-    def _put_object(self, container, object_name, object_size, upload_func,
-                    upload_func_kwargs, file_path=None, extra=None,
-                    verify_hash=True, blob_type=None, use_lease=False):
+    def _put_object(self, container, object_name, object_size,
+                    file_path=None, extra=None,
+                    verify_hash=True, blob_type=None, use_lease=False,
+                    stream=None):
         """
         Control function that does the real job of uploading data to a blob
         """
@@ -917,20 +909,17 @@ class AzureBlobsStorageDriver(StorageDriver):
 
         # Get a lease if required and do the operations
         with AzureBlobLease(self, object_path, use_lease) as lease:
-            if 'lease' in upload_func_kwargs:
-                upload_func_kwargs['lease'] = lease
-
             lease.update_headers(headers)
 
             result_dict = self._upload_object(object_name, content_type,
                                               object_path, headers=headers,
-                                              file_path=file_path)
+                                              file_path=file_path,
+                                              stream=stream)
 
             response = result_dict['response']
             bytes_transferred = result_dict['bytes_transferred']
             data_hash = result_dict['data_hash']
             headers = response.headers
-            response = response.response
 
         if response.status != httplib.CREATED:
             raise LibcloudError(

http://git-wip-us.apache.org/repos/asf/libcloud/blob/6e0040d8/libcloud/test/__init__.py
----------------------------------------------------------------------
diff --git a/libcloud/test/__init__.py b/libcloud/test/__init__.py
index c4db57c..ba911a0 100644
--- a/libcloud/test/__init__.py
+++ b/libcloud/test/__init__.py
@@ -196,7 +196,7 @@ class MockHttp(BaseMockHttpObject):
         self.host = host
         self.port = port
 
-    def request(self, method, url, body=None, headers=None, raw=False):
+    def request(self, method, url, body=None, headers=None, raw=False, stream=False):
         # Find a method we can use for this request
         parsed = urlparse.urlparse(url)
         scheme, netloc, path, params, query, fragment = parsed
@@ -285,7 +285,8 @@ class MockHttpTestCase(MockHttp, unittest.TestCase):
 
 
 class StorageMockHttp(MockHttp):
-    def prepared_request(self, method, url, body=None, headers=None, raw=False):
+    def prepared_request(self, method, url, body=None, headers=None, raw=False,
+                         stream=False):
         pass
 
     def putrequest(self, method, action, skip_host=0, skip_accept_encoding=0):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/6e0040d8/libcloud/test/storage/test_azure_blobs.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_azure_blobs.py b/libcloud/test/storage/test_azure_blobs.py
index 9f42298..356c31d 100644
--- a/libcloud/test/storage/test_azure_blobs.py
+++ b/libcloud/test/storage/test_azure_blobs.py
@@ -19,10 +19,12 @@ import os
 import sys
 import unittest
 import tempfile
+from io import BytesIO
 
 from libcloud.utils.py3 import httplib
 from libcloud.utils.py3 import urlparse
 from libcloud.utils.py3 import parse_qs
+from libcloud.utils.py3 import b
 
 from libcloud.common.types import InvalidCredsError
 from libcloud.common.types import LibcloudError
@@ -839,7 +841,7 @@ class AzureBlobsTests(unittest.TestCase):
                               driver=self.driver)
 
         object_name = 'foo_test_upload'
-        iterator = DummyIterator(data=['2', '3', '5'])
+        iterator = BytesIO(b('345'))
         extra = {'content_type': 'text/plain'}
         obj = self.driver.upload_object_via_stream(container=container,
                                                    object_name=object_name,
@@ -857,7 +859,7 @@ class AzureBlobsTests(unittest.TestCase):
                               driver=self.driver)
 
         object_name = 'foo_test_upload'
-        iterator = DummyIterator(data=['2', '3', '5'])
+        iterator = BytesIO(b('345'))
         extra = {'content_type': 'text/plain'}
         obj = self.driver.upload_object_via_stream(container=container,
                                                    object_name=object_name,
@@ -877,7 +879,7 @@ class AzureBlobsTests(unittest.TestCase):
 
         object_name = 'foo_test_upload'
         blob_size = AZURE_PAGE_CHUNK_SIZE
-        iterator = DummyIterator(data=['1'] * blob_size)
+        iterator = BytesIO(b('1'*blob_size))
         extra = {'content_type': 'text/plain'}
         obj = self.driver.upload_object_via_stream(container=container,
                                                    object_name=object_name,
@@ -897,7 +899,7 @@ class AzureBlobsTests(unittest.TestCase):
 
         object_name = 'foo_test_upload'
         blob_size = AZURE_PAGE_CHUNK_SIZE
-        iterator = DummyIterator(data=['1'] * blob_size)
+        iterator = BytesIO(b('1'*blob_size))
         extra = {'content_type': 'text/plain'}
         obj = self.driver.upload_object_via_stream(container=container,
                                                    object_name=object_name,


Mime
View raw message