From f31238ed3c29e064ef7aca2b1644d857b709781a Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Jan 28 2019 07:21:45 +0000 Subject: Generate Pulp repos in case we are generating extra ODCS compose for unpublished image. In case when image is unpublished, we need to generate an extra ODCS compose with possibly unpublished RPMs which exist only in Koji so far. We can pass this extra compose to Koji using "compose_ids" build option. But the issue is that when "compose_ids" is set, Koji/OSBS completely ignores the Pulp repos defined in the content_sets.yml file and it overrides it by whathever we passes to it using compose_ids. Because of that, we need to generate also the Pulp repos on Freshmaker's side in this case and pass it together with extra compose in the compose_ids. --- 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 8afccce..46b6d3c 100644 --- a/freshmaker/handlers/koji/rebuild_images_on_rpm_advisory_change.py +++ b/freshmaker/handlers/koji/rebuild_images_on_rpm_advisory_change.py @@ -272,8 +272,13 @@ class RebuildImagesOnRPMAdvisoryChange(ContainerBuildHandler): db.session.commit() if state != ArtifactBuildState.FAILED.value: - # Store odcs pulp compose to build - if image["generate_pulp_repos"]: + # Store odcs pulp compose to build. + # Also generate pulp repos in case the image is unpublished, + # because in this case, we have to generate extra ODCS compose + # with all the RPMs in the image anyway later. And OSBS works + # in a way that we have to pass all the ODCS composes to it or + # no ODCS compose at all. + if image["generate_pulp_repos"] or not image["published"]: # Check if the compose for these content_sets is # already cached and use it in this case. cache_key = " ".join(sorted(image["content_sets"])) 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 d9e6046..a7d8985 100644 --- a/tests/handlers/internal/test_update_db_on_advisory_change.py +++ b/tests/handlers/internal/test_update_db_on_advisory_change.py @@ -784,7 +784,7 @@ class TestRecordBatchesImages(helpers.ModelsTestCase): "generate_pulp_repos": False, "arches": "x86_64", "odcs_compose_ids": None, - "published": False, + "published": True, })] ] @@ -800,6 +800,46 @@ class TestRecordBatchesImages(helpers.ModelsTestCase): self.assertEqual(ArtifactBuildState.PLANNED.value, parent_image.state) self.mock_prepare_pulp_repo.assert_not_called() + def test_record_batches_generate_pulp_repos_when_image_unpublished(self): + batches = [ + [ContainerImage({ + "brew": { + "completion_date": "20170420T17:05:37.000-0400", + "build": "rhel-server-docker-7.3-82", + "package": "rhel-server-docker" + }, + 'parsed_data': { + 'layers': [ + 'sha512:12345678980', + 'sha512:10987654321' + ] + }, + "parent": None, + "content_sets": ["content-set-1"], + "repository": "repo-1", + "commit": "123456789", + "target": "target-candidate", + "git_branch": "rhel-7", + "error": None, + "generate_pulp_repos": False, + "arches": "x86_64", + "odcs_compose_ids": None, + "published": False, + })] + ] + + handler = RebuildImagesOnRPMAdvisoryChange() + handler._record_batches(batches, self.mock_event) + + # Check parent image + query = db.session.query(ArtifactBuild) + parent_image = query.filter( + ArtifactBuild.original_nvr == 'rhel-server-docker-7.3-82' + ).first() + self.assertNotEqual(None, parent_image) + self.assertEqual(ArtifactBuildState.PLANNED.value, parent_image.state) + self.mock_prepare_pulp_repo.assert_called() + def test_pulp_compose_generated_just_once(self): batches = [ [ContainerImage({