Browse Source

Merge "Fix multiple image imports if boolean input passed as string"

tags/20.0.0.0b3
Zuul 3 months ago
committed by Gerrit Code Review
parent
commit
b66342a3d8
2 changed files with 37 additions and 0 deletions
  1. +11
    -0
      glance/api/v2/images.py
  2. +26
    -0
      glance/tests/unit/v2/test_images_resource.py

+ 11
- 0
glance/api/v2/images.py 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)


+ 26
- 0
glance/tests/unit/v2/test_images_resource.py 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 = {


Loading…
Cancel
Save