and or test
This commit is contained in:
@@ -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
|
returns the full, unfiltered list of hosts. Flavor is a hard coded
|
||||||
matching mechanism based on flavor criteria and JSON is an ad-hoc
|
matching mechanism based on flavor criteria and JSON is an ad-hoc
|
||||||
query grammar.
|
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
|
import json
|
||||||
@@ -61,7 +65,7 @@ class AllHostsQuery:
|
|||||||
def filter_hosts(self, zone_manager, query):
|
def filter_hosts(self, zone_manager, query):
|
||||||
"""Return a list of hosts from ZoneManager list."""
|
"""Return a list of hosts from ZoneManager list."""
|
||||||
return [(host, services)
|
return [(host, services)
|
||||||
for host, services in zone_manager.service_state.iteritems()]
|
for host, services in zone_manager.service_states.iteritems()]
|
||||||
|
|
||||||
|
|
||||||
class FlavorQuery:
|
class FlavorQuery:
|
||||||
@@ -174,9 +178,6 @@ class JsonQuery:
|
|||||||
return False
|
return False
|
||||||
return not args[0]
|
return not args[0]
|
||||||
|
|
||||||
def _must(self, args):
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _or(self, args):
|
def _or(self, args):
|
||||||
return True in args
|
return True in args
|
||||||
|
|
||||||
@@ -191,7 +192,6 @@ class JsonQuery:
|
|||||||
'<=': _less_than_equal,
|
'<=': _less_than_equal,
|
||||||
'>=': _greater_than_equal,
|
'>=': _greater_than_equal,
|
||||||
'not': _not,
|
'not': _not,
|
||||||
'must': _must,
|
|
||||||
'or': _or,
|
'or': _or,
|
||||||
'and': _and,
|
'and': _and,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
Tests For Scheduler Query Drivers
|
Tests For Scheduler Query Drivers
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import test
|
from nova import test
|
||||||
@@ -118,3 +120,27 @@ class QueryTestCase(test.TestCase):
|
|||||||
just_hosts.sort()
|
just_hosts.sort()
|
||||||
self.assertEquals('host4', just_hosts[0])
|
self.assertEquals('host4', just_hosts[0])
|
||||||
self.assertEquals('host9', just_hosts[5])
|
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])
|
||||||
|
|||||||
Reference in New Issue
Block a user