summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/scheduler/query.py10
-rw-r--r--nova/tests/test_query.py26
2 files changed, 31 insertions, 5 deletions
diff --git a/nova/scheduler/query.py b/nova/scheduler/query.py
index 1b84e6b1d..3233cc0d8 100644
--- a/nova/scheduler/query.py
+++ b/nova/scheduler/query.py
@@ -19,6 +19,10 @@ Three plug-ins are included: AllHosts, Flavor & JSON. AllHosts just
returns the full, unfiltered list of hosts. Flavor is a hard coded
matching mechanism based on flavor criteria and JSON is an ad-hoc
query grammar.
+
+Note: These are hard filters. All capabilities used must be present
+or the host will excluded. If you want soft filters use the weighting
+mechanism which is intended for the more touchy-feely capabilities.
"""
import json
@@ -61,7 +65,7 @@ class AllHostsQuery:
def filter_hosts(self, zone_manager, query):
"""Return a list of hosts from ZoneManager list."""
return [(host, services)
- for host, services in zone_manager.service_state.iteritems()]
+ for host, services in zone_manager.service_states.iteritems()]
class FlavorQuery:
@@ -174,9 +178,6 @@ class JsonQuery:
return False
return not args[0]
- def _must(self, args):
- return True
-
def _or(self, args):
return True in args
@@ -191,7 +192,6 @@ class JsonQuery:
'<=': _less_than_equal,
'>=': _greater_than_equal,
'not': _not,
- 'must': _must,
'or': _or,
'and': _and,
}
diff --git a/nova/tests/test_query.py b/nova/tests/test_query.py
index 7a036a4d8..896b2364d 100644
--- a/nova/tests/test_query.py
+++ b/nova/tests/test_query.py
@@ -16,6 +16,8 @@
Tests For Scheduler Query Drivers
"""
+import json
+
from nova import exception
from nova import flags
from nova import test
@@ -118,3 +120,27 @@ class QueryTestCase(test.TestCase):
just_hosts.sort()
self.assertEquals('host4', just_hosts[0])
self.assertEquals('host9', just_hosts[5])
+
+ # Try some custom queries
+
+ raw = ['or',
+ ['and',
+ ['<', '$compute.host_memory.free', 30],
+ ['<', '$compute.disk.available', 300]
+ ],
+ ['and',
+ ['>', '$compute.host_memory.free', 70],
+ ['>', '$compute.disk.available', 700]
+ ]
+ ]
+ cooked = json.dumps(raw)
+ hosts = driver.filter_hosts(self.zone_manager, cooked)
+
+ self.assertEquals(5, len(hosts))
+ just_hosts = [host for host, caps in hosts]
+ just_hosts.sort()
+ self.assertEquals('host0', just_hosts[0])
+ self.assertEquals('host1', just_hosts[1])
+ self.assertEquals('host7', just_hosts[2])
+ self.assertEquals('host8', just_hosts[3])
+ self.assertEquals('host9', just_hosts[4])