How to use the koji.canonArch 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_all_excluded(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=[], excludearch=tag_arches)
            with self.assertRaises(koji.BuildError):
                result = self.handler.choose_taskarch('noarch', 'srpm', 'build_tag')
github koji-project / koji / plugins / builder / runroot.py View on Github external
weight = max(weight, 0.5)
            self.session.host.setTaskWeight(self.id, weight)
        #noarch is funny
        if arch == "noarch":
            #we need a buildroot arch. Pick one that:
            #  a) this host can handle
            #  b) the build tag can support
            #  c) is canonical
            host_arches = self.session.host.getHost()['arches']
            if not host_arches:
                raise koji.BuildError("No arch list for this host")
            tag_arches = self.session.getBuildConfig(root)['arches']
            if not tag_arches:
                raise koji.BuildError("No arch list for tag: %s" % root)
            #index canonical host arches
            host_arches = set([koji.canonArch(a) for a in host_arches.split()])
            #pick the first suitable match from tag's archlist
            for br_arch in tag_arches.split():
                br_arch = koji.canonArch(br_arch)
                if br_arch in host_arches:
                    #we're done
                    break
            else:
                #no overlap
                raise koji.BuildError("host does not match tag arches: %s (%s)" % (root, tag_arches))
        else:
            br_arch = arch
        if repo_id:
            repo_info = self.session.repoInfo(repo_id, strict=True)
            if repo_info['tag_name'] != root:
                raise koji.BuildError("build tag (%s) does not match repo tag (%s)" % (root, repo_info['tag_name']))
            if repo_info['state'] not in (koji.REPO_STATES['READY'], koji.REPO_STATES['EXPIRED']):
github koji-project / koji / plugins / builder / runroot.py View on Github external
if arch == "noarch":
            #we need a buildroot arch. Pick one that:
            #  a) this host can handle
            #  b) the build tag can support
            #  c) is canonical
            host_arches = self.session.host.getHost()['arches']
            if not host_arches:
                raise koji.BuildError("No arch list for this host")
            tag_arches = self.session.getBuildConfig(root)['arches']
            if not tag_arches:
                raise koji.BuildError("No arch list for tag: %s" % root)
            #index canonical host arches
            host_arches = set([koji.canonArch(a) for a in host_arches.split()])
            #pick the first suitable match from tag's archlist
            for br_arch in tag_arches.split():
                br_arch = koji.canonArch(br_arch)
                if br_arch in host_arches:
                    #we're done
                    break
            else:
                #no overlap
                raise koji.BuildError("host does not match tag arches: %s (%s)" % (root, tag_arches))
        else:
            br_arch = arch
        if repo_id:
            repo_info = self.session.repoInfo(repo_id, strict=True)
            if repo_info['tag_name'] != root:
                raise koji.BuildError("build tag (%s) does not match repo tag (%s)" % (root, repo_info['tag_name']))
            if repo_info['state'] not in (koji.REPO_STATES['READY'], koji.REPO_STATES['EXPIRED']):
                raise koji.BuildError("repos in the %s state may not be used by runroot" % koji.REPO_STATES[repo_info['state']])
        else:
            repo_info = self.session.getRepo(root)
github fedora-infra / koschei / koschei / backend / koji_util.py View on Github external
if buildarchs:
        archlist = buildarchs
    if exclusivearch:
        archlist = [arch for arch in archlist if arch in exclusivearch]
    if excludearch:
        archlist = [arch for arch in archlist if arch not in excludearch]

    if ('noarch' not in excludearch and
            ('noarch' in buildarchs or 'noarch' in exclusivearch)):
        archlist.append('noarch')

    if arch_override:
        # we also allow inverse overrides
        if arch_override.startswith('^'):
            excluded = {koji.canonArch(arch) for arch in arch_override[1:].split()}
            archlist = [arch for arch in archlist if koji.canonArch(arch) not in excluded]
        else:
            archlist = arch_override.split()

    if not build_arches:
        build_arches = get_config('koji_config').get('build_arches')
    build_arches = {koji.canonArch(arch) for arch in build_arches}
    allowed_arches = tag_archlist & build_arches

    arches = set()
    for arch in archlist:
        if arch == 'noarch' or koji.canonArch(arch) in allowed_arches:
            arches.add(arch)

    return arches
github koji-project / koji / plugins / hub / runroot_hub.py View on Github external
raise koji.GenericError('no arches defined for tag %s' % tag['name'])

        #get all known arches for the system
        fullarches = kojihub.get_all_arches()

        tagarches = tag['arches'].split()

        # If our tag can't do all arches, then we need to
        # specify one of the arches it can do.
        if set(fullarches) - set(tagarches):
            chanarches = get_channel_arches(taskopts['channel'])
            choices = [x for x in tagarches if x in chanarches]
            if not choices:
                raise koji.GenericError('no common arches for tag/channel: %s/%s' \
                            % (tagInfo, taskopts['channel']))
            taskopts['arch'] = koji.canonArch(random.choice(choices))

    args = koji.encode_args(tagInfo, arch, command, **opts)
    return kojihub.make_task('runroot', args, **taskopts)
github koji-project / koji / plugins / builder / runroot.py View on Github external
weight = max(weight, 0.5)
            self.session.host.setTaskWeight(self.id, weight)
        #noarch is funny
        if arch == "noarch":
            #we need a buildroot arch. Pick one that:
            #  a) this host can handle
            #  b) the build tag can support
            #  c) is canonical
            host_arches = self.session.host.getHost()['arches']
            if not host_arches:
                raise koji.BuildError("No arch list for this host")
            tag_arches = self.session.getBuildConfig(root)['arches']
            if not tag_arches:
                raise koji.BuildError("No arch list for tag: %s" % root)
            #index canonical host arches
            host_arches = dict([(koji.canonArch(a), 1) for a in host_arches.split()])
            #pick the first suitable match from tag's archlist
            for br_arch in tag_arches.split():
                br_arch = koji.canonArch(br_arch)
                if br_arch in host_arches:
                    #we're done
                    break
            else:
                #no overlap
                raise koji.BuildError("host does not match tag arches: %s (%s)" % (root, tag_arches))
        else:
            br_arch = arch
        if repo_id:
            repo_info = self.session.repoInfo(repo_id, strict=True)
            if repo_info['tag_name'] != root:
                raise koji.BuildError("build tag (%s) does not match repo tag (%s)" % (root, repo_info['tag_name']))
            if repo_info['state'] not in (koji.REPO_STATES['READY'], koji.REPO_STATES['EXPIRED']):
github koji-project / koji / plugins / hub / runroot_hub.py View on Github external
def get_channel_arches(channel):
    """determine arches available in channel"""
    chan = context.handlers.call('getChannel', channel, strict=True)
    ret = {}
    for host in context.handlers.call('listHosts', channelID=chan['id'], enabled=True):
        for a in host['arches'].split():
            ret[koji.canonArch(a)] = 1
    return ret
github fedora-infra / koschei / koschei / backend / koji_util.py View on Github external
def get_srpm_arches(koji_session, all_arches, nvra, arch_override=None,
                    build_arches=None):
    """
    Compute architectures that should be used for a build. Computation is based on the one
    in Koji (kojid/getArchList).

    :param koji_session: Koji session to be used for the query
    :param all_arches: List of all arches obtained from `get_koji_arches`
    :param nvra: NVRA dict of the SRPM
    :param arch_override: User specified arch override
    :param build_arches: List of allowed arches for building. Taken from config by default
    :return: Set of architectures that can be passed to `koji_scratch_build`. May be
             empty, in which case no build should be submitted.
    """
    archlist = all_arches
    tag_archlist = {koji.canonArch(a) for a in archlist}
    headers = koji_session.getRPMHeaders(
        rpmID=nvra,
        headers=['BUILDARCHS', 'EXCLUDEARCH', 'EXCLUSIVEARCH'],
    )
    if not headers:
        return None
    buildarchs = headers.get('BUILDARCHS', [])
    exclusivearch = headers.get('EXCLUSIVEARCH', [])
    excludearch = headers.get('EXCLUDEARCH', [])
    if buildarchs:
        archlist = buildarchs
    if exclusivearch:
        archlist = [arch for arch in archlist if arch in exclusivearch]
    if excludearch:
        archlist = [arch for arch in archlist if arch not in excludearch]