def test_update_db_fail(self, mock_update, mock_get_volume_type): mock_update.side_effect = exception.VolumeTypeUpdateFailed( id=DEFAULT_VOLUME_TYPE) mock_get_volume_type.return_value = fake_volume_type( DEFAULT_VOLUME_TYPE) body = { "volume_type": { "name": "vol_type_1_1", "description": "vol_type_desc_1_1" } } req = fakes.HTTPRequest.blank('/v2/%s/types/%s' % (fake.PROJECT_ID, DEFAULT_VOLUME_TYPE)) req.method = 'PUT' self.assertEqual(0, len(self.notifier.notifications)) self.assertRaises(webob.exc.HTTPInternalServerError, self.controller._update, req, DEFAULT_VOLUME_TYPE, body=body) self.assertEqual(1, len(self.notifier.notifications))
def update(context, id, name, description, is_public=None): """Update volume type by id.""" if id is None: msg = _("id cannot be None") raise exception.InvalidVolumeType(reason=msg) elevated = context if context.is_admin else context.elevated() old_volume_type = get_volume_type(elevated, id) try: type_updated = db.volume_type_update(elevated, id, dict(name=name, description=description, is_public=is_public)) # Rename resource in quota if volume type name is changed. if name: old_type_name = old_volume_type.get('name') if old_type_name != name: QUOTAS.update_quota_resource(elevated, old_type_name, name) except db_exc.DBError: LOG.exception(_LE('DB error:')) raise exception.VolumeTypeUpdateFailed(id=id) return type_updated
def return_volume_types_update_fail(context, id, name, description): raise exception.VolumeTypeUpdateFailed(id=id)
def set_volume(self, volume): changed = self.get_changed_fields(volume) if not changed: changed = self.get_fields(volume) extra_specs = changed.pop('extra_specs', None) qos_specs = changed.pop('qos_specs', None) # Since OVOs are not tracking QoS or Extra specs dictionary changes, # we only support setting QoS or Extra specs on creation or add them # later. vol_type_id = changed.get('volume_type_id') if vol_type_id == self.DEFAULT_TYPE.id: if extra_specs or qos_specs: raise cinder_exception.VolumeTypeUpdateFailed( id=self.DEFAULT_TYPE.name) elif vol_type_id: vol_type_fields = { 'id': volume.volume_type_id, 'name': volume.volume_type_id, 'extra_specs': extra_specs, 'is_public': True } if qos_specs: res = self.db.qos_specs_create( objects.CONTEXT, { 'name': volume.volume_type_id, 'consumer': 'back-end', 'specs': qos_specs }) # Cinder is automatically generating an ID, replace it query = sqla_api.model_query(objects.CONTEXT, models.QualityOfServiceSpecs) query.filter_by(id=res['id']).update( {'id': volume.volume_type.qos_specs_id}) self.db.volume_type_create(objects.CONTEXT, vol_type_fields) else: if extra_specs is not None: self.db.volume_type_extra_specs_update_or_create( objects.CONTEXT, volume.volume_type_id, extra_specs) self.db.qos_specs_update( objects.CONTEXT, volume.volume_type.qos_specs_id, { 'name': volume.volume_type_id, 'consumer': 'back-end', 'specs': qos_specs }) else: volume._ovo.volume_type = self.DEFAULT_TYPE volume._ovo.volume_type_id = self.DEFAULT_TYPE.id changed['volume_type_id'] = self.DEFAULT_TYPE.id # Create the volume if 'id' in changed: LOG.debug('set_volume creating %s', changed) try: self.db.volume_create(objects.CONTEXT, changed) changed = None except exception.DBDuplicateEntry: del changed['id'] if changed: LOG.debug('set_volume updating %s', changed) self.db.volume_update(objects.CONTEXT, volume.id, changed) super(DBPersistence, self).set_volume(volume)