Merge "Ensure anti affinity scheduling works"
This commit is contained in:
@@ -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:
|
||||
@@ -1808,7 +1808,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
|
||||
@@ -1896,7 +1896,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,
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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 "
|
||||
|
||||
@@ -1470,6 +1470,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,
|
||||
|
||||
Reference in New Issue
Block a user