Fix header passed to requests
The VMware glance store is failing to upload images with requests>=2.11.0 since headers passed to requests should be string or bytes. The Content-Length header is currently being passed as int. Closes-Bug: #1614307 Change-Id: I7a85ed1e2de1d5662f949bfa5307ed3c35ebe558
This commit is contained in:
parent
ab3dfc2802
commit
6263547a04
@ -558,7 +558,7 @@ class Store(glance_store.Store):
|
||||
image_file = _Reader(image_file, verifier)
|
||||
headers = {}
|
||||
if image_size > 0:
|
||||
headers.update({'Content-Length': image_size})
|
||||
headers.update({'Content-Length': six.text_type(image_size)})
|
||||
data = image_file
|
||||
else:
|
||||
data = utils.chunkiter(image_file, CHUNKSIZE)
|
||||
|
@ -131,10 +131,12 @@ class TestStore(base.StoreBaseTest,
|
||||
HttpConn.return_value = utils.fake_response(status_code=404)
|
||||
self.assertRaises(exceptions.NotFound, self.store.get, loc)
|
||||
|
||||
@mock.patch.object(vm_store.Store, '_build_vim_cookie_header')
|
||||
@mock.patch.object(vm_store.Store, 'select_datastore')
|
||||
@mock.patch.object(vm_store._Reader, 'size')
|
||||
@mock.patch.object(api, 'VMwareAPISession')
|
||||
def test_add(self, fake_api_session, fake_size, fake_select_datastore):
|
||||
def test_add(self, fake_api_session, fake_size, fake_select_datastore,
|
||||
fake_cookie):
|
||||
"""Test that we can add an image via the VMware backend."""
|
||||
fake_select_datastore.return_value = self.store.datastores[0][0]
|
||||
expected_image_id = str(uuid.uuid4())
|
||||
@ -143,6 +145,10 @@ class TestStore(base.StoreBaseTest,
|
||||
hash_code = hashlib.md5(expected_contents)
|
||||
expected_checksum = hash_code.hexdigest()
|
||||
fake_size.__get__ = mock.Mock(return_value=expected_size)
|
||||
expected_cookie = 'vmware_soap_session=fake-uuid'
|
||||
fake_cookie.return_value = expected_cookie
|
||||
expected_headers = {'Content-Length': six.text_type(expected_size),
|
||||
'Cookie': expected_cookie}
|
||||
with mock.patch('hashlib.md5') as md5:
|
||||
md5.return_value = hash_code
|
||||
expected_location = format_location(
|
||||
@ -156,6 +162,8 @@ class TestStore(base.StoreBaseTest,
|
||||
location, size, checksum, _ = self.store.add(expected_image_id,
|
||||
image,
|
||||
expected_size)
|
||||
_, kwargs = HttpConn.call_args
|
||||
self.assertEqual(expected_headers, kwargs['headers'])
|
||||
self.assertEqual(utils.sort_url_by_qs_keys(expected_location),
|
||||
utils.sort_url_by_qs_keys(location))
|
||||
self.assertEqual(expected_size, size)
|
||||
|
Loading…
Reference in New Issue
Block a user