image_uuid = None
if self.ext_mgr.is_loaded('os-image-create'):
image_href = volume.get('imageRef')
- if snapshot_id and image_href:
- msg = _("Snapshot and image cannot be specified together.")
- raise exc.HTTPBadRequest(explanation=msg)
if image_href:
image_uuid = self._image_uuid_from_href(image_href)
kwargs['image_id'] = image_uuid
image_uuid = None
if self.ext_mgr.is_loaded('os-image-create'):
image_href = volume.get('imageRef')
- if snapshot_id and image_href:
- msg = _("Snapshot and image cannot be specified together.")
- raise exc.HTTPBadRequest(explanation=msg)
if image_href:
image_uuid = self._image_uuid_from_href(image_href)
kwargs['image_id'] = image_uuid
res_dict = self.controller.create(req, body)
self.assertEqual(res_dict, expected)
- def test_volume_create_with_image_id_and_snapshot_id(self):
- self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
- self.stubs.Set(volume_api.API, "get_snapshot", stub_snapshot_get)
- 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": 'c905cedb-7281-47e4-8a62-f26bc5fc4c77',
- "source_volid": None,
- "snapshot_id": TEST_SNAPSHOT_UUID}
- body = {"volume": vol}
- req = fakes.HTTPRequest.blank('/v1/volumes')
- self.assertRaises(webob.exc.HTTPBadRequest,
- self.controller.create,
- req,
- body)
-
def test_volume_create_with_image_id_is_integer(self):
self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
self.ext_mgr.extensions = {'os-image-create': 'fake'}
res_dict = self.controller.create(req, body)
self.assertEqual(res_dict, expected)
- def test_volume_create_with_image_id_and_snapshot_id(self):
- self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
- self.stubs.Set(volume_api.API, "get_snapshot", stub_snapshot_get)
- self.ext_mgr.extensions = {'os-image-create': 'fake'}
- vol = {
- "size": '1',
- "name": "Volume Test Name",
- "description": "Volume Test Desc",
- "availability_zone": "cinder",
- "imageRef": 'c905cedb-7281-47e4-8a62-f26bc5fc4c77',
- "snapshot_id": TEST_SNAPSHOT_UUID
- }
- body = {"volume": vol}
- req = fakes.HTTPRequest.blank('/v2/volumes')
- self.assertRaises(webob.exc.HTTPBadRequest,
- self.controller.create,
- req,
- body)
-
def test_volume_create_with_image_id_is_integer(self):
self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
self.ext_mgr.extensions = {'os-image-create': 'fake'}
self.volume.delete_snapshot(self.context, snapshot_id)
self.volume.delete_volume(self.context, volume_src['id'])
+ def test_create_volume_with_invalid_exclusive_options(self):
+ """Test volume create with multiple exclusive options fails."""
+ volume_api = cinder.volume.api.API()
+ self.assertRaises(exception.InvalidInput,
+ volume_api.create,
+ self.context,
+ 1,
+ 'name',
+ 'description',
+ snapshot='fake_id',
+ image_id='fake_id',
+ source_volume='fake_id')
+
def test_too_big_volume(self):
"""Ensure failure if a too large of a volume is requested."""
# FIXME(vish): validation needs to move into the data layer in
image_id=None, volume_type=None, metadata=None,
availability_zone=None, source_volume=None):
- if ((snapshot is not None) and (source_volume is not None)):
- msg = (_("May specify either snapshot, "
- "or src volume but not both!"))
+ exclusive_options = (snapshot, image_id, source_volume)
+ exclusive_options_set = sum(1 for option in
+ exclusive_options if option is not None)
+ if exclusive_options_set > 1:
+ msg = (_("May specify only one of snapshot, imageRef "
+ "or source volume"))
raise exception.InvalidInput(reason=msg)
check_policy(context, 'create')