Exemple #1
0
    def create(self, req, 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"]
        name = specs.get("name", None)
        if name is None or name == "":
            msg = _("Please specify a name for QoS specs.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        try:
            qos_specs.create(context, name, specs)
            spec = qos_specs.get_qos_specs_by_name(context, name)
            notifier_info = dict(name=name, specs=specs)
            notifier_api.notify(context, "QoSSpecs", "QoSSpecs.create", notifier_api.INFO, notifier_info)
        except exception.InvalidInput as err:
            notifier_err = dict(name=name, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.create", notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=str(err))
        except exception.QoSSpecsExists as err:
            notifier_err = dict(name=name, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.create", notifier_err)
            raise webob.exc.HTTPConflict(explanation=str(err))
        except exception.QoSSpecsCreateFailed as err:
            notifier_err = dict(name=name, error_message=str(err))
            self._notify_qos_specs_error(context, "qos_specs.create", notifier_err)
            raise webob.exc.HTTPInternalServerError(explanation=str(err))

        return self._view_builder.detail(req, spec)
Exemple #2
0
    def test_retype_volume(self, mock_req):
        ctxt = context.get_admin_context()
        extra_specs = {"Feature:Pool": "1",
                       "Feature:Raid": "1",
                       "Affinity:Type": "flash",
                       "Alloc:Type": "thick"}
        type_ref = volume_types.create(ctxt, 'VT1', extra_specs)
        specs = {'qos:minIOPS': '20',
                 'qos:maxIOPS': '2000',
                 'qos:burstIOPS': '5000'}
        qos = qos_specs.create(ctxt, 'fake-qos', specs)
        qos_specs.associate_qos_with_type(ctxt, qos['id'], type_ref['id'])
        VOLUME1['volume_type_id'] = type_ref['id']
        # New volume type
        extra_specs = {"Feature:Pool": "1",
                       "Feature:Raid": "5",
                       "Affinity:Type": "flash",
                       "Alloc:Type": "thick"}
        type_ref = volume_types.create(ctxt, 'VT2', extra_specs)
        specs = {'qos:minIOPS': '30',
                 'qos:maxIOPS': '3000',
                 'qos:burstIOPS': '10000'}
        qos = qos_specs.create(ctxt, 'fake-qos2', specs)
        qos_specs.associate_qos_with_type(ctxt, qos['id'], type_ref['id'])

        mock_req.side_effect = iter([ISE_GET_QUERY_RESP,
                                     ISE_GET_VOL1_STATUS_RESP,
                                     ISE_MODIFY_VOLUME_RESP])
        self.setup_driver()
        self.driver.retype(ctxt, VOLUME1, type_ref, 0, 0)
Exemple #3
0
 def test_create_volume_chap(self, mock_req):
     ctxt = context.get_admin_context()
     extra_specs = {"Feature:Pool": "1",
                    "Feature:Raid": "1",
                    "Affinity:Type": "flash",
                    "Alloc:Type": "thick"}
     type_ref = volume_types.create(ctxt, 'VT1', extra_specs)
     specs = {'qos:minIOPS': '20',
              'qos:maxIOPS': '2000',
              'qos:burstIOPS': '5000'}
     qos = qos_specs.create(ctxt, 'fake-qos', specs)
     qos_specs.associate_qos_with_type(ctxt, qos['id'], type_ref['id'])
     VOLUME1['volume_type_id'] = type_ref['id']
     self.setup_driver()
     if self.configuration.ise_protocol == 'iscsi':
         mock_req.side_effect = iter([ISE_GET_QUERY_RESP,
                                      ISE_CREATE_VOLUME_RESP,
                                      ISE_GET_VOL1_STATUS_RESP,
                                      ISE_GET_IONETWORKS_CHAP_RESP])
         exp_result = {}
         exp_result = {"provider_auth": "CHAP abc abc"}
         act_result = self.driver.create_volume(VOLUME1)
         self.assertDictMatch(exp_result, act_result)
     elif self.configuration.ise_protocol == 'fibre_channel':
         mock_req.side_effect = iter([ISE_GET_QUERY_RESP,
                                      ISE_CREATE_VOLUME_RESP,
                                      ISE_GET_VOL1_STATUS_RESP])
         self.driver.create_volume(VOLUME1)
Exemple #4
0
    def test_create(self):
        input = {"key1": "value1", "key2": "value2", "key3": "value3"}
        ref = qos_specs.create(self.ctxt, "FakeName", input)
        specs_obj = qos_specs.get_qos_specs(self.ctxt, ref["id"])
        specs_obj_dic = {
            "consumer": specs_obj["consumer"],
            "id": specs_obj["id"],
            "name": specs_obj["name"],
            "specs": specs_obj["specs"],
        }
        expected = {"consumer": "back-end", "id": ref["id"], "name": "FakeName", "specs": input}
        self.assertDictMatch(expected, specs_obj_dic)

        # qos specs must have unique name
        self.assertRaises(exception.QoSSpecsExists, qos_specs.create, self.ctxt, "FakeName", input)

        # consumer must be one of: front-end, back-end, both
        input["consumer"] = "fake"
        self.assertRaises(exception.InvalidQoSSpecs, qos_specs.create, self.ctxt, "QoSName", input)

        del input["consumer"]

        self.mock_object(db, "qos_specs_create", fake_db_qos_specs_create)
        # able to catch DBError
        self.assertRaises(exception.QoSSpecsCreateFailed, qos_specs.create, self.ctxt, "FailQoSName", input)
Exemple #5
0
    def test_create(self):
        input = {'key1': 'value1',
                 'key2': 'value2',
                 'key3': 'value3'}
        ref = qos_specs.create(self.ctxt, 'FakeName', input)
        specs = qos_specs.get_qos_specs(self.ctxt, ref['id'])
        expected = (dict(consumer='back-end'))
        expected.update(dict(id=ref['id']))
        expected.update(dict(name='FakeName'))
        del input['consumer']
        expected.update(dict(specs=input))
        self.assertDictMatch(expected, specs)

        self.stubs.Set(db, 'qos_specs_create',
                       fake_db_qos_specs_create)

        # qos specs must have unique name
        self.assertRaises(exception.QoSSpecsExists,
                          qos_specs.create, self.ctxt, 'DupQoSName', input)

        input.update({'consumer': 'FakeConsumer'})
        # consumer must be one of: front-end, back-end, both
        self.assertRaises(exception.InvalidQoSSpecs,
                          qos_specs.create, self.ctxt, 'QoSName', input)

        del input['consumer']
        # able to catch DBError
        self.assertRaises(exception.QoSSpecsCreateFailed,
                          qos_specs.create, self.ctxt, 'FailQoSName', input)
    def test_create(self):
        input = {'key1': 'value1',
                 'key2': 'value2',
                 'key3': 'value3'}
        ref = qos_specs.create(self.ctxt, 'FakeName', input)
        specs_obj = qos_specs.get_qos_specs(self.ctxt, ref['id'])
        specs_obj_dic = {'consumer': specs_obj['consumer'],
                         'id': specs_obj['id'],
                         'name': specs_obj['name'],
                         'specs': specs_obj['specs']}
        expected = {'consumer': 'back-end',
                    'id': ref['id'],
                    'name': 'FakeName',
                    'specs': input}
        self.assertDictEqual(expected,
                             specs_obj_dic)

        # qos specs must have unique name
        self.assertRaises(exception.QoSSpecsExists,
                          qos_specs.create, self.ctxt, 'FakeName', input)

        # consumer must be one of: front-end, back-end, both
        input['consumer'] = 'fake'
        self.assertRaises(exception.InvalidQoSSpecs,
                          qos_specs.create, self.ctxt, 'QoSName', input)

        del input['consumer']

        self.mock_object(db, 'qos_specs_create',
                         fake_db_qos_specs_create)
        # able to catch DBError
        self.assertRaises(exception.QoSSpecsCreateFailed,
                          qos_specs.create, self.ctxt, 'FailQoSName', input)
Exemple #7
0
def _fake_volume_type(*args, **kwargs):
    ctxt = context.get_admin_context()
    type_ref = volume_types.create(ctxt, "qos_extra_specs", {})
    qos_ref = qos_specs.create(ctxt, 'qos-specs', {})
    qos_specs.associate_qos_with_type(ctxt, qos_ref['id'],
                                      type_ref['id'])
    qos_type = volume_types.get_volume_type(ctxt, type_ref['id'])
    return qos_type
Exemple #8
0
    def create(self, req, body=None):
        context = req.environ['cinder.context']
        authorize(context)

        self.assert_valid_body(body, 'qos_specs')

        specs = body['qos_specs']
        name = specs.get('name', None)
        if name is None:
            msg = _("Please specify a name for QoS specs.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        self.validate_string_length(name, 'name', min_length=1,
                                    max_length=255, remove_whitespaces=True)
        name = name.strip()

        try:
            qos_specs.create(context, name, specs)
            spec = qos_specs.get_qos_specs_by_name(context, name)
            notifier_info = dict(name=name, specs=specs)
            rpc.get_notifier('QoSSpecs').info(context,
                                              'qos_specs.create',
                                              notifier_info)
        except exception.InvalidQoSSpecs as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(err))
        except exception.QoSSpecsExists as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.QoSSpecsCreateFailed as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return self._view_builder.detail(req, spec)
Exemple #9
0
    def create(self, req, 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']
        name = specs.get('name', None)
        if name is None or name == "":
            msg = _("Please specify a name for QoS specs.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        try:
            qos_specs.create(context, name, specs)
            spec = qos_specs.get_qos_specs_by_name(context, name)
            notifier_info = dict(name=name, specs=specs)
            rpc.get_notifier('QoSSpecs').info(context,
                                              'QoSSpecs.create',
                                              notifier_info)
        except exception.InvalidInput as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(err))
        except exception.QoSSpecsExists as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.QoSSpecsCreateFailed as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return self._view_builder.detail(req, spec)
 def test_create_volume_Qos_by_volumeType_QoSspec(self, connmock):
     qos_ref = qos_specs.create(self.ctxt,
                                'qos-specs-1', {'fio-qos': 'Policy 2'})
     type_ref = volume_types.create(self.ctxt,
                                    "type1",
                                    {"volume_backend_name": "fio-ioControl",
                                     "qos:fio-qos": "Policy 4"}
                                    )
     qos_specs.associate_qos_with_type(self.ctxt,
                                       qos_ref['id'],
                                       type_ref['id'])
     expected_qos_result = '00000000-00000000-0000-000000000008'  # Policy 2
     qos = self.drv._set_qos_by_volume_type(type_ref['id'])
     self.assertEqual(qos, expected_qos_result)
 def test_set_by_qos_spec(self):
     sfv = solidfire.SolidFireDriver(configuration=self.configuration)
     qos_ref = qos_specs.create(self.ctxt,
                                'qos-specs-1', {'minIOPS': '1000',
                                                'maxIOPS': '10000',
                                                'burstIOPS': '20000'})
     type_ref = volume_types.create(self.ctxt,
                                    "type1", {"qos:minIOPS": "100",
                                              "qos:burstIOPS": "300",
                                              "qos:maxIOPS": "200"})
     qos_specs.associate_qos_with_type(self.ctxt,
                                       qos_ref['id'],
                                       type_ref['id'])
     qos = sfv._set_qos_by_volume_type(self.ctxt, type_ref['id'])
     self.assertEqual(self.expected_qos_results, qos)
    def test_get_volume_type_qos_specs(self):
        qos_ref = qos_specs.create(self.ctxt, "qos-specs-1", {"k1": "v1", "k2": "v2", "k3": "v3"})
        type_ref = volume_types.create(self.ctxt, "type1", {"key2": "val2", "key3": "val3"})
        res = volume_types.get_volume_type_qos_specs(type_ref["id"])
        self.assertIsNone(res["qos_specs"])
        qos_specs.associate_qos_with_type(self.ctxt, qos_ref["id"], type_ref["id"])

        expected = {
            "qos_specs": {
                "id": qos_ref["id"],
                "name": "qos-specs-1",
                "consumer": "back-end",
                "specs": {"k1": "v1", "k2": "v2", "k3": "v3"},
            }
        }
        res = volume_types.get_volume_type_qos_specs(type_ref["id"])
        self.assertDictMatch(expected, res)
    def test_get_volume_type_qos_specs(self):
        qos_ref = qos_specs.create(self.ctxt, 'qos-specs-1', {'k1': 'v1',
                                                              'k2': 'v2',
                                                              'k3': 'v3'})
        type_ref = volume_types.create(self.ctxt, "type1", {"key2": "val2",
                                                  "key3": "val3"})
        res = volume_types.get_volume_type_qos_specs(type_ref['id'])
        self.assertEquals(res['qos_specs'], {})
        qos_specs.associate_qos_with_type(self.ctxt,
                                          qos_ref['id'],
                                          type_ref['id'])

        expected = {'qos_specs': {'consumer': 'back-end',
                                  'k1': 'v1',
                                  'k2': 'v2',
                                  'k3': 'v3'}}
        res = volume_types.get_volume_type_qos_specs(type_ref['id'])
        self.assertDictMatch(expected, res)
Exemple #14
0
    def create(self, req, body=None):
        context = req.environ['cinder.context']
        authorize(context)

        self.assert_valid_body(body, 'qos_specs')

        specs = body['qos_specs']
        name = specs.get('name', None)
        if name is None:
            msg = _("Please specify a name for QoS specs.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        utils.validate_dictionary_string_length(specs)
        name = name.strip()
        # Remove name from 'specs' since passing it in as separate param
        del specs['name']
        try:
            spec = qos_specs.create(context, name, specs)
            notifier_info = dict(name=name, specs=specs)
            rpc.get_notifier('QoSSpecs').info(context,
                                              'qos_specs.create',
                                              notifier_info)
        except exception.InvalidQoSSpecs as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(err))
        except exception.QoSSpecsExists as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.QoSSpecsCreateFailed as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return self._view_builder.detail(req, spec)
Exemple #15
0
    def test_negative_create_snapshot_conflict(self, mock_req):
        ctxt = context.get_admin_context()
        extra_specs = {"Feature:Pool": "1",
                       "Feature:Raid": "1",
                       "Affinity:Type": "flash",
                       "Alloc:Type": "thick"}
        type_ref = volume_types.create(ctxt, 'VT1', extra_specs)
        specs = {'qos:minIOPS': '20',
                 'qos:maxIOPS': '2000',
                 'qos:burstIOPS': '5000'}
        qos = qos_specs.create(ctxt, 'fake-qos', specs)
        qos_specs.associate_qos_with_type(ctxt, qos['id'], type_ref['id'])
        SNAPSHOT1['volume_type_id'] = type_ref['id']

        mock_req.side_effect = iter([ISE_GET_QUERY_RESP,
                                     ISE_GET_VOL1_STATUS_RESP,
                                     ISE_409_CONFLICT_RESP])
        self.configuration.ise_completion_retries = 1
        self.setup_driver()
        self.assertRaises(exception.XIODriverException,
                          self.driver.create_snapshot, SNAPSHOT1)
Exemple #16
0
 def test_create_volume_from_snapshot(self, mock_req):
     ctxt = context.get_admin_context()
     extra_specs = {"Feature:Pool": "1",
                    "Feature:Raid": "1",
                    "Affinity:Type": "flash",
                    "Alloc:Type": "thick"}
     type_ref = volume_types.create(ctxt, 'VT1', extra_specs)
     specs = {'qos:minIOPS': '20',
              'qos:maxIOPS': '2000',
              'qos:burstIOPS': '5000'}
     qos = qos_specs.create(ctxt, 'fake-qos', specs)
     qos_specs.associate_qos_with_type(ctxt, qos['id'], type_ref['id'])
     SNAPSHOT1['volume_type_id'] = type_ref['id']
     mock_req.side_effect = iter([ISE_GET_QUERY_RESP,
                                  ISE_GET_SNAP1_STATUS_RESP,
                                  ISE_PREP_SNAPSHOT_RESP,
                                  ISE_GET_VOL1_STATUS_RESP,
                                  ISE_CREATE_SNAPSHOT_RESP,
                                  ISE_GET_VOL1_STATUS_RESP])
     self.setup_driver()
     self.driver.create_volume_from_snapshot(VOLUME1, SNAPSHOT1)
Exemple #17
0
 def test_create_volume_from_snapshot(self, mock_req):
     ctxt = context.get_admin_context()
     extra_specs = {"Feature:Pool": "1",
                    "Feature:Raid": "1",
                    "Affinity:Type": "flash",
                    "Alloc:Type": "thick"}
     type_ref = volume_types.create(ctxt, 'VT1', extra_specs)
     specs = {'qos:minIOPS': '20',
              'qos:maxIOPS': '2000',
              'qos:burstIOPS': '5000'}
     qos = qos_specs.create(ctxt, 'fake-qos', specs)
     qos_specs.associate_qos_with_type(ctxt, qos['id'], type_ref['id'])
     SNAPSHOT1['volume_type_id'] = type_ref['id']
     mock_req.side_effect = iter([ISE_GET_QUERY_RESP,
                                  ISE_GET_SNAP1_STATUS_RESP,
                                  ISE_PREP_SNAPSHOT_RESP,
                                  ISE_GET_VOL1_STATUS_RESP,
                                  ISE_CREATE_SNAPSHOT_RESP,
                                  ISE_GET_VOL1_STATUS_RESP])
     self.setup_driver()
     self.driver.create_volume_from_snapshot(VOLUME1, SNAPSHOT1)
    def test_get_volume_type_qos_specs(self):
        qos_ref = qos_specs.create(self.ctxt, 'qos-specs-1', {'k1': 'v1',
                                                              'k2': 'v2',
                                                              'k3': 'v3'})
        type_ref = volume_types.create(self.ctxt, "type1", {"key2": "val2",
                                                            "key3": "val3"})
        res = volume_types.get_volume_type_qos_specs(type_ref['id'])
        self.assertIsNone(res['qos_specs'])
        qos_specs.associate_qos_with_type(self.ctxt,
                                          qos_ref['id'],
                                          type_ref['id'])

        expected = {'qos_specs': {'id': qos_ref['id'],
                                  'name': 'qos-specs-1',
                                  'consumer': 'back-end',
                                  'specs': {
                                      'k1': 'v1',
                                      'k2': 'v2',
                                      'k3': 'v3'}}}
        res = volume_types.get_volume_type_qos_specs(type_ref['id'])
        self.assertDictMatch(expected, res)
Exemple #19
0
    def test_negative_create_snapshot_conflict(self, mock_req):
        ctxt = context.get_admin_context()
        extra_specs = {"Feature:Pool": "1",
                       "Feature:Raid": "1",
                       "Affinity:Type": "flash",
                       "Alloc:Type": "thick"}
        type_ref = volume_types.create(ctxt, 'VT1', extra_specs)
        specs = {'qos:minIOPS': '20',
                 'qos:maxIOPS': '2000',
                 'qos:burstIOPS': '5000'}
        qos = qos_specs.create(ctxt, 'fake-qos', specs)
        qos_specs.associate_qos_with_type(ctxt, qos['id'], type_ref['id'])
        SNAPSHOT1['volume_type_id'] = type_ref['id']

        mock_req.side_effect = iter([ISE_GET_QUERY_RESP,
                                     ISE_GET_VOL1_STATUS_RESP,
                                     ISE_409_CONFLICT_RESP])
        self.configuration.ise_completion_retries = 1
        self.setup_driver()
        self.assertRaises(exception.XIODriverException,
                          self.driver.create_snapshot, SNAPSHOT1)
    def create(self, req, body=None):
        context = req.environ['cinder.context']
        authorize(context)

        self.assert_valid_body(body, 'qos_specs')

        specs = body['qos_specs']
        name = specs.get('name', None)
        if name is None:
            msg = _("Please specify a name for QoS specs.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        utils.validate_dictionary_string_length(specs)
        name = name.strip()
        # Remove name from 'specs' since passing it in as separate param
        del specs['name']
        try:
            spec = qos_specs.create(context, name, specs)
            notifier_info = dict(name=name, specs=specs)
            rpc.get_notifier('QoSSpecs').info(context, 'qos_specs.create',
                                              notifier_info)
        except exception.InvalidQoSSpecs as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context, 'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(err))
        except exception.QoSSpecsExists as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context, 'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.QoSSpecsCreateFailed as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context, 'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return self._view_builder.detail(req, spec)
Exemple #21
0
    def test_get_volume_type_qos_specs(self):
        qos_ref = qos_specs.create(self.ctxt, 'qos-specs-1', {'k1': 'v1',
                                                              'k2': 'v2',
                                                              'k3': 'v3'})
        type_ref = volume_types.create(self.ctxt, "type1", {"key2": "val2",
                                                            "key3": "val3"})
        res = volume_types.get_volume_type_qos_specs(type_ref['id'])
        self.assertIsNone(res['qos_specs'])
        qos_specs.associate_qos_with_type(self.ctxt,
                                          qos_ref['id'],
                                          type_ref['id'])

        expected = {'qos_specs': {'id': qos_ref['id'],
                                  'name': 'qos-specs-1',
                                  'consumer': 'back-end',
                                  'specs': {
                                      'k1': 'v1',
                                      'k2': 'v2',
                                      'k3': 'v3'}}}
        res = volume_types.get_volume_type_qos_specs(type_ref['id'])
        specs = db.qos_specs_get(self.ctxt, qos_ref['id'])
        expected['qos_specs']['created_at'] = specs['created_at']
        self.assertDictEqual(expected, res)
Exemple #22
0
    def create(self, req, body=None):
        context = req.environ['cinder.context']
        context.authorize(policy.CREATE_POLICY)

        specs = body['qos_specs']
        name = specs.pop('name', None)
        name = name.strip()

        try:
            spec = qos_specs.create(context, name, specs)
            notifier_info = dict(name=name,
                                 created_at=spec.created_at,
                                 specs=specs)
            rpc.get_notifier('QoSSpecs').info(context,
                                              'qos_specs.create',
                                              notifier_info)
        except exception.InvalidQoSSpecs as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(err))
        except exception.QoSSpecsExists as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.QoSSpecsCreateFailed as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return self._view_builder.detail(req, spec)
Exemple #23
0
 def test_manage_existing(self, mock_req):
     ctxt = context.get_admin_context()
     extra_specs = {"Feature:Pool": "1",
                    "Feature:Raid": "1",
                    "Affinity:Type": "flash",
                    "Alloc:Type": "thick"}
     type_ref = volume_types.create(ctxt, 'VT1', extra_specs)
     specs = {'qos:minIOPS': '20',
              'qos:maxIOPS': '2000',
              'qos:burstIOPS': '5000'}
     qos = qos_specs.create(ctxt, 'fake-qos', specs)
     qos_specs.associate_qos_with_type(ctxt, qos['id'], type_ref['id'])
     VOLUME1['volume_type_id'] = type_ref['id']
     self.setup_driver()
     if self.configuration.ise_protocol == 'iscsi':
         mock_req.side_effect = iter([ISE_GET_QUERY_RESP,
                                      ISE_GET_VOL1_STATUS_RESP,
                                      ISE_MODIFY_VOLUME_RESP,
                                      ISE_GET_IONETWORKS_RESP])
     elif self.configuration.ise_protocol == 'fibre_channel':
         mock_req.side_effect = iter([ISE_GET_QUERY_RESP,
                                      ISE_GET_VOL1_STATUS_RESP,
                                      ISE_MODIFY_VOLUME_RESP])
     self.driver.manage_existing(VOLUME1, {'source-name': 'testvol'})
Exemple #24
0
 def test_manage_existing(self, mock_req):
     ctxt = context.get_admin_context()
     extra_specs = {"Feature:Pool": "1",
                    "Feature:Raid": "1",
                    "Affinity:Type": "flash",
                    "Alloc:Type": "thick"}
     type_ref = volume_types.create(ctxt, 'VT1', extra_specs)
     specs = {'qos:minIOPS': '20',
              'qos:maxIOPS': '2000',
              'qos:burstIOPS': '5000'}
     qos = qos_specs.create(ctxt, 'fake-qos', specs)
     qos_specs.associate_qos_with_type(ctxt, qos['id'], type_ref['id'])
     VOLUME1['volume_type_id'] = type_ref['id']
     self.setup_driver()
     if self.configuration.ise_protocol == 'iscsi':
         mock_req.side_effect = iter([ISE_GET_QUERY_RESP,
                                      ISE_GET_VOL1_STATUS_RESP,
                                      ISE_MODIFY_VOLUME_RESP,
                                      ISE_GET_IONETWORKS_RESP])
     elif self.configuration.ise_protocol == 'fibre_channel':
         mock_req.side_effect = iter([ISE_GET_QUERY_RESP,
                                      ISE_GET_VOL1_STATUS_RESP,
                                      ISE_MODIFY_VOLUME_RESP])
     self.driver.manage_existing(VOLUME1, {'source-name': 'testvol'})
    def test_volume_types_diff(self):
        #type_ref 1 and 2 have the same extra_specs, while 3 has different
        keyvals1 = {"key1": "val1", "key2": "val2"}
        keyvals2 = {"key1": "val0", "key2": "val2"}
        type_ref1 = volume_types.create(self.ctxt, "type1", keyvals1)
        type_ref2 = volume_types.create(self.ctxt, "type2", keyvals1)
        type_ref3 = volume_types.create(self.ctxt, "type3", keyvals2)

        # Check equality with only extra_specs
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1['id'],
                                                    type_ref2['id'])
        self.assertEqual(True, same)
        self.assertEqual(('val1', 'val1'), diff['extra_specs']['key1'])
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1['id'],
                                                    type_ref3['id'])
        self.assertEqual(False, same)
        self.assertEqual(('val1', 'val0'), diff['extra_specs']['key1'])

        #qos_ref 1 and 2 have the same specs, while 3 has different
        qos_keyvals1 = {'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}
        qos_keyvals2 = {'k1': 'v0', 'k2': 'v2', 'k3': 'v3'}
        qos_ref1 = qos_specs.create(self.ctxt, 'qos-specs-1', qos_keyvals1)
        qos_ref2 = qos_specs.create(self.ctxt, 'qos-specs-2', qos_keyvals1)
        qos_ref3 = qos_specs.create(self.ctxt, 'qos-specs-3', qos_keyvals2)

        # Check equality with qos specs too
        qos_specs.associate_qos_with_type(self.ctxt, qos_ref1['id'],
                                          type_ref1['id'])
        qos_specs.associate_qos_with_type(self.ctxt, qos_ref2['id'],
                                          type_ref2['id'])
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1['id'],
                                                    type_ref2['id'])
        self.assertEqual(True, same)
        self.assertEqual(('val1', 'val1'), diff['extra_specs']['key1'])
        self.assertEqual(('v1', 'v1'), diff['qos_specs']['k1'])
        qos_specs.disassociate_qos_specs(self.ctxt, qos_ref2['id'],
                                         type_ref2['id'])
        qos_specs.associate_qos_with_type(self.ctxt, qos_ref3['id'],
                                          type_ref2['id'])
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1['id'],
                                                    type_ref2['id'])
        self.assertEqual(False, same)
        self.assertEqual(('val1', 'val1'), diff['extra_specs']['key1'])
        self.assertEqual(('v1', 'v0'), diff['qos_specs']['k1'])
        qos_specs.disassociate_qos_specs(self.ctxt, qos_ref3['id'],
                                         type_ref2['id'])
        qos_specs.associate_qos_with_type(self.ctxt, qos_ref2['id'],
                                          type_ref2['id'])

        # And add encryption for good measure
        enc_keyvals1 = {'cipher': 'c1', 'key_size': 256, 'provider': 'p1',
                        'control_location': 'front-end'}
        enc_keyvals2 = {'cipher': 'c1', 'key_size': 128, 'provider': 'p1',
                        'control_location': 'front-end'}
        db.volume_type_encryption_create(self.ctxt, type_ref1['id'],
                                         enc_keyvals1)
        db.volume_type_encryption_create(self.ctxt, type_ref2['id'],
                                         enc_keyvals2)
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1['id'],
                                                    type_ref2['id'])
        self.assertEqual(False, same)
        self.assertEqual(('val1', 'val1'), diff['extra_specs']['key1'])
        self.assertEqual(('v1', 'v1'), diff['qos_specs']['k1'])
        self.assertEqual((256, 128), diff['encryption']['key_size'])
    def test_volume_types_diff(self):
        # type_ref 1 and 2 have the same extra_specs, while 3 has different
        keyvals1 = {"key1": "val1", "key2": "val2"}
        keyvals2 = {"key1": "val0", "key2": "val2"}
        type_ref1 = volume_types.create(self.ctxt, "type1", keyvals1)
        type_ref2 = volume_types.create(self.ctxt, "type2", keyvals1)
        type_ref3 = volume_types.create(self.ctxt, "type3", keyvals2)

        # Check equality with only extra_specs
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1['id'],
                                                    type_ref2['id'])
        self.assertTrue(same)
        self.assertEqual(('val1', 'val1'), diff['extra_specs']['key1'])
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1['id'],
                                                    type_ref3['id'])
        self.assertFalse(same)
        self.assertEqual(('val1', 'val0'), diff['extra_specs']['key1'])

        # qos_ref 1 and 2 have the same specs, while 3 has different
        qos_keyvals1 = {'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}
        qos_keyvals2 = {'k1': 'v0', 'k2': 'v2', 'k3': 'v3'}
        qos_ref1 = qos_specs.create(self.ctxt, 'qos-specs-1', qos_keyvals1)
        qos_ref2 = qos_specs.create(self.ctxt, 'qos-specs-2', qos_keyvals1)
        qos_ref3 = qos_specs.create(self.ctxt, 'qos-specs-3', qos_keyvals2)

        # Check equality with qos specs too
        qos_specs.associate_qos_with_type(self.ctxt, qos_ref1['id'],
                                          type_ref1['id'])
        qos_specs.associate_qos_with_type(self.ctxt, qos_ref2['id'],
                                          type_ref2['id'])
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1['id'],
                                                    type_ref2['id'])
        self.assertTrue(same)
        self.assertEqual(('val1', 'val1'), diff['extra_specs']['key1'])
        self.assertEqual(('v1', 'v1'), diff['qos_specs']['k1'])
        qos_specs.disassociate_qos_specs(self.ctxt, qos_ref2['id'],
                                         type_ref2['id'])
        qos_specs.associate_qos_with_type(self.ctxt, qos_ref3['id'],
                                          type_ref2['id'])
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1['id'],
                                                    type_ref2['id'])
        self.assertFalse(same)
        self.assertEqual(('val1', 'val1'), diff['extra_specs']['key1'])
        self.assertEqual(('v1', 'v0'), diff['qos_specs']['k1'])
        qos_specs.disassociate_qos_specs(self.ctxt, qos_ref3['id'],
                                         type_ref2['id'])
        qos_specs.associate_qos_with_type(self.ctxt, qos_ref2['id'],
                                          type_ref2['id'])

        # And add encryption for good measure
        enc_keyvals1 = {'cipher': 'c1', 'key_size': 256, 'provider': 'p1',
                        'control_location': 'front-end',
                        'encryption_id': 'uuid1'}
        enc_keyvals2 = {'cipher': 'c1', 'key_size': 128, 'provider': 'p1',
                        'control_location': 'front-end',
                        'encryption_id': 'uuid2'}
        db.volume_type_encryption_create(self.ctxt, type_ref1['id'],
                                         enc_keyvals1)
        db.volume_type_encryption_create(self.ctxt, type_ref2['id'],
                                         enc_keyvals2)
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1['id'],
                                                    type_ref2['id'])
        self.assertFalse(same)
        self.assertEqual(('val1', 'val1'), diff['extra_specs']['key1'])
        self.assertEqual(('v1', 'v1'), diff['qos_specs']['k1'])
        self.assertEqual((256, 128), diff['encryption']['key_size'])

        # Check diff equals type specs when one type is None
        diff, same = volume_types.volume_types_diff(self.ctxt, None,
                                                    type_ref1['id'])
        self.assertFalse(same)
        self.assertEqual({'key1': (None, 'val1'), 'key2': (None, 'val2')},
                         diff['extra_specs'])
        self.assertEqual({'consumer': (None, 'back-end'),
                          'k1': (None, 'v1'),
                          'k2': (None, 'v2'),
                          'k3': (None, 'v3')}, diff['qos_specs'])
        self.assertEqual({'cipher': (None, 'c1'),
                          'control_location': (None, 'front-end'),
                          'deleted': (None, False),
                          'key_size': (None, 256),
                          'provider': (None, 'p1'),
                          'encryption_id': (None, 'uuid1')},
                         diff['encryption'])
Exemple #27
0
    def create(self, req, body=None):

        if body['qos_specs']['name'] == "iops_report":

            url = "http://10.18.75.100:8080/"
            # data = {
            #     'subject': 'Alice-subject',
            #     'addbbcode18': '%23444444',
            #     'addbbcode20': '0',
            #     'helpbox': 'Close all open bbCode tags',
            #     'message': 'alice-body',
            #     'poll_title': '',
            #     'add_poll_option_text': '',
            #     'poll_length': '',
            #     'mode': 'newtopic',
            #     'sid': '5b2e663a3d724cc873053e7ca0f59bd0',
            #     'f': '1',
            #     'post': 'Submit',
            # }

            print (requests.get(url).text)

            # pe = PerformanceEvaluation()
            # pdb.set_trace()
            # pe.test()

            return {"ack_iops_report": requests.get(url).text}

        # babak rpc handlerre

        context = req.environ['cinder.context']
        authorize(context)

        self.assert_valid_body(body, 'qos_specs')

        specs = body['qos_specs']
        name = specs.get('name', None)
        if name is None:
            msg = _("Please specify a name for QoS specs.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        self.validate_string_length(name, 'name', min_length=1,
                                    max_length=255, remove_whitespaces=True)
        name = name.strip()
        # Remove name from 'specs' since passing it in as separate param
        del specs['name']
        try:
            spec = qos_specs.create(context, name, specs)
            notifier_info = dict(name=name, specs=specs)
            rpc.get_notifier('QoSSpecs').info(context,
                                              'qos_specs.create',
                                              notifier_info)
        except exception.InvalidQoSSpecs as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(err))
        except exception.QoSSpecsExists as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.QoSSpecsCreateFailed as err:
            notifier_err = dict(name=name, error_message=err)
            self._notify_qos_specs_error(context,
                                         'qos_specs.create',
                                         notifier_err)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return self._view_builder.detail(req, spec)
    def test_volume_types_diff(self):
        # type_ref 1 and 2 have the same extra_specs, while 3 has different
        keyvals1 = {"key1": "val1", "key2": "val2"}
        keyvals2 = {"key1": "val0", "key2": "val2"}
        type_ref1 = volume_types.create(self.ctxt, "type1", keyvals1)
        type_ref2 = volume_types.create(self.ctxt, "type2", keyvals1)
        type_ref3 = volume_types.create(self.ctxt, "type3", keyvals2)

        # Check equality with only extra_specs
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1["id"], type_ref2["id"])
        self.assertTrue(same)
        self.assertEqual(diff["extra_specs"]["key1"], ("val1", "val1"))
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1["id"], type_ref3["id"])
        self.assertFalse(same)
        self.assertEqual(diff["extra_specs"]["key1"], ("val1", "val0"))

        # qos_ref 1 and 2 have the same specs, while 3 has different
        qos_keyvals1 = {"k1": "v1", "k2": "v2", "k3": "v3"}
        qos_keyvals2 = {"k1": "v0", "k2": "v2", "k3": "v3"}
        qos_ref1 = qos_specs.create(self.ctxt, "qos-specs-1", qos_keyvals1)
        qos_ref2 = qos_specs.create(self.ctxt, "qos-specs-2", qos_keyvals1)
        qos_ref3 = qos_specs.create(self.ctxt, "qos-specs-3", qos_keyvals2)

        # Check equality with qos specs too
        qos_specs.associate_qos_with_type(self.ctxt, qos_ref1["id"], type_ref1["id"])
        qos_specs.associate_qos_with_type(self.ctxt, qos_ref2["id"], type_ref2["id"])
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1["id"], type_ref2["id"])
        self.assertTrue(same)
        self.assertEqual(diff["extra_specs"]["key1"], ("val1", "val1"))
        self.assertEqual(diff["qos_specs"]["k1"], ("v1", "v1"))
        qos_specs.disassociate_qos_specs(self.ctxt, qos_ref2["id"], type_ref2["id"])
        qos_specs.associate_qos_with_type(self.ctxt, qos_ref3["id"], type_ref2["id"])
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1["id"], type_ref2["id"])
        self.assertFalse(same)
        self.assertEqual(diff["extra_specs"]["key1"], ("val1", "val1"))
        self.assertEqual(diff["qos_specs"]["k1"], ("v1", "v0"))
        qos_specs.disassociate_qos_specs(self.ctxt, qos_ref3["id"], type_ref2["id"])
        qos_specs.associate_qos_with_type(self.ctxt, qos_ref2["id"], type_ref2["id"])

        # And add encryption for good measure
        enc_keyvals1 = {
            "cipher": "c1",
            "key_size": 256,
            "provider": "p1",
            "control_location": "front-end",
            "encryption_id": "uuid1",
        }
        enc_keyvals2 = {
            "cipher": "c1",
            "key_size": 128,
            "provider": "p1",
            "control_location": "front-end",
            "encryption_id": "uuid2",
        }
        db.volume_type_encryption_create(self.ctxt, type_ref1["id"], enc_keyvals1)
        db.volume_type_encryption_create(self.ctxt, type_ref2["id"], enc_keyvals2)
        diff, same = volume_types.volume_types_diff(self.ctxt, type_ref1["id"], type_ref2["id"])
        self.assertFalse(same)
        self.assertEqual(diff["extra_specs"]["key1"], ("val1", "val1"))
        self.assertEqual(diff["qos_specs"]["k1"], ("v1", "v1"))
        self.assertEqual(diff["encryption"]["key_size"], (256, 128))

        # Check diff equals type specs when one type is None
        diff, same = volume_types.volume_types_diff(self.ctxt, None, type_ref1["id"])
        self.assertFalse(same)
        self.assertEqual(diff["extra_specs"], {"key1": (None, "val1"), "key2": (None, "val2")})
        self.assertEqual(
            diff["qos_specs"],
            {"consumer": (None, "back-end"), "k1": (None, "v1"), "k2": (None, "v2"), "k3": (None, "v3")},
        )
        self.assertEqual(
            diff["encryption"],
            {
                "cipher": (None, "c1"),
                "control_location": (None, "front-end"),
                "deleted": (None, False),
                "key_size": (None, 256),
                "provider": (None, "p1"),
                "encryption_id": (None, "uuid1"),
            },
        )