Fix invalid error message of volume create
When create a volume with image name, the error message return to user is invalid if there are several image share the same name. This change provides a more user-friendly message. Change-Id: Idac6149ce6944986af9716e60738b3cd62434a5a Closes-bug: 1565653
This commit is contained in:
parent
09fa5ab22d
commit
5ab43c81e9
|
@ -277,11 +277,14 @@ class VolumeController(wsgi.Controller):
|
|||
if len(images) > 1:
|
||||
msg = _("Multiple matches found for '%s', use an ID to be more"
|
||||
" specific.") % image_ref
|
||||
raise exc.HTTPConflict(msg)
|
||||
raise exc.HTTPConflict(explanation=msg)
|
||||
for img in images:
|
||||
return img['id']
|
||||
except exc.HTTPConflict:
|
||||
raise
|
||||
except Exception:
|
||||
# Pass and let default not found error handling take care of it
|
||||
# Pass the other exception and let default not found error
|
||||
# handling take care of it
|
||||
pass
|
||||
|
||||
msg = _("Invalid image identifier or unable to "
|
||||
|
|
|
@ -423,6 +423,9 @@ class VolumeApiTest(test.TestCase):
|
|||
|
||||
def test_volume_create_with_image_ref_not_uuid_format(self):
|
||||
self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
|
||||
self.stubs.Set(fake_image._FakeImageService,
|
||||
"detail",
|
||||
stubs.stub_image_service_detail)
|
||||
self.ext_mgr.extensions = {'os-image-create': 'fake'}
|
||||
vol = self._vol_in_request_body(availability_zone="cinder",
|
||||
image_ref="12345")
|
||||
|
@ -435,6 +438,9 @@ class VolumeApiTest(test.TestCase):
|
|||
|
||||
def test_volume_create_with_image_ref_with_empty_string(self):
|
||||
self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
|
||||
self.stubs.Set(fake_image._FakeImageService,
|
||||
"detail",
|
||||
stubs.stub_image_service_detail)
|
||||
self.ext_mgr.extensions = {'os-image-create': 'fake'}
|
||||
vol = self._vol_in_request_body(availability_zone="cinder",
|
||||
image_ref="")
|
||||
|
@ -477,6 +483,9 @@ class VolumeApiTest(test.TestCase):
|
|||
|
||||
def test_volume_create_with_image_id_not_uuid_format(self):
|
||||
self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
|
||||
self.stubs.Set(fake_image._FakeImageService,
|
||||
"detail",
|
||||
stubs.stub_image_service_detail)
|
||||
self.ext_mgr.extensions = {'os-image-create': 'fake'}
|
||||
vol = self._vol_in_request_body(availability_zone="cinder",
|
||||
image_id="12345")
|
||||
|
@ -489,6 +498,9 @@ class VolumeApiTest(test.TestCase):
|
|||
|
||||
def test_volume_create_with_image_id_with_empty_string(self):
|
||||
self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
|
||||
self.stubs.Set(fake_image._FakeImageService,
|
||||
"detail",
|
||||
stubs.stub_image_service_detail)
|
||||
self.ext_mgr.extensions = {'os-image-create': 'fake'}
|
||||
vol = self._vol_in_request_body(availability_zone="cinder",
|
||||
image_id="")
|
||||
|
@ -533,7 +545,7 @@ class VolumeApiTest(test.TestCase):
|
|||
image_ref=test_id)
|
||||
body = {"volume": vol}
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes')
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.assertRaises(webob.exc.HTTPConflict,
|
||||
self.controller.create,
|
||||
req,
|
||||
body)
|
||||
|
|
Loading…
Reference in New Issue