From 507ad575e1653572aa30baec93374a26e40141b9 Mon Sep 17 00:00:00 2001 From: Jan Kaluža Date: Feb 06 2019 06:51:05 +0000 Subject: Merge #356 `Use ArtifactBuild.dep_on to find out the rebuilt_nvr of the parent image.` --- diff --git a/freshmaker/handlers/__init__.py b/freshmaker/handlers/__init__.py index 8b7c552..44855f2 100644 --- a/freshmaker/handlers/__init__.py +++ b/freshmaker/handlers/__init__.py @@ -471,7 +471,16 @@ class ContainerBuildHandler(BaseHandler): args["commit"]) branch = args["branch"] target = args["target"] - parent = args["parent"] + + # If this container image depends on another container image + # we are going to rebuild, use the new NVR of that image + # as a dependency. Otherwise fallback to build_args, which means + # the parent is not rebuilt by Freshmaker, but we just take existing + # parent from Koji. + if build.dep_on: + parent = build.dep_on.rebuilt_nvr + else: + parent = args["original_parent"] # If set to None, then OSBS defaults to using the arches # of the build tag associated with the target. diff --git a/freshmaker/handlers/koji/rebuild_images_on_rpm_advisory_change.py b/freshmaker/handlers/koji/rebuild_images_on_rpm_advisory_change.py index 0546ce1..7c58248 100644 --- a/freshmaker/handlers/koji/rebuild_images_on_rpm_advisory_change.py +++ b/freshmaker/handlers/koji/rebuild_images_on_rpm_advisory_change.py @@ -155,8 +155,11 @@ class RebuildImagesOnRPMAdvisoryChange(ContainerBuildHandler): ((build.dep_on and build.dep_on.original_nvr in printed) or (not build.dep_on and batch == 0))): args = json.loads(build.build_args) - based_on = "based on %s" % args["parent"] \ - if args["parent"] else "base image" + if build.dep_on: + based_on = "based on %s" % build.dep_on.rebuilt_nvr + else: + based_on = "based on %s" % args["original_parent"] \ + if args["original_parent"] else "base image" self.log_info( ' - %s#%s (%s)' % (args["repository"], args["commit"], based_on)) @@ -224,12 +227,6 @@ class RebuildImagesOnRPMAdvisoryChange(ContainerBuildHandler): if "parent" in image and image["parent"] else None dep_on = builds[parent_nvr] if parent_nvr in builds else None - # If this container image depends on another container image - # we are going to rebuild, use the new NVR of that image - # as a dependency instead of the original one. - if dep_on: - parent_nvr = dep_on.rebuilt_nvr - if "error" in image and image["error"]: state_reason = image["error"] state = ArtifactBuildState.FAILED.value @@ -262,7 +259,7 @@ class RebuildImagesOnRPMAdvisoryChange(ContainerBuildHandler): build_args = {} build_args["repository"] = image["repository"] build_args["commit"] = image["commit"] - build_args["parent"] = parent_nvr + build_args["original_parent"] = parent_nvr build_args["target"] = image["target"] build_args["branch"] = image["git_branch"] build_args["arches"] = image["arches"] diff --git a/tests/handlers/internal/test_update_db_on_advisory_change.py b/tests/handlers/internal/test_update_db_on_advisory_change.py index a7d8985..9b4b682 100644 --- a/tests/handlers/internal/test_update_db_on_advisory_change.py +++ b/tests/handlers/internal/test_update_db_on_advisory_change.py @@ -365,8 +365,8 @@ class TestBatches(helpers.ModelsTestCase): args = json.loads(build.build_args) self.assertEqual(args["repository"], build.name + "_repo") self.assertEqual(args["commit"], build.name + "_123") - self.assertEqual(args["parent"], - build.dep_on.rebuilt_nvr if build.dep_on else None) + self.assertEqual(args["original_parent"], + build.dep_on.original_nvr if build.dep_on else None) self.assertEqual(args["renewed_odcs_compose_ids"], [10, 11]) @@ -378,7 +378,7 @@ class TestCheckImagesToRebuild(helpers.ModelsTestCase): super(TestCheckImagesToRebuild, self).setUp() build_args = json.dumps({ - "parent": "nvr", + "original_parent": "nvr", "repository": "repo", "target": "target", "commit": "hash", diff --git a/tests/test_handler.py b/tests/test_handler.py index f406386..66cfdfb 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -116,7 +116,7 @@ class TestGetRepoURLs(helpers.ModelsTestCase): build_args = {} build_args["repository"] = "repo" build_args["commit"] = "hash" - build_args["parent"] = None + build_args["original_parent"] = None build_args["target"] = "target" build_args["branch"] = "branch" build_args["arches"] = "x86_64"