Ensure anti affinity scheduling works

The query for the group in the system_metadata would not correctly
filter the instances with the groups.

In addition to this change 4a03071db2
ensured that the scheduling filter was only run once.
In cases when provisioning fails and rescheduling
takes place the filter must be invoked (if it is in the filter tool
chain).

Fixes bug: 1218878
Fixes bug: 1206502

Change-Id: I623c73635c36ffa038ae01476a25ba0c0863e536
This commit is contained in:
Gary Kotton
2013-09-08 04:29:24 -07:00
parent db6721b5f8
commit 4233e16ba2
4 changed files with 13 additions and 8 deletions

View File

@@ -252,7 +252,7 @@ def exact_filter(query, model, filters, legal_keys):
# OK, filtering on this key; what value do we search for?
value = filters.pop(key)
if key == 'metadata':
if key == 'metadata' or key == 'system_metadata':
column_attr = getattr(model, key)
if isinstance(value, list):
for item in value:
@@ -1804,7 +1804,7 @@ def instance_get_all_by_filters(context, filters, sort_key, sort_dir,
['project_id', 'user_id', 'image_ref',
'vm_state', 'instance_type_id', 'uuid',
'metadata', 'host']
'metadata', 'host', 'system_metadata']
A third type of filter (also using exact matching), filters
@@ -1892,7 +1892,8 @@ def instance_get_all_by_filters(context, filters, sort_key, sort_dir,
# For other filters that don't match this, we will do regexp matching
exact_match_filter_names = ['project_id', 'user_id', 'image_ref',
'vm_state', 'instance_type_id', 'uuid',
'metadata', 'host', 'task_state']
'metadata', 'host', 'task_state',
'system_metadata']
# Filter the query
query_prefix = exact_filter(query_prefix, models.Instance,

View File

@@ -121,7 +121,7 @@ class Scheduler(object):
# The system_metadata 'group' will be filtered
members = db.instance_get_all_by_filters(context,
{'deleted': False, 'group': group})
{'deleted': False, 'system_metadata': {'group': group}})
return [member['host']
for member in members
if member.get('host') is not None]

View File

@@ -103,10 +103,6 @@ class GroupAntiAffinityFilter(AffinityFilter):
hosts.
"""
# The hosts the instances in the group are running on doesn't change
# within a request
run_filter_once_per_request = True
def host_passes(self, host_state, filter_properties):
group_hosts = filter_properties.get('group_hosts') or []
LOG.debug(_("Group anti affinity: check if %(host)s not "

View File

@@ -1478,6 +1478,14 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin):
{'metadata': {'foo': 'bar'}})
self._assertEqualListsOfInstances([instance], result)
def test_instance_get_all_by_filters_system_metadata(self):
instance = self.create_instance_with_args(
system_metadata={'foo': 'bar'})
self.create_instance_with_args()
result = db.instance_get_all_by_filters(self.ctxt,
{'system_metadata': {'foo': 'bar'}})
self._assertEqualListsOfInstances([instance], result)
def test_instance_get_all_by_filters_unicode_value(self):
instance = self.create_instance_with_args(display_name=u'test♥')
result = db.instance_get_all_by_filters(self.ctxt,