Add support for image size in v2 api upload
Some backend stores e.g. RBD, will fail if told to create an image without a valid size (RBD will fail to write to a zero-size image). Here we add support to allow the image size to be provided when doing an upload. The result is that the upload content-length will be set if available either from checking the supplied file object or as provided by user. Closes-Bug: 1220197 Change-Id: Ia1f2ea5680a139750d931591949b3e0058148b4b
This commit is contained in:
@@ -474,6 +474,15 @@ class TestController(testtools.TestCase):
|
||||
image_data)]
|
||||
self.assertEqual(self.api.calls, expect)
|
||||
|
||||
def test_data_upload_w_size(self):
|
||||
image_data = 'CCC'
|
||||
image_id = '606b0e88-7c5a-4d54-b5bb-046105d4de6f'
|
||||
self.controller.upload(image_id, image_data, image_size=3)
|
||||
expect = [('PUT', '/v2/images/%s/file' % image_id,
|
||||
{'Content-Type': 'application/octet-stream'},
|
||||
image_data, 3)]
|
||||
self.assertEqual(self.api.calls, expect)
|
||||
|
||||
def test_data_without_checksum(self):
|
||||
body = self.controller.data('5cc4bebc-db27-11e1-a1eb-080027cbe205',
|
||||
do_checksum=False)
|
||||
|
||||
@@ -221,13 +221,13 @@ class ShellV2Test(testtools.TestCase):
|
||||
self.gc.schemas.get.assert_called_once_with('test')
|
||||
|
||||
def test_image_upload(self):
|
||||
args = self._make_args({'id': 'IMG-01', 'file': 'test'})
|
||||
args = self._make_args({'id': 'IMG-01', 'file': 'test', 'size': 1024})
|
||||
|
||||
with mock.patch.object(self.gc.images, 'upload') as mocked_upload:
|
||||
utils.get_data_file = mock.Mock(return_value='testfile')
|
||||
mocked_upload.return_value = None
|
||||
test_shell.do_image_upload(self.gc, args)
|
||||
mocked_upload.assert_called_once_with('IMG-01', 'testfile')
|
||||
mocked_upload.assert_called_once_with('IMG-01', 'testfile', 1024)
|
||||
|
||||
def test_image_download(self):
|
||||
args = self._make_args(
|
||||
|
||||
Reference in New Issue
Block a user