Пример #1
0
    def test_update(self):
        def fake_db_update(context, specs_id, values):
            raise db_exc.DBError()

        qos = {'consumer': 'back-end', 'specs': {'key1': 'value1'}}

        # qos specs must exists
        self.assertRaises(exception.QoSSpecsNotFound, qos_specs.update,
                          self.ctxt, 'fake_id', qos)

        specs_id = self._create_qos_specs('Name', qos['consumer'],
                                          qos['specs'])

        qos_specs.update(self.ctxt, specs_id, {
            'key1': 'newvalue1',
            'key2': 'value2'
        })

        specs = qos_specs.get_qos_specs(self.ctxt, specs_id)
        self.assertEqual('newvalue1', specs['specs']['key1'])
        self.assertEqual('value2', specs['specs']['key2'])

        # consumer must be one of: front-end, back-end, both
        self.assertRaises(exception.InvalidQoSSpecs, qos_specs.update,
                          self.ctxt, specs_id, {'consumer': 'not-real'})

        self.stubs.Set(db, 'qos_specs_update', fake_db_update)
        self.assertRaises(exception.QoSSpecsUpdateFailed, qos_specs.update,
                          self.ctxt, specs_id, {'key': 'new_key'})
Пример #2
0
    def update(self, req, id, body=None):
        context = req.environ['cinder.context']
        authorize(context)

        self.assert_valid_body(body, 'qos_specs')
        specs = body['qos_specs']
        try:
            qos_specs.update(context, id, specs)
            notifier_info = dict(id=id, specs=specs)
            rpc.get_notifier('QoSSpecs').info(context,
                                              'qos_specs.update',
                                              notifier_info)
        except (exception.QoSSpecsNotFound, exception.InvalidQoSSpecs) as err:
            notifier_err = dict(id=id, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.update',
                                         notifier_err)
            # Not found exception will be handled at the wsgi level
            raise
        except exception.QoSSpecsUpdateFailed as err:
            notifier_err = dict(id=id, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.update',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return body
Пример #3
0
    def update(self, req, id, body=None):
        context = req.environ['cinder.context']
        authorize(context)

        if not self.is_valid_body(body, 'qos_specs'):
            raise webob.exc.HTTPBadRequest()
        specs = body['qos_specs']
        try:
            qos_specs.update(context, id, specs)
            notifier_info = dict(id=id, specs=specs)
            rpc.get_notifier('QoSSpecs').info(context,
                                              'qos_specs.update',
                                              notifier_info)
        except exception.QoSSpecsNotFound as err:
            notifier_err = dict(id=id, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.update',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
        except exception.InvalidQoSSpecs as err:
            notifier_err = dict(id=id, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.update',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(err))
        except exception.QoSSpecsUpdateFailed as err:
            notifier_err = dict(id=id, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.update',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return body
Пример #4
0
    def update(self, req, id, body=None):
        context = req.environ["cinder.context"]
        authorize(context)

        if not self.is_valid_body(body, "qos_specs"):
            raise webob.exc.HTTPBadRequest()
        specs = body["qos_specs"]
        try:
            qos_specs.update(context, id, specs)
            notifier_info = dict(id=id, specs=specs)
            notifier_api.notify(context, "QoSSpecs", "qos_specs.update", 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.update", notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.InvalidQoSSpecs as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.update", notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=str(err))
        except exception.QoSSpecsUpdateFailed as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.update", notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return body
Пример #5
0
    def test_update(self):
        def fake_db_update(context, specs_id, values):
            raise db_exc.DBError()

        input = {'key1': 'value1',
                 'consumer': 'WrongPlace'}
        # consumer must be one of: front-end, back-end, both
        self.assertRaises(exception.InvalidQoSSpecs,
                          qos_specs.update, self.ctxt, 'fake_id', input)

        input['consumer'] = 'front-end'
        # qos specs must exists
        self.assertRaises(exception.QoSSpecsNotFound,
                          qos_specs.update, self.ctxt, 'fake_id', input)

        specs_id = self._create_qos_specs('Name', input)
        qos_specs.update(self.ctxt, specs_id,
                         {'key1': 'newvalue1',
                          'key2': 'value2'})
        specs = qos_specs.get_qos_specs(self.ctxt, specs_id)
        self.assertEqual('newvalue1', specs['specs']['key1'])
        self.assertEqual('value2', specs['specs']['key2'])

        self.stubs.Set(db, 'qos_specs_update', fake_db_update)
        self.assertRaises(exception.QoSSpecsUpdateFailed,
                          qos_specs.update, self.ctxt, 'fake_id', input)
Пример #6
0
    def test_update(self):
        def fake_db_update(context, specs_id, values):
            raise db_exc.DBError()

        input = {'key1': 'value1', 'consumer': 'WrongPlace'}
        # consumer must be one of: front-end, back-end, both
        self.assertRaises(exception.InvalidQoSSpecs, qos_specs.update,
                          self.ctxt, 'fake_id', input)

        input['consumer'] = 'front-end'
        # qos specs must exists
        self.assertRaises(exception.QoSSpecsNotFound, qos_specs.update,
                          self.ctxt, 'fake_id', input)

        specs_id = self._create_qos_specs('Name', input)
        qos_specs.update(self.ctxt, specs_id, {
            'key1': 'newvalue1',
            'key2': 'value2'
        })
        specs = qos_specs.get_qos_specs(self.ctxt, specs_id)
        self.assertEqual(specs['specs']['key1'], 'newvalue1')
        self.assertEqual(specs['specs']['key2'], 'value2')

        self.stubs.Set(db, 'qos_specs_update', fake_db_update)
        self.assertRaises(exception.QoSSpecsUpdateFailed, qos_specs.update,
                          self.ctxt, 'fake_id', input)
Пример #7
0
    def test_update(self):
        def fake_db_update(context, specs_id, values):
            raise db_exc.DBError()

        qos = {'consumer': 'back-end',
               'specs': {'key1': 'value1'}}

        # qos specs must exists
        self.assertRaises(exception.QoSSpecsNotFound,
                          qos_specs.update, self.ctxt, 'fake_id', qos['specs'])

        specs_id = self._create_qos_specs('Name',
                                          qos['consumer'],
                                          qos['specs'])

        qos_specs.update(self.ctxt, specs_id,
                         {'key1': 'newvalue1', 'key2': 'value2'})

        specs = qos_specs.get_qos_specs(self.ctxt, specs_id)
        self.assertEqual('newvalue1', specs['specs']['key1'])
        self.assertEqual('value2', specs['specs']['key2'])

        # consumer must be one of: front-end, back-end, both
        self.assertRaises(exception.InvalidQoSSpecs,
                          qos_specs.update, self.ctxt, specs_id,
                          {'consumer': 'not-real'})

        self.mock_object(db, 'qos_specs_update', fake_db_update)
        self.assertRaises(exception.QoSSpecsUpdateFailed,
                          qos_specs.update, self.ctxt, specs_id, {'key':
                                                                  'new_key'})
    def update(self, req, id, body=None):
        context = req.environ['cinder.context']
        authorize(context)

        if not self.is_valid_body(body, 'qos_specs'):
            raise webob.exc.HTTPBadRequest()
        specs = body['qos_specs']
        try:
            qos_specs.update(context, id, specs)
            notifier_info = dict(id=id, specs=specs)
            notifier_api.notify(context, 'QoSSpecs', 'qos_specs.update',
                                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.update',
                                         notifier_err)
            raise webob.exc.HTTPNotFound(explanation=str(err))
        except exception.InvalidQoSSpecs as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.update',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=str(err))
        except exception.QoSSpecsUpdateFailed as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_qos_specs_error(context, 'qos_specs.update',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return body
Пример #9
0
    def update(self, req, id, body=None):
        context = req.environ['cinder.context']
        context.authorize(policy.UPDATE_POLICY)

        specs = body['qos_specs']
        try:
            spec = qos_specs.get_qos_specs(context, id)

            qos_specs.update(context, id, specs)
            notifier_info = dict(id=id,
                                 created_at=spec.created_at,
                                 updated_at=timeutils.utcnow(),
                                 specs=specs)
            rpc.get_notifier('QoSSpecs').info(context,
                                              'qos_specs.update',
                                              notifier_info)
        except (exception.QoSSpecsNotFound, exception.InvalidQoSSpecs) as err:
            notifier_err = dict(id=id, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.update',
                                         notifier_err)
            # Not found exception will be handled at the wsgi level
            raise
        except exception.QoSSpecsUpdateFailed as err:
            notifier_err = dict(id=id, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.update',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return body
Пример #10
0
    def update(self, req, id, body=None):
        context = req.environ['cinder.context']
        context.authorize(policy.UPDATE_POLICY)

        specs = body['qos_specs']
        try:
            spec = qos_specs.get_qos_specs(context, id)

            qos_specs.update(context, id, specs)
            notifier_info = dict(id=id,
                                 created_at=spec.created_at,
                                 updated_at=timeutils.utcnow(),
                                 specs=specs)
            rpc.get_notifier('QoSSpecs').info(context, 'qos_specs.update',
                                              notifier_info)
        except (exception.QoSSpecsNotFound, exception.InvalidQoSSpecs) as err:
            notifier_err = dict(id=id, error_message=err)
            self._notify_qos_specs_error(context, 'qos_specs.update',
                                         notifier_err)
            # Not found exception will be handled at the wsgi level
            raise
        except exception.QoSSpecsUpdateFailed as err:
            notifier_err = dict(id=id, error_message=err)
            self._notify_qos_specs_error(context, 'qos_specs.update',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return body
Пример #11
0
    def test_update(self):
        def fake_db_update(context, specs_id, values):
            raise db_exc.DBError()

        qos = {"consumer": "back-end", "specs": {"key1": "value1"}}

        # qos specs must exists
        self.assertRaises(exception.QoSSpecsNotFound, qos_specs.update, self.ctxt, "fake_id", qos)

        specs_id = self._create_qos_specs("Name", qos["consumer"], qos["specs"])

        qos_specs.update(self.ctxt, specs_id, {"key1": "newvalue1", "key2": "value2"})

        specs = qos_specs.get_qos_specs(self.ctxt, specs_id)
        self.assertEqual("newvalue1", specs["specs"]["key1"])
        self.assertEqual("value2", specs["specs"]["key2"])

        # consumer must be one of: front-end, back-end, both
        self.assertRaises(exception.InvalidQoSSpecs, qos_specs.update, self.ctxt, specs_id, {"consumer": "not-real"})

        self.mock_object(db, "qos_specs_update", fake_db_update)
        self.assertRaises(exception.QoSSpecsUpdateFailed, qos_specs.update, self.ctxt, specs_id, {"key": "new_key"})