Repository: fedora-infra/bodhi

Issue:
Bodhi should not allow retired releases to be composed
Today composes for F26 (currently EOL) were accidentally run, which failed and required manual clean up. Bodhi should not allow composing retired releases.


Discussion:

Resolving patch:
diff --git a/bodhi/server/push.py b/bodhi/server/push.py
--- a/bodhi/server/push.py
+++ b/bodhi/server/push.py
@@ -207,6 +207,10 @@ def _filter_releases(session, query, releases=None):
     # Filter only releases composed by Bodhi.
     releases_query = session.query(Release).filter(Release.composed_by_bodhi == True)
 
+    # Filter only releases that are current or pending.
+    releases_query = releases_query.filter(or_(Release.state == ReleaseState.current,
+                                               Release.state == ReleaseState.pending))
+
     if releases:
         for r in releases.split(','):
             release = releases_query.filter(
@@ -214,14 +218,15 @@ def _filter_releases(session, query, releases=None):
                     Release.name == r.upper(),
                     Release.version == r)).first()
             if not release:
-                raise click.BadParameter('Unknown release: %s' % r)
+                raise click.BadParameter(
+                    'Unknown release, or release not allowed to be composed: %s' % r
+                )
             else:
                 _releases.append(release)
     else:
         # Since the user didn't ask for specific Releases, let's just filter for releases that are
         # current or pending.
-        _releases = releases_query.filter(or_(Release.state == ReleaseState.current,
-                                              Release.state == ReleaseState.pending))
+        _releases = releases_query
 
     return query.filter(or_(*[Update.release == r for r in _releases]))
 


Test patch:
diff --git a/bodhi/tests/server/test_push.py b/bodhi/tests/server/test_push.py
--- a/bodhi/tests/server/test_push.py
+++ b/bodhi/tests/server/test_push.py
@@ -140,21 +140,34 @@ def test_one_release(self):
         """
         query = self.db.query(models.Update)
 
-        query = push._filter_releases(self.db, query, u'F22')
+        query = push._filter_releases(self.db, query, u'F17')
 
-        # Make sure only F22 made it in.
-        self.assertEqual([u.release.name for u in query], [u'F22'])
+        # Make sure only F17 made it in.
+        self.assertEqual([u.release.name for u in query], [u'F17'])
 
     def test_two_releases(self):
         """
         Test with two releases.
         """
-        query = self.db.query(models.Update)
+        # Create yet another release with 'current' state and update for it
+        current_release = self.create_release(u'18')
+        pkg = self.db.query(models.RpmPackage).filter_by(name=u'bodhi').one()
+        current_build = models.RpmBuild(nvr=u'bodhi-2.3.2-1.fc18', release=current_release,
+                                        package=pkg)
+        self.db.add(current_build)
+        current_release_update = models.Update(
+            title=u'bodhi-2.3.2-1.fc18', builds=[current_build], user=self.user,
+            request=models.UpdateRequest.stable, notes=u'Useful details!', release=current_release,
+            date_submitted=datetime(2016, 10, 28), requirements=u'', stable_karma=3,
+            unstable_karma=-3, type=models.UpdateType.bugfix)
+        self.db.add(current_release_update)
+        self.db.commit()
 
-        query = push._filter_releases(self.db, query, u'F22,F17')
+        query = self.db.query(models.Update)
+        query = push._filter_releases(self.db, query, u'F18,F17')
 
-        # Make sure F17 and F22 made it in.
-        self.assertEqual(set([u.release.name for u in query]), {u'F17', u'F22'})
+        # Make sure F17 and F18 made it in.
+        self.assertEqual(set([u.release.name for u in query]), {u'F17', u'F18'})
 
     def test_unknown_release(self):
         """
@@ -166,6 +179,18 @@ def test_unknown_release(self):
             push._filter_releases(self.db, query, u'RELEASE WITH NO NAME')
             self.assertEqual(str(ex.exception), 'Unknown release: RELEASE WITH NO NAME')
 
+    def test_archived_release(self):
+        """
+        Ensure that we inform the user when they pass archived release.
+        """
+        query = self.db.query(models.Update)
+
+        with self.assertRaises(click.BadParameter) as ex:
+            push._filter_releases(self.db, query, u'F22')
+        self.assertEqual(
+            str(ex.exception), 'Unknown release, or release not allowed to be composed: F22'
+        )
+
 
 TEST_ABORT_PUSH_EXPECTED_OUTPUT = """