summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/scheduler/filters/json_filter.py5
-rw-r--r--nova/tests/scheduler/test_host_filters.py32
2 files changed, 20 insertions, 17 deletions
diff --git a/nova/scheduler/filters/json_filter.py b/nova/scheduler/filters/json_filter.py
index 19c80b019..c0aa49b89 100644
--- a/nova/scheduler/filters/json_filter.py
+++ b/nova/scheduler/filters/json_filter.py
@@ -128,7 +128,10 @@ class JsonFilter(filters.BaseHostFilter):
"""Return a list of hosts that can fulfill the requirements
specified in the query.
"""
- query = filter_properties.get('query', None)
+ try:
+ query = filter_properties['scheduler_hints']['query']
+ except KeyError:
+ query = None
if not query:
return True
diff --git a/nova/tests/scheduler/test_host_filters.py b/nova/tests/scheduler/test_host_filters.py
index f56a14565..1696809ea 100644
--- a/nova/tests/scheduler/test_host_filters.py
+++ b/nova/tests/scheduler/test_host_filters.py
@@ -306,7 +306,7 @@ class HostFiltersTestCase(test.TestCase):
filter_properties = {'instance_type': {'memory_mb': 1024,
'root_gb': 200,
'ephemeral_gb': 0},
- 'query': self.json_query}
+ 'scheduler_hints': {'query': self.json_query}}
capabilities = {'enabled': True}
host = fakes.FakeHostState('host1', 'compute',
{'free_ram_mb': 1024,
@@ -331,7 +331,7 @@ class HostFiltersTestCase(test.TestCase):
filter_properties = {'instance_type': {'memory_mb': 1024,
'root_gb': 200,
'ephemeral_gb': 0},
- 'query': self.json_query}
+ 'scheduler_hints': {'query': self.json_query}}
capabilities = {'enabled': True}
host = fakes.FakeHostState('host1', 'compute',
{'free_ram_mb': 1023,
@@ -344,7 +344,7 @@ class HostFiltersTestCase(test.TestCase):
filter_properties = {'instance_type': {'memory_mb': 1024,
'root_gb': 200,
'ephemeral_gb': 0},
- 'query': self.json_query}
+ 'scheduler_hints': {'query': self.json_query}}
capabilities = {'enabled': True}
host = fakes.FakeHostState('host1', 'compute',
{'free_ram_mb': 1024,
@@ -361,7 +361,7 @@ class HostFiltersTestCase(test.TestCase):
filter_properties = {'instance_type': {'memory_mb': 1024,
'root_gb': 200,
'ephemeral_gb': 0},
- 'query': json_query}
+ 'scheduler_hints': {'query': json_query}}
capabilities = {'enabled': False}
host = fakes.FakeHostState('host1', 'compute',
{'free_ram_mb': 1024,
@@ -377,7 +377,7 @@ class HostFiltersTestCase(test.TestCase):
['not', '$service.disabled']])
filter_properties = {'instance_type': {'memory_mb': 1024,
'local_gb': 200},
- 'query': json_query}
+ 'scheduler_hints': {'query': json_query}}
capabilities = {'enabled': True}
service = {'disabled': True}
host = fakes.FakeHostState('host1', 'compute',
@@ -399,7 +399,7 @@ class HostFiltersTestCase(test.TestCase):
['and',
['>', '$free_ram_mb', 30],
['>', '$free_disk_mb', 300]]]]
- filter_properties = {'query': json.dumps(raw)}
+ filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
# Passes
capabilities = {'enabled': True, 'opt1': 'match'}
@@ -496,26 +496,26 @@ class HostFiltersTestCase(test.TestCase):
for (op, args, expected) in ops_to_test:
raw = [op] + args
- filter_properties = {'query': json.dumps(raw)}
+ filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
self.assertEqual(expected,
filt_cls.host_passes(host, filter_properties))
# This results in [False, True, False, True] and if any are True
# then it passes...
raw = ['not', True, False, True, False]
- filter_properties = {'query': json.dumps(raw)}
+ filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
self.assertTrue(filt_cls.host_passes(host, filter_properties))
# This results in [False, False, False] and if any are True
# then it passes...which this doesn't
raw = ['not', True, True, True]
- filter_properties = {'query': json.dumps(raw)}
+ filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
self.assertFalse(filt_cls.host_passes(host, filter_properties))
def test_json_filter_unknown_operator_raises(self):
filt_cls = self.class_map['JsonFilter']()
raw = ['!=', 1, 2]
- filter_properties = {'query': json.dumps(raw)}
+ filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
host = fakes.FakeHostState('host1', 'compute',
{'capabilities': {'enabled': True}})
self.assertRaises(KeyError,
@@ -527,10 +527,10 @@ class HostFiltersTestCase(test.TestCase):
{'capabilities': {'enabled': True}})
raw = []
- filter_properties = {'query': json.dumps(raw)}
+ filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
self.assertTrue(filt_cls.host_passes(host, filter_properties))
raw = {}
- filter_properties = {'query': json.dumps(raw)}
+ filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
self.assertTrue(filt_cls.host_passes(host, filter_properties))
def test_json_filter_invalid_num_arguments_fails(self):
@@ -539,11 +539,11 @@ class HostFiltersTestCase(test.TestCase):
{'capabilities': {'enabled': True}})
raw = ['>', ['and', ['or', ['not', ['<', ['>=', ['<=', ['in', ]]]]]]]]
- filter_properties = {'query': json.dumps(raw)}
+ filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
self.assertFalse(filt_cls.host_passes(host, filter_properties))
raw = ['>', 1]
- filter_properties = {'query': json.dumps(raw)}
+ filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
self.assertFalse(filt_cls.host_passes(host, filter_properties))
def test_json_filter_unknown_variable_ignored(self):
@@ -552,11 +552,11 @@ class HostFiltersTestCase(test.TestCase):
{'capabilities': {'enabled': True}})
raw = ['=', '$........', 1, 1]
- filter_properties = {'query': json.dumps(raw)}
+ filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
self.assertTrue(filt_cls.host_passes(host, filter_properties))
raw = ['=', '$foo', 2, 2]
- filter_properties = {'query': json.dumps(raw)}
+ filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
self.assertTrue(filt_cls.host_passes(host, filter_properties))
def test_core_filter_passes(self):