示例#1
0
    def test_volume_type_get_with_extra_specs(self):
        volume_type = db.volume_type_get(context.get_admin_context(),
                                         self.volume_type1_id)
        self.assertEquals(volume_type['extra_specs'], self.vol_type1_specs)

        volume_type = db.volume_type_get(context.get_admin_context(),
                                         self.vol_type2_id)
        self.assertEquals(volume_type['extra_specs'], {})
    def test_volume_type_get_with_extra_specs(self):
        volume_type = db.volume_type_get(
            context.get_admin_context(),
            self.volume_type1_id)
        self.assertEqual(volume_type['extra_specs'], self.vol_type1_specs)

        volume_type = db.volume_type_get(
            context.get_admin_context(),
            self.vol_type2_id)
        self.assertEqual(volume_type['extra_specs'], {})
示例#3
0
文件: manager.py 项目: artofwar/stack
    def create_volume(self, context, topic, volume_id, snapshot_id=None,
                      image_id=None, request_spec=None,
                      filter_properties=None):
        try:
            if request_spec is None:
                # For RPC version < 1.2 backward compatibility
                request_spec = {}
                volume_ref = db.volume_get(context, volume_id)
                size = volume_ref.get('size')
                availability_zone = volume_ref.get('availability_zone')
                volume_type_id = volume_ref.get('volume_type_id')
                vol_type = db.volume_type_get(context, volume_type_id)
                volume_properties = {'size': size,
                                     'availability_zone': availability_zone,
                                     'volume_type_id': volume_type_id}
                request_spec.update(
                    {'volume_id': volume_id,
                     'snapshot_id': snapshot_id,
                     'image_id': image_id,
                     'volume_properties': volume_properties,
                     'volume_type': dict(vol_type).iteritems()})

            self.driver.schedule_create_volume(context, request_spec,
                                               filter_properties)
        except exception.NoValidHost as ex:
            volume_state = {'volume_state': {'status': 'error'}}
            self._set_volume_state_and_notify('create_volume',
                                              volume_state,
                                              context, ex, request_spec)
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                volume_state = {'volume_state': {'status': 'error'}}
                self._set_volume_state_and_notify('create_volume',
                                                  volume_state,
                                                  context, ex, request_spec)
示例#4
0
    def test_volume_create_with_type(self):
        vol_type = db.volume_type_create(
            context.get_admin_context(),
            dict(name=CONF.default_volume_type, extra_specs={})
        )

        db_vol_type = db.volume_type_get(context.get_admin_context(),
                                         vol_type.id)

        vol = {
            "size": 100,
            "name": "Volume Test Name",
            "description": "Volume Test Desc",
            "availability_zone": "zone1:host1",
            "volume_type": db_vol_type['id'],
        }
        body = {"volume": vol}
        req = fakes.HTTPRequest.blank('/v2/volumes')
        res_dict = self.controller.create(req, body)
        volume_id = res_dict['volume']['id']
        self.assertEquals(len(res_dict), 1)

        self.stubs.Set(volume_api.API, 'get_all',
                       lambda *args, **kwargs:
                       [stubs.stub_volume(volume_id,
                                          volume_type={'name': vol_type})])
        req = fakes.HTTPRequest.blank('/v2/volumes/detail')
        res_dict = self.controller.detail(req)
示例#5
0
    def test_volume_create_with_type(self):
        vol_type = db.volume_type_create(
            context.get_admin_context(),
            dict(name=FLAGS.default_volume_type, extra_specs={}))

        db_vol_type = db.volume_type_get(context.get_admin_context(),
                                         vol_type.id)

        vol = {
            "size": 100,
            "name": "Volume Test Name",
            "description": "Volume Test Desc",
            "availability_zone": "zone1:host1",
            "volume_type": db_vol_type['id'],
        }
        body = {"volume": vol}
        req = fakes.HTTPRequest.blank('/v2/volumes')
        res_dict = self.controller.create(req, body)
        volume_id = res_dict['volume']['id']
        self.assertEquals(len(res_dict), 1)

        self.stubs.Set(
            volume_api.API, 'get_all', lambda *args, **kwargs:
            [stubs.stub_volume(volume_id, volume_type={'name': vol_type})])
        req = fakes.HTTPRequest.blank('/v2/volumes/detail')
        res_dict = self.controller.detail(req)
示例#6
0
文件: test_cg.py 项目: suman-d/cinder
    def test_create_volume_with_consistencygroup_invalid_type(self):
        """Test volume creation with ConsistencyGroup & invalid volume type."""
        vol_type = db.volume_type_create(
            context.get_admin_context(),
            dict(name=conf_fixture.def_vol_type, extra_specs={})
        )
        db_vol_type = db.volume_type_get(context.get_admin_context(),
                                         vol_type.id)
        cg = {
            'id': '1',
            'name': 'cg1',
            'volume_type_id': db_vol_type['id'],
        }
        fake_type = {
            'id': '9999',
            'name': 'fake',
        }
        vol_api = cinder.volume.api.API()

        # Volume type must be provided when creating a volume in a
        # consistency group.
        self.assertRaises(exception.InvalidInput,
                          vol_api.create,
                          self.context, 1, 'vol1', 'volume 1',
                          consistencygroup=cg)

        # Volume type must be valid.
        self.assertRaises(exception.InvalidInput,
                          vol_api.create,
                          self.context, 1, 'vol1', 'volume 1',
                          volume_type=fake_type,
                          consistencygroup=cg)
示例#7
0
    def test_create_volume_with_group_invalid_type(self):
        """Test volume creation with group & invalid volume type."""
        vol_type = db.volume_type_create(
            context.get_admin_context(),
            dict(name=conf_fixture.def_vol_type, extra_specs={})
        )
        db_vol_type = db.volume_type_get(context.get_admin_context(),
                                         vol_type.id)

        grp = tests_utils.create_group(
            self.context,
            availability_zone=CONF.storage_availability_zone,
            status=fields.GroupStatus.AVAILABLE,
            volume_type_ids=[db_vol_type['id']],
            group_type_id=fake.GROUP_TYPE_ID,
            host=CONF.host)

        fake_type = {
            'id': '9999',
            'name': 'fake',
        }

        # Volume type must be provided when creating a volume in a
        # group.
        self.assertRaises(exception.InvalidInput,
                          self.volume_api.create,
                          self.context, 1, 'vol1', 'volume 1',
                          group=grp)

        # Volume type must be valid.
        self.assertRaises(exception.InvalidInput,
                          self.volume_api.create,
                          self.context, 1, 'vol1', 'volume 1',
                          volume_type=fake_type,
                          group=grp)
示例#8
0
 def test_volume_type_update(self):
     vol_type_ref = volume_types.create(self.ctxt, 'fake volume type')
     updates = dict(name='test_volume_type_update',
                    description=None,
                    is_public=None)
     db.volume_type_update(self.ctxt, vol_type_ref.id, updates)
     updated_vol_type = db.volume_type_get(self.ctxt, vol_type_ref.id)
     self.assertEqual('test_volume_type_update', updated_vol_type['name'])
     volume_types.destroy(self.ctxt, vol_type_ref.id)
 def test_volume_type_update(self):
     vol_type_ref = volume_types.create(self.ctxt, 'fake volume type')
     updates = dict(name='test_volume_type_update',
                    description=None,
                    is_public=None)
     db.volume_type_update(self.ctxt, vol_type_ref.id, updates)
     updated_vol_type = db.volume_type_get(self.ctxt, vol_type_ref.id)
     self.assertEqual('test_volume_type_update', updated_vol_type['name'])
     volume_types.destroy(self.ctxt, vol_type_ref.id)
示例#10
0
def get_volume_type(ctxt, id):
    """Retrieves single volume type by id."""
    if id is None:
        msg = _("id cannot be None")
        raise exception.InvalidVolumeType(reason=msg)

    if ctxt is None:
        ctxt = context.get_admin_context()

    return db.volume_type_get(ctxt, id)
示例#11
0
def get_volume_type(ctxt, id, expected_fields=None):
    """Retrieves single volume type by id."""
    if id is None:
        msg = _("id cannot be None")
        raise exception.InvalidVolumeType(reason=msg)

    if ctxt is None:
        ctxt = context.get_admin_context()

    return db.volume_type_get(ctxt, id, expected_fields=expected_fields)
示例#12
0
    def test_volume_type_get_with_projects(self):
        """Ensure volume types get can load projects."""
        projects = [fake.PROJECT_ID, fake.PROJECT2_ID, fake.PROJECT3_ID]
        vol_type = db.volume_type_create(self.ctxt,
                                         {'name': 'my-vol-type'},
                                         projects=projects)

        db_vol_type = db.volume_type_get(self.ctxt, vol_type.id,
                                         expected_fields=['projects'])

        self.assertEqual(set(projects), set(db_vol_type['projects']))
示例#13
0
    def test_volume_type_get_with_projects(self):
        """Ensure volume types get can load projects."""
        projects = [fake.PROJECT_ID, fake.PROJECT2_ID, fake.PROJECT3_ID]
        vol_type = db.volume_type_create(self.ctxt, {'name': 'my-vol-type'},
                                         projects=projects)

        db_vol_type = db.volume_type_get(self.ctxt,
                                         vol_type.id,
                                         expected_fields=['projects'])

        self.assertEqual(set(projects), set(db_vol_type['projects']))
示例#14
0
    def test_qos_specs_disassociate(self):
        type_id = volume_types.create(self.ctxt, "TypeName")["id"]
        specs_id = self._create_qos_specs("FakeQos")
        db.volume_type_qos_associate(self.ctxt, type_id, specs_id)
        res = db.qos_specs_associations_get(self.ctxt, specs_id)
        self.assertEqual(res[0]["id"], type_id)
        self.assertEqual(res[0]["qos_specs_id"], specs_id)

        db.qos_specs_disassociate(self.ctxt, specs_id, type_id)
        res = db.qos_specs_associations_get(self.ctxt, specs_id)
        self.assertEqual(len(res), 0)
        res = db.volume_type_get(self.ctxt, type_id)
        self.assertIsNone(res["qos_specs_id"])
示例#15
0
def get_volume_type(
        ctxt: Optional[context.RequestContext],
        id: Optional[str],
        expected_fields: Optional[Iterable[str]] = None) -> dict[str, Any]:
    """Retrieves single volume type by id."""
    if id is None:
        msg = _("id cannot be None")
        raise exception.InvalidVolumeType(reason=msg)

    if ctxt is None:
        ctxt = context.get_admin_context()

    return db.volume_type_get(ctxt, id, expected_fields=expected_fields)
示例#16
0
    def test_qos_specs_disassociate(self):
        type_id = volume_types.create(self.ctxt, 'TypeName')['id']
        specs_id = self._create_qos_specs('FakeQos')
        db.volume_type_qos_associate(self.ctxt, type_id, specs_id)
        res = db.qos_specs_associations_get(self.ctxt, specs_id)
        self.assertEqual(res[0]['id'], type_id)
        self.assertEqual(res[0]['qos_specs_id'], specs_id)

        db.qos_specs_disassociate(self.ctxt, specs_id, type_id)
        res = db.qos_specs_associations_get(self.ctxt, specs_id)
        self.assertEqual(len(res), 0)
        res = db.volume_type_get(self.ctxt, type_id)
        self.assertEqual(res['qos_specs_id'], None)
示例#17
0
    def test_qos_specs_disassociate(self):
        type_id = volume_types.create(self.ctxt, 'TypeName')['id']
        specs_id = self._create_qos_specs('FakeQos')
        db.volume_type_qos_associate(self.ctxt, type_id, specs_id)
        res = db.qos_specs_associations_get(self.ctxt, specs_id)
        self.assertEqual(type_id, res[0]['id'])
        self.assertEqual(specs_id, res[0]['qos_specs_id'])

        db.qos_specs_disassociate(self.ctxt, specs_id, type_id)
        res = db.qos_specs_associations_get(self.ctxt, specs_id)
        self.assertEqual(0, len(res))
        res = db.volume_type_get(self.ctxt, type_id)
        self.assertIsNone(res['qos_specs_id'])
示例#18
0
    def test_volume_type_get_with_qos_specs(self):
        """Ensure volume types get can load qos_specs."""
        qos_data = {'name': 'qos', 'consumer': 'front-end',
                    'specs': {'key': 'value', 'key2': 'value2'}}
        qos = utils.create_qos(self.ctxt, **qos_data)
        vol_type = db.volume_type_create(self.ctxt,
                                         {'name': 'my-vol-type',
                                          'qos_specs_id': qos['id']})

        db_vol_type = db.volume_type_get(self.ctxt, vol_type.id,
                                         expected_fields=['qos_specs'])

        expected = {('QoS_Specs_Name', 'qos'), ('consumer', 'front-end'),
                    ('key', 'value'), ('key2', 'value2')}
        actual = {(spec.key, spec.value) for spec in db_vol_type['qos_specs']}
        self.assertEqual(expected, actual)
示例#19
0
    def test_volume_type_get_with_qos_specs(self):
        """Ensure volume types get can load qos_specs."""
        qos_data = {'name': 'qos', 'consumer': 'front-end',
                    'specs': {'key': 'value', 'key2': 'value2'}}
        qos = utils.create_qos(self.ctxt, **qos_data)
        vol_type = db.volume_type_create(self.ctxt,
                                         {'name': 'my-vol-type',
                                          'qos_specs_id': qos['id']})

        db_vol_type = db.volume_type_get(self.ctxt, vol_type.id,
                                         expected_fields=['qos_specs'])

        expected = {('QoS_Specs_Name', 'qos'), ('consumer', 'front-end'),
                    ('key', 'value'), ('key2', 'value2')}
        actual = {(spec.key, spec.value) for spec in db_vol_type['qos_specs']}
        self.assertEqual(expected, actual)
示例#20
0
    def create_volume(self,
                      context,
                      topic,
                      volume_id,
                      snapshot_id=None,
                      image_id=None,
                      request_spec=None,
                      filter_properties=None):
        try:
            if request_spec is None:
                # For RPC version < 1.2 backward compatibility
                request_spec = {}
                volume_ref = db.volume_get(context, volume_id)
                size = volume_ref.get('size')
                availability_zone = volume_ref.get('availability_zone')
                volume_type_id = volume_ref.get('volume_type_id')
                vol_type = db.volume_type_get(context, volume_type_id)
                volume_properties = {
                    'size': size,
                    'availability_zone': availability_zone,
                    'volume_type_id': volume_type_id
                }
                request_spec.update({
                    'volume_id': volume_id,
                    'snapshot_id': snapshot_id,
                    'image_id': image_id,
                    'volume_properties': volume_properties,
                    'volume_type': dict(vol_type).iteritems()
                })

            self.driver.schedule_create_volume(context, request_spec,
                                               filter_properties)
        except exception.NoValidHost as ex:
            volume_state = {'volume_state': {'status': 'error'}}
            self._set_volume_state_and_notify('create_volume', volume_state,
                                              context, ex, request_spec)
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                volume_state = {'volume_state': {'status': 'error'}}
                self._set_volume_state_and_notify('create_volume',
                                                  volume_state, context, ex,
                                                  request_spec)
示例#21
0
    def test_volume_create_with_type(self, mock_service_get):
        vol_type = db.volume_type_create(
            context.get_admin_context(),
            dict(name=CONF.default_volume_type, extra_specs={}))
        db_vol_type = db.volume_type_get(context.get_admin_context(),
                                         vol_type.id)

        vol = {
            "size": 100,
            "display_name": "Volume Test Name",
            "display_description": "Volume Test Desc",
            "availability_zone": "zone1:host1",
            "volume_type": "FakeTypeName"
        }
        body = {"volume": vol}
        req = fakes.HTTPRequest.blank('/v1/volumes')
        # Raise 404 when type name isn't valid
        self.assertRaises(exc.VolumeTypeNotFoundByName, self.controller.create,
                          req, body)

        # Use correct volume type name
        vol.update(dict(volume_type=CONF.default_volume_type))
        body.update(dict(volume=vol))
        res_dict = self.controller.create(req, body)
        self.assertIn('id', res_dict['volume'])
        self.assertEqual(1, len(res_dict))
        self.assertEqual(db_vol_type['name'],
                         res_dict['volume']['volume_type'])

        # Use correct volume type id
        vol.update(dict(volume_type=db_vol_type['id']))
        body.update(dict(volume=vol))
        res_dict = self.controller.create(req, body)
        self.assertIn('id', res_dict['volume'])
        self.assertEqual(1, len(res_dict))
        self.assertEqual(db_vol_type['name'],
                         res_dict['volume']['volume_type'])
示例#22
0
文件: quota.py 项目: NeCTAR-RC/cinder
    def add_volume_type_opts(self, context, opts, volume_type_id):
        """Add volume type resource options.

        Adds elements to the opts hash for volume type quotas.
        If a resource is being reserved ('gigabytes', etc) and the volume
        type is set up for its own quotas, these reservations are copied
        into keys for 'gigabytes_<volume type name>', etc.

        :param context: The request context, for access checks.
        :param opts: The reservations options hash.
        :param volume_type_id: The volume type id for this reservation.
        """
        if not volume_type_id:
            return

        # NOTE(jdg): set inactive to True in volume_type_get, as we
        # may be operating on a volume that was created with a type
        # that has since been deleted.
        volume_type = db.volume_type_get(context, volume_type_id, True)

        for quota in ('volumes', 'gigabytes', 'snapshots'):
            if quota in opts:
                vtype_quota = "%s_%s" % (quota, volume_type['name'])
                opts[vtype_quota] = opts[quota]
示例#23
0
文件: quota.py 项目: skyniluyy/cinder
    def add_volume_type_opts(self, context, opts, volume_type_id):
        """Add volume type resource options.

        Adds elements to the opts hash for volume type quotas.
        If a resource is being reserved ('gigabytes', etc) and the volume
        type is set up for its own quotas, these reservations are copied
        into keys for 'gigabytes_<volume type name>', etc.

        :param context: The request context, for access checks.
        :param opts: The reservations options hash.
        :param volume_type_id: The volume type id for this reservation.
        """
        if not volume_type_id:
            return

        # NOTE(jdg): set inactive to True in volume_type_get, as we
        # may be operating on a volume that was created with a type
        # that has since been deleted.
        volume_type = db.volume_type_get(context, volume_type_id, True)

        for quota in ('volumes', 'gigabytes', 'snapshots'):
            if quota in opts:
                vtype_quota = "%s_%s" % (quota, volume_type['name'])
                opts[vtype_quota] = opts[quota]
示例#24
0
def is_public_volume_type(context, volume_type_id):
    """Return is_public boolean value of volume type"""
    volume_type = db.volume_type_get(context, volume_type_id)
    return volume_type['is_public']
def is_public_volume_type(context, volume_type_id):
    """Return is_public boolean value of volume type"""
    volume_type = db.volume_type_get(context, volume_type_id)
    return volume_type["is_public"]
示例#26
0
def is_public_volume_type(context: context.RequestContext,
                          volume_type_id: str) -> bool:
    """Return is_public boolean value of volume type"""
    volume_type = db.volume_type_get(context, volume_type_id)
    return volume_type['is_public']