You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2017/05/05 11:46:36 UTC

[17/20] libcloud git commit: Fix raise in s3.upload_object_via_stream

Fix raise in s3.upload_object_via_stream

Since libcloud 2.0, it was raising a generic
libcloud.common.types.LibcloudError on all exceptions, but we now raise
the correct exception. This also removes a comment that is probably
outdated.

Closes #1055


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

Branch: refs/heads/trunk
Commit: 6e4c2e15e8dcbc7b7c5c9a895f7b78f11fd3ba6b
Parents: 6c0b17f
Author: Quentin Pradet <qu...@clustree.com>
Authored: Fri May 5 15:21:43 2017 +0400
Committer: Anthony Shaw <an...@apache.org>
Committed: Fri May 5 21:39:02 2017 +1000

----------------------------------------------------------------------
 libcloud/storage/base.py                     |  3 +--
 libcloud/storage/drivers/oss.py              |  4 ----
 libcloud/storage/drivers/s3.py               |  4 ----
 libcloud/test/storage/test_google_storage.py | 19 +++++++++++++++++++
 4 files changed, 20 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/6e4c2e15/libcloud/storage/base.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/base.py b/libcloud/storage/base.py
index 6db1d4d..b3de63d 100644
--- a/libcloud/storage/base.py
+++ b/libcloud/storage/base.py
@@ -631,8 +631,7 @@ class StorageDriver(BaseDriver):
                     self._get_hash_function())
 
         if not response.success():
-            raise LibcloudError(
-                value='Object upload failed, Perhaps a timeout?', driver=self)
+            response.parse_error()
 
         if upload_func:
             upload_func(**upload_func_kwargs)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/6e4c2e15/libcloud/storage/drivers/oss.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/oss.py b/libcloud/storage/drivers/oss.py
index d374413..820b8b3 100644
--- a/libcloud/storage/drivers/oss.py
+++ b/libcloud/storage/drivers/oss.py
@@ -610,10 +610,6 @@ class OSSStorageDriver(StorageDriver):
         if query_args:
             request_path = '?'.join((request_path, query_args))
 
-        # TODO: Let the underlying exceptions bubble up and capture the SIGPIPE
-        # here.
-        # SIGPIPE is thrown if the provided container does not exist or the
-        # user does not have correct permission
         result_dict = self._upload_object(
             object_name=object_name, content_type=content_type,
             request_path=request_path, request_method=method,

http://git-wip-us.apache.org/repos/asf/libcloud/blob/6e4c2e15/libcloud/storage/drivers/s3.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/s3.py b/libcloud/storage/drivers/s3.py
index 826ed77..f9f4b6c 100644
--- a/libcloud/storage/drivers/s3.py
+++ b/libcloud/storage/drivers/s3.py
@@ -805,10 +805,6 @@ class BaseS3StorageDriver(StorageDriver):
         if query_args:
             request_path = '?'.join((request_path, query_args))
 
-        # TODO: Let the underlying exceptions bubble up and capture the SIGPIPE
-        # here.
-        # SIGPIPE is thrown if the provided container does not exist or the
-        # user does not have correct permission
         result_dict = self._upload_object(
             object_name=object_name, content_type=content_type,
             request_path=request_path, request_method=method,

http://git-wip-us.apache.org/repos/asf/libcloud/blob/6e4c2e15/libcloud/test/storage/test_google_storage.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_google_storage.py b/libcloud/test/storage/test_google_storage.py
index fa7a5e3..19eb7df 100644
--- a/libcloud/test/storage/test_google_storage.py
+++ b/libcloud/test/storage/test_google_storage.py
@@ -20,9 +20,14 @@ import re
 import sys
 import unittest
 
+from io import BytesIO
+
 import email.utils
+import pytest
 
 from libcloud.common.google import GoogleAuthType
+from libcloud.common.types import InvalidCredsError
+from libcloud.storage.base import Container
 from libcloud.storage.drivers import google_storage
 from libcloud.test import StorageMockHttp
 from libcloud.test.common.test_google import GoogleTestCase
@@ -70,6 +75,12 @@ class GoogleStorageMockHttp(S3MockHttp):
 
         return httplib.OK, body, headers, httplib.responses[httplib.OK]
 
+    def _container_path_UNAUTHORIZED(self, method, url, body, headers):
+        return (httplib.UNAUTHORIZED,
+                '',
+                self.base_headers,
+                httplib.responses[httplib.OK])
+
 
 class GoogleStorageJSONMockHttp(StorageMockHttp):
     """
@@ -470,5 +481,13 @@ class GoogleStorageTests(S3Tests, GoogleTestCase):
             url, method='POST',
             data=json.dumps({'role': 'OWNER', 'entity': 'user-foo@foo.com'}))
 
+    def test_invalid_credentials_on_upload(self):
+        self.mock_response_klass.type = 'UNAUTHORIZED'
+        container = Container(name='container', driver=self.driver, extra={})
+        with pytest.raises(InvalidCredsError):
+            self.driver.upload_object_via_stream(
+                BytesIO(b' '), container, 'path')
+
+
 if __name__ == '__main__':
     sys.exit(unittest.main())