From 5117d0b555796b3223b1259514cf47bbeb56168f Mon Sep 17 00:00:00 2001 From: Giulia Naponiello Date: May 05 2020 08:16:02 +0000 Subject: No need to get unpublished images anymore We used to get unpublished images from lightblue when finding layers to get the parent image. This is not needed anymore because we use the `parent_brew_build` field in koji now. So we can remove this code. Signed-off-by: Giulia Naponiello --- diff --git a/freshmaker/lightblue.py b/freshmaker/lightblue.py index ec952eb..4a250a8 100644 --- a/freshmaker/lightblue.py +++ b/freshmaker/lightblue.py @@ -1009,47 +1009,6 @@ class LightBlue(object): images = self.filter_out_images_with_higher_srpm_nvr(images, srpm_name_to_nvrs) return images - def find_unpublished_image_for_build(self, build): - """ - Returns the unpublished variant of Docker image specified by `build` - Brew build N-V-R. - - :param str build: Brew build N-V-R. - :return: Unpublished container image. - :rtype: ContainerImage. - """ - image_request = { - "objectType": "containerImage", - "query": { - "$and": [ - { - "field": "brew.build", - "op": "=", - "rvalue": build - }, - { - "$or": [ - { - "field": "repositories.*.published", - "op": "=", - "rvalue": False - }, - { - "field": "repositories#", - "op": "=", - "rvalue": 0 - } - ] - } - ] - }, - "projection": self._get_default_projection(include_rpm_manifest=False) - } - images = self.find_container_images(image_request) - if not images: - return None - return images[0] - def find_parent_brew_build_nvr_from_child(self, child_image): """ Returns the parent brew build NVR of the input image. If the parent is not found it returns None. @@ -1492,14 +1451,6 @@ class LightBlue(object): # This `srpm_name` is not in image. continue - unpublished = self.find_unpublished_image_for_build(image.nvr) - if not unpublished: - image.log_error( - "Cannot find unpublished version of image, Lightblue " - "data is probably incomplete") - rebuild_list[srpm_name] = [image] - continue - rebuild_list[srpm_name] = self.find_parent_images_with_package( image, srpm_name, []) if rebuild_list[srpm_name]: diff --git a/tests/test_lightblue.py b/tests/test_lightblue.py index 576070f..9f0b281 100644 --- a/tests/test_lightblue.py +++ b/tests/test_lightblue.py @@ -1506,11 +1506,9 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): @patch('freshmaker.lightblue.LightBlue.find_images_with_packages_from_content_set') @patch('freshmaker.lightblue.LightBlue.find_parent_images_with_package') - @patch('freshmaker.lightblue.LightBlue.find_unpublished_image_for_build') @patch('os.path.exists') def test_images_to_rebuild(self, exists, - find_unpublished_image_for_build, find_parent_images_with_package, find_images_with_packages_from_content_set): exists.return_value = True @@ -1640,7 +1638,6 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): }] image["directly_affected"] = True - find_unpublished_image_for_build.side_effect = images find_images_with_packages_from_content_set.return_value = images leaf_image6_as_parent = copy.deepcopy(leaf_image6) @@ -1720,11 +1717,10 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): @patch("freshmaker.lightblue.LightBlue.get_images_by_nvrs") @patch('freshmaker.lightblue.LightBlue.find_images_with_packages_from_content_set') - @patch('freshmaker.lightblue.LightBlue.find_unpublished_image_for_build') @patch('freshmaker.lightblue.LightBlue.find_parent_images_with_package') @patch('os.path.exists') def test_parent_images_with_package_using_field_parent_brew_build_parent_empty( - self, exists, find_parent_images_with_package, find_unpublished_image_for_build, + self, exists, find_parent_images_with_package, find_images_with_packages_from_content_set, cont_images): exists.return_value = True @@ -1742,7 +1738,6 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): }) find_parent_images_with_package.return_value = [] - find_unpublished_image_for_build.return_value = image_a find_images_with_packages_from_content_set.return_value = [image_a] cont_images.side_effect = [self.fake_container_images_with_parent_brew_build, [], []] @@ -1798,41 +1793,6 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): self.assertEqual(set(ret[0]["content_sets"]), set(["dummy-content-set-1", "dummy-content-set-2"])) - @patch('freshmaker.lightblue.LightBlue.find_images_with_packages_from_content_set') - @patch('freshmaker.lightblue.LightBlue.find_unpublished_image_for_build') - @patch('os.path.exists') - def test_images_to_rebuild_cannot_find_unpublished( - self, exists, find_unpublished_image_for_build, - find_images_with_packages_from_content_set): - exists.return_value = True - - image_a = ContainerImage.create({ - 'brew': {'package': 'image-a', 'build': 'image-a-v-r1'}, - 'repository': 'repo-1', - 'commit': 'image-a-commit', - 'repositories': [{"repository": "foo/bar"}], - 'rpm_manifest': [{ - "rpms": [ - {"srpm_name": "dummy"} - ] - }] - }) - - find_unpublished_image_for_build.return_value = None - find_images_with_packages_from_content_set.return_value = [image_a] - - lb = LightBlue(server_url=self.fake_server_url, - cert=self.fake_cert_file, - private_key=self.fake_private_key) - batches = lb.find_images_to_rebuild(["dummy-1-1"], ["dummy"]) - - self.assertEqual(len(batches), 1) - self.assertEqual(len(batches[0]), 1) - self.assertEqual( - list(batches[0])[0]["error"], - "Cannot find unpublished version of image, " - "Lightblue data is probably incomplete") - @patch('freshmaker.lightblue.LightBlue.find_container_repositories') @patch('freshmaker.lightblue.LightBlue.find_container_images') @patch('os.path.exists')