"""The consistencygroups api."""
from oslo_log import log as logging
+from oslo_utils import strutils
import webob
from webob import exc
context = req.environ['cinder.context']
force = False
if body:
+ if not self.is_valid_body(body, 'consistencygroup'):
+ msg = _("Missing required element 'consistencygroup' in "
+ "request body.")
+ raise exc.HTTPBadRequest(explanation=msg)
+
cg_body = body['consistencygroup']
- force = cg_body.get('force', False)
+ try:
+ force = strutils.bool_from_string(cg_body.get('force', False),
+ strict=True)
+ except ValueError:
+ msg = _("Invalid value '%s' for force.") % force
+ raise exc.HTTPBadRequest(explanation=msg)
LOG.info(_LI('Delete consistency group with id: %s'), id,
context=context)
cg['id'])
self.assertEqual(cg['status'], 'deleted')
+ def test_delete_consistencygroup_with_invalid_body(self):
+ consistencygroup_id = self._create_consistencygroup(status='available')
+ req = webob.Request.blank('/v2/fake/consistencygroups/%s/delete' %
+ consistencygroup_id)
+ req.method = 'POST'
+ req.headers['Content-Type'] = 'application/json'
+ body = {"invalid_request_element": {"force": False}}
+ req.body = json.dumps(body)
+ res = req.get_response(fakes.wsgi_app())
+
+ self.assertEqual(400, res.status_int)
+
+ def test_delete_consistencygroup_with_invalid_force_value_in_body(self):
+ consistencygroup_id = self._create_consistencygroup(status='available')
+ req = webob.Request.blank('/v2/fake/consistencygroups/%s/delete' %
+ consistencygroup_id)
+ req.method = 'POST'
+ req.headers['Content-Type'] = 'application/json'
+ body = {"consistencygroup": {"force": "abcd"}}
+ req.body = json.dumps(body)
+ res = req.get_response(fakes.wsgi_app())
+
+ self.assertEqual(400, res.status_int)
+
+ def test_delete_consistencygroup_with_empty_force_value_in_body(self):
+ consistencygroup_id = self._create_consistencygroup(status='available')
+ req = webob.Request.blank('/v2/fake/consistencygroups/%s/delete' %
+ consistencygroup_id)
+ req.method = 'POST'
+ req.headers['Content-Type'] = 'application/json'
+ body = {"consistencygroup": {"force": ""}}
+ req.body = json.dumps(body)
+ res = req.get_response(fakes.wsgi_app())
+
+ self.assertEqual(400, res.status_int)
+
def test_create_consistencygroup_failed_no_volume_type(self):
name = 'cg1'
body = {"consistencygroup": {"name": name,