Repository: fedora-infra/bodhi

Issue:
Inform since when the update is locked
Bodhi2 now shows lock messages:

> This update is currently locked and cannot be modified.

Please say since when the update is locked, so that it's easier to discover locking bugs (when we see it has been locked for 24 hours, we immediately know something is wrong).

E.g.

> This update has been locked since YYYY-MM-DD hh:mm:ss (UTC) and cannot be modified.

Thanks.



Discussion:

Resolving patch:
diff --git a/alembic/versions/3c72757fa59e_add_column_date_locked_to_update_table.py b/alembic/versions/3c72757fa59e_add_column_date_locked_to_update_table.py
new file mode 100644
--- /dev/null
+++ b/alembic/versions/3c72757fa59e_add_column_date_locked_to_update_table.py
@@ -0,0 +1,26 @@
+"""Add column date_locked to Update table
+
+Revision ID: 3c72757fa59e
+Revises: 3aae6532b560
+Create Date: 2016-05-15 11:33:14.849331
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '3c72757fa59e'
+down_revision = 'a1d8dae7cc'
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+    ### commands auto generated by Alembic - please adjust! ###
+    op.add_column('updates', sa.Column('date_locked', sa.DateTime(), nullable=True))
+    ### end Alembic commands ###
+
+
+def downgrade():
+    ### commands auto generated by Alembic - please adjust! ###
+    op.drop_column('updates', 'date_locked')
+    ### end Alembic commands ###
diff --git a/bodhi/consumers/masher.py b/bodhi/consumers/masher.py
--- a/bodhi/consumers/masher.py
+++ b/bodhi/consumers/masher.py
@@ -28,6 +28,7 @@
 import hashlib
 import threading
 import fedmsg.consumers
+from datetime import datetime
 
 from collections import defaultdict
 from pyramid.paster import get_appsettings
@@ -274,6 +275,9 @@ def results(self):
         #        src=src, dest=dest, nvr=nvr)
 
     def work(self):
+        # Update datetime for locking on update
+        self.locked_date_for_update()
+
         self.koji = buildsys.get_session()
         self.release = self.db.query(Release)\
                               .filter_by(name=self.release).one()
@@ -403,6 +407,21 @@ def unlock_updates(self):
             update.locked = False
         self.db.flush()
 
+    def locked_date_for_update(self):
+        """ Return the date & time when an update has been locked """
+        for update in self.updates:
+            # Return datetime when an update is locked and datetime is
+            # not yet assigned to the column date_locked
+            if update.locked and not update.date_locked:
+                update.date_locked = datetime.utcnow()
+                self.db.commit()
+                self.db.refresh(update)
+                return update.date_locked
+            # Reset the column date_locked to None when an update gets unlocked
+            elif not update.locked and update.date_locked:
+                update.date_locked = None
+                self.db.commit()
+
     def check_all_karma_thresholds(self):
         """
         If we just pushed testing updates see if any of them now meet either of
diff --git a/bodhi/models/models.py b/bodhi/models/models.py
--- a/bodhi/models/models.py
+++ b/bodhi/models/models.py
@@ -637,6 +637,7 @@ class Update(Base):
     date_pushed = Column(DateTime)
     date_testing = Column(DateTime)
     date_stable = Column(DateTime)
+    date_locked = Column(DateTime)
 
     # eg: FEDORA-EPEL-2009-12345
     alias = Column(Unicode(32), unique=True, nullable=True)


Test patch: