build can wait for actual repo
New options --wait-for-build and --wait-for-repo for build command are simplification of using wait-repo + build command succession. They have same semantices as the original one. Fixes: https://pagure.io/koji/issue/1619
This commit is contained in:
parent
160780cedf
commit
418376dc81
4 changed files with 43 additions and 21 deletions
|
|
@ -995,7 +995,9 @@ class BuildTask(BaseTaskHandler):
|
|||
# use of this option is governed by policy
|
||||
self.session.host.assertPolicy('build_from_repo_id', policy_data)
|
||||
if not repo_info:
|
||||
repo_info = self.getRepo(build_tag) #(subtask)
|
||||
wait_builds = [koji.parse_NVR(nvr) for nvr in opts.get('wait_builds', [])]
|
||||
repo_info = self.getRepo(build_tag, builds=wait_builds,
|
||||
wait=opts.get('wait_repo')) #(subtask)
|
||||
self.event_id = self.session.getLastEvent()['id']
|
||||
srpm = self.getSRPM(src, build_tag, repo_info['id'])
|
||||
h = self.readSRPMHeader(srpm)
|
||||
|
|
|
|||
|
|
@ -445,6 +445,10 @@ def handle_build(options, session, args):
|
|||
help=_("Wait on the build, even if running in the background"))
|
||||
parser.add_option("--nowait", action="store_false", dest="wait",
|
||||
help=_("Don't wait on build"))
|
||||
parser.add_option("--wait-repo", action="store_true",
|
||||
help=_("Wait for the actual buildroot repo of given target"))
|
||||
parser.add_option("--wait-build", metavar="NVR", action="append", dest="wait_builds",
|
||||
default=[], help=_("Wait for the given nvr to appear in buildroot repo"))
|
||||
parser.add_option("--quiet", action="store_true",
|
||||
help=_("Do not print the task information"), default=options.quiet)
|
||||
parser.add_option("--arch-override", help=_("Override build arches"))
|
||||
|
|
@ -478,7 +482,7 @@ def handle_build(options, session, args):
|
|||
opts = {}
|
||||
if build_opts.arch_override:
|
||||
opts['arch_override'] = koji.parse_arches(build_opts.arch_override)
|
||||
for key in ('skip_tag', 'scratch', 'repo_id', 'fail_fast'):
|
||||
for key in ('skip_tag', 'scratch', 'repo_id', 'fail_fast', 'wait_repo', 'wait_builds'):
|
||||
val = getattr(build_opts, key)
|
||||
if val is not None:
|
||||
opts[key] = val
|
||||
|
|
|
|||
|
|
@ -544,21 +544,35 @@ class BaseTaskHandler(object):
|
|||
tag['name'],
|
||||
', '.join(sorted(tag_arches))))
|
||||
|
||||
def getRepo(self, tag):
|
||||
def getRepo(self, tag, builds=None, wait=False):
|
||||
"""
|
||||
Get the active repo for the given tag. If there is no repo available,
|
||||
wait for a repo to be created.
|
||||
|
||||
if wait is True - always wait for new repo
|
||||
if builds are present, wait until repo doesn't contain these
|
||||
"""
|
||||
repo_info = self.session.getRepo(tag)
|
||||
if not repo_info:
|
||||
#make sure there is a target
|
||||
if wait:
|
||||
create_ts = time.time()
|
||||
else:
|
||||
create_ts = None
|
||||
repo_info = self.session.getRepo(tag)
|
||||
taginfo = self.session.getTag(tag, strict=True)
|
||||
targets = self.session.getBuildTargets(buildTagID=taginfo['id'])
|
||||
if not targets:
|
||||
raise koji.BuildError('no repo (and no target) for tag %s' % taginfo['name'])
|
||||
#wait for it
|
||||
if not repo_info:
|
||||
#make sure there is a target
|
||||
targets = self.session.getBuildTargets(buildTagID=taginfo['id'])
|
||||
if not targets:
|
||||
raise koji.BuildError('no repo (and no target) for tag %s' % taginfo['name'])
|
||||
wait = True
|
||||
elif builds:
|
||||
build_infos = [koji.parse_NVR(build) for build in builds]
|
||||
if not koji.util.checkForBuilds(self.session, taginfo['id'],
|
||||
build_infos, repo_info['create_event']):
|
||||
wait = True
|
||||
|
||||
if wait:
|
||||
task_id = self.session.host.subtask(method='waitrepo',
|
||||
arglist=[tag, None, None],
|
||||
arglist=[tag, create_ts, builds],
|
||||
parent=self.id)
|
||||
repo_info = self.wait(task_id)[task_id]
|
||||
return repo_info
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class TestBuild(unittest.TestCase):
|
|||
source = 'srpm'
|
||||
task_id = 1
|
||||
args = [target, source]
|
||||
opts = {}
|
||||
opts = {'wait_builds': []}
|
||||
priority = None
|
||||
|
||||
self.session.getBuildTarget.return_value = target_info
|
||||
|
|
@ -94,7 +94,7 @@ Task info: weburl/taskinfo?taskID=1
|
|||
source = 'http://scm'
|
||||
task_id = 1
|
||||
args = [target, source]
|
||||
opts = {}
|
||||
opts = {'wait_builds': []}
|
||||
priority = None
|
||||
|
||||
self.session.getBuildTarget.return_value = target_info
|
||||
|
|
@ -201,6 +201,8 @@ Options:
|
|||
--scratch Perform a scratch build
|
||||
--wait Wait on the build, even if running in the background
|
||||
--nowait Don't wait on build
|
||||
--wait-repo Wait for the actual buildroot repo of given target
|
||||
--wait-build=NVR Wait for the given nvr to appear in buildroot repo
|
||||
--quiet Do not print the task information
|
||||
--arch-override=ARCH_OVERRIDE
|
||||
Override build arches
|
||||
|
|
@ -295,7 +297,7 @@ Options:
|
|||
task_id = 1
|
||||
repo_id = 2
|
||||
args = ['--repo-id=' + str(repo_id), target, source]
|
||||
opts = {'repo_id': repo_id, 'skip_tag': True}
|
||||
opts = {'repo_id': repo_id, 'skip_tag': True, 'wait_builds': []}
|
||||
priority = None
|
||||
|
||||
self.session.build.return_value = task_id
|
||||
|
|
@ -498,7 +500,7 @@ Task info: weburl/taskinfo?taskID=1
|
|||
'--scratch',
|
||||
target,
|
||||
source]
|
||||
opts = {'arch_override': arch_override, 'scratch': True}
|
||||
opts = {'arch_override': arch_override, 'scratch': True, 'wait_builds': []}
|
||||
priority = None
|
||||
|
||||
self.session.getBuildTarget.return_value = target_info
|
||||
|
|
@ -549,7 +551,7 @@ Task info: weburl/taskinfo?taskID=1
|
|||
task_id = 1
|
||||
args = ['--background', target, source]
|
||||
priority = 5
|
||||
opts = {}
|
||||
opts = {'wait_builds': []}
|
||||
|
||||
self.session.getBuildTarget.return_value = target_info
|
||||
self.session.getTag.return_value = dest_tag_info
|
||||
|
|
@ -597,7 +599,7 @@ Task info: weburl/taskinfo?taskID=1
|
|||
source = 'srpm'
|
||||
task_id = 1
|
||||
args = [target, source]
|
||||
opts = {}
|
||||
opts = {'wait_builds': []}
|
||||
priority = None
|
||||
|
||||
self.session.getBuildTarget.return_value = target_info
|
||||
|
|
@ -648,7 +650,7 @@ Task info: weburl/taskinfo?taskID=1
|
|||
source = 'srpm'
|
||||
task_id = 1
|
||||
args = ['--noprogress', target, source]
|
||||
opts = {}
|
||||
opts = {'wait_builds': []}
|
||||
priority = None
|
||||
|
||||
self.session.getBuildTarget.return_value = target_info
|
||||
|
|
@ -702,7 +704,7 @@ Task info: weburl/taskinfo?taskID=1
|
|||
task_id = 1
|
||||
quiet = True
|
||||
args = ['--quiet', target, source]
|
||||
opts = {}
|
||||
opts = {'wait_builds': []}
|
||||
priority = None
|
||||
|
||||
self.session.getBuildTarget.return_value = target_info
|
||||
|
|
@ -752,7 +754,7 @@ Task info: weburl/taskinfo?taskID=1
|
|||
task_id = 1
|
||||
quiet = None
|
||||
args = ['--wait', target, source]
|
||||
opts = {}
|
||||
opts = {'wait_builds': []}
|
||||
priority = None
|
||||
|
||||
self.session.getBuildTarget.return_value = target_info
|
||||
|
|
@ -805,7 +807,7 @@ Task info: weburl/taskinfo?taskID=1
|
|||
source = 'srpm'
|
||||
task_id = 1
|
||||
args = ['--nowait', target, source]
|
||||
opts = {}
|
||||
opts = {'wait_builds': []}
|
||||
priority = None
|
||||
|
||||
self.session.getBuildTarget.return_value = target_info
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue