From 5e7555b538c8fb4f27535efdd6b669671851f3cb Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: May 30 2018 13:29:41 +0000 Subject: Remove code which gets content_sets from ContainerRepository (deprecated). --- diff --git a/freshmaker/lightblue.py b/freshmaker/lightblue.py index 1e5adef..ebd478d 100644 --- a/freshmaker/lightblue.py +++ b/freshmaker/lightblue.py @@ -329,9 +329,7 @@ class ContainerImage(dict): self.update(data) - def resolve_content_sets( - self, lb_instance, children=None, published=True, - deprecated=False, release_category="Generally Available"): + def resolve_content_sets(self, lb_instance, children=None): """ Find out the content_sets this image uses and store it as "content_sets" key in image. @@ -340,13 +338,7 @@ class ContainerImage(dict): queries. :param list children: List of children to take the content_sets from in case this container image is unpublished and therefore without - repositories from which we could get the list of content_sets. - :param bool published: whether to limit queries to published - repositories - :param bool deprecated: set to True to limit results to deprecated - repositories - :param str release_category: filter only repositories with specific - release category (options: Deprecated, Generally Available, Beta, Tech Preview) + "content_sets" set. """ data = self._get_additional_data_from_distgit( self["repository"], self["git_branch"], self["commit"]) @@ -354,6 +346,8 @@ class ContainerImage(dict): # ContainerImage now has content_sets field, so use it if available. if "content_sets" in self and self["content_sets"]: + log.info("Container image %s uses following content sets: %r", + self["brew"]["build"], self["content_sets"]) if "content_sets_source" not in self: self["content_sets_source"] = "lightblue_container_image" return @@ -366,60 +360,38 @@ class ContainerImage(dict): self["brew"]["build"], data["content_sets"]) return - # In case content_sets cannot be get from content_sets.yml, try - # getting them from Lightblue data. - if "repositories" not in self or len(self["repositories"]) == 0: - self["content_sets_source"] = "child_image" - if not children: - log.warning("Container image %s does not have 'repositories' set " - "in Lightblue, this is suspicious.", - self["brew"]["build"]) - self.update({"content_sets": []}) - return - - for child in children: - # The child['content_sets'] should be always set for children - # passed here, but in case it is not, just try it. - if "content_sets" not in child: - child.resolve(lb_instance, None, published, - deprecated, release_category) - if not child["content_sets"]: - continue + # In case content_sets cannot be get from content_sets.yml and also + # are not set directly in this ContainerImage, try to get them from + # children image. + self["content_sets_source"] = "child_image" + if not children: + log.warning("Container image %s does not have 'content_sets' set " + "in Lightblue and also does not have any children, " + "this is suspicious.", self["brew"]["build"]) + self.update({"content_sets": []}) + return - log.info("Container image %s does not have 'repositories' set " - "in Lightblue. Using child image %s content_sets: %r", - self["brew"]["build"], child["brew"]["build"], - child["content_sets"]) - self.update({"content_sets": child["content_sets"]}) - return + for child in children: + # The child['content_sets'] should be always set for children + # passed here, but in case it is not, just try it. + if "content_sets" not in child: + child.resolve(lb_instance, None) + if not child["content_sets"]: + continue - log.warning("Container image %s does not have 'repositories' set " - "in Lightblue as well as its children, this " - "is suspicious.", self["brew"]["build"]) - self.update({"content_sets": []}) + log.info("Container image %s does not have 'content-sets' set " + "in Lightblue. Using child image %s content_sets: %r", + self["brew"]["build"], child["brew"]["build"], + child["content_sets"]) + self.update({"content_sets": child["content_sets"]}) return - # Checking only the first repository is OK, because if an image - # is in multiple repositories, the content_sets of all of them - # must be the same by definition. - # But some older repositories don't have to have the content_sets - # set, so try to iterate over all of them and stop once we find - # some repository which returns some content_sets. - for repository in self["repositories"]: - image_content_sets = lb_instance.find_content_sets_for_repository( - repository["repository"], published, deprecated, - release_category) - if image_content_sets: - break - - 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}) - - def resolve( - self, lb_instance, children=None, published=True, - deprecated=False, release_category="Generally Available"): + log.warning("Container image %s does not have 'content_sets' set " + "in Lightblue as well as its children, this " + "is suspicious.", self["brew"]["build"]) + self.update({"content_sets": []}) + + def resolve(self, lb_instance, children=None): """ Resolves the Container image - populates additional metadata by querying Koji and dist-git. @@ -427,8 +399,7 @@ class ContainerImage(dict): Calls self.resolve_commit() and self.resolve_content_sets(). """ self.resolve_commit() - self.resolve_content_sets( - lb_instance, children, published, deprecated, release_category) + self.resolve_content_sets(lb_instance, children) class LightBlue(object): @@ -626,51 +597,6 @@ class LightBlue(object): repositories = self.find_container_repositories(repo_request) return [repository["repository"] for repository in repositories] - def find_content_sets_for_repository( - self, repository, published=True, deprecated=False, - release_category="Generally Available"): - """ - Query lightblue and find content sets which are used for Container - image in repository `repository` - - :param str repository: name of the repository for which the content - sets will be returned - :param bool published: whether to limit queries to published - repositories - :return: list of found content sets, each of which is content set name. - Empty list is returned if no repository is found. - :rtype: list - """ - repo_request = { - "objectType": "containerRepository", - "query": { - "$and": [ - { - "field": "repository", - "op": "=", - "rvalue": repository - }, - ] - }, - "projection": [ - {"field": "content_sets", "include": True, "recursive": True} - ] - } - - repo_request = self._set_container_repository_filters( - repo_request, published, deprecated, release_category) - repos = self.find_container_repositories(repo_request) - if not repos: - return [] - - ret = set() - for repo in repos: - if "content_sets" not in repo: - continue - ret |= set(repo["content_sets"]) - - return sorted(list(ret)) - def _get_default_projection(self, srpm_names=None, include_rpms=True): """ Returns the default projection list for containerImage objects. @@ -890,9 +816,7 @@ class LightBlue(object): return images[0] - def find_parent_images_with_package( - self, child_image, srpm_name, layers, published=True, - deprecated=False, release_category="Generally Available"): + def find_parent_images_with_package(self, child_image, srpm_name, layers): """ Returns the chain of all parent images of the image with parsed_data.layers `layers` which contain the package `srpm_name` @@ -938,8 +862,7 @@ class LightBlue(object): srpm_name=srpm_name) children = images if images else [child_image] if image: - image.resolve(self, children, published, - deprecated, release_category) + image.resolve(self, children) if images: if image: @@ -964,9 +887,7 @@ class LightBlue(object): images[-1]['error'] = err if parent: - parent.resolve( - self, images, published, deprecated, - release_category) + parent.resolve(self, images) images[-1]['parent'] = parent if not image: return images @@ -1046,7 +967,7 @@ class LightBlue(object): for image in images: # We do not set "children" here in resolve_content_sets call, because # published images should have the content_set set. - image.resolve(self, None, published, deprecated, release_category) + image.resolve(self, None) # Images returned by this method are latest released images, so # mark them like that. image["latest_released"] = True @@ -1262,9 +1183,7 @@ class LightBlue(object): else: parent = self.get_image_by_layer(layers[1], len(layers) - 1) if parent: - parent.resolve( - self, [image], published, deprecated, - release_category) + parent.resolve(self, [image]) elif len(layers) != 2: image.log_error( "Cannot find parent image with layer %s and layer " diff --git a/tests/test_lightblue.py b/tests/test_lightblue.py index 91c450b..0fb1f93 100644 --- a/tests/test_lightblue.py +++ b/tests/test_lightblue.py @@ -488,6 +488,8 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): 'build': 'package-name-1-4-12.10', 'package': 'package-name-1' }, + "content_sets": ["dummy-content-set-1", + "dummy-content-set-2"], 'repositories': [ {'repository': 'product1/repo1', 'published': True, 'tags': [{"name": "latest"}]} @@ -520,6 +522,7 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): 'build': 'package-name-2-4-12.10', 'package': 'package-name-2' }, + "content_sets": ["dummy-content-set-1"], 'repositories': [ {'repository': 'product2/repo2', 'published': True, 'tags': [{"name": "latest"}]} @@ -886,8 +889,8 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): "build": "package-name-2-4-12.10", "package": "package-name-2" }, - 'content_sets': ['dummy-content-set-1', 'dummy-content-set-2'], - 'content_sets_source': 'lightblue_container_repository', + 'content_sets': ["dummy-content-set-1"], + 'content_sets_source': 'lightblue_container_image', 'repositories': [ {'repository': 'product2/repo2', 'published': True, 'tags': [{"name": "latest"}]} @@ -921,13 +924,12 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): }, ]) - @patch('freshmaker.lightblue.LightBlue.find_content_sets_for_repository') @patch('freshmaker.lightblue.LightBlue.find_container_images') @patch('os.path.exists') @patch('freshmaker.kojiservice.KojiService.get_build') @patch('freshmaker.kojiservice.KojiService.get_task_request') def test_parent_images_with_package(self, get_task_request, get_build, - exists, cont_images, cont_sets): + exists, cont_images): get_build.return_value = {"task_id": 123456} get_task_request.return_value = [ @@ -944,7 +946,6 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): cont_images.side_effect = [images_without_repositories, [], images_without_repositories] - cont_sets.return_value = set(["content-set"]) lb = LightBlue(server_url=self.fake_server_url, cert=self.fake_cert_file, @@ -955,7 +956,8 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): self.assertEqual(1, len(ret)) self.assertEqual(ret[0]["brew"]["package"], "package-name-1") - self.assertEqual(ret[0]["content_sets"], set(["content-set"])) + self.assertEqual(set(ret[0]["content_sets"]), + set(["dummy-content-set-1", "dummy-content-set-2"])) @patch('freshmaker.lightblue.LightBlue.find_container_images') @patch('os.path.exists') @@ -1001,13 +1003,12 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): self.assertEqual(0, len(ret)) - @patch('freshmaker.lightblue.LightBlue.find_content_sets_for_repository') @patch('freshmaker.lightblue.LightBlue.find_container_images') @patch('os.path.exists') @patch('freshmaker.kojiservice.KojiService.get_build') @patch('freshmaker.kojiservice.KojiService.get_task_request') def test_parent_images_with_package_last_parent_content_sets( - self, get_task_request, get_build, exists, cont_images, cont_sets): + self, get_task_request, get_build, exists, cont_images): get_build.return_value = {"task_id": 123456} get_task_request.return_value = [ @@ -1026,7 +1027,6 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): images_without_repositories, images_without_repositories, [], images_without_repositories] - cont_sets.return_value = set(["content-set"]) lb = LightBlue(server_url=self.fake_server_url, cert=self.fake_cert_file, @@ -1037,9 +1037,12 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): self.assertEqual(3, len(ret)) self.assertEqual(ret[0]["brew"]["package"], "package-name-1") - self.assertEqual(ret[0]["content_sets"], set(["content-set"])) - self.assertEqual(ret[1]["content_sets"], set(["content-set"])) - self.assertEqual(ret[2]["content_sets"], set(["content-set"])) + self.assertEqual(set(ret[0]["content_sets"]), + set(['dummy-content-set-1', 'dummy-content-set-2'])) + self.assertEqual(set(ret[1]["content_sets"]), + set(['dummy-content-set-1', 'dummy-content-set-2'])) + self.assertEqual(set(ret[2]["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_parent_images_with_package')