Skip to content

Commit 78e8b75

Browse files
committed
Fix image/tasks API for in-progress tasks
A slight error in the tasks_get_by_image() DB API method resulted in our excluding in-progress tasks from the returned list. This is because those tasks have expires_at=NULL, and we were comparing the expires_at>=$NOW to find unexpired tasks. This makes us check for "NULL or not expired" instead. We did have a test asserting the wrong behavior, but it was done to increase coverage and thus was asserting the behavior of the code and not the *desired* behavior. This fixes that as well. Closes-Bug: #1922928 Change-Id: I1b6971888673b64ef60bed8fbcc97bbcbcf5c2ac (cherry picked from commit 2a0d230)
1 parent b543777 commit 78e8b75

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

glance/db/sqlalchemy/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,8 @@ def tasks_get_by_image(context, image_id, session=None):
16721672
).filter_by(image_id=image_id)
16731673

16741674
expires_at = models.Task.expires_at
1675-
query = query.filter(expires_at >= timeutils.utcnow())
1675+
query = query.filter(sa_sql.or_(expires_at == None,
1676+
expires_at >= timeutils.utcnow()))
16761677
updated_at = models.Task.updated_at
16771678
query.filter(
16781679
updated_at <= (timeutils.utcnow() +

glance/tests/functional/db/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,13 +1774,13 @@ def test_task_get_by_image_expired(self):
17741774
self.assertTrue(tasks[0]['deleted'])
17751775

17761776
def test_task_get_by_image_no_expiry(self):
1777-
# Make sure we do not retrieve the expired task
1777+
# Make sure we find the task that has expires_at=NULL
17781778
task_id, tasks = self._test_task_get_by_image(expired=None)
1779-
self.assertEqual(0, len(tasks))
1779+
self.assertEqual(1, len(tasks))
17801780

1781-
# The task should not have been retrieved at all above,
1782-
# but it's also not deleted because it doesn't have an expiry,
1783-
# so it should still be in the DB.
1781+
# The task should have been retrieved above, and it's also not
1782+
# deleted because it doesn't have an expiry, so it should
1783+
# still be in the DB.
17841784
tasks = self.db_api.task_get_all(self.adm_context)
17851785
self.assertEqual(1, len(tasks))
17861786
self.assertEqual(task_id, tasks[0]['id'])

0 commit comments

Comments
 (0)