'Updates group.
Update group by adding volumes to the group,
or removing volumes from the group.'

def update_group(self, context, group, add_volumes=None, remove_volumes=None):

    add_volumes_ref = self._collect_volumes_for_group(context, group, add_volumes, add=True)
    remove_volumes_ref = self._collect_volumes_for_group(context, group, remove_volumes, add=False)
    self._notify_about_group_usage(context, group, 'update.start')
    try:
        utils.require_driver_initialized(self.driver)
        try:
            (model_update, add_volumes_update, remove_volumes_update) = self.driver.update_group(context, group, add_volumes=add_volumes_ref, remove_volumes=remove_volumes_ref)
        except NotImplementedError:
            cgsnap_type = group_types.get_default_cgsnapshot_type()
            if (group.group_type_id != cgsnap_type['id']):
                (model_update, add_volumes_update, remove_volumes_update) = self._update_group_generic(context, group, add_volumes=add_volumes_ref, remove_volumes=remove_volumes_ref)
            else:
                (cg, remove_volumes_ref) = self._convert_group_to_cg(group, remove_volumes_ref)
                (model_update, add_volumes_update, remove_volumes_update) = self.driver.update_consistencygroup(context, cg, add_volumes=add_volumes_ref, remove_volumes=remove_volumes_ref)
                self._remove_consistencygroup_id_from_volumes(remove_volumes_ref)
        volumes_to_update = []
        if add_volumes_update:
            volumes_to_update.extend(add_volumes_update)
        if remove_volumes_update:
            volumes_to_update.extend(remove_volumes_update)
        self.db.volumes_update(context, volumes_to_update)
        if model_update:
            if (model_update['status'] in [fields.GroupStatus.ERROR]):
                msg = (_('Error    occurred    when    updating    group    %s.') % group.id)
                LOG.error(msg)
                raise exception.VolumeDriverException(message=msg)
            group.update(model_update)
            group.save()
    except Exception as e:
        with excutils.save_and_reraise_exception():
            if isinstance(e, exception.VolumeDriverException):
                LOG.error('Error    occurred    in    the    volume    driver    when    updating    group    %(group_id)s.', {'group_id': group.id})
            else:
                LOG.error('Failed    to    update    group    %(group_id)s.', {'group_id': group.id})
            group.status = fields.GroupStatus.ERROR
            group.save()
            for add_vol in add_volumes_ref:
                add_vol.status = 'error'
                add_vol.save()
            for rem_vol in remove_volumes_ref:
                if isinstance(e, exception.VolumeDriverException):
                    rem_vol.consistencygroup_id = None
                    rem_vol.consistencygroup = None
                rem_vol.status = 'error'
                rem_vol.save()
    for add_vol in add_volumes_ref:
        add_vol.group_id = group.id
        add_vol.save()
    for rem_vol in remove_volumes_ref:
        rem_vol.group_id = None
        rem_vol.save()
    group.status = fields.GroupStatus.AVAILABLE
    group.save()
    self._notify_about_group_usage(context, group, 'update.end')
    LOG.info('Update    group    completed    successfully.', resource={'type': 'group', 'id': group.id})
