From bcdab01b5e76a66779c78e637d154bfa59ab528b Mon Sep 17 00:00:00 2001
From: Ralph Bean <rbean@redhat.com>
Date: Apr 18 2019 14:28:24 +0000
Subject: [PATCH 1/2] Rebuild also for tech preview and beta images  [FACTORY-3508]


---

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 9de2e69..bb20443 100644
--- a/freshmaker/handlers/koji/rebuild_images_on_rpm_advisory_change.py
+++ b/freshmaker/handlers/koji/rebuild_images_on_rpm_advisory_change.py
@@ -370,13 +370,13 @@ class RebuildImagesOnRPMAdvisoryChange(ContainerBuildHandler):
                        private_key=conf.lightblue_private_key)
 
         # Check if we are allowed to rebuild unpublished images and clear
-        # published and release_category if so.
+        # published and release_categories if so.
         if self.event.is_allowed(self, published=True):
             published = True
-            release_category = "Generally Available"
+            release_categories = ("Generally Available", "Tech Preview",)
         else:
             published = None
-            release_category = None
+            release_categories = None
 
         # Limit the Lightblue query to particular leaf images if set in Event.
         leaf_container_images = None
@@ -392,6 +392,6 @@ class RebuildImagesOnRPMAdvisoryChange(ContainerBuildHandler):
         batches = lb.find_images_to_rebuild(
             srpm_nvrs, content_sets,
             filter_fnc=self._filter_out_not_allowed_builds,
-            published=published, release_category=release_category,
+            published=published, release_categories=release_categories,
             leaf_container_images=leaf_container_images)
         return batches
diff --git a/freshmaker/lightblue.py b/freshmaker/lightblue.py
index 7988a46..e5a2eae 100644
--- a/freshmaker/lightblue.py
+++ b/freshmaker/lightblue.py
@@ -675,14 +675,14 @@ class LightBlue(object):
 
     def _set_container_repository_filters(
             self, request, published=True,
-            release_category="Generally Available"):
+            release_categories=("Generally Available", "Tech Preview",)):
         """
         Sets the additional filters to containerRepository request
-        based on the self.published, self.release_category attributes.
+        based on the self.published, self.release_categories attributes.
         :param bool published: whether to limit queries to published
             repositories
-        :param str release_category: filter only repositories with specific
-            release category (options: Deprecated, Generally Available, Beta, Tech Preview)
+        :param tuple release_categories: filter only repositories with specific
+            release categories (options: Deprecated, Generally Available, Beta, Tech Preview)
         """
         if published is not None:
             request["query"]["$and"].append({
@@ -691,25 +691,26 @@ class LightBlue(object):
                 "rvalue": published
             })
 
-        if release_category:
+        if release_categories:  # Check if release_categories is None or empty
             request["query"]["$and"].append({
                 "field": "release_categories.*",
-                "op": "=",
-                "rvalue": release_category
+                "op": "$in",
+                "rvalue": release_categories,
             })
 
         return request
 
     def find_all_container_repositories(
-            self, published=True, release_category="Generally Available"):
+            self, published=True,
+            release_categories=("Generally Available", "Tech Preview",)):
         """
         Returns dict with repository name as key and ContainerRepository as
         value.
 
         :param bool published: whether to limit queries to published
             repositories
-        :param str release_category: filter only repositories with specific
-            release category (options: Deprecated, Generally Available, Beta,
+        :param tuple release_categories: filter only repositories with specific
+            release categories (options: Deprecated, Generally Available, Beta,
             Tech Preview)
         :rtype: dict
         :return: Dict with repository name as key and ContainerRepository as
@@ -726,7 +727,7 @@ class LightBlue(object):
             ]
         }
         repo_request = self._set_container_repository_filters(
-            repo_request, published, release_category)
+            repo_request, published, release_categories)
         repositories = self.find_container_repositories(repo_request)
         return {r["repository"]: r for r in repositories}
 
@@ -1201,8 +1202,8 @@ class LightBlue(object):
             images.append(image)
 
     def find_images_with_packages_from_content_set(
-            self, srpm_nvrs, content_sets, filter_fnc=None,
-            published=True, release_category="Generally Available",
+            self, srpm_nvrs, content_sets, filter_fnc=None, published=True,
+            release_categories=("Generally Available", "Tech Preview",),
             leaf_container_images=None):
         """Query lightblue and find containers which contain given
         package from one of content sets
@@ -1218,8 +1219,8 @@ class LightBlue(object):
             Freshmaker configuration.
         :param bool published: whether to limit queries to published
             repositories
-        :param str release_category: filter only repositories with specific
-            release category (options: Deprecated, Generally Available, Beta, Tech Preview)
+        :param str release_categories: filter only repositories with specific
+            release categories (options: Deprecated, Generally Available, Beta, Tech Preview)
         :param list leaf_container_images: List of NVRs of leaf images to
             consider for the rebuild. If not set, all images found in
             Lightblue will be considered for rebuild.
@@ -1231,7 +1232,7 @@ class LightBlue(object):
             the given image - can be used for comparisons if needed
         :rtype: list
         """
-        repos = self.find_all_container_repositories(published, release_category)
+        repos = self.find_all_container_repositories(published, release_categories)
         if not repos:
             return []
         if not leaf_container_images:
@@ -1491,8 +1492,8 @@ class LightBlue(object):
 
     def find_images_to_rebuild(
             self, srpm_nvrs, content_sets, published=True,
-            release_category="Generally Available", filter_fnc=None,
-            leaf_container_images=None):
+            release_categories=("Generally Available", "Tech Preview",),
+            filter_fnc=None, leaf_container_images=None):
         """
         Find images to rebuild through image build layers
 
@@ -1507,8 +1508,8 @@ class LightBlue(object):
             when looking for the packages
         :param bool published: whether to limit queries to published
             repositories
-        :param str release_category: filter only repositories with specific
-            release category (options: Deprecated, Generally Available, Beta, Tech Preview)
+        :param tuple release_categories: filter only repositories with specific
+            release categories (options: Deprecated, Generally Available, Beta, Tech Preview)
         :param function filter_fnc: Function called as
             filter_fnc(container_image) with container_image being
             ContainerImage instance. If this function returns True, the image
@@ -1522,7 +1523,7 @@ class LightBlue(object):
         """
         images = self.find_images_with_packages_from_content_set(
             srpm_nvrs, content_sets, filter_fnc, published,
-            release_category, leaf_container_images=leaf_container_images)
+            release_categories, leaf_container_images=leaf_container_images)
 
         srpm_names = [koji.parse_NVR(srpm_nvr)["name"] for srpm_nvr in srpm_nvrs]
 
diff --git a/tests/handlers/koji/test_rebuild_images_on_rpm_advisory_change.py b/tests/handlers/koji/test_rebuild_images_on_rpm_advisory_change.py
index c090acc..c5779a1 100644
--- a/tests/handlers/koji/test_rebuild_images_on_rpm_advisory_change.py
+++ b/tests/handlers/koji/test_rebuild_images_on_rpm_advisory_change.py
@@ -439,7 +439,7 @@ class TestFindImagesToRebuild(helpers.FreshmakerTestCase):
         self.find_images_to_rebuild.assert_called_once_with(
             set(['httpd-2.4-11.el7']), ['content-set-1'],
             filter_fnc=self.handler._filter_out_not_allowed_builds,
-            published=True, release_category='Generally Available',
+            published=True, release_categories=('Generally Available', 'Tech Preview'),
             leaf_container_images=None)
 
     @patch.object(freshmaker.conf, 'handler_build_whitelist', new={
@@ -456,7 +456,7 @@ class TestFindImagesToRebuild(helpers.FreshmakerTestCase):
         self.find_images_to_rebuild.assert_called_once_with(
             set(['httpd-2.4-11.el7', 'httpd-2.2-11.el6']), ['content-set-1'],
             filter_fnc=self.handler._filter_out_not_allowed_builds,
-            published=True, release_category='Generally Available',
+            published=True, release_categories=('Generally Available', 'Tech Preview'),
             leaf_container_images=None)
 
     @patch.object(freshmaker.conf, 'handler_build_whitelist', new={
@@ -475,7 +475,7 @@ class TestFindImagesToRebuild(helpers.FreshmakerTestCase):
         self.find_images_to_rebuild.assert_called_once_with(
             set(['httpd-2.4-11.el7']), ['content-set-1'],
             filter_fnc=self.handler._filter_out_not_allowed_builds,
-            published=None, release_category=None,
+            published=None, release_categories=None,
             leaf_container_images=None)
 
     @patch.object(freshmaker.conf, 'handler_build_whitelist', new={
@@ -492,7 +492,7 @@ class TestFindImagesToRebuild(helpers.FreshmakerTestCase):
         self.find_images_to_rebuild.assert_called_once_with(
             set(['httpd-2.4-11.el7']), ['content-set-1'],
             filter_fnc=self.handler._filter_out_not_allowed_builds,
-            published=True, release_category='Generally Available',
+            published=True, release_categories=('Generally Available', 'Tech Preview'),
             leaf_container_images=None)
 
     @patch.object(freshmaker.conf, 'handler_build_whitelist', new={
@@ -510,5 +510,5 @@ class TestFindImagesToRebuild(helpers.FreshmakerTestCase):
         self.find_images_to_rebuild.assert_called_once_with(
             set(['httpd-2.4-11.el7']), ['content-set-1'],
             filter_fnc=self.handler._filter_out_not_allowed_builds,
-            published=True, release_category='Generally Available',
+            published=True, release_categories=('Generally Available', 'Tech Preview'),
             leaf_container_images=["foo", "bar"])
diff --git a/tests/test_lightblue.py b/tests/test_lightblue.py
index 8247e15..c39847b 100644
--- a/tests/test_lightblue.py
+++ b/tests/test_lightblue.py
@@ -924,9 +924,9 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase):
                     },
                     {
                         "field": "release_categories.*",
-                        "op": "=",
-                        "rvalue": "Generally Available"
-                    }
+                        "op": "$in",
+                        "rvalue": ("Generally Available", "Tech Preview"),
+                    },
                 ]
             },
             "projection": [

From 0f622981cc128fd96fdef93bd6ed9ebcfa5dbbd2 Mon Sep 17 00:00:00 2001
From: Ralph Bean <rbean@redhat.com>
Date: Apr 18 2019 14:39:07 +0000
Subject: [PATCH 2/2] Also, Beta.


---

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 bb20443..c92b6e4 100644
--- a/freshmaker/handlers/koji/rebuild_images_on_rpm_advisory_change.py
+++ b/freshmaker/handlers/koji/rebuild_images_on_rpm_advisory_change.py
@@ -373,7 +373,7 @@ class RebuildImagesOnRPMAdvisoryChange(ContainerBuildHandler):
         # published and release_categories if so.
         if self.event.is_allowed(self, published=True):
             published = True
-            release_categories = ("Generally Available", "Tech Preview",)
+            release_categories = ("Generally Available", "Tech Preview", "Beta",)
         else:
             published = None
             release_categories = None
diff --git a/freshmaker/lightblue.py b/freshmaker/lightblue.py
index e5a2eae..6efc3e9 100644
--- a/freshmaker/lightblue.py
+++ b/freshmaker/lightblue.py
@@ -675,7 +675,7 @@ class LightBlue(object):
 
     def _set_container_repository_filters(
             self, request, published=True,
-            release_categories=("Generally Available", "Tech Preview",)):
+            release_categories=("Generally Available", "Tech Preview", "Beta",)):
         """
         Sets the additional filters to containerRepository request
         based on the self.published, self.release_categories attributes.
@@ -702,7 +702,7 @@ class LightBlue(object):
 
     def find_all_container_repositories(
             self, published=True,
-            release_categories=("Generally Available", "Tech Preview",)):
+            release_categories=("Generally Available", "Tech Preview", "Beta",)):
         """
         Returns dict with repository name as key and ContainerRepository as
         value.
@@ -1203,7 +1203,7 @@ class LightBlue(object):
 
     def find_images_with_packages_from_content_set(
             self, srpm_nvrs, content_sets, filter_fnc=None, published=True,
-            release_categories=("Generally Available", "Tech Preview",),
+            release_categories=("Generally Available", "Tech Preview", "Beta",),
             leaf_container_images=None):
         """Query lightblue and find containers which contain given
         package from one of content sets
@@ -1492,7 +1492,7 @@ class LightBlue(object):
 
     def find_images_to_rebuild(
             self, srpm_nvrs, content_sets, published=True,
-            release_categories=("Generally Available", "Tech Preview",),
+            release_categories=("Generally Available", "Tech Preview", "Beta",),
             filter_fnc=None, leaf_container_images=None):
         """
         Find images to rebuild through image build layers
diff --git a/tests/handlers/koji/test_rebuild_images_on_rpm_advisory_change.py b/tests/handlers/koji/test_rebuild_images_on_rpm_advisory_change.py
index c5779a1..6efefa2 100644
--- a/tests/handlers/koji/test_rebuild_images_on_rpm_advisory_change.py
+++ b/tests/handlers/koji/test_rebuild_images_on_rpm_advisory_change.py
@@ -439,7 +439,7 @@ class TestFindImagesToRebuild(helpers.FreshmakerTestCase):
         self.find_images_to_rebuild.assert_called_once_with(
             set(['httpd-2.4-11.el7']), ['content-set-1'],
             filter_fnc=self.handler._filter_out_not_allowed_builds,
-            published=True, release_categories=('Generally Available', 'Tech Preview'),
+            published=True, release_categories=('Generally Available', 'Tech Preview', 'Beta'),
             leaf_container_images=None)
 
     @patch.object(freshmaker.conf, 'handler_build_whitelist', new={
@@ -456,7 +456,7 @@ class TestFindImagesToRebuild(helpers.FreshmakerTestCase):
         self.find_images_to_rebuild.assert_called_once_with(
             set(['httpd-2.4-11.el7', 'httpd-2.2-11.el6']), ['content-set-1'],
             filter_fnc=self.handler._filter_out_not_allowed_builds,
-            published=True, release_categories=('Generally Available', 'Tech Preview'),
+            published=True, release_categories=('Generally Available', 'Tech Preview', 'Beta'),
             leaf_container_images=None)
 
     @patch.object(freshmaker.conf, 'handler_build_whitelist', new={
@@ -492,7 +492,7 @@ class TestFindImagesToRebuild(helpers.FreshmakerTestCase):
         self.find_images_to_rebuild.assert_called_once_with(
             set(['httpd-2.4-11.el7']), ['content-set-1'],
             filter_fnc=self.handler._filter_out_not_allowed_builds,
-            published=True, release_categories=('Generally Available', 'Tech Preview'),
+            published=True, release_categories=('Generally Available', 'Tech Preview', 'Beta'),
             leaf_container_images=None)
 
     @patch.object(freshmaker.conf, 'handler_build_whitelist', new={
@@ -510,5 +510,5 @@ class TestFindImagesToRebuild(helpers.FreshmakerTestCase):
         self.find_images_to_rebuild.assert_called_once_with(
             set(['httpd-2.4-11.el7']), ['content-set-1'],
             filter_fnc=self.handler._filter_out_not_allowed_builds,
-            published=True, release_categories=('Generally Available', 'Tech Preview'),
+            published=True, release_categories=('Generally Available', 'Tech Preview', 'Beta'),
             leaf_container_images=["foo", "bar"])
diff --git a/tests/test_lightblue.py b/tests/test_lightblue.py
index c39847b..8379207 100644
--- a/tests/test_lightblue.py
+++ b/tests/test_lightblue.py
@@ -925,7 +925,7 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase):
                     {
                         "field": "release_categories.*",
                         "op": "$in",
-                        "rvalue": ("Generally Available", "Tech Preview"),
+                        "rvalue": ("Generally Available", "Tech Preview", "Beta"),
                     },
                 ]
             },

