Browse Source

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
changes/18/785218/2
Dan Smith 2 weeks ago
parent
commit
2a0d2303c3
2 changed files with 7 additions and 6 deletions
  1. +2
    -1
      glance/db/sqlalchemy/api.py
  2. +5
    -5
      glance/tests/functional/db/base.py

+ 2
- 1
glance/db/sqlalchemy/api.py View File

@ -1672,7 +1672,8 @@ def tasks_get_by_image(context, image_id, session=None):
).filter_by(image_id=image_id)
expires_at = models.Task.expires_at
query = query.filter(expires_at >= timeutils.utcnow())
query = query.filter(sa_sql.or_(expires_at == None,
expires_at >= timeutils.utcnow()))
updated_at = models.Task.updated_at
query.filter(
updated_at <= (timeutils.utcnow() +


+ 5
- 5
glance/tests/functional/db/base.py View File

@ -1774,13 +1774,13 @@ class TaskTests(test_utils.BaseTestCase):
self.assertTrue(tasks[0]['deleted'])
def test_task_get_by_image_no_expiry(self):
# Make sure we do not retrieve the expired task
# Make sure we find the task that has expires_at=NULL
task_id, tasks = self._test_task_get_by_image(expired=None)
self.assertEqual(0, len(tasks))
self.assertEqual(1, len(tasks))
# The task should not have been retrieved at all above,
# but it's also not deleted because it doesn't have an expiry,
# so it should still be in the DB.
# The task should have been retrieved above, and it's also not
# deleted because it doesn't have an expiry, so it should
# still be in the DB.
tasks = self.db_api.task_get_all(self.adm_context)
self.assertEqual(1, len(tasks))
self.assertEqual(task_id, tasks[0]['id'])


Loading…
Cancel
Save