From d87bd44d0211a633efd545dc7b2027a613897b85 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Thu, 5 Dec 2013 23:43:32 +0900 Subject: [PATCH] Fix changes-since filter for list-servers API On list-servers API, "changes-since" parameter filters out servers which have been created at the same date as the specified timestamp. For example, the following server is filtered out with "changes-since= 2013-12-05T15:03:25": mysql> select display_name, updated_at from instances; +--------------+---------------------+ | display_name | updated_at | +--------------+---------------------+ | vm01 | 2013-12-05 15:03:25 | +--------------+---------------------+ This bug causes some Tempest test failures, if the timestamp of server creations are the same as the "changes-since" timestamp in second unit. In addition, the behavior would be wrong from the viewpoint of its name which includes "since". This patch chanegs the server list for including the ones created at the specified timestamp. Change-Id: Icc10a1363503b3553d810c6be20b86b3da7ac1a0 Closes-Bug: #1236585 --- nova/db/sqlalchemy/api.py | 2 +- nova/tests/db/test_db_api.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 0c31b3ada07a..f0c14e1d7d60 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -1875,7 +1875,7 @@ def instance_get_all_by_filters(context, filters, sort_key, sort_dir, if 'changes-since' in filters: changes_since = timeutils.normalize_time(filters['changes-since']) query_prefix = query_prefix.\ - filter(models.Instance.updated_at > changes_since) + filter(models.Instance.updated_at >= changes_since) if 'deleted' in filters: # Instances can be soft or hard deleted and the query needs to diff --git a/nova/tests/db/test_db_api.py b/nova/tests/db/test_db_api.py index 50bfd6ebb283..0dbf9dd30ee7 100644 --- a/nova/tests/db/test_db_api.py +++ b/nova/tests/db/test_db_api.py @@ -1518,6 +1518,23 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): {'display_name': 't.*st.'}) self._assertEqualListsOfInstances(result, [i1, i2]) + def test_instance_get_all_by_filters_changes_since(self): + i1 = self.create_instance_with_args(updated_at= + '2013-12-05T15:03:25.000000') + i2 = self.create_instance_with_args(updated_at= + '2013-12-05T15:03:26.000000') + changes_since = iso8601.parse_date('2013-12-05T15:03:25.000000') + result = db.instance_get_all_by_filters(self.ctxt, + {'changes-since': + changes_since}) + self._assertEqualListsOfInstances([i1, i2], result) + + changes_since = iso8601.parse_date('2013-12-05T15:03:26.000000') + result = db.instance_get_all_by_filters(self.ctxt, + {'changes-since': + changes_since}) + self._assertEqualListsOfInstances([i2], result) + def test_instance_get_all_by_filters_exact_match(self): instance = self.create_instance_with_args(host='host1') self.create_instance_with_args(host='host12')