Fixes the use of dates when listing images
When listing images there are several optional parameters that can be used to filter the list of images retrieved by the API. The following two parameters are not working properly: the created_at and the updated_at. Before the Mitaka release it was possible to use these filters just using a datetime in the format ISO 8601, starting on Mitaka, you need to add an operator along with the datetime stamp or the API call fails. This commit adds backwards compatibility so it is possible to filter the images list using only a datetime stamp without also specifing an operator. If no operator is used an eq operator is assumed. Change-Id: Id5d5455e77637e0dc7baec25c8163b21634d72c4 Partial-Bug: 1584415
This commit is contained in:
parent
e72e12b8c4
commit
bb89dd91fa
|
@ -44,6 +44,7 @@ import six
|
|||
from webob import exc
|
||||
|
||||
from glance.common import exception
|
||||
from glance.common import timeutils
|
||||
from glance.i18n import _, _LE, _LW
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
@ -603,8 +604,17 @@ def split_filter_op(expression):
|
|||
"""
|
||||
left, sep, right = expression.partition(':')
|
||||
if sep:
|
||||
op = left
|
||||
threshold = right
|
||||
# If the expression is a date of the format ISO 8601 like
|
||||
# CCYY-MM-DDThh:mm:ss+hh:mm and has no operator, it should
|
||||
# not be partitioned, and a default operator of eq should be
|
||||
# assumed.
|
||||
try:
|
||||
timeutils.parse_isotime(expression)
|
||||
op = 'eq'
|
||||
threshold = expression
|
||||
except ValueError:
|
||||
op = left
|
||||
threshold = right
|
||||
else:
|
||||
op = 'eq' # default operator
|
||||
threshold = left
|
||||
|
|
|
@ -450,6 +450,16 @@ class SplitFilterOpTestCase(test_utils.BaseTestCase):
|
|||
returned = utils.split_filter_op(expr)
|
||||
self.assertEqual(('eq', expr), returned)
|
||||
|
||||
def test_default_operator_with_datetime(self):
|
||||
expr = '2015-08-27T09:49:58Z'
|
||||
returned = utils.split_filter_op(expr)
|
||||
self.assertEqual(('eq', expr), returned)
|
||||
|
||||
def test_operator_with_datetime(self):
|
||||
expr = 'lt:2015-08-27T09:49:58Z'
|
||||
returned = utils.split_filter_op(expr)
|
||||
self.assertEqual(('lt', '2015-08-27T09:49:58Z'), returned)
|
||||
|
||||
|
||||
class EvaluateFilterOpTestCase(test_utils.BaseTestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue