Add strict Boolean checking for qos delete
There is no strict boolean checking for the parameter "force" of API /qos-specs. This patch adds a strict checking for it to prevent invalid value, and adds a test case for this change as well. Closes-Bug: #1594261 Change-Id: I59c24454a885310d463690cd08d0b39a0624163e
This commit is contained in:
parent
46f7142313
commit
91540227e3
|
@ -16,7 +16,6 @@
|
|||
"""The QoS specs extension"""
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import strutils
|
||||
import six
|
||||
import webob
|
||||
|
||||
|
@ -170,10 +169,8 @@ class QoSSpecsController(wsgi.Controller):
|
|||
context = req.environ['cinder.context']
|
||||
authorize(context)
|
||||
|
||||
force = req.params.get('force', None)
|
||||
|
||||
# Convert string to bool type in strict manner
|
||||
force = strutils.bool_from_string(force)
|
||||
force = utils.get_bool_param('force', req.params)
|
||||
LOG.debug("Delete qos_spec: %(id)s, force: %(force)s",
|
||||
{'id': id, 'force': force})
|
||||
|
||||
|
|
|
@ -323,6 +323,16 @@ class QoSSpecManageApiTest(test.TestCase):
|
|||
req, fake.IN_USE_ID)
|
||||
self.assertEqual(1, notifier.get_notification_count())
|
||||
|
||||
def test_qos_specs_delete_with_invalid_force(self):
|
||||
invalid_force = "invalid_bool"
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v2/%s/qos-specs/%s/delete_keys?force=%s' %
|
||||
(fake.PROJECT_ID, fake.QOS_SPEC_ID, invalid_force))
|
||||
|
||||
self.assertRaises(exception.InvalidParameterValue,
|
||||
self.controller.delete,
|
||||
req, fake.QOS_SPEC_ID)
|
||||
|
||||
@mock.patch('cinder.volume.qos_specs.delete_keys',
|
||||
side_effect=return_qos_specs_delete_keys)
|
||||
def test_qos_specs_delete_keys(self, mock_qos_delete_keys):
|
||||
|
|
Loading…
Reference in New Issue