Repository: fedora-infra/bodhi

Issue:
obsoleting updates not working right
I had: 

https://bodhi.fedoraproject.org/updates/calibre-2.35.0-1.fc23
https://bodhi.fedoraproject.org/updates/calibre-2.35.0-1.fc22

But rex was building a new qt5, so he rebuilt calibre against that and submitted: 

https://bodhi.fedoraproject.org/updates/calibre-2.35.0-1.fc22.1%20python-qt5-5.5-1.fc22%20PyQt4-4.11.4-1.fc22%20sip-4.16.9-1.fc22

but it didn't obsolete my ilder ones.

obsoleting updates not working right
I had: 

https://bodhi.fedoraproject.org/updates/calibre-2.35.0-1.fc23
https://bodhi.fedoraproject.org/updates/calibre-2.35.0-1.fc22

But rex was building a new qt5, so he rebuilt calibre against that and submitted: 

https://bodhi.fedoraproject.org/updates/calibre-2.35.0-1.fc22.1%20python-qt5-5.5-1.fc22%20PyQt4-4.11.4-1.fc22%20sip-4.16.9-1.fc22

but it didn't obsolete my ilder ones.



Discussion:
Likewise, https://bodhi.fedoraproject.org/updates/FEDORA-2015-13858 should have obsoleted https://bodhi.fedoraproject.org/updates/FEDORA-2015-13284 but didn't.

Likewise, https://bodhi.fedoraproject.org/updates/FEDORA-2015-13858 should have obsoleted https://bodhi.fedoraproject.org/updates/FEDORA-2015-13284 but didn't.


Resolving patch:
diff --git a/bodhi/models/models.py b/bodhi/models/models.py
--- a/bodhi/models/models.py
+++ b/bodhi/models/models.py
@@ -805,6 +805,7 @@ def obsolete_older_updates(self, request):
         """
         db = request.db
         buildinfo = request.buildinfo
+        caveats = []
         for build in self.builds:
             for oldBuild in db.query(Build).join(Update).filter(
                 and_(Build.nvr != build.nvr,
@@ -820,15 +821,6 @@ def obsolete_older_updates(self, request):
                     log.debug("%s is newer than %s" % (nvr, oldBuild.nvr))
                     obsoletable = True
 
-                # Ensure the same number of builds are present
-                if len(oldBuild.update.builds) != len(self.builds):
-                    obsoletable = False
-                    if oldBuild.update.user.name != self.user.name:
-                        request.session.flash('Please be aware that %s is'
-                                'part of a multi-build update that is currently '
-                                'in testing' % oldBuild.nvr)
-                    break
-
                 # Ensure that all of the packages in the old update are
                 # present in the new one.
                 pkgs = [b.package.name for b in self.builds]
@@ -837,6 +829,21 @@ def obsolete_older_updates(self, request):
                         obsoletable = False
                         break
 
+                # Warn if you're stomping on another user but don't necessarily
+                # obsolete them
+                if len(oldBuild.update.builds) != len(self.builds):
+                    if oldBuild.update.user.name != self.user.name:
+                        caveats.append({
+                            'name': 'update',
+                            'description': 'Please be aware that there '
+                            'is another update in flight owned by %s, '
+                            'containing %s.  Are you coordinating with '
+                            'them?' % (
+                                oldBuild.update.user.name,
+                                oldBuild.nvr,
+                            )
+                        })
+
                 if obsoletable:
                     log.info('%s is obsoletable' % oldBuild.nvr)
 
@@ -849,9 +856,12 @@ def obsolete_older_updates(self, request):
                     # add a markdown separator between the new and old ones.
                     self.notes += '\n\n----\n\n' + oldBuild.update.notes
                     oldBuild.update.obsolete(newer=build.nvr)
-                    self.comment('This update has obsoleted %s, and has '
-                                 'inherited its bugs and notes.' % oldBuild.nvr,
-                                 author='bodhi')
+                    text = ('This update has obsoleted %s, and has '
+                            'inherited its bugs and notes.') % oldBuild.nvr
+                    self.comment(text, author='bodhi')
+                    caveats.append({'name': 'update', 'description': text})
+
+        return caveats
 
     def get_tags(self):
         """ Return all koji tags for all builds on this update. """
diff --git a/bodhi/services/updates.py b/bodhi/services/updates.py
--- a/bodhi/services/updates.py
+++ b/bodhi/services/updates.py
@@ -382,7 +382,7 @@ def new_update(request):
 
     for update in updates:
         try:
-            update.obsolete_older_updates(request)
+            caveats.extend(update.obsolete_older_updates(request))
         except Exception as e:
             caveats.append({
                 'name': 'update',


Test patch:
diff --git a/bodhi/tests/functional/test_updates.py b/bodhi/tests/functional/test_updates.py
--- a/bodhi/tests/functional/test_updates.py
+++ b/bodhi/tests/functional/test_updates.py
@@ -1405,6 +1405,13 @@ def test_obsoletion(self, publish, *args):
         args = self.get_update('bodhi-2.0.0-3.fc17')
         r = self.app.post_json('/updates/', args).json_body
         self.assertEquals(r['request'], 'testing')
+
+        # Since we're obsoleting something owned by someone else.
+        self.assertEquals(r['caveats'][0]['description'],
+                          'This update has obsoleted bodhi-2.0.0-2.fc17, '
+                          'and has inherited its bugs and notes.')
+
+        # Check for the comment multiple ways
         self.assertEquals(r['comments'][-1]['text'],
                           u'This update has obsoleted bodhi-2.0.0-2.fc17, '
                           'and has inherited its bugs and notes.')
@@ -1639,9 +1646,14 @@ def test_update_with_older_build_in_testing_from_diff_user(self, r):
         args = self.get_update(newtitle)
         resp = self.app.post_json('/updates/', args)
 
-        # The TestResponse doesn't track the session, so we can't peek at the
-        # flash messages. So, let's just make sure the session cookie was set.
-        assert resp.headers.get('Set-Cookie', '').startswith('session='), '%s\n%s' % (resp.headers, resp)
+        # Note that this does **not** obsolete the other update
+        print resp.json_body['caveats']
+        self.assertEquals(len(resp.json_body['caveats']), 1)
+        self.assertEquals(resp.json_body['caveats'][0]['description'],
+                          "Please be aware that there is another update in "
+                          "flight owned by bob, containing "
+                          "bodhi-2.0-2.fc17.  Are you coordinating with "
+                          "them?")
 
         # Ensure the second update was created successfully
         session.query(Update).filter_by(title=newtitle).one()