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
This commit is contained in:
Tomas Kopecek 2019-10-08 18:14:52 +02:00
parent f94deee618
commit dd8fd935f4
2 changed files with 18 additions and 3 deletions

View file

@ -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

View file

@ -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