Fixes bug #
1014689
* Add is_valid_boolstr function in utils.py
* Add force parameter check in SnapshotsController.create()
* Add unittest for invalid force parameter.
Change-Id: I0f64326f33eb4fad1cf384bd825f56f09e935f40
from cinder import exception
from cinder import flags
from cinder.openstack.common import log as logging
+from cinder import utils
from cinder import volume
msg = _("Create snapshot from volume %s")
LOG.audit(msg, volume_id, context=context)
- if force:
+ if not utils.is_valid_boolstr(force):
+ msg = _("Invalid value '%s' for force. ") % force
+ raise exception.InvalidParameterValue(err=msg)
+
+ if utils.bool_from_str(force):
new_snapshot = self.volume_api.create_snapshot_force(context,
volume,
snapshot.get('display_name'),
self.assertEqual(resp_dict['snapshot']['display_description'],
snapshot['display_description'])
+ snapshot = {"volume_id": "12",
+ "force": "**&&^^%%$$##@@",
+ "display_name": "Snapshot Test Name",
+ "display_description": "Snapshot Test Desc"}
+ body = dict(snapshot=snapshot)
+ req = fakes.HTTPRequest.blank('/v1/snapshots')
+ self.assertRaises(exception.InvalidParameterValue,
+ self.controller.create,
+ req,
+ body)
+
def test_snapshot_update(self):
self.stubs.Set(volume.api.API, "get_snapshot", stub_snapshot_get)
self.stubs.Set(volume.api.API, "update_snapshot",
return val.lower() == 'true'
+def is_valid_boolstr(val):
+ """Check if the provided string is a valid bool string or not. """
+ val = str(val).lower()
+ return val == 'true' or val == 'false' or \
+ val == 'yes' or val == 'no' or \
+ val == 'y' or val == 'n' or \
+ val == '1' or val == '0'
+
+
def is_valid_ipv4(address):
"""valid the address strictly as per format xxx.xxx.xxx.xxx.
where xxx is a value between 0 and 255.