You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2017/09/19 19:00:56 UTC

[1/7] libcloud git commit: Fix Azure blobs driver, make sure Content-Length header value is a string and not a number.

Repository: libcloud
Updated Branches:
  refs/heads/trunk 59b44a0d1 -> a594266de


Fix Azure blobs driver, make sure Content-Length header value is a
string and not a number.

Part of LIBCLOUD-945

Closes #1111


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

Branch: refs/heads/trunk
Commit: 28a5590425aefc2983d40b71b4372e3340ceeecf
Parents: 59b44a0
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Tue Sep 19 17:27:27 2017 +0200
Committer: Tomaz Muraus <to...@tomaz.me>
Committed: Tue Sep 19 21:00:02 2017 +0200

----------------------------------------------------------------------
 libcloud/storage/drivers/azure_blobs.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/28a55904/libcloud/storage/drivers/azure_blobs.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/azure_blobs.py b/libcloud/storage/drivers/azure_blobs.py
index e1bb722..82ee03a 100644
--- a/libcloud/storage/drivers/azure_blobs.py
+++ b/libcloud/storage/drivers/azure_blobs.py
@@ -634,7 +634,7 @@ class AzureBlobsStorageDriver(StorageDriver):
             chunk_hash = base64.b64encode(b(chunk_hash.digest()))
 
             headers['Content-MD5'] = chunk_hash.decode('utf-8')
-            headers['Content-Length'] = content_length
+            headers['Content-Length'] = str(content_length)
 
             if blob_type == 'BlockBlob':
                 # Block id can be any unique string that is base64 encoded
@@ -861,10 +861,10 @@ class AzureBlobsStorageDriver(StorageDriver):
         self._update_metadata(headers, meta_data)
 
         if object_size is not None:
-            headers['Content-Length'] = object_size
+            headers['Content-Length'] = str(object_size)
 
         if blob_type == 'PageBlob':
-            headers['Content-Length'] = 0
+            headers['Content-Length'] = str('0')
             headers['x-ms-blob-content-length'] = object_size
 
         return headers


[6/7] libcloud git commit: Also make sure we normalize all the header values in the connection mock classes.

Posted by to...@apache.org.
Also make sure we normalize all the header values in the connection
mock classes.


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

Branch: refs/heads/trunk
Commit: e954cdffb424b86ed61c18ddabd7e3d74b4c1dd6
Parents: 1c33d58
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Tue Sep 19 17:47:52 2017 +0200
Committer: Tomaz Muraus <to...@tomaz.me>
Committed: Tue Sep 19 21:00:18 2017 +0200

----------------------------------------------------------------------
 libcloud/test/__init__.py | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/e954cdff/libcloud/test/__init__.py
----------------------------------------------------------------------
diff --git a/libcloud/test/__init__.py b/libcloud/test/__init__.py
index 6691766..645105e 100644
--- a/libcloud/test/__init__.py
+++ b/libcloud/test/__init__.py
@@ -133,6 +133,7 @@ class MockHttp(LibcloudConnection):
         return meth(method, url, body, headers)
 
     def request(self, method, url, body=None, headers=None, raw=False, stream=False):
+        headers = self._normalize_headers(headers=headers)
         r_status, r_body, r_headers, r_reason = self._get_request(method, url, body, headers)
         if r_body is None:
             r_body = ''
@@ -153,6 +154,7 @@ class MockHttp(LibcloudConnection):
 
     def prepared_request(self, method, url, body=None,
                          headers=None, raw=False, stream=False):
+        headers = self._normalize_headers(headers=headers)
         r_status, r_body, r_headers, r_reason = self._get_request(method, url, body, headers)
 
         with requests_mock.mock() as m:


[5/7] libcloud git commit: Move functionality for normalizing header values to a utility method.

Posted by to...@apache.org.
Move functionality for normalizing header values to a utility method.


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

Branch: refs/heads/trunk
Commit: 1c33d584f622c2f97560461f8bad304f83c3e346
Parents: cf88425
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Tue Sep 19 17:39:01 2017 +0200
Committer: Tomaz Muraus <to...@tomaz.me>
Committed: Tue Sep 19 21:00:18 2017 +0200

----------------------------------------------------------------------
 libcloud/http.py | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/1c33d584/libcloud/http.py
----------------------------------------------------------------------
diff --git a/libcloud/http.py b/libcloud/http.py
index 8f41124..567a2a2 100644
--- a/libcloud/http.py
+++ b/libcloud/http.py
@@ -201,10 +201,8 @@ class LibcloudConnection(LibcloudBaseConnection):
     def request(self, method, url, body=None, headers=None, raw=False,
                 stream=False):
         url = urlparse.urljoin(self.host, url)
-        # all headers should be strings
-        for header, value in headers.items():
-            if isinstance(headers[header], int):
-                headers[header] = str(value)
+        headers = self._normalize_headers(headers=headers)
+
         self.response = self.session.request(
             method=method.lower(),
             url=url,
@@ -217,10 +215,8 @@ class LibcloudConnection(LibcloudBaseConnection):
 
     def prepared_request(self, method, url, body=None,
                          headers=None, raw=False, stream=False):
-        # all headers should be strings
-        for header, value in headers.items():
-            if isinstance(headers[header], int):
-                headers[header] = str(value)
+        headers = self._normalize_headers(headers=headers)
+
         req = requests.Request(method, ''.join([self.host, url]),
                                data=body, headers=headers)
 
@@ -262,6 +258,16 @@ class LibcloudConnection(LibcloudBaseConnection):
         # return connection back to pool
         self.response.close()
 
+    def _normalize_headers(self, headers):
+        headers = headers or {}
+
+        # all headers should be strings
+        for key, value in headers.items():
+            if isinstance(value, (int, float)):
+                headers[key] = str(value)
+
+        return headers
+
 
 class HttpLibResponseProxy(object):
     """


[4/7] libcloud git commit: Add changelog entry.

Posted by to...@apache.org.
Add changelog entry.


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

Branch: refs/heads/trunk
Commit: 90a20bbeaeb1bc72262ad3a0e0906d627ba36f31
Parents: e954cdf
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Tue Sep 19 19:10:53 2017 +0200
Committer: Tomaz Muraus <to...@tomaz.me>
Committed: Tue Sep 19 21:00:18 2017 +0200

----------------------------------------------------------------------
 CHANGES.rst | 9 +++++++++
 1 file changed, 9 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/90a20bbe/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 1df56dd..bbabae4 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -22,6 +22,15 @@ Compute
   manner to finish faster.
   [Tomaz Muraus]
 
+Tests
+~~~~~
+
+- Make sure we normalize header values and cast all the numbers to string in
+  base connection classes used by tests. (LIBCLOUD-945, GITHUB-1111)
+
+  Reported by Erich Eckner.
+  [Tomaz Muraus]
+
 Changes in Apache Libcloud 2.2.0
 --------------------------------
 


[7/7] libcloud git commit: Only run code codecov on travis.

Posted by to...@apache.org.
Only run code codecov on travis.


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

Branch: refs/heads/trunk
Commit: a594266de5aa86e51567ff12de47c7652db8ef4a
Parents: 1ff65ab
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Tue Sep 19 20:51:52 2017 +0200
Committer: Tomaz Muraus <to...@tomaz.me>
Committed: Tue Sep 19 21:00:19 2017 +0200

----------------------------------------------------------------------
 .travis.yml | 2 +-
 tox.ini     | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/a594266d/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index 8109850..fe62c3e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -31,7 +31,7 @@ matrix:
       before_script: TOX_ENV=pylint
     - env: ENV=coverage
       python: 2.7
-      before_script: TOX_ENV=coverage
+      before_script: TOX_ENV=coverage-travis
     - env: ENV=docs
       python: 3.5
       before_script: TOX_ENV=docs-travis

http://git-wip-us.apache.org/repos/asf/libcloud/blob/a594266d/tox.ini
----------------------------------------------------------------------
diff --git a/tox.ini b/tox.ini
index f33912e..5355223 100644
--- a/tox.ini
+++ b/tox.ini
@@ -91,6 +91,13 @@ deps = -r{toxinidir}/integration/requirements.txt
 commands = python -m integration
 
 [testenv:coverage]
+deps =
+    -r{toxinidir}/requirements-tests.txt
+set-env =
+commands = cp libcloud/test/secrets.py-dist libcloud/test/secrets.py
+           coverage run --source=libcloud setup.py test
+
+[testenv:coverage-travis]
 passenv = TOXENV CI TRAVIS TRAVIS_*
 deps =
     -r{toxinidir}/requirements-tests.txt


[2/7] libcloud git commit: Fix typo.

Posted by to...@apache.org.
Fix typo.


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

Branch: refs/heads/trunk
Commit: 1ff65abf097512635547913b2eb8c3cdb8f342e5
Parents: 90a20bb
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Tue Sep 19 19:13:10 2017 +0200
Committer: Tomaz Muraus <to...@tomaz.me>
Committed: Tue Sep 19 21:00:18 2017 +0200

----------------------------------------------------------------------
 CHANGES.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/1ff65abf/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index bbabae4..79f9eff 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -25,7 +25,7 @@ Compute
 Tests
 ~~~~~
 
-- Make sure we normalize header values and cast all the numbers to string in
+- Make sure we normalize header values and cast all the numbers to strings in
   base connection classes used by tests. (LIBCLOUD-945, GITHUB-1111)
 
   Reported by Erich Eckner.


[3/7] libcloud git commit: Add test cases for it.

Posted by to...@apache.org.
Add test cases for it.

Part of LIBCLOUD-745.


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

Branch: refs/heads/trunk
Commit: cf884251d98f7a67a5b35055caa4108500dbc654
Parents: 28a5590
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Tue Sep 19 17:28:08 2017 +0200
Committer: Tomaz Muraus <to...@tomaz.me>
Committed: Tue Sep 19 21:00:18 2017 +0200

----------------------------------------------------------------------
 libcloud/test/storage/test_azure_blobs.py | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/cf884251/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 eb12c0d..95ab3f1 100644
--- a/libcloud/test/storage/test_azure_blobs.py
+++ b/libcloud/test/storage/test_azure_blobs.py
@@ -17,7 +17,6 @@ from __future__ import with_statement
 
 import os
 import sys
-import unittest
 import tempfile
 from io import BytesIO
 
@@ -25,6 +24,7 @@ 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.utils.py3 import basestring
 
 from libcloud.common.types import InvalidCredsError
 from libcloud.common.types import LibcloudError
@@ -39,12 +39,13 @@ from libcloud.storage.drivers.azure_blobs import AzureBlobsStorageDriver
 from libcloud.storage.drivers.azure_blobs import AZURE_BLOCK_MAX_SIZE
 from libcloud.storage.drivers.azure_blobs import AZURE_PAGE_CHUNK_SIZE
 
+from libcloud.test import unittest
 from libcloud.test import MockHttp, generate_random_data  # pylint: disable-msg=E0611
 from libcloud.test.file_fixtures import StorageFileFixtures  # pylint: disable-msg=E0611
 from libcloud.test.secrets import STORAGE_AZURE_BLOBS_PARAMS
 
 
-class AzureBlobsMockHttp(MockHttp):
+class AzureBlobsMockHttp(MockHttp, unittest.TestCase):
 
     fixtures = StorageFileFixtures('azure_blobs')
     base_headers = {}
@@ -247,6 +248,8 @@ class AzureBlobsMockHttp(MockHttp):
 
     def _foo_bar_container_foo_test_upload(self, method, url, body, headers):
         # test_upload_object_success
+        self._assert_content_length_header_is_string(headers=headers)
+
         body = ''
         headers = {}
         headers['etag'] = '0x8CFB877BB56A6FB'
@@ -259,6 +262,8 @@ class AzureBlobsMockHttp(MockHttp):
     def _foo_bar_container_foo_test_upload_block(self, method, url,
                                                  body, headers):
         # test_upload_object_success
+        self._assert_content_length_header_is_string(headers=headers)
+
         body = ''
         headers = {}
         headers['etag'] = '0x8CFB877BB56A6FB'
@@ -281,6 +286,8 @@ class AzureBlobsMockHttp(MockHttp):
     def _foo_bar_container_foo_test_upload_blocklist(self, method, url,
                                                      body, headers):
         # test_upload_object_success
+        self._assert_content_length_header_is_string(headers=headers)
+
         body = ''
         headers = {}
         headers['etag'] = '0x8CFB877BB56A6FB'
@@ -294,6 +301,8 @@ class AzureBlobsMockHttp(MockHttp):
     def _foo_bar_container_foo_test_upload_lease(self, method, url,
                                                  body, headers):
         # test_upload_object_success
+        self._assert_content_length_header_is_string(headers=headers)
+
         action = headers['x-ms-lease-action']
         rheaders = {'x-ms-lease-id': 'someleaseid'}
         body = ''
@@ -318,12 +327,14 @@ class AzureBlobsMockHttp(MockHttp):
 
     def _foo_bar_container_foo_test_upload_INVALID_HASH(self, method, url,
                                                         body, headers):
+        # test_upload_object_invalid_hash1
+        self._assert_content_length_header_is_string(headers=headers)
+
         body = ''
         headers = {}
         headers['etag'] = '0x8CFB877BB56A6FB'
         headers['content-md5'] = 'd4fe4c9829f7ca1cc89db7ad670d2bbd'
 
-        # test_upload_object_invalid_hash1
         return (httplib.CREATED,
                 body,
                 headers,
@@ -331,6 +342,8 @@ class AzureBlobsMockHttp(MockHttp):
 
     def _foo_bar_container_foo_bar_object(self, method, url, body, headers):
         # test_upload_object_invalid_file_size
+        self._assert_content_length_header_is_string(headers=headers)
+
         body = generate_random_data(1000)
         return (httplib.OK,
                 body,
@@ -340,12 +353,18 @@ class AzureBlobsMockHttp(MockHttp):
     def _foo_bar_container_foo_bar_object_INVALID_SIZE(self, method, url,
                                                        body, headers):
         # test_upload_object_invalid_file_size
+        self._assert_content_length_header_is_string(headers=headers)
+
         body = ''
         return (httplib.OK,
                 body,
                 headers,
                 httplib.responses[httplib.OK])
 
+    def _assert_content_length_header_is_string(self, headers):
+        if 'Content-Length' in headers:
+            self.assertTrue(isinstance(headers['Content-Length'], basestring))
+
 
 class AzureBlobsTests(unittest.TestCase):
     driver_type = AzureBlobsStorageDriver