Merge "Fixed incorrect name of 'tag' and 'tag-any' filters"
This commit is contained in:
commit
fca290549e
|
@ -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
|
based on instance tags (not metadata tags). There are two types
|
||||||
of these tags:
|
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.
|
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.
|
an OR expression.
|
||||||
|
|
||||||
Tags should be represented as list::
|
Tags should be represented as list::
|
||||||
|
|
||||||
| filters = {
|
| filters = {
|
||||||
| 'tag': [some-tag, some-another-tag],
|
| 'tags': [some-tag, some-another-tag],
|
||||||
| 'tag-any: [some-any-tag, some-another-any-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:
|
else:
|
||||||
query_prefix = query_prefix.filter(models.Instance.cleaned == 0)
|
query_prefix = query_prefix.filter(models.Instance.cleaned == 0)
|
||||||
|
|
||||||
if 'tag' in filters:
|
if 'tags' in filters:
|
||||||
tags = filters.pop('tag')
|
tags = filters.pop('tags')
|
||||||
# We build a JOIN ladder expression for each tag, JOIN'ing
|
# We build a JOIN ladder expression for each tag, JOIN'ing
|
||||||
# the first tag to the instances table, and each subsequent
|
# the first tag to the instances table, and each subsequent
|
||||||
# tag to the last JOIN'd tags table
|
# 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)
|
models.Instance.tags)
|
||||||
query_prefix = query_prefix.filter(tag_alias.tag == tag)
|
query_prefix = query_prefix.filter(tag_alias.tag == tag)
|
||||||
|
|
||||||
if 'tag-any' in filters:
|
if 'tags-any' in filters:
|
||||||
tags = filters.pop('tag-any')
|
tags = filters.pop('tags-any')
|
||||||
tag_alias = aliased(models.Tag)
|
tag_alias = aliased(models.Tag)
|
||||||
query_prefix = query_prefix.join(tag_alias, models.Instance.tags)
|
query_prefix = query_prefix.join(tag_alias, models.Instance.tags)
|
||||||
query_prefix = query_prefix.filter(tag_alias.tag.in_(tags))
|
query_prefix = query_prefix.filter(tag_alias.tag.in_(tags))
|
||||||
|
|
|
@ -2432,7 +2432,7 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||||
db.instance_tag_set(self.ctxt, inst3.uuid, [t3])
|
db.instance_tag_set(self.ctxt, inst3.uuid, [t3])
|
||||||
|
|
||||||
result = db.instance_get_all_by_filters(self.ctxt,
|
result = db.instance_get_all_by_filters(self.ctxt,
|
||||||
{'tag-any': [t1, t2]})
|
{'tags-any': [t1, t2]})
|
||||||
self._assertEqualListsOfObjects([inst1, inst2], result,
|
self._assertEqualListsOfObjects([inst1, inst2], result,
|
||||||
ignored_keys=['deleted', 'deleted_at', 'metadata', 'extra',
|
ignored_keys=['deleted', 'deleted_at', 'metadata', 'extra',
|
||||||
'system_metadata', 'info_cache', 'pci_devices'])
|
'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])
|
db.instance_tag_set(self.ctxt, inst2.uuid, [t1, t2])
|
||||||
|
|
||||||
result = db.instance_get_all_by_filters(self.ctxt,
|
result = db.instance_get_all_by_filters(self.ctxt,
|
||||||
{'tag-any': [t3, t4]})
|
{'tags-any': [t3, t4]})
|
||||||
self.assertEqual([], result)
|
self.assertEqual([], result)
|
||||||
|
|
||||||
def test_instance_get_all_by_filters_tag(self):
|
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])
|
db.instance_tag_set(self.ctxt, inst3.uuid, [t1, t2, t3])
|
||||||
|
|
||||||
result = db.instance_get_all_by_filters(self.ctxt,
|
result = db.instance_get_all_by_filters(self.ctxt,
|
||||||
{'tag': [t1, t2]})
|
{'tags': [t1, t2]})
|
||||||
self._assertEqualListsOfObjects([inst2, inst3], result,
|
self._assertEqualListsOfObjects([inst2, inst3], result,
|
||||||
ignored_keys=['deleted', 'deleted_at', 'metadata', 'extra',
|
ignored_keys=['deleted', 'deleted_at', 'metadata', 'extra',
|
||||||
'system_metadata', 'info_cache', 'pci_devices'])
|
'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])
|
db.instance_tag_set(self.ctxt, inst2.uuid, [t1, t2])
|
||||||
|
|
||||||
result = db.instance_get_all_by_filters(self.ctxt,
|
result = db.instance_get_all_by_filters(self.ctxt,
|
||||||
{'tag': [t3]})
|
{'tags': [t3]})
|
||||||
self.assertEqual([], result)
|
self.assertEqual([], result)
|
||||||
|
|
||||||
def test_instance_get_all_by_filters_tag_any_and_tag(self):
|
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])
|
db.instance_tag_set(self.ctxt, inst3.uuid, [t2, t3])
|
||||||
|
|
||||||
result = db.instance_get_all_by_filters(self.ctxt,
|
result = db.instance_get_all_by_filters(self.ctxt,
|
||||||
{'tag': [t1, t2],
|
{'tags': [t1, t2],
|
||||||
'tag-any': [t3, t4]})
|
'tags-any': [t3, t4]})
|
||||||
self._assertEqualListsOfObjects([inst2], result,
|
self._assertEqualListsOfObjects([inst2], result,
|
||||||
ignored_keys=['deleted', 'deleted_at', 'metadata', 'extra',
|
ignored_keys=['deleted', 'deleted_at', 'metadata', 'extra',
|
||||||
'system_metadata', 'info_cache', 'pci_devices'])
|
'system_metadata', 'info_cache', 'pci_devices'])
|
||||||
|
|
Loading…
Reference in New Issue