Skip to content

Commit

Permalink
Skip build option, to update just buildconfig for autorebuilds
Browse files Browse the repository at this point in the history
* OSBS-7711

Signed-off-by: Robert Cerven <rcerven@redhat.com>
  • Loading branch information
rcerven committed Sep 13, 2019
1 parent 88217a9 commit f3edc3f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 18 deletions.
47 changes: 39 additions & 8 deletions koji_containerbuild/plugins/builder_containerbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,17 +393,20 @@ def resultdir(self):
os.makedirs(path)
return path

def _incremental_upload_logs(self, child_pid):
def _incremental_upload_logs(self, child_pid=None):
resultdir = self.resultdir()
uploadpath = self.getUploadPath()
watcher = FileWatcher(resultdir, logger=self.logger)
finished = False
try:
while not finished:
time.sleep(1)
status = os.waitpid(child_pid, os.WNOHANG)
if status[0] != 0:
if child_pid is None:
finished = True
else:
time.sleep(1)
status = os.waitpid(child_pid, os.WNOHANG)
if status[0] != 0:
finished = True

for result in watcher.files_to_upload():
if result is False:
Expand Down Expand Up @@ -528,7 +531,7 @@ def runBuilds(self, src, target_info, arches, scratch=False, isolated=False,
yum_repourls=None, branch=None, push_url=None,
koji_parent_build=None, release=None,
flatpak=False, signing_intent=None,
compose_ids=None):
compose_ids=None, skip_build=False):

self.logger.debug("Spawning jobs for arches: %r" % (arches))

Expand All @@ -547,10 +550,14 @@ def runBuilds(self, src, target_info, arches, scratch=False, isolated=False,
release=release,
flatpak=flatpak,
signing_intent=signing_intent,
compose_ids=compose_ids
compose_ids=compose_ids,
skip_build=skip_build
)

results = [self.createContainer(**kwargs)]
results = []
semi_results = self.createContainer(**kwargs)
if semi_results is not None:
results = [semi_results]

self.logger.debug("Results: %r", results)
return results
Expand All @@ -559,7 +566,7 @@ def createContainer(self, src=None, target_info=None, arches=None,
scratch=None, isolated=None, yum_repourls=[],
branch=None, push_url=None, koji_parent_build=None,
release=None, flatpak=False, signing_intent=None,
compose_ids=None):
compose_ids=None, skip_build=False):
if not yum_repourls:
yum_repourls = []

Expand Down Expand Up @@ -600,6 +607,8 @@ def createContainer(self, src=None, target_info=None, arches=None,
create_build_args['git_push_url'] = push_url
if flatpak:
create_build_args['flatpak'] = True
if skip_build:
create_build_args['skip_build'] = True

try:
orchestrator_create_build_args = create_build_args.copy()
Expand All @@ -622,11 +631,24 @@ def createContainer(self, src=None, target_info=None, arches=None,
except (AttributeError, OsbsOrchestratorNotEnabled):
# Older osbs-client, or else orchestration not enabled
create_build_args['architecture'] = arch = arches[0]
create_build_args.pop('skip_build', None)
create_method = self.osbs().create_build
self.logger.debug("Starting %s with params: '%s'",
create_method, create_build_args)
build_response = create_method(**create_build_args)

if build_response is None:
self.logger.debug("Build was skipped")

osbs_logs_dir = self.resultdir()
koji.ensuredir(osbs_logs_dir)
try:
self._incremental_upload_logs()
except koji.ActionNotAllowed:
pass

return

build_id = build_response.get_build_name()
self.logger.debug("OSBS build id: %r", build_id)

Expand Down Expand Up @@ -875,9 +897,18 @@ def handler(self, src, target, opts=None):
flatpak=flatpak,
compose_ids=opts.get('compose_ids', None),
signing_intent=opts.get('signing_intent', None),
skip_build=opts.get('skip_build', False),
)
all_repositories = []
all_koji_builds = []

if not results:
return {
'repositories': all_repositories,
'koji_builds': all_koji_builds,
'build': 'skipped',
}

for result in results:
try:
repository = result.get('repositories')
Expand Down
6 changes: 5 additions & 1 deletion koji_containerbuild/plugins/cli_containerbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def parse_arguments(options, args, flatpak):
help=_("ODCS composes used. May be used multiple times. Cannot be"
" used with --signing-intent"),
dest='compose_ids', action='append', metavar="COMPOSE_ID", type="int")
parser.add_option("--skip-build", action="store_true",
help=_("Skip build and update buildconfig. "
"Use this option to update autorebuild settings"))

if not flatpak:
parser.add_option("--release",
help=_("Set release value"))
Expand All @@ -126,7 +130,7 @@ def parse_arguments(options, args, flatpak):
if not build_opts.git_branch:
parser.error(_("git-branch must be specified"))

keys = ('scratch', 'epoch', 'yum_repourls', 'git_branch', 'signing_intent', 'compose_ids')
keys = ('scratch', 'epoch', 'yum_repourls', 'git_branch', 'signing_intent', 'compose_ids', 'skip_build')

if flatpak:
opts['flatpak'] = True
Expand Down
45 changes: 36 additions & 9 deletions tests/test_builder_containerbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,18 @@ def _mock_osbs(self, koji_build_id, src, koji_task_id,
if not create_build_args.get('signing_intent'):
create_build_args.pop('signing_intent', None)

build_response = flexmock()
(build_response
.should_receive('get_build_name')
.and_return('os-build-id'))
skip_build = True
if not create_build_args.get('skip_build'):
create_build_args.pop('skip_build', None)
skip_build = False

if skip_build and orchestrator:
build_response = None
else:
build_response = flexmock()
(build_response
.should_receive('get_build_name')
.and_return('os-build-id'))

build_finished_response = flexmock(status='200', json={})
(build_finished_response
Expand Down Expand Up @@ -297,6 +305,7 @@ def _mock_osbs(self, koji_build_id, src, koji_task_id,
.and_raise(OsbsOrchestratorNotEnabled))

legacy_args = create_build_args.copy()
legacy_args.pop('skip_build', None)
legacy_args.pop('platforms', None)
legacy_args.pop('koji_parent_build', None)
legacy_args.pop('isolated', None)
Expand Down Expand Up @@ -667,6 +676,7 @@ def test_private_branch(self, tmpdir):
.and_return(True))
task.fetchDockerfile(source, 'build_tag')

@pytest.mark.parametrize('log_upload_raises', (True, False))
@pytest.mark.parametrize('orchestrator', (True, False))
@pytest.mark.parametrize('additional_args', (
{'koji_parent_build': 'fedora-26-99'},
Expand All @@ -675,8 +685,10 @@ def test_private_branch(self, tmpdir):
{'isolated': True},
{'isolated': False},
{'release': '13'},
{'skip_build': True},
{'skip_build': False},
))
def test_additional_args(self, tmpdir, orchestrator, additional_args):
def test_additional_args(self, tmpdir, log_upload_raises, orchestrator, additional_args):
koji_task_id = 123
last_event_id = 456
koji_build_id = 999
Expand Down Expand Up @@ -707,6 +719,14 @@ def test_additional_args(self, tmpdir, orchestrator, additional_args):
(flexmock(task)
.should_receive('_write_combined_log'))

if log_upload_raises:
(flexmock(task)
.should_receive('_incremental_upload_logs')
.and_raise(koji.ActionNotAllowed))
else:
(flexmock(task)
.should_call('_incremental_upload_logs'))

task._osbs = self._mock_osbs(koji_build_id=koji_build_id,
src=src,
koji_task_id=koji_task_id,
Expand All @@ -715,10 +735,17 @@ def test_additional_args(self, tmpdir, orchestrator, additional_args):

task_response = task.handler(src['src'], 'target', opts=additional_args)

assert task_response == {
'repositories': ['unique-repo', 'primary-repo'],
'koji_builds': [koji_build_id]
}
if orchestrator and additional_args.get('skip_build', None):
assert task_response == {
'repositories': [],
'koji_builds': [],
'build': 'skipped'
}
else:
assert task_response == {
'repositories': ['unique-repo', 'primary-repo'],
'koji_builds': [koji_build_id]
}

def test_flatpak_build(self, tmpdir):
task_id = 123
Expand Down

0 comments on commit f3edc3f

Please sign in to comment.