summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSandy Walsh <sandy.walsh@rackspace.com>2011-05-05 05:29:31 -0700
committerSandy Walsh <sandy.walsh@rackspace.com>2011-05-05 05:29:31 -0700
commit5a066cf5c2b952371eea753dcd0f95f917d08744 (patch)
tree6b8dc6cceac6350104b4b7726c9153ef3c552d3b
parent5f4fc98c9648fd3f124819e0f4a26cb1d2d7f0e8 (diff)
not =
-rw-r--r--nova/scheduler/query.py7
-rw-r--r--nova/tests/test_query.py29
2 files changed, 26 insertions, 10 deletions
diff --git a/nova/scheduler/query.py b/nova/scheduler/query.py
index 3233cc0d8..0279efc9e 100644
--- a/nova/scheduler/query.py
+++ b/nova/scheduler/query.py
@@ -176,7 +176,7 @@ class JsonQuery:
def _not(self, args):
if len(args) == 0:
return False
- return not args[0]
+ return [not arg for arg in args]
def _or(self, args):
return True in args
@@ -244,7 +244,10 @@ class JsonQuery:
hosts = []
for host, services in zone_manager.service_states.iteritems():
print "-----"
- if self._process_query(zone_manager, expanded, host, services):
+ r = self._process_query(zone_manager, expanded, host, services)
+ if isinstance(r, list):
+ r = True in r
+ if r:
hosts.append((host, services))
return hosts
diff --git a/nova/tests/test_query.py b/nova/tests/test_query.py
index 90ae80dc0..9bfc83b75 100644
--- a/nova/tests/test_query.py
+++ b/nova/tests/test_query.py
@@ -33,7 +33,7 @@ class QueryTestCase(test.TestCase):
def _host_caps(self, multiplier):
# Returns host capabilities in the following way:
- # host0 = memory:free 10 (100max)
+ # host1 = memory:free 10 (100max)
# disk:available 100 (1000max)
# hostN = memory:free 10 + 10N
# disk:available 100 + 100N
@@ -69,7 +69,7 @@ class QueryTestCase(test.TestCase):
self.zone_manager = FakeZoneManager()
states = {}
for x in xrange(10):
- states['host%s' % x] = {'compute': self._host_caps(x)}
+ states['host%02d' % (x + 1)] = {'compute': self._host_caps(x)}
self.zone_manager.service_states = states
def tearDown(self):
@@ -106,8 +106,8 @@ class QueryTestCase(test.TestCase):
self.assertEquals(6, len(hosts))
just_hosts = [host for host, caps in hosts]
just_hosts.sort()
- self.assertEquals('host4', just_hosts[0])
- self.assertEquals('host9', just_hosts[5])
+ self.assertEquals('host05', just_hosts[0])
+ self.assertEquals('host10', just_hosts[5])
def test_json_driver(self):
driver = query.JsonQuery()
@@ -118,8 +118,8 @@ class QueryTestCase(test.TestCase):
self.assertEquals(6, len(hosts))
just_hosts = [host for host, caps in hosts]
just_hosts.sort()
- self.assertEquals('host4', just_hosts[0])
- self.assertEquals('host9', just_hosts[5])
+ self.assertEquals('host05', just_hosts[0])
+ self.assertEquals('host10', just_hosts[5])
# Try some custom queries
@@ -139,5 +139,18 @@ class QueryTestCase(test.TestCase):
self.assertEquals(5, len(hosts))
just_hosts = [host for host, caps in hosts]
just_hosts.sort()
- for index, host in zip([0, 1, 7, 8, 9], just_hosts):
- self.assertEquals('host%d' % index, host)
+ for index, host in zip([1, 2, 8, 9, 10], just_hosts):
+ self.assertEquals('host%02d' % index, host)
+
+ raw = ['not',
+ ['=', '$compute.host_memory.free', 30],
+ ]
+ cooked = json.dumps(raw)
+ hosts = driver.filter_hosts(self.zone_manager, cooked)
+
+ self.assertEquals(9, len(hosts))
+ just_hosts = [host for host, caps in hosts]
+ just_hosts.sort()
+ for index, host in zip([1, 2, 4, 5, 6, 7, 8, 9, 10], just_hosts):
+ self.assertEquals('host%02d' % index, host)
+