def delete(self, req, id): """Deletes an existing qos specs.""" context = req.environ['cinder.context'] authorize(context) # Convert string to bool type in strict manner force = utils.get_bool_param('force', req.params) LOG.debug("Delete qos_spec: %(id)s, force: %(force)s", {'id': id, 'force': force}) try: qos_specs.delete(context, id, force) notifier_info = dict(id=id) rpc.get_notifier('QoSSpecs').info(context, 'qos_specs.delete', notifier_info) except exception.QoSSpecsNotFound as err: notifier_err = dict(id=id, error_message=err) self._notify_qos_specs_error(context, 'qos_specs.delete', notifier_err) # Not found exception will be handled at the wsgi level raise except exception.QoSSpecsInUse as err: notifier_err = dict(id=id, error_message=err) self._notify_qos_specs_error(context, 'qos_specs.delete', notifier_err) if force: msg = _('Failed to disassociate qos specs.') raise webob.exc.HTTPInternalServerError(explanation=msg) msg = _('Qos specs still in use.') raise webob.exc.HTTPBadRequest(explanation=msg) return webob.Response(status_int=202)
def delete(self, req, id): """Deletes an existing qos specs.""" 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) LOG.debug("Delete qos_spec: %(id)s, force: %(force)s" % {"id": id, "force": force}) try: qos_specs.delete(context, id, force) notifier_info = dict(id=id) notifier_api.notify(context, "QoSSpecs", "qos_specs.delete", notifier_api.INFO, notifier_info) except exception.QoSSpecsNotFound as err: notifier_err = dict(id=id, error_message=str(err)) self._notify_qos_specs_error(context, "qos_specs.delete", notifier_err) raise webob.exc.HTTPNotFound(explanation=str(err)) except exception.QoSSpecsInUse as err: notifier_err = dict(id=id, error_message=str(err)) self._notify_qos_specs_error(context, "qos_specs.delete", notifier_err) if force: msg = _("Failed to disassociate qos specs.") raise webob.exc.HTTPInternalServerError(explanation=msg) msg = _("Qos specs still in use.") raise webob.exc.HTTPBadRequest(explanation=msg) return webob.Response(status_int=202)
def test_delete(self): qos_id = self._create_qos_specs('my_qos') def fake_db_associations_get(context, id): vol_types = [] if id == qos_id: vol_types = [fake_db_get_vol_type(id)] return vol_types def fake_db_delete(context, id): return {'deleted': True, 'deleted_at': timeutils.utcnow()} def fake_disassociate_all(context, id): pass self.stubs.Set(db, 'qos_specs_associations_get', fake_db_associations_get) self.stubs.Set(qos_specs, 'disassociate_all', fake_disassociate_all) self.stubs.Set(db, 'qos_specs_delete', fake_db_delete) self.assertRaises(exception.InvalidQoSSpecs, qos_specs.delete, self.ctxt, None) self.assertRaises(exception.QoSSpecsNotFound, qos_specs.delete, self.ctxt, 'NotFound') self.assertRaises(exception.QoSSpecsInUse, qos_specs.delete, self.ctxt, qos_id) # able to delete in-use qos specs if force=True qos_specs.delete(self.ctxt, qos_id, force=True) # Can delete without forcing when no volume types qos_id_with_no_vol_types = self._create_qos_specs('no_vol_types') qos_specs.delete(self.ctxt, qos_id_with_no_vol_types, force=False)
def test_delete(self): def fake_db_associations_get(context, id): if id == 'InUse': return True else: return False def fake_db_delete(context, id): if id == 'NotFound': raise exception.QoSSpecsNotFound(specs_id=id) def fake_disassociate_all(context, id): pass self.stubs.Set(db, 'qos_specs_associations_get', fake_db_associations_get) self.stubs.Set(qos_specs, 'disassociate_all', fake_disassociate_all) self.stubs.Set(db, 'qos_specs_delete', fake_db_delete) self.assertRaises(exception.InvalidQoSSpecs, qos_specs.delete, self.ctxt, None) self.assertRaises(exception.QoSSpecsNotFound, qos_specs.delete, self.ctxt, 'NotFound') self.assertRaises(exception.QoSSpecsInUse, qos_specs.delete, self.ctxt, 'InUse') # able to delete in-use qos specs if force=True qos_specs.delete(self.ctxt, 'InUse', force=True)
def test_delete(self): qos_id = self._create_qos_specs('my_qos') def fake_db_associations_get(context, id): vol_types = [] if id == qos_id: vol_types = [fake_db_get_vol_type(id)] return vol_types def fake_db_delete(context, id): return {'deleted': True, 'deleted_at': timeutils.utcnow()} def fake_disassociate_all(context, id): pass self.mock_object(db, 'qos_specs_associations_get', fake_db_associations_get) self.mock_object(qos_specs, 'disassociate_all', fake_disassociate_all) self.mock_object(db, 'qos_specs_delete', fake_db_delete) self.assertRaises(exception.InvalidQoSSpecs, qos_specs.delete, self.ctxt, None) self.assertRaises(exception.QoSSpecsNotFound, qos_specs.delete, self.ctxt, 'NotFound') self.assertRaises(exception.QoSSpecsInUse, qos_specs.delete, self.ctxt, qos_id) # able to delete in-use qos specs if force=True qos_specs.delete(self.ctxt, qos_id, force=True) # Can delete without forcing when no volume types qos_id_with_no_vol_types = self._create_qos_specs('no_vol_types') qos_specs.delete(self.ctxt, qos_id_with_no_vol_types, force=False)
def delete(self, req, id): """Deletes an existing qos specs.""" 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) LOG.debug("Delete qos_spec: %(id)s, force: %(force)s" % { 'id': id, 'force': force }) try: qos_specs.delete(context, id, force) notifier_info = dict(id=id) notifier_api.notify(context, 'QoSSpecs', 'qos_specs.delete', notifier_api.INFO, notifier_info) except exception.QoSSpecsNotFound as err: notifier_err = dict(id=id, error_message=str(err)) self._notify_qos_specs_error(context, 'qos_specs.delete', notifier_err) raise webob.exc.HTTPNotFound(explanation=str(err)) except exception.QoSSpecsInUse as err: notifier_err = dict(id=id, error_message=str(err)) self._notify_qos_specs_error(context, 'qos_specs.delete', notifier_err) if force: msg = _('Failed to disassociate qos specs.') raise webob.exc.HTTPInternalServerError(explanation=msg) msg = _('Qos specs still in use.') raise webob.exc.HTTPBadRequest(explanation=msg) return webob.Response(status_int=202)
def delete(self, req, id): """Deletes an existing qos specs.""" context = req.environ['cinder.context'] authorize(context) force = req.params.get('force', None) LOG.debug("Delete qos_spec: %(id)s, force: %(force)s" % {'id': id, 'force': force}) try: qos_specs.get_qos_specs(context, id) qos_specs.delete(context, id, force) notifier_info = dict(id=id) notifier_api.notify(context, 'QoSSpecs', 'qos_specs.delete', notifier_api.INFO, notifier_info) except exception.QoSSpecsNotFound as err: notifier_err = dict(id=id, error_message=str(err)) self._notify_qos_specs_error(context, 'qos_specs.delete', notifier_err) raise webob.exc.HTTPNotFound(explanation=str(err)) except exception.QoSSpecsInUse as err: notifier_err = dict(id=id, error_message=str(err)) self._notify_qos_specs_error(context, 'qos_specs.delete', notifier_err) if force: msg = _('Failed to disassociate qos specs.') raise webob.exc.HTTPInternalServerError(explanation=msg) msg = _('Qos specs still in use.') raise webob.exc.HTTPBadRequest(explanation=msg) return webob.Response(status_int=202)