When call create volume api with image id "", it will create an empty
volume.
But when create volume with snapshot id "" or srv volume "", it will
return an 404 error.
So it should create volume fail when call create volume api with image id
"".
Change-Id: If2c7b061753bbbd172a09d35b343e73e90a1b7b4
Closes-Bug: #
1302609
if self.ext_mgr.is_loaded('os-image-create'):
# NOTE(jdg): misleading name "imageRef" as it's an image-id
image_href = volume.get('imageRef')
- if image_href:
+ if image_href is not None:
image_uuid = self._image_uuid_from_href(image_href)
kwargs['image_id'] = image_uuid
if self.ext_mgr.is_loaded('os-image-create'):
image_href = volume.get('imageRef')
- if image_href:
+ if image_href is not None:
image_uuid = self._image_uuid_from_href(image_href)
kwargs['image_id'] = image_uuid
req,
body)
+ def test_volume_create_with_image_id_with_empty_string(self):
+ self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
+ self.ext_mgr.extensions = {'os-image-create': 'fake'}
+ vol = {"size": 1,
+ "display_name": "Volume Test Name",
+ "display_description": "Volume Test Desc",
+ "availability_zone": "cinder",
+ "imageRef": ''}
+ body = {"volume": vol}
+ req = fakes.HTTPRequest.blank('/v1/volumes')
+ self.assertRaises(webob.exc.HTTPBadRequest,
+ self.controller.create,
+ req,
+ body)
+
def test_volume_update(self):
self.stubs.Set(db, 'volume_get', stubs.stub_volume_get_db)
self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
req,
body)
+ def test_volume_create_with_image_id_with_empty_string(self):
+ self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
+ self.ext_mgr.extensions = {'os-image-create': 'fake'}
+ vol = {"size": 1,
+ "display_name": "Volume Test Name",
+ "display_description": "Volume Test Desc",
+ "availability_zone": "cinder",
+ "imageRef": ''}
+ body = {"volume": vol}
+ req = fakes.HTTPRequest.blank('/v2/volumes')
+ self.assertRaises(webob.exc.HTTPBadRequest,
+ self.controller.create,
+ req,
+ body)
+
def test_volume_update(self):
self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
"""Checks image existence and validates that the image metadata."""
# Check image existence
- if not image_id:
+ if image_id is None:
return
# NOTE(harlowja): this should raise an error if the image does not