Fix multiple image imports if boolean input passed as string

If user passes 'all_stores_must_succeed' as 'false' in copy-image, multiple
image imports request body then it does not work as expected. Expected is
to skip the failure store and continue copying/importing image to other
stores but instead it stops execution of task and revert it and deletes
the image data copied/imported to previois stores.

Raised 400 BadRequest if 'all_stores_must_succeed' and 'all_stores' are
other thatn than boolean values.

NOTE: Documentation clearly suggest that we expect boolean values for
'all_stores_must_succeed' and 'all_stores'

Closes-Bug: #1871588
Change-Id: I5118489284fea007f8f29663581221b07a575cf3
This commit is contained in:
Abhishek Kekane 2020-04-08 09:47:44 +00:00
parent 3b990c9c12
commit 55b7c86ecf
2 changed files with 37 additions and 0 deletions

View File

@ -1115,6 +1115,17 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer):
msg = _("Unknown import method name '%s'.") % method_name
raise webob.exc.HTTPBadRequest(explanation=msg)
# Validate 'all_stores_must_succeed' and 'all_stores'
all_stores_must_succeed = body.get('all_stores_must_succeed', True)
if not isinstance(all_stores_must_succeed, bool):
msg = (_("'all_stores_must_succeed' must be boolean value only"))
raise webob.exc.HTTPBadRequest(explanation=msg)
all_stores = body.get('all_stores', False)
if not isinstance(all_stores, bool):
msg = (_("'all_stores' must be boolean value only"))
raise webob.exc.HTTPBadRequest(explanation=msg)
def import_image(self, request):
body = self._get_request_body(request)
self._validate_import_body(body)

View File

@ -4127,6 +4127,32 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
self.deserializer.import_image,
request)
def test_import_image_with_all_stores_not_boolean(self):
request = unit_test_utils.get_fake_request()
import_body = {
'method': {
'name': 'glance-direct'
},
'all_stores': "true"
}
request.body = jsonutils.dump_as_bytes(import_body)
self.assertRaises(webob.exc.HTTPBadRequest,
self.deserializer.import_image,
request)
def test_import_image_with_allow_failure_not_boolean(self):
request = unit_test_utils.get_fake_request()
import_body = {
'method': {
'name': 'glance-direct'
},
'all_stores_must_succeed': "true"
}
request.body = jsonutils.dump_as_bytes(import_body)
self.assertRaises(webob.exc.HTTPBadRequest,
self.deserializer.import_image,
request)
def _get_request_for_method(self, method_name):
request = unit_test_utils.get_fake_request()
import_body = {