From 1fdf99d1fd7be9f2042be7dac68d9aca9c75ce0f Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Jan 29 2019 07:04:35 +0000 Subject: Include full RPM manifest in unpublished images, so we can generate extra ODCS compose with them. Usually we do not store complete RPM manifest, but when image is unpublished, we need complete RPM manifest in order to check for possible unpublished RPMs. We do not want to get the complete manifest for every container image, because it is relatively big, so fetch it only when needed. --- diff --git a/freshmaker/lightblue.py b/freshmaker/lightblue.py index 4137825..42da34e 100644 --- a/freshmaker/lightblue.py +++ b/freshmaker/lightblue.py @@ -502,12 +502,25 @@ class ContainerImage(dict): # Get the published version of this image to find out if the image # was actually published. images = lb_instance.get_images_by_nvrs( - [self["brew"]["build"]], published=True) + [self["brew"]["build"]], published=True, include_rpms=False) if images: self["published"] = True else: self["published"] = False + # Usually we do not store complete RPM manifest, but when + # image is unpublished, we need complete RPM manifest in order + # to check for possible unpublished RPMs. + # We do not want to get the complete manifest for every container + # image, because it is relatively big, so fetch it only when needed. + images = lb_instance.get_images_by_nvrs( + [self["brew"]["build"]]) + if images: + self["rpm_manifest"] = images[0]["rpm_manifest"] + else: + log.warning("No image %s found in Lightblue.", + self["brew"]["build"]) + def resolve(self, lb_instance, children=None): """ Resolves the Container image - populates additional metadata by @@ -918,7 +931,7 @@ class LightBlue(object): return images def get_images_by_nvrs(self, nvrs, published=True, content_sets=None, - srpm_nvrs=None): + srpm_nvrs=None, include_rpms=True): """Query lightblue and returns containerImages defined by list of `nvrs`. @@ -927,6 +940,8 @@ class LightBlue(object): :param list content_sets: List of content_sets the image includes RPMs from. :param list srpm_nvrs: list of SRPM NVRs to look for + :param bool include_rpms: When True, the rpm_manifest is included in + the returned ContainerImages. :return: List of containerImages. :rtype: list of ContainerImages. """ @@ -948,7 +963,8 @@ class LightBlue(object): }, ] }, - "projection": self._get_default_projection() + "projection": self._get_default_projection( + include_rpms=include_rpms) } if content_sets is not None: diff --git a/tests/test_lightblue.py b/tests/test_lightblue.py index e2499dc..1f2a5db 100644 --- a/tests/test_lightblue.py +++ b/tests/test_lightblue.py @@ -535,7 +535,8 @@ class TestContainerImageObject(helpers.FreshmakerTestCase): image.resolve_published(lb) self.assertEqual(image["published"], True) lb.get_images_by_nvrs.assert_called_once_with( - ["package-name-1-4-12.10"], published=True) + ["package-name-1-4-12.10"], published=True, + include_rpms=False) def test_resolve_published_unpublished(self): image = ContainerImage.create({ @@ -546,9 +547,26 @@ class TestContainerImageObject(helpers.FreshmakerTestCase): }) lb = Mock() - lb.get_images_by_nvrs.return_value = [] + lb.get_images_by_nvrs.side_effect = [[], [{"rpm_manifest": "x"}]] image.resolve_published(lb) self.assertEqual(image["published"], False) + lb.get_images_by_nvrs.asssert_has_calls([ + call(["package-name-1-4-12.10"], published=True, include_rpms=False), + call(["package-name-1-4-12.10"])]) + + self.assertEqual(image["rpm_manifest"], "x") + + def test_resolve_published_not_image_in_lb(self): + image = ContainerImage.create({ + '_id': '1233829', + 'brew': { + 'build': 'package-name-1-4-12.10', + }, + }) + + lb = Mock() + lb.get_images_by_nvrs.return_value = [] + image.resolve_published(lb) class TestContainerRepository(helpers.FreshmakerTestCase):