Ejemplo n.º 1
0
    def repair(self, request):
        reviews = []
        reqid = str(request)
        req = get_request(self.api.apiurl, reqid)

        if not req: 
            raise oscerr.WrongArgs('Request {} not found'.format(reqid))

        if req.state.name != 'review':
            print('Request "{}" is not in review state'.format(reqid))
            return

        reviews = [r.by_project for r in req.reviews if ':Staging:' in str(r.by_project) and r.state == 'new']

        if reviews:
            if len(reviews) > 1:
                raise oscerr.WrongArgs('Request {} had multiple review opened by different staging project'.format(reqid))
        else:
            raise oscerr.WrongArgs('Request {} is not for staging project'.format(reqid))

        staging_project = reviews[0]
        data = self.api.get_prj_pseudometa(staging_project)
        for request in data['requests']:
            if request['id'] == reqid:
                print('Request "{}" had the good setup in "{}"'.format(reqid, staging_project))
                return

        # a bad request setup found
        print('Repairing "{}"'.format(reqid))
        change_review_state(self.api.apiurl, reqid, newstate='accepted', message='Re-evaluation needed', by_project=staging_project)
        self.api.add_review(reqid, by_group=self.api.cstaging_group, msg='Requesting new staging review')
Ejemplo n.º 2
0
 def accept_fallback_review(self, request_id):
     self.osc_user(self.review_user)
     change_review_state(apiurl=self.wf.apiurl,
                         reqid=request_id,
                         newstate='accepted',
                         by_group=self.review_group,
                         message='approved')
     self.osc_user_pop()
Ejemplo n.º 3
0
    def repair(self, request):
        reviews = []
        reqid = str(request)
        req = get_request(self.api.apiurl, reqid)

        if not req:
            raise oscerr.WrongArgs('Request {} not found'.format(reqid))

        if req.state.name != 'review':
            print('Request "{}" is not in review state'.format(reqid))
            return

        reviews = [
            r.by_project for r in req.reviews
            if ':Staging:' in str(r.by_project) and r.state == 'new'
        ]

        if reviews:
            if len(reviews) > 1:
                raise oscerr.WrongArgs(
                    'Request {} had multiple review opened by different staging project'
                    .format(reqid))
        else:
            raise oscerr.WrongArgs(
                'Request {} is not for staging project'.format(reqid))

        staging_project = reviews[0]
        try:
            data = self.api.project_status(staging_project)
        except HTTPError as e:
            if e.code == 404:
                data = None

        # Pre-check and pre-setup
        if data is not None:
            for request in data.findall('staged_requests/requests'):
                if request.get('id') == reqid:
                    print('Request "{}" had the good setup in "{}"'.format(
                        reqid, staging_project))
                    return
        else:
            # this situation should only happen on adi staging
            print('Project is not exist, re-creating "{}"'.format(
                staging_project))
            name = self.api.create_adi_project(staging_project)

        # a bad request setup found
        print('Repairing "{}"'.format(reqid))
        change_review_state(self.api.apiurl,
                            reqid,
                            newstate='accepted',
                            message='Re-evaluation needed',
                            by_project=staging_project)
        self.api.add_review(reqid,
                            by_group=self.api.cstaging_group,
                            msg='Requesting new staging review')
Ejemplo n.º 4
0
    def do_change_review_state(self, request_id, newstate, message=None,
                               by_group=None, by_user=None, by_project=None):
        """
        Change review state of the staging request
        :param request_id: id of the request
        :param newstate: state of the new request
        :param message: message for the review
        :param by_group, by_user, by_project: review type
        """

        message = '' if not message else message

        req = get_request(self.apiurl, str(request_id))
        if not req:
            raise oscerr.WrongArgs('Request {} not found'.format(request_id))

        for review in req.reviews:
            if review.by_group == by_group and \
               review.by_user == by_user and \
               review.by_project == by_project and \
               review.state == 'new':

                # call osc's function
                return change_review_state(self.apiurl, str(request_id),
                                           newstate,
                                           message=message,
                                           by_group=by_group,
                                           by_user=by_user,
                                           by_project=by_project)

        return False
Ejemplo n.º 5
0
    def do_change_review_state(self, request_id, newstate, message=None,
                               by_group=None, by_user=None, by_project=None):
        """
        Change review state of the staging request
        :param request_id: id of the request
        :param newstate: state of the new request
        :param message: message for the review
        :param by_group, by_user, by_project: review type
        """

        message = '' if not message else message

        req = get_request(self.apiurl, str(request_id))
        if not req:
            raise oscerr.WrongArgs('Request {} not found'.format(request_id))

        for review in req.reviews:
            if review.by_group == by_group and \
               review.by_user == by_user and \
               review.by_project == by_project and \
               review.state == 'new':

                # call osc's function
                return change_review_state(self.apiurl, str(request_id),
                                           newstate,
                                           message=message,
                                           by_group=by_group,
                                           by_user=by_user,
                                           by_project=by_project)

        return False
Ejemplo n.º 6
0
    def repair(self, request):
        reviews = []
        reqid = str(request)
        req = get_request(self.api.apiurl, reqid)

        if not req:
            raise oscerr.WrongArgs('Request {} not found'.format(reqid))

        if req.state.name != 'review':
            print('Request "{}" is not in review state'.format(reqid))
            return

        reviews = [
            r.by_project for r in req.reviews
            if ':Staging:' in str(r.by_project) and r.state == 'new'
        ]

        if reviews:
            if len(reviews) > 1:
                raise oscerr.WrongArgs(
                    'Request {} had multiple review opened by different staging project'
                    .format(reqid))
        else:
            raise oscerr.WrongArgs(
                'Request {} is not for staging project'.format(reqid))

        staging_project = reviews[0]
        data = self.api.get_prj_pseudometa(staging_project)
        for request in data['requests']:
            if request['id'] == reqid:
                print('Request "{}" had the good setup in "{}"'.format(
                    reqid, staging_project))
                return

        # a bad request setup found
        print('Repairing "{}"'.format(reqid))
        change_review_state(self.api.apiurl,
                            reqid,
                            newstate='accepted',
                            message='Re-evaluation needed',
                            by_project=staging_project)
        self.api.add_review(reqid,
                            by_group=self.api.cstaging_group,
                            msg='Requesting new staging review')
    def repair(self, request):
        reviews = []
        reqid = str(request)
        req = get_request(self.api.apiurl, reqid)

        if not req:
            raise oscerr.WrongArgs('Request {} not found'.format(reqid))

        if req.state.name != 'review':
            print('Request "{}" is not in review state'.format(reqid))
            return

        reviews = [r.by_project for r in req.reviews if ':Staging:' in str(r.by_project) and r.state == 'new']

        if reviews:
            if len(reviews) > 1:
                raise oscerr.WrongArgs('Request {} had multiple review opened by different staging project'.format(reqid))
        else:
            raise oscerr.WrongArgs('Request {} is not for staging project'.format(reqid))

        staging_project = reviews[0]
        try:
            data = self.api.get_prj_pseudometa(staging_project)
        except HTTPError as e:
            if e.code == 404:
                data = None

        # Pre-check and pre-setup
        if data:
            for request in data['requests']:
                if request['id'] == reqid:
                    print('Request "{}" had the good setup in "{}"'.format(reqid, staging_project))
                    return
        else:
            # this situation should only happens on adi staging
            print('Project is not exist, re-creating "{}"'.format(staging_project))
            name = self.api.create_adi_project(staging_project)

        # a bad request setup found
        print('Repairing "{}"'.format(reqid))
        change_review_state(self.api.apiurl, reqid, newstate='accepted', message='Re-evaluation needed', by_project=staging_project)
        self.api.add_review(reqid, by_group=self.api.cstaging_group, msg='Requesting new staging review')
    def test_happy_path(self):
        """Tests the ideal case in which all bots are happy and the request successfully goes
        through staging"""
        # Initial state: reviews have been created for the bots and for the staging workflow
        reqid = self.request.reqid
        self.assertReview(reqid, by_user=('factory-auto', 'new'))
        self.assertReview(reqid, by_user=('licensedigger', 'new'))
        self.assertReview(reqid, by_group=('factory-staging', 'new'))

        # Let bots come into play
        self.execute_review_bot([reqid], 'factory-auto')
        self.execute_review_bot([reqid], 'licensedigger')

        # Bots are happy, now it's time for manual review (requested by the bots) and
        # for the staging work
        self.assertReview(reqid, by_user=('factory-auto', 'accepted'))
        self.assertReview(reqid, by_user=('licensedigger', 'accepted'))

        # This review will be accepted when the Staging Manager puts it into a staging project
        self.assertReview(reqid, by_group=('factory-staging', 'new'))

        # Review created by CheckSource bot. This review should be manually accepted.
        self.assertReview(reqid, by_group=('opensuse-review-team', 'new'))

        # Let's first accept the manual review
        change_review_state(apiurl=self.wf.apiurl,
                            reqid=reqid,
                            newstate='accepted',
                            by_group='opensuse-review-team')

        # Now only the staging workflow is pending
        self.assertReview(reqid, by_user=('factory-auto', 'accepted'))
        self.assertReview(reqid, by_user=('licensedigger', 'accepted'))
        self.assertReview(reqid, by_group=('opensuse-review-team', 'accepted'))
        self.assertReview(reqid, by_group=('factory-staging', 'new'))

        # Before using the staging plugin, we need to force a reload of the configuration
        # because execute_review_bot temporarily switches the user and that causes problems
        self.wf.load_config()

        # The Staging Manager puts the request into a staging project
        SelectCommand(self.wf.api, STAGING_PROJECT_NAME).perform(['wine'])

        # The factory-staging review is now accepted and a new review associated to the
        # staging project has been created
        self.assertReview(reqid, by_group=('factory-staging', 'accepted'))
        self.assertReview(reqid, by_project=(STAGING_PROJECT_NAME, 'new'))

        # Let's say everything looks good in the staging project and the Staging Manager accepts it
        AcceptCommand(self.wf.api).accept_all([STAGING_PROJECT_NAME], True)

        # Finally, all the reviews are accepted: one for each bot, one for manual review and
        # two for the staging project (one as a consequence of selecting the package into a
        # staging project and the other as a consequence of accepting the staging)
        self.assertReview(reqid, by_user=('factory-auto', 'accepted'))
        self.assertReview(reqid, by_user=('licensedigger', 'accepted'))
        self.assertReview(reqid, by_group=('opensuse-review-team', 'accepted'))
        self.assertReview(reqid, by_group=('factory-staging', 'accepted'))
        self.assertReview(reqid, by_project=(STAGING_PROJECT_NAME, 'accepted'))

        # So it's time to accept the request
        self.request.change_state('accepted')
        self.assertRequestState(reqid, name='accepted')
 def __accept_license(self):
     """See :func:`__mock_licensedigger`"""
     change_review_state(apiurl=self.wf.apiurl,
                         reqid=self.request.reqid,
                         newstate='accepted',
                         by_user='******')
Ejemplo n.º 10
0
    def test_happy_path(self):
        """Tests the ideal case in which all bots are happy and the request successfully goes
        through staging"""

        reqid = self.request.reqid

        # Initial state: reviews have been created for...
        # ...three human reviewers...
        self.assertReview(reqid, by_group=('sle-release-managers', 'new'))
        self.assertReview(reqid, by_group=('autobuild-team', 'new'))
        self.assertReview(reqid, by_group=('origin-reviewers', 'new'))
        # ...for the staging workflow...
        self.assertReview(reqid, by_group=('sle-staging-managers', 'new'))

        # ...and for the bots.
        # So let's first execute the bots and verify their results
        self.assertReviewBot(reqid, 'factory-auto', 'new', 'accepted')
        self.assertReviewBot(reqid, 'licensedigger', 'new', 'accepted')
        self.assertReviewBot(reqid, 'origin-manager', 'new', 'accepted')
        self.assertReviewBot(reqid, 'sle-changelog-checker', 'new', 'accepted')

        # So now that bots are happy, let's accept the manual reviews
        self.osc_user(HUMAN_REVIEWER)
        change_review_state(self.wf.apiurl,
                            reqid,
                            'accepted',
                            by_group='sle-release-managers')
        change_review_state(self.wf.apiurl,
                            reqid,
                            'accepted',
                            by_group='autobuild-team')
        change_review_state(self.wf.apiurl,
                            reqid,
                            'accepted',
                            by_group='origin-reviewers')
        self.osc_user_pop()

        # Now only the staging workflow is pending
        self.assertReview(reqid, by_group=('sle-release-managers', 'accepted'))
        self.assertReview(reqid, by_group=('autobuild-team', 'accepted'))
        self.assertReview(reqid, by_group=('origin-reviewers', 'accepted'))
        self.assertReview(reqid, by_group=('sle-staging-managers', 'new'))

        # Before using the staging plugin, we need to force a reload of the configuration
        # because assertReviewBot temporarily switches the user and that causes problems
        self.wf.load_config()

        # One staging manager puts the request into the staging project
        SelectCommand(self.wf.api, STAGING_PROJECT_NAME).perform(['wine'])

        # The sle-staging-managers review is now accepted and a new review associated to
        # the staging project has been created
        self.assertReview(reqid, by_group=('sle-staging-managers', 'accepted'))
        self.assertReview(reqid, by_project=(STAGING_PROJECT_NAME, 'new'))

        # Let's say everything looks good in the staging project, so the staging manager can
        # accept that staging
        AcceptCommand(self.wf.api).accept_all([STAGING_PROJECT_NAME], True)

        # Finally, all the reviews are accepted:
        # ...one for each bot,
        self.assertReview(reqid, by_user=('factory-auto', 'accepted'))
        self.assertReview(reqid, by_user=('licensedigger', 'accepted'))
        self.assertReview(reqid, by_user=('sle-changelog-checker', 'accepted'))
        self.assertReview(reqid, by_user=('origin-manager', 'accepted'))
        # ...one for each manual review
        self.assertReview(reqid, by_group=('sle-release-managers', 'accepted'))
        self.assertReview(reqid, by_group=('autobuild-team', 'accepted'))
        self.assertReview(reqid, by_group=('origin-reviewers', 'accepted'))
        # ...and two for the staging project (one as a consequence of selecting the package into a
        # staging project and the other as a consequence of accepting the staging)
        self.assertReview(reqid, by_group=('sle-staging-managers', 'accepted'))
        self.assertReview(reqid, by_project=(STAGING_PROJECT_NAME, 'accepted'))

        # So it's time to accept the request
        self.request.change_state('accepted')
        self.assertRequestState(reqid, name='accepted')