diff --git a/glance_store/_drivers/vmware_datastore.py b/glance_store/_drivers/vmware_datastore.py index 0c3c4d8..a996328 100644 --- a/glance_store/_drivers/vmware_datastore.py +++ b/glance_store/_drivers/vmware_datastore.py @@ -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) diff --git a/glance_store/tests/unit/test_vmware_store.py b/glance_store/tests/unit/test_vmware_store.py index 569309d..c77b9fd 100644 --- a/glance_store/tests/unit/test_vmware_store.py +++ b/glance_store/tests/unit/test_vmware_store.py @@ -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)