def osrt_origin_update(apiurl, opts, *packages):
    if opts.listen:
        from osclib.origin_listener import OriginSourceChangeListener

        logger = logging.getLogger()
        logger.setLevel(logging.INFO)
        listener = OriginSourceChangeListener(apiurl, logger, opts.project, opts.dry)
        try:
            runtime = int(opts.listen_seconds) if opts.listen_seconds else None
            listener.run(runtime=runtime)
        except KeyboardInterrupt:
            listener.stop()

        return

    if not opts.project:
        for project in origin_updatable(apiurl):
            opts.project = project
            osrt_origin_update(apiurl, opts, *packages)

        return

    if len(packages) == 0:
        packages = osrt_origin_update_packages(apiurl, opts.project)

    for package in packages:
        print('checking for updates to {}/{}...'.format(opts.project, package))

        request_future = origin_update(apiurl, opts.project, package)
        if request_future:
            request_future.print_and_create(opts.dry)
    def update_consider(self, origins, origin_project, package):
        if origin_project not in origins:
            self.logger.info('skipped irrelevant origin: {}'.format(origin_project))
            return

        for project in origins[origin_project]:
            if self.project and project != self.project:
                self.logger.info('skipping filtered target project: {}'.format(project))
                continue

            # Check if package is of kind source in target or does not exists in
            # target and is source in origin project -- this allows for deletes
            # and new submissions. Execute the check lazily due to expense.
            kind_target = package_kind(self.apiurl, project, package)
            kind_target_source = kind_target == 'source'
            kind_new_source = (kind_target is None and
                               package_kind(self.apiurl, origin_project, package) == 'source')
            if kind_target_source or kind_new_source:
                self.logger.info('checking for updates to {}/{}...'.format(project, package))
                request_future = origin_update(self.apiurl, project, package)
                if request_future:
                    request_future.print_and_create(self.dry)
            elif not kind_target_source:
                self.logger.info(f'skipped updating non-source package {project}/{package}')
            else:
                self.logger.info(f'skipped submitting new non-source package {project}/{package}')
示例#3
0
    def _assertUpdate(self, package, desired):
        memoize_session_reset()
        self.osc_user(self.bot_user)
        request_future = origin_update(self.wf.apiurl, self.wf.project, package)
        if desired:
            self.assertNotEqual(request_future, False)
            request_id = request_future.print_and_create()
        else:
            self.assertEqual(request_future, False)
            request_id = None
        self.osc_user_pop()

        return request_id
示例#4
0
def osrt_origin_update(apiurl, opts, *packages):
    if not opts.project:
        for project in origin_updatable(apiurl):
            opts.project = project
            osrt_origin_update(apiurl, opts, *packages)

        return

    if len(packages) == 0:
        packages = osrt_origin_update_packages(apiurl, opts.project)

    for package in packages:
        print('checking for updates to {}/{}...'.format(opts.project, package))

        request_future = origin_update(apiurl, opts.project, package)
        if request_future:
            request_future.print_and_create(opts.dry)
示例#5
0
    def test_new_package_submission(self):
        self.remote_config_set_age_minimum()

        upstream1_project = self.randomString('upstream1')
        upstream2_project = self.randomString('upstream2')
        upstream3_project = self.randomString('upstream3')
        package1 = self.randomString('package1')
        package2 = self.randomString('package2')
        package3 = self.randomString('package3')

        target_package1 = self.wf.create_package(self.target_project, package1)
        upstream1_package1 = self.wf.create_package(upstream1_project, package1)
        upstream2_package1 = self.wf.create_package(upstream2_project, package1)

        upstream1_package1.create_commit()
        copy_package(self.wf.apiurl, upstream1_project, package1,
                     self.wf.apiurl, upstream2_project, package1)

        upstream3_package2 = self.wf.create_package(upstream3_project, package2)
        upstream3_package2.create_commit()

        upstream1_package3 = self.wf.create_package(upstream1_project, package3)
        upstream1_package3.create_commit()

        attribute_value_save(self.wf.apiurl, upstream1_project, 'ApprovedRequestSource', '', 'OBS')
        attribute_value_save(self.wf.apiurl, upstream2_project, 'ApprovedRequestSource', '', 'OBS')
        attribute_value_save(self.wf.apiurl, upstream3_project, 'ApprovedRequestSource', '', 'OBS')

        self.origin_config_write([
            {upstream1_project: { 'automatic_updates_initial': True }},
            {upstream2_project: { 'automatic_updates_initial': True }},
            {upstream3_project: {}},
        ])

        self.osc_user(self.bot_user)
        memoize_session_reset()
        request_future = origin_update(self.wf.apiurl, self.wf.project, package1)
        self.assertNotEqual(request_future, False)
        if request_future:
            request_id_package1 = request_future.print_and_create()

        # Ensure a second request is not triggered.
        memoize_session_reset()
        request_future = origin_update(self.wf.apiurl, self.wf.project, package1)
        self.assertEqual(request_future, False)

        # No new package submission from upstream3 since not automatic_updates_initial.
        memoize_session_reset()
        request_future = origin_update(self.wf.apiurl, self.wf.project, package2)
        self.assertEqual(request_future, False)
        self.osc_user_pop()

        upstream2_package2 = self.wf.create_package(upstream2_project, package2)
        upstream2_package2.create_commit()

        self.osc_user(self.bot_user)
        memoize_session_reset()
        request_future = origin_update(self.wf.apiurl, self.wf.project, package2)
        self.assertNotEqual(request_future, False)
        if request_future:
            request_id_package2 = request_future.print_and_create()
        self.osc_user_pop()

        request_state_change(self.wf.apiurl, request_id_package2, 'declined')
        upstream2_package2.create_commit()

        self.osc_user(self.bot_user)
        # No new package submission from upstream2 for new revision since
        # declined initial package submission.
        memoize_session_reset()
        request_future = origin_update(self.wf.apiurl, self.wf.project, package2)
        self.assertEqual(request_future, False)
        self.osc_user_pop()

        # Ensure blacklist prevents initial package submission.
        self.wf.create_attribute_type('OSRT', 'OriginUpdateInitialBlacklist', 1)
        attribute_value_save(self.wf.apiurl, self.target_project, 'OriginUpdateInitialBlacklist', package3)
        self.assertNoUpdate(package3)

        attribute_value_delete(self.wf.apiurl, self.target_project, 'OriginUpdateInitialBlacklist')
        self.assertUpdate(package3)
示例#6
0
    def devel_workflow(self, only_devel):
        self.remote_config_set_age_minimum()

        devel_project = self.randomString('devel')
        package = self.randomString('package')
        request = self.wf.create_submit_request(devel_project, package)
        attribute_value_save(self.wf.apiurl, devel_project, 'ApprovedRequestSource', '', 'OBS')

        if not only_devel:
            self.assertReviewBot(request.reqid, self.bot_user, 'new', 'new')

            comment = [
                '<!-- OriginManager state=seen result=None -->',
                'Source not found in allowed origins:',
                f'- {self.product_project}',
                f'Decision may be overridden via `@{self.bot_user} override`.',
            ]
            self.assertComment(request.reqid, comment)

            CommentAPI(self.wf.api.apiurl).add_comment(
                request_id=request.reqid, comment=f'@{self.bot_user} change_devel')

            comment = 'change_devel command by {}'.format('Admin')
        else:
            comment = 'only devel origin allowed'

        self.assertReviewBot(request.reqid, self.bot_user, 'new', 'accepted')
        self.assertAnnotation(request.reqid, {
            'comment': comment,
            'origin': devel_project,
        })

        request.change_state('accepted')

        memoize_session_reset()
        self.osc_user(self.bot_user)
        request_future = origin_update(self.wf.apiurl, self.wf.project, package)
        self.assertNotEqual(request_future, False)
        if request_future:
            request_id_change_devel = request_future.print_and_create()

        # Ensure a second request is not triggered.
        request_future = origin_update(self.wf.apiurl, self.wf.project, package)
        self.assertEqual(request_future, False)
        self.osc_user_pop()

        memoize_session_reset()
        origin_info = origin_find(self.wf.apiurl, self.wf.project, package)
        self.assertEqual(origin_info, None)

        self.assertReviewBot(request_id_change_devel, self.bot_user, 'new', 'accepted')
        self.assertAnnotation(request_id_change_devel, {
            'origin': devel_project,
        })

        # Origin should change before request is accepted since it is properly
        # annotated and without fallback review.
        memoize_session_reset()
        origin_info = origin_find(self.wf.apiurl, self.wf.project, package)
        self.assertEqual(str(origin_info), devel_project)

        self.wf.projects[devel_project].packages[0].create_commit()

        self.osc_user(self.bot_user)
        request_future = origin_update(self.wf.apiurl, self.wf.project, package)
        self.assertNotEqual(request_future, False)
        if request_future:
            request_id_update = request_future.print_and_create()

        request_future = origin_update(self.wf.apiurl, self.wf.project, package)
        self.assertEqual(request_future, False)
        self.osc_user_pop()

        self.assertReviewBot(request_id_update, self.bot_user, 'new', 'accepted')
        self.assertAnnotation(request_id_update, {
            'origin': devel_project,
        })

        memoize_session_reset()
        devel_project_actual, _ = devel_project_get(self.wf.apiurl, self.wf.project, package)
        self.assertEqual(devel_project_actual, None)

        request = get_request(self.wf.apiurl, request_id_change_devel)
        request_state_change(self.wf.apiurl, request_id_change_devel, 'accepted')

        memoize_session_reset()
        devel_project_actual, devel_package_actual = devel_project_get(
            self.wf.apiurl, self.wf.project, package)
        self.assertEqual(devel_project_actual, devel_project)
        self.assertEqual(devel_package_actual, package)

        request = get_request(self.wf.apiurl, request_id_update)
        request_state_change(self.wf.apiurl, request_id_update, 'accepted')

        devel_project_new = self.randomString('develnew')
        self.wf.create_package(devel_project_new, package)
        attribute_value_save(self.wf.apiurl, devel_project_new, 'ApprovedRequestSource', '', 'OBS')

        copy_package(self.wf.apiurl, devel_project, package,
                     self.wf.apiurl, devel_project_new, package)

        request_future = request_create_change_devel(
            self.wf.apiurl, devel_project_new, package, self.wf.project)
        self.assertNotEqual(request_future, False)
        if request_future:
            request_id_change_devel_new = request_future.print_and_create()

        self.assertReviewBot(request_id_change_devel_new, self.bot_user, 'new', 'accepted')
        self.assertAnnotation(request_id_change_devel_new, {
            'origin': devel_project_new,
            'origin_old': devel_project,
        })

        self.accept_fallback_review(request_id_change_devel_new)
        request_state_change(self.wf.apiurl, request_id_change_devel_new, 'accepted')

        memoize_session_reset()
        origin_info = origin_find(self.wf.apiurl, self.wf.project, package)
        self.assertEqual(str(origin_info), devel_project_new)