How to use the koji.BuildError function in koji

To help you get started, we’ve selected a few koji examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github koji-project / koji / tests / test_builder / test_choose_taskarch.py View on Github external
def test_too_exclusive(self):
        tag_arches = [koji.canonArch(a) for a in self.getBuildConfig()['arches'].split()]
        # random choice involved, so we repeat this a few times
        for i in range(20):
            self.readSRPMHeader.return_value = FakeHeader(
                    buildarchs=['noarch'], exclusivearch=['missing_arch'], excludearch=[])
            with self.assertRaises(koji.BuildError):
                result = self.handler.choose_taskarch('noarch', 'srpm', 'build_tag')
github koji-project / koji / tests / test_hub / test_rpmdiff.py View on Github external
def test_rpmdiff_simple_failure(self, Rpmdiff):
        d = mock.MagicMock()
        d.differs.return_value = True
        Rpmdiff.return_value = d
        with self.assertRaises(koji.BuildError):
            kojihub.rpmdiff('basepath', ['12/1234/foo', '13/1345/bar'], hashes={})
        Rpmdiff.assert_called_once_with('basepath/12/1234/foo', 'basepath/13/1345/bar', ignore='S5TN')
        d.textdiff.assert_called_once_with()
github containerbuildsystem / koji-containerbuild / koji_containerbuild / plugins / builder_containerbuild.py View on Github external
def get_source_build_info(self, build_id, build_nvr):
        build_identifier = build_nvr or build_id

        koji_build = self.session.getBuild(build_identifier)
        if not koji_build:
            raise koji.BuildError("specified source build '%s' doesn't exist" % build_identifier)

        if build_id and (build_id != koji_build['build_id']):
            err_msg = (
                'koji_build_id {} does not match koji_build_nvr {} with id {}. '
                'When specifying both an id and an nvr, they should point to the same image build'
                .format(build_id, build_nvr, koji_build['build_id'])
                )
            raise koji.BuildError(err_msg)

        build_extras = koji_build['extra']
        if 'image' not in build_extras:
            err_msg = ('koji build {} is not image build which source container requires'
                       .format(koji_build['nvr']))
            raise koji.BuildError(err_msg)

        elif 'sources_for_nvr' in koji_build['extra']['image']:
github rebase-helper / rebase-helper / rebasehelper / plugins / build_tools / rpm / koji_.py View on Github external
def _verify_tasks(cls, session, task_dict):
        """Checks if any of the tasks failed and tries to extract mock exit code from it.

        Args:
            session (koji.ClientSession): Active Koji session instance.
            task_dict (dict): Dict mapping Koji task ID to its state.

        Returns:
            int: Mock exit code or -1 if any task failed, otherwise None.

        """
        for task_id, state in task_dict.items():
            if state == koji.TASK_STATES['FAILED']:
                try:
                    session.getTaskResult(task_id)
                except koji.BuildError as e:
                    # typical error message:
                    #   BuildError: error building package (arch noarch),
                    #   mock exited with status 1; see build.log for more information
                    match = re.search(r'mock exited with status (\d+)', str(e))
                    if match:
                        return int(match.group(1))
                    else:
                        return -1
        return None
github containerbuildsystem / koji-containerbuild / koji_containerbuild / plugins / builder_containerbuild.py View on Github external
'sources_for_koji_build_nvr': koji_build_nvr,
            'target': target_info['name'],
            'scratch': scratch,
            'koji_task_id': self.id,
        }

        if signing_intent:
            create_build_args['signing_intent'] = signing_intent

        try:
            create_method = self.osbs().create_source_container_build
            self.logger.debug("Starting %s with params: '%s",
                              create_method, create_build_args)
            build_response = create_method(**create_build_args)
        except AttributeError:
            raise koji.BuildError("method %s doesn't exists in osbs" % create_method)

        return self.handle_build_response(build_response)
github containerbuildsystem / koji-containerbuild / koji_containerbuild / plugins / builder_containerbuild.py View on Github external
def get_source_build_info(self, build_id, build_nvr):
        build_identifier = build_nvr or build_id

        koji_build = self.session.getBuild(build_identifier)
        if not koji_build:
            raise koji.BuildError("specified source build '%s' doesn't exist" % build_identifier)

        if build_id and (build_id != koji_build['build_id']):
            err_msg = (
                'koji_build_id {} does not match koji_build_nvr {} with id {}. '
                'When specifying both an id and an nvr, they should point to the same image build'
                .format(build_id, build_nvr, koji_build['build_id'])
                )
            raise koji.BuildError(err_msg)

        build_extras = koji_build['extra']
        if 'image' not in build_extras:
            err_msg = ('koji build {} is not image build which source container requires'
                       .format(koji_build['nvr']))
            raise koji.BuildError(err_msg)

        elif 'sources_for_nvr' in koji_build['extra']['image']:
            err_msg = ('koji build {} is source container build, source container can not '
                       'use source container build image'.format(koji_build['nvr']))
            raise koji.BuildError(err_msg)

        if not build_id:
            build_id = koji_build['build_id']
        if not build_nvr:
            build_nvr = koji_build['nvr']
github containerbuildsystem / koji-containerbuild / koji_containerbuild / plugins / builder_containerbuild.py View on Github external
this_task = self.session.getTaskInfo(self.id)
        self.logger.debug("This task: %r", this_task)
        owner_info = self.session.getUser(this_task['owner'])
        self.logger.debug("Started by %s", owner_info['name'])

        scm = My_SCM(src)
        scm.assert_allowed(self.options.allowed_scms)
        git_uri = scm.get_git_uri()
        component = scm.get_component()
        arch = None

        if not arches:
            raise koji.BuildError("arches aren't specified")

        if signing_intent and compose_ids:
            raise koji.BuildError("signing_intent used with compose_ids")

        create_build_args = {
            'git_uri': git_uri,
            'git_ref': scm.revision,
            'user': owner_info['name'],
            'component': component,
            'target': target_info['name'],
            'dependency_replacements': dependency_replacements,
            'yum_repourls': yum_repourls,
            'scratch': scratch,
            'koji_task_id': self.id,
            'architecture': arch,
        }
        if branch:
            create_build_args['git_branch'] = branch
        if push_url:
github containerbuildsystem / koji-containerbuild / koji_containerbuild / plugins / builder_containerbuild.py View on Github external
def handler(self, src, target, opts=None):
        jsonschema.validate([src, target, opts], self.PARAMS_SCHEMA)
        self.opts = opts
        component = None

        if not opts.get('git_branch'):
            raise koji.BuildError("Git branch must be specified")

        if opts.get('scratch') and opts.get('isolated'):
            raise koji.BuildError("Build cannot be both isolated and scratch")

        self.event_id = self.session.getLastEvent()['id']
        target_info = self.session.getBuildTarget(target, event=self.event_id)
        if not target_info:
            raise koji.BuildError("Target `%s` not found" % target)

        build_tag = target_info['build_tag']
        archlist = self.getArchList(build_tag)

        flatpak = opts.get('flatpak', False)
        if flatpak:
            if not osbs_flatpak_support:
                raise koji.BuildError("osbs-client on koji builder doesn't have Flatpak support")
            release_overwrite = None
        else:
            label_overwrites = {}
github containerbuildsystem / koji-containerbuild / koji_containerbuild / plugins / builder_containerbuild.py View on Github external
uploadpath = self.getUploadDir()

        koji.ensuredir(uploadpath)

        self.run_callbacks('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag,
                           scratch=self.opts.get('scratch', False))

        # Check out sources from the SCM
        sourcedir = scm.checkout(scmdir, self.session, uploadpath, logfile)

        self.run_callbacks("postSCMCheckout", scminfo=scm.get_info(), build_tag=build_tag,
                           scratch=self.opts.get('scratch', False), srcdir=sourcedir)

        fn = os.path.join(sourcedir, 'Dockerfile')
        if not os.path.exists(fn):
            raise koji.BuildError("Dockerfile file missing: %s" % fn)
        return fn