From f6fcd09b7aff28992e09c0a03edc72b35a51f35a Mon Sep 17 00:00:00 2001 From: Giulia Naponiello Date: Mar 02 2020 16:22:37 +0000 Subject: Revert "No need to convert compose ids or verify 'done' state" This reverts commit 7d381c1e1001faff98dd3c47555e32e605d88d9c. --- diff --git a/freshmaker/handlers/__init__.py b/freshmaker/handlers/__init__.py index a7de567..eda01ea 100644 --- a/freshmaker/handlers/__init__.py +++ b/freshmaker/handlers/__init__.py @@ -533,18 +533,34 @@ class ContainerBuildHandler(BaseHandler): if args["renewed_odcs_compose_ids"]: compose_ids += args["renewed_odcs_compose_ids"] - for compose_id in compose_ids: - odcs_compose = self.odcs_get_compose(compose_id) - if odcs_compose["state"] in [COMPOSE_STATES['wait'], - COMPOSE_STATES['generating']]: - # In case the ODCS compose is still generating, raise an - # exception. - msg = ("Compose %s has not been generated yet. Waiting with " - "rebuild." % (str(compose_id))) - self.log_info(msg) - raise ODCSComposeNotReady(msg) - # OSBS can renew a compose if it needs to, so we can just pass - # it along without further verification for other states. + # OSBS cannot handle both repo_urls and compose_ids in the same time. + # We use repo_urls only in special cases to build base images. In this + # cases, we want to convert compose_ids to repository URLs. Otherwise, + # just pass compose_ids to OSBS via Koji. + if repo_urls is not None: + for compose_id in compose_ids: + odcs_compose = self.odcs_get_compose(compose_id) + if odcs_compose["state"] in [COMPOSE_STATES['wait'], + COMPOSE_STATES['generating']]: + # In case the ODCS compose is still generating, raise an + # exception. + msg = ("Compose %s is not in done state. Waiting with " + "rebuild." % (str(compose_id))) + self.log_info(msg) + raise ODCSComposeNotReady(msg) + elif odcs_compose["state"] != COMPOSE_STATES["done"]: + # In case the compose is not in 'done' state, mark the + # build as failed. We should never get expired here, + # because the compose has been submitted just a minutes + # ago. If we get "expired" here, it is sign of an issue, + # because that means we are trying to build quite old + # image. + build.transition( + ArtifactBuildState.FAILED.value, + "Compose %s is not in 'done' state." % str(compose_id)) + return + repo_urls.append(odcs_compose["result_repofile"]) + compose_ids = [] return self.build_container( scm_url, branch, target, repo_urls=repo_urls, diff --git a/tests/test_handler.py b/tests/test_handler.py index 6970d4f..a63c8fa 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -218,10 +218,13 @@ class TestGetRepoURLs(helpers.ModelsTestCase): handler = MyHandler() handler.build_image_artifact_build(self.build_1, ["http://localhost/x.repo"]) - repo_urls = ['http://localhost/x.repo'] + repo_urls = [ + 'http://localhost/x.repo', 'http://localhost/5.repo', + 'http://localhost/6.repo', 'http://localhost/7.repo', + 'http://localhost/8.repo'] build_container.assert_called_once_with( 'git://pkgs.fedoraproject.org/repo#hash', 'branch', 'target', - arch_override='x86_64', compose_ids=[5, 6, 7, 8], isolated=True, + arch_override='x86_64', compose_ids=[], isolated=True, koji_parent_build=None, release='2', repo_urls=repo_urls) @patch("freshmaker.handlers.ContainerBuildHandler.build_container")