def test_volume_type_delete_with_group_in_use(self): volume_type = db.volume_type_create(self.ctxt, {'name': 'fake volume type'}) group = db.group_create(self.ctxt, {}) db.group_volume_type_mapping_create(self.ctxt, group['id'], volume_type['id']) self.assertRaises(exception.VolumeTypeInUse, volume_types.destroy, self.ctxt, volume_type['id']) db.group_destroy(self.ctxt, group['id']) volume_types.destroy(self.ctxt, volume_type['id'])
def test_volume_type_delete_with_group_in_use(self): volume_type = db.volume_type_create(self.ctxt, {'name': 'fake volume type'}) group = db.group_create(self.ctxt, {}) db.group_volume_type_mapping_create(self.ctxt, group['id'], volume_type['id']) self.assertRaises(exception.VolumeTypeInUse, volume_types.destroy, self.ctxt, volume_type['id']) db.group_destroy(self.ctxt, group['id']) volume_types.destroy(self.ctxt, volume_type['id'])
def _create_group_from_source_group(self, context, group, source_group_id): try: source_group = objects.Group.get_by_id(context, source_group_id) source_vols = objects.VolumeList.get_all_by_generic_group( context, source_group.id) if not source_vols: msg = _("Source Group is empty. No group " "will be created.") raise exception.InvalidGroup(reason=msg) for source_vol in source_vols: kwargs = {} kwargs['availability_zone'] = group.availability_zone kwargs['source_group'] = source_group kwargs['group'] = group kwargs['source_volume'] = source_vol volume_type_id = source_vol.volume_type_id if volume_type_id: kwargs['volume_type'] = volume_types.get_volume_type( context, volume_type_id) # Create group volume_type mapping entries try: db.group_volume_type_mapping_create( context, group.id, volume_type_id) except exception.GroupVolumeTypeMappingExists: # Only need to create one group volume_type mapping # entry for the same combination, skipping. LOG.info( _LI("A mapping entry already exists for group" " %(grp)s and volume type %(vol_type)s. " "Do not need to create again."), { 'grp': group.id, 'vol_type': volume_type_id }) pass # Since source_group is passed in, the following call will # create a db entry for the volume, but will not call the # volume manager to create a real volume in the backend yet. # If error happens, taskflow will handle rollback of quota # and removal of volume entry in the db. try: self.volume_api.create(context, source_vol.size, None, None, **kwargs) except exception.CinderException: with excutils.save_and_reraise_exception(): LOG.error( _LE("Error occurred when creating cloned " "volume in the process of creating " "group %(group)s from " "source group %(source_group)s."), { 'group': group.id, 'source_group': source_group.id }) except Exception: with excutils.save_and_reraise_exception(): try: group.destroy() finally: LOG.error( _LE("Error occurred when creating " "group %(group)s from source group " "%(source_group)s."), { 'group': group.id, 'source_group': source_group.id }) volumes = objects.VolumeList.get_all_by_generic_group( context, group.id) for vol in volumes: # Update the host field for the volume. vol.host = group.host vol.save() self.volume_rpcapi.create_group_from_src(context, group, None, source_group)
def _create_group_from_source_group(self, context, group, source_group_id): try: source_group = objects.Group.get_by_id(context, source_group_id) source_vols = objects.VolumeList.get_all_by_generic_group( context, source_group.id) if not source_vols: msg = _("Source Group is empty. No group " "will be created.") raise exception.InvalidGroup(reason=msg) for source_vol in source_vols: kwargs = {} kwargs['availability_zone'] = group.availability_zone kwargs['source_group'] = source_group kwargs['group'] = group kwargs['source_volume'] = source_vol volume_type_id = source_vol.volume_type_id if volume_type_id: kwargs['volume_type'] = volume_types.get_volume_type( context, volume_type_id) # Create group volume_type mapping entries try: db.group_volume_type_mapping_create(context, group.id, volume_type_id) except exception.GroupVolumeTypeMappingExists: # Only need to create one group volume_type mapping # entry for the same combination, skipping. LOG.info(_LI("A mapping entry already exists for group" " %(grp)s and volume type %(vol_type)s. " "Do not need to create again."), {'grp': group.id, 'vol_type': volume_type_id}) pass # Since source_group is passed in, the following call will # create a db entry for the volume, but will not call the # volume manager to create a real volume in the backend yet. # If error happens, taskflow will handle rollback of quota # and removal of volume entry in the db. try: self.volume_api.create(context, source_vol.size, None, None, **kwargs) except exception.CinderException: with excutils.save_and_reraise_exception(): LOG.error(_LE("Error occurred when creating cloned " "volume in the process of creating " "group %(group)s from " "source group %(source_group)s."), {'group': group.id, 'source_group': source_group.id}) except Exception: with excutils.save_and_reraise_exception(): try: group.destroy() finally: LOG.error(_LE("Error occurred when creating " "group %(group)s from source group " "%(source_group)s."), {'group': group.id, 'source_group': source_group.id}) volumes = objects.VolumeList.get_all_by_generic_group(context, group.id) for vol in volumes: # Update the host field for the volume. vol.host = group.host vol.save() self.volume_rpcapi.create_group_from_src(context, group, None, source_group)