コード例 #1
0
    def set_retention_product(self, job_t_id, retention_tag_name,
                              product_name):
        """
        XML-RPC method to update a job's retention tag, product, or both.

        There is an important distinction between product_name of None, which 
        means do not change the existing value, vs. empty string, which means 
        clear the existing product.
        """
        job = TaskBase.get_by_t_id(job_t_id)
        if job.can_change_product(identity.current.user) and \
            job.can_change_retention_tag(identity.current.user):
            if retention_tag_name and product_name:
                retention_tag = RetentionTag.by_name(retention_tag_name)
                product = Product.by_name(product_name)
                old_tag = job.retention_tag if job.retention_tag else None
                result = Utility.update_retention_tag_and_product(
                    job, retention_tag, product)
                job.record_activity(user=identity.current.user,
                                    service=u'XMLRPC',
                                    field=u'Retention Tag',
                                    action='Changed',
                                    old=old_tag.tag,
                                    new=retention_tag.tag)
            elif retention_tag_name and product_name == '':
                retention_tag = RetentionTag.by_name(retention_tag_name)
                old_tag = job.retention_tag if job.retention_tag else None
                result = Utility.update_retention_tag_and_product(
                    job, retention_tag, None)
                job.record_activity(user=identity.current.user,
                                    service=u'XMLRPC',
                                    field=u'Retention Tag',
                                    action='Changed',
                                    old=old_tag.tag,
                                    new=retention_tag.tag)
            elif retention_tag_name:
                retention_tag = RetentionTag.by_name(retention_tag_name)
                old_tag = job.retention_tag if job.retention_tag else None
                result = Utility.update_retention_tag(job, retention_tag)
                job.record_activity(user=identity.current.user,
                                    service=u'XMLRPC',
                                    field=u'Retention Tag',
                                    action='Changed',
                                    old=old_tag.tag,
                                    new=retention_tag.tag)
            elif product_name:
                product = Product.by_name(product_name)
                result = Utility.update_product(job, product)
            elif product_name == '':
                result = Utility.update_product(job, None)
            else:
                result = {'success': False, 'msg': 'Nothing to do'}

            if not result['success'] is True:
                raise BeakerException(
                    'Job %s not updated: %s' %
                    (job.id, result.get('msg', 'Unknown reason')))
        else:
            raise BeakerException('No permission to modify %s' % job)
コード例 #2
0
    def delete_jobs(self,
                    jobs=None,
                    tag=None,
                    complete_days=None,
                    family=None,
                    dryrun=False,
                    product=None):
        """
        delete_jobs will mark the job to be deleted

        To select jobs by id, pass an array for the *jobs* argument. Elements
        of the array must be strings of the form ``'J:123'``.
        Alternatively, pass some combination of the *tag*, *complete_days*, or
        *family* arguments to select jobs for deletion. These arguments behave
        as per the :meth:`jobs.list` method.

        If *dryrun* is True, deletions will be reported but nothing will be
        modified.

        Admins are not be able to delete jobs which are not owned by
        themselves by using the tag, complete_days etc kwargs, instead, they
        should do that via the *jobs* argument.
        """
        if jobs:  #Turn them into job objects
            if not isinstance(jobs, list):
                jobs = [jobs]
            jobs_to_try_to_del = []
            for j_id in jobs:
                job = TaskBase.get_by_t_id(j_id)
                if not isinstance(job, Job):
                    raise BeakerException('Incorrect task type passed %s' %
                                          j_id)
                if not job.can_delete(identity.current.user):
                    raise BeakerException(
                        "You don't have permission to delete job %s" % j_id)
                jobs_to_try_to_del.append(job)
            delete_jobs_kw = dict(jobs=jobs_to_try_to_del)
        else:
            # only allow people to delete their own jobs while using these kwargs
            delete_jobs_kw = dict(
                query=Job.find_jobs(tag=tag,
                                    complete_days=complete_days,
                                    family=family,
                                    product=product,
                                    owner=identity.current.user.user_name))

        deleted_jobs = Job.delete_jobs(**delete_jobs_kw)

        msg = 'Jobs deleted'
        if dryrun:
            session.rollback()
            msg = 'Dryrun only. %s' % (msg)
        return '%s: %s' % (msg, [j.t_id for j in deleted_jobs])
コード例 #3
0
    def update(self, email_address=None, tg_errors=None):
        """
        Update user preferences

        :param email_address: email address
        :type email_address: string
        """
        if tg_errors:
            raise BeakerException(', '.join(
                str(item) for item in tg_errors.values()))
        if email_address:
            if email_address == identity.current.user.email_address:
                raise BeakerException(
                    "Email address not changed: new address is same as before")
            else:
                identity.current.user.email_address = email_address
コード例 #4
0
    def set_response(self, taskid, response):
        """
        Updates the response (ack/nak) for a recipe set, or for all recipe sets 
        in a job. This is part of the results reviewing system.

        :param taskid: see above
        :type taskid: string
        :param response: new response, either ``'ack'`` or ``'nak'``
        :type response: string
        """
        job = TaskBase.get_by_t_id(taskid)
        if job.can_set_response(identity.current.user):
            job.set_response(response)
        else:
            raise BeakerException('No permission to modify %s' % job)
コード例 #5
0
 def _check_job_deletability(self, t_id, job):
     if not isinstance(job, Job):
         raise TypeError('%s is not of type %s' % (t_id, Job.__name__))
     if not job.can_delete(identity.current.user):
         raise BeakerException(
             _(u'You do not have permission to delete %s' % t_id))