From 2ee69d9679e2b039086f1b66279ff99dbef95d9d Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: May 29 2018 14:15:38 +0000 Subject: LB: ContainerImage now contains 'content_sets' field, so we don't have to resolve it when available. --- diff --git a/freshmaker/lightblue.py b/freshmaker/lightblue.py index 3c75f36..9db3884 100644 --- a/freshmaker/lightblue.py +++ b/freshmaker/lightblue.py @@ -334,6 +334,13 @@ class ContainerImage(dict): data = self._get_additional_data_from_distgit( self["repository"], self["git_branch"], self["commit"]) self["generate_pulp_repos"] = data["generate_pulp_repos"] + + # ContainerImage now has content_sets field, so use it if available. + if "content_sets" in self and self["content_sets"]: + if "content_sets_source" not in self: + self["content_sets_source"] = "lightblue_container_image" + return + # Prefer content_sets from content_sets.yml. if data["content_sets"]: self["content_sets"] = data["content_sets"] @@ -388,7 +395,7 @@ class ContainerImage(dict): if image_content_sets: break - self["content_sets_source"] = "lightblue" + self["content_sets_source"] = "lightblue_container_repository" log.info("Container image %s uses following content sets: %r", self["brew"]["build"], image_content_sets) self.update({"content_sets": image_content_sets}) @@ -671,6 +678,7 @@ class LightBlue(object): {"field": "repositories.*.published", "include": True, "recursive": True}, {"field": "repositories.*.repository", "include": True, "recursive": True}, {"field": "repositories.*.tags.*.name", "include": True, "recursive": True}, + {"field": "content_sets", "include": True, "recursive": True}, ] if include_rpms: if srpm_names: diff --git a/tests/test_lightblue.py b/tests/test_lightblue.py index 01e8320..bbb6a91 100644 --- a/tests/test_lightblue.py +++ b/tests/test_lightblue.py @@ -340,6 +340,24 @@ class TestContainerImageObject(helpers.FreshmakerTestCase): self.assertTrue(self.dummy_image["error"].find( "Cannot find valid source of Koji build") != -1) + def test_resolve_content_sets_already_included_in_lb_response(self): + image = ContainerImage.create({ + '_id': '1233829', + 'brew': { + 'build': 'package-name-1-4-12.10', + }, + 'repository': 'foo', + 'git_branch': 'branch', + 'commit': 'commithash', + 'content_sets': ['dummy-contentset'], + }) + + lb = Mock() + image.resolve_content_sets(lb) + self.assertEqual(image["content_sets"], ['dummy-contentset']) + self.assertEqual(image["content_sets_source"], + "lightblue_container_image") + def test_resolve_content_sets_no_repositories(self): image = ContainerImage.create({ '_id': '1233829', @@ -860,7 +878,7 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): "package": "package-name-2" }, 'content_sets': ['dummy-content-set-1', 'dummy-content-set-2'], - 'content_sets_source': 'lightblue', + 'content_sets_source': 'lightblue_container_repository', 'repositories': [ {'repository': 'product2/repo2', 'published': True, 'tags': [{"name": "latest"}]}