def delete_keys(self, req, id, body): """Deletes specified keys in qos specs.""" context = req.environ['cinder.context'] authorize(context) if not (body and 'keys' in body and isinstance(body.get('keys'), list)): raise webob.exc.HTTPBadRequest() keys = body['keys'] LOG.debug("Delete_key spec: %(id)s, keys: %(keys)s" % {'id': id, 'keys': keys}) try: qos_specs.delete_keys(context, id, keys) notifier_info = dict(id=id) rpc.get_notifier().info(context, 'qos_specs.delete_keys', notifier_info) except exception.QoSSpecsNotFound as err: notifier_err = dict(id=id, error_message=err) self._notify_qos_specs_error(context, 'qos_specs.delete_keys', notifier_err) raise webob.exc.HTTPNotFound(explanation=six.text_type(err)) except exception.QoSSpecsKeyNotFound as err: notifier_err = dict(id=id, error_message=err) self._notify_qos_specs_error(context, 'qos_specs.delete_keys', notifier_err) raise webob.exc.HTTPBadRequest(explanation=six.text_type(err)) return webob.Response(status_int=202)
def delete_keys(self, req, id, body): """Deletes specified keys in qos specs.""" context = req.environ['cinder.context'] authorize(context) if not (body and 'keys' in body and isinstance(body.get('keys'), list)): raise webob.exc.HTTPBadRequest() keys = body['keys'] LOG.debug("Delete_key spec: %(id)s, keys: %(keys)s", {'id': id, 'keys': keys}) try: qos_specs.delete_keys(context, id, keys) notifier_info = dict(id=id) rpc.get_notifier('QoSSpecs').info(context, 'qos_specs.delete_keys', notifier_info) except exception.NotFound as err: notifier_err = dict(id=id, error_message=err) self._notify_qos_specs_error(context, 'qos_specs.delete_keys', notifier_err) # Not found exception will be handled at the wsgi level raise return webob.Response(status_int=202)
def delete_keys(self, req, id, body): """Deletes specified keys in qos specs.""" context = req.environ["cinder.context"] authorize(context) if not (body and "keys" in body and isinstance(body.get("keys"), list)): raise webob.exc.HTTPBadRequest() keys = body["keys"] LOG.debug("Delete_key spec: %(id)s, keys: %(keys)s" % {"id": id, "keys": keys}) try: qos_specs.delete_keys(context, id, keys) notifier_info = dict(id=id) notifier_api.notify(context, "QoSSpecs", "qos_specs.delete_keys", 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_keys", notifier_err) raise webob.exc.HTTPNotFound(explanation=str(err)) except exception.QoSSpecsKeyNotFound as err: notifier_err = dict(id=id, error_message=str(err)) self._notify_qos_specs_error(context, "qos_specs.delete_keys", notifier_err) raise webob.exc.HTTPBadRequest(explanation=str(err)) return webob.Response(status_int=202)
def delete_keys(self, req, id, body): """Deletes specified keys in qos specs.""" context = req.environ['cinder.context'] authorize(context) if not (body and 'keys' in body and isinstance(body.get('keys'), list)): raise webob.exc.HTTPBadRequest() keys = body['keys'] LOG.debug("Delete_key spec: %(id)s, keys: %(keys)s" % { 'id': id, 'keys': keys }) try: qos_specs.delete_keys(context, id, keys) notifier_info = dict(id=id) notifier_api.notify(context, 'QoSSpecs', 'qos_specs.delete_keys', 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_keys', notifier_err) raise webob.exc.HTTPNotFound(explanation=str(err)) except exception.QoSSpecsKeyNotFound as err: notifier_err = dict(id=id, error_message=str(err)) self._notify_qos_specs_error(context, 'qos_specs.delete_keys', notifier_err) raise webob.exc.HTTPBadRequest(explanation=str(err)) return webob.Response(status_int=202)
def delete_keys(self, req, id, body): """Deletes specified keys in qos specs.""" context = req.environ['cinder.context'] context.authorize(policy.DELETE_POLICY) keys = body['keys'] LOG.debug("Delete_key spec: %(id)s, keys: %(keys)s", {'id': id, 'keys': keys}) try: qos_specs.delete_keys(context, id, keys) spec = qos_specs.get_qos_specs(context, id) notifier_info = dict(id=id, created_at=spec.created_at, updated_at=spec.updated_at) rpc.get_notifier('QoSSpecs').info(context, 'qos_specs.delete_keys', notifier_info) except exception.NotFound as err: notifier_err = dict(id=id, error_message=err) self._notify_qos_specs_error(context, 'qos_specs.delete_keys', notifier_err) # Not found exception will be handled at the wsgi level raise return webob.Response(status_int=http_client.ACCEPTED)
def delete_keys(self, req, id, body): """Deletes specified keys in qos specs.""" context = req.environ['cinder.context'] context.authorize(policy.DELETE_POLICY) keys = body['keys'] LOG.debug("Delete_key spec: %(id)s, keys: %(keys)s", { 'id': id, 'keys': keys }) try: qos_specs.delete_keys(context, id, keys) spec = qos_specs.get_qos_specs(context, id) notifier_info = dict(id=id, created_at=spec.created_at, updated_at=spec.updated_at) rpc.get_notifier('QoSSpecs').info(context, 'qos_specs.delete_keys', notifier_info) except exception.NotFound as err: notifier_err = dict(id=id, error_message=err) self._notify_qos_specs_error(context, 'qos_specs.delete_keys', notifier_err) # Not found exception will be handled at the wsgi level raise return webob.Response(status_int=HTTPStatus.ACCEPTED)
def test_delete_keys(self): def fake_db_qos_delete_key(context, id, key): if key == "NotFound": raise exception.QoSSpecsKeyNotFound(specs_id=id, specs_key=key) else: pass value = {"foo": "Foo", "bar": "Bar", "zoo": "tiger"} name = "QoSName" consumer = "front-end" specs_id = self._create_qos_specs(name, consumer, value) qos_specs.delete_keys(self.ctxt, specs_id, ["foo", "bar"]) del value["foo"] del value["bar"] expected = {"name": name, "id": specs_id, "consumer": consumer, "specs": value} specs = qos_specs.get_qos_specs(self.ctxt, specs_id) specs_dic = {"consumer": specs["consumer"], "id": specs["id"], "name": specs["name"], "specs": specs["specs"]} self.assertDictMatch(expected, specs_dic) self.mock_object(db, "qos_specs_item_delete", fake_db_qos_delete_key) self.assertRaises(exception.InvalidQoSSpecs, qos_specs.delete_keys, self.ctxt, None, []) self.assertRaises(exception.QoSSpecsNotFound, qos_specs.delete_keys, self.ctxt, "NotFound", []) self.assertRaises(exception.QoSSpecsKeyNotFound, qos_specs.delete_keys, self.ctxt, specs_id, ["NotFound"]) self.assertRaises( exception.QoSSpecsKeyNotFound, qos_specs.delete_keys, self.ctxt, specs_id, ["foo", "bar", "NotFound"] )
def test_delete_keys(self): def fake_db_qos_delete_key(context, id, key): if key == 'NotFound': raise exception.QoSSpecsKeyNotFound(specs_id=id, specs_key=key) else: pass def fake_qos_specs_get(context, id): if id == 'NotFound': raise exception.QoSSpecsNotFound(specs_id=id) else: pass value = {'foo': 'Foo', 'bar': 'Bar', 'zoo': 'tiger'} name = 'QoSName' consumer = 'front-end' specs_id = self._create_qos_specs(name, consumer, value) qos_specs.delete_keys(self.ctxt, specs_id, ['foo', 'bar']) del value['foo'] del value['bar'] expected = { 'name': name, 'id': specs_id, 'consumer': consumer, 'specs': value } specs = qos_specs.get_qos_specs(self.ctxt, specs_id) specs_dic = { 'consumer': specs['consumer'], 'id': specs['id'], 'name': specs['name'], 'specs': specs['specs'] } self.assertDictMatch(expected, specs_dic) self.stubs.Set(db, 'qos_specs_item_delete', fake_db_qos_delete_key) self.assertRaises(exception.InvalidQoSSpecs, qos_specs.delete_keys, self.ctxt, None, []) self.assertRaises(exception.QoSSpecsNotFound, qos_specs.delete_keys, self.ctxt, 'NotFound', []) self.assertRaises(exception.QoSSpecsKeyNotFound, qos_specs.delete_keys, self.ctxt, specs_id, ['NotFound']) self.assertRaises(exception.QoSSpecsKeyNotFound, qos_specs.delete_keys, self.ctxt, specs_id, ['foo', 'bar', 'NotFound'])
def test_delete_keys(self): def fake_db_qos_delete_key(context, id, key): if key == 'NotFound': raise exception.QoSSpecsKeyNotFound(specs_id=id, specs_key=key) else: pass def fake_qos_specs_get(context, id): if id == 'NotFound': raise exception.QoSSpecsNotFound(specs_id=id) else: pass value = {'foo': 'Foo', 'bar': 'Bar', 'zoo': 'tiger'} name = 'QoSName' consumer = 'front-end' specs_id = self._create_qos_specs(name, consumer, value) qos_specs.delete_keys(self.ctxt, specs_id, ['foo', 'bar']) del value['foo'] del value['bar'] expected = {'name': name, 'id': specs_id, 'consumer': consumer, 'specs': value} specs = qos_specs.get_qos_specs(self.ctxt, specs_id) specs_dic = {'consumer': specs['consumer'], 'id': specs['id'], 'name': specs['name'], 'specs': specs['specs']} self.assertDictMatch(expected, specs_dic) self.stubs.Set(db, 'qos_specs_item_delete', fake_db_qos_delete_key) self.assertRaises(exception.InvalidQoSSpecs, qos_specs.delete_keys, self.ctxt, None, []) self.assertRaises(exception.QoSSpecsNotFound, qos_specs.delete_keys, self.ctxt, 'NotFound', []) self.assertRaises(exception.QoSSpecsKeyNotFound, qos_specs.delete_keys, self.ctxt, specs_id, ['NotFound']) self.assertRaises(exception.QoSSpecsKeyNotFound, qos_specs.delete_keys, self.ctxt, specs_id, ['foo', 'bar', 'NotFound'])