From 1b5bc16d4cc68522344bc495f1087b3d95336f8d Mon Sep 17 00:00:00 2001 From: Sergey Nikitin Date: Fri, 16 Oct 2015 12:18:16 +0300 Subject: [PATCH] Fixed incorrect name of 'tag' and 'tag-any' filters According to spec http://specs.openstack.org/openstack/nova-specs/specs/mitaka/approved/tag-instances.html these filters should be named 'tags' and 'tags-any'. Closes-Bug: #1506786 Change-Id: If5fabe5c6afa3bf6cc8e5045250fefdce58e6930 --- nova/db/sqlalchemy/api.py | 16 ++++++++-------- nova/tests/unit/db/test_db_api.py | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index f5046c7f6dcc..9bde27287804 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -1922,17 +1922,17 @@ def instance_get_all_by_filters_sort(context, filters, limit=None, marker=None, based on instance tags (not metadata tags). There are two types of these tags: - `tag` -- One or more strings that will be used to filter results + `tags` -- One or more strings that will be used to filter results in an AND expression. - `tag-any` -- One or more strings that will be used to filter results in + `tags-any` -- One or more strings that will be used to filter results in an OR expression. Tags should be represented as list:: | filters = { - | 'tag': [some-tag, some-another-tag], - | 'tag-any: [some-any-tag, some-another-any-tag] + | 'tags': [some-tag, some-another-tag], + | 'tags-any: [some-any-tag, some-another-any-tag] | } """ @@ -2010,8 +2010,8 @@ def instance_get_all_by_filters_sort(context, filters, limit=None, marker=None, else: query_prefix = query_prefix.filter(models.Instance.cleaned == 0) - if 'tag' in filters: - tags = filters.pop('tag') + if 'tags' in filters: + tags = filters.pop('tags') # We build a JOIN ladder expression for each tag, JOIN'ing # the first tag to the instances table, and each subsequent # tag to the last JOIN'd tags table @@ -2025,8 +2025,8 @@ def instance_get_all_by_filters_sort(context, filters, limit=None, marker=None, models.Instance.tags) query_prefix = query_prefix.filter(tag_alias.tag == tag) - if 'tag-any' in filters: - tags = filters.pop('tag-any') + if 'tags-any' in filters: + tags = filters.pop('tags-any') tag_alias = aliased(models.Tag) query_prefix = query_prefix.join(tag_alias, models.Instance.tags) query_prefix = query_prefix.filter(tag_alias.tag.in_(tags)) diff --git a/nova/tests/unit/db/test_db_api.py b/nova/tests/unit/db/test_db_api.py index bd8db1e4fa2d..cef6334c269b 100644 --- a/nova/tests/unit/db/test_db_api.py +++ b/nova/tests/unit/db/test_db_api.py @@ -2432,7 +2432,7 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): db.instance_tag_set(self.ctxt, inst3.uuid, [t3]) result = db.instance_get_all_by_filters(self.ctxt, - {'tag-any': [t1, t2]}) + {'tags-any': [t1, t2]}) self._assertEqualListsOfObjects([inst1, inst2], result, ignored_keys=['deleted', 'deleted_at', 'metadata', 'extra', 'system_metadata', 'info_cache', 'pci_devices']) @@ -2450,7 +2450,7 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): db.instance_tag_set(self.ctxt, inst2.uuid, [t1, t2]) result = db.instance_get_all_by_filters(self.ctxt, - {'tag-any': [t3, t4]}) + {'tags-any': [t3, t4]}) self.assertEqual([], result) def test_instance_get_all_by_filters_tag(self): @@ -2467,7 +2467,7 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): db.instance_tag_set(self.ctxt, inst3.uuid, [t1, t2, t3]) result = db.instance_get_all_by_filters(self.ctxt, - {'tag': [t1, t2]}) + {'tags': [t1, t2]}) self._assertEqualListsOfObjects([inst2, inst3], result, ignored_keys=['deleted', 'deleted_at', 'metadata', 'extra', 'system_metadata', 'info_cache', 'pci_devices']) @@ -2484,7 +2484,7 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): db.instance_tag_set(self.ctxt, inst2.uuid, [t1, t2]) result = db.instance_get_all_by_filters(self.ctxt, - {'tag': [t3]}) + {'tags': [t3]}) self.assertEqual([], result) def test_instance_get_all_by_filters_tag_any_and_tag(self): @@ -2502,8 +2502,8 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): db.instance_tag_set(self.ctxt, inst3.uuid, [t2, t3]) result = db.instance_get_all_by_filters(self.ctxt, - {'tag': [t1, t2], - 'tag-any': [t3, t4]}) + {'tags': [t1, t2], + 'tags-any': [t3, t4]}) self._assertEqualListsOfObjects([inst2], result, ignored_keys=['deleted', 'deleted_at', 'metadata', 'extra', 'system_metadata', 'info_cache', 'pci_devices'])