From f15761fcbef37e487515f9636f0833cf472aa97e Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Oct 08 2019 16:14:52 +0000 Subject: use preferred arch if there is more options https://pagure.io/koji/pull-request/323 introduced option to force an arch for noarch packages. Nevertheless, it is only task architecture and not buildroot one. So, if builder can provide more possible archs (32/64 bit), it will pick one of these randomly and can go against preferred arch. Patch introduces "preferred_arch" option for find_arch and use the task's one when it works with noarch rpm. Fixes: https://pagure.io/koji/issue/789 --- diff --git a/builder/kojid b/builder/kojid index d96a8ae..54d7ee5 100755 --- a/builder/kojid +++ b/builder/kojid @@ -1349,8 +1349,17 @@ class BuildArchTask(BaseBuildTask): rootopts = { 'repo_id': repo_id - } - br_arch = self.find_arch(arch, self.session.host.getHost(), self.session.getBuildConfig(root, event=event_id)) + } + if arch == "noarch": + # There could have been forced taskarch Exclusive/ExcludeArch, + # so we should honor it here. + task = self.session.getTaskInfo(self.id) + preferred_arch = task['arch'] + else: + preferred_arch = None + br_arch = self.find_arch(arch, self.session.host.getHost(), + self.session.getBuildConfig(root, event=event_id), + preferred_arch=preferred_arch) broot = BuildRoot(self.session, self.options, root, br_arch, self.id, **rootopts) broot.workdir = self.workdir diff --git a/koji/tasks.py b/koji/tasks.py index 6ed02b6..9284d53 100644 --- a/koji/tasks.py +++ b/koji/tasks.py @@ -495,10 +495,12 @@ class BaseTaskHandler(object): def subtask2(self, __taskopts, __method, *args, **kwargs): return self.session.host.subtask2(self.id, __taskopts, __method, *args, **kwargs) - def find_arch(self, arch, host, tag): + def find_arch(self, arch, host, tag, preferred_arch=None): """ For noarch tasks, find a canonical arch that is supported by both the host and tag. If the arch is anything other than noarch, return it unmodified. + + If preferred_arch is set, try to get it, but not fail on that """ if arch != "noarch": return arch @@ -521,6 +523,10 @@ class BaseTaskHandler(object): # find the intersection of host and tag arches common_arches = list(host_arches & tag_arches) if common_arches: + if preferred_arch and preferred_arch in common_arches: + self.logger.info('Valid arches: %s, using preferred: %s' % + (' '.join(sorted(common_arches)), preferred_arch)) + return preferred_arch # pick one of the common arches randomly # need to re-seed the prng or we'll get the same arch every time, # because we just forked from a common parent