Merge "Add ALL-IN operator to extra spec ops"

This commit is contained in:
Jenkins 2015-01-15 13:39:29 +00:00 committed by Gerrit Code Review
commit 441ddd0471
3 changed files with 43 additions and 5 deletions

View File

@ -61,9 +61,10 @@ There are some standard filter classes to use (:mod:`nova.scheduler.filters`):
* s<= (less than or equal to as a string)
* s< (less than as a string)
* <in> (substring)
* <all-in> (all elements contained in collection)
* <or> (find one of these)
Examples are: ">= 5", "s== 2.1.0", "<in> gcc", and "<or> fpu <or> gpu"
Examples are: ">= 5", "s== 2.1.0", "<in> gcc", "<all-in> aes mmx", and "<or> fpu <or> gpu"
* |AggregateInstanceExtraSpecsFilter| - checks that the aggregate metadata
satisfies any extra specifications associated with the instance type (that

View File

@ -16,12 +16,13 @@
import operator
# 1. The following operations are supported:
# =, s==, s!=, s>=, s>, s<=, s<, <in>, <or>, ==, !=, >=, <=
# =, s==, s!=, s>=, s>, s<=, s<, <in>, <all-in>, <or>, ==, !=, >=, <=
# 2. Note that <or> is handled in a different way below.
# 3. If the first word in the extra_specs is not one of the operators,
# it is ignored.
_op_methods = {'=': lambda x, y: float(x) >= float(y),
'<in>': lambda x, y: y in x,
'<all-in>': lambda x, y: all(val in x for val in y),
'==': lambda x, y: float(x) == float(y),
'!=': lambda x, y: float(x) != float(y),
'>=': lambda x, y: float(x) >= float(y),
@ -59,7 +60,8 @@ def match(value, req):
break
return False
if words and method(value, words[0]):
return True
if words:
if op == '<all-in>': # requires a list not a string
return method(value, words)
return method(value, words[0])
return False

View File

@ -198,3 +198,38 @@ class ExtraSpecsOpsTestCase(test.NoDBTestCase):
value='2',
req='>= 3',
matches=False)
def test_extra_specs_matches_all_with_op_allin(self):
values = ['aes', 'mmx', 'aux']
self._do_extra_specs_ops_test(
value=str(values),
req='<all-in> aes mmx',
matches=True)
def test_extra_specs_matches_one_with_op_allin(self):
values = ['aes', 'mmx', 'aux']
self._do_extra_specs_ops_test(
value=str(values),
req='<all-in> mmx',
matches=True)
def test_extra_specs_fails_with_op_allin(self):
values = ['aes', 'mmx', 'aux']
self._do_extra_specs_ops_test(
value=str(values),
req='<all-in> txt',
matches=False)
def test_extra_specs_fails_all_with_op_allin(self):
values = ['aes', 'mmx', 'aux']
self._do_extra_specs_ops_test(
value=str(values),
req='<all-in> txt 3dnow',
matches=False)
def test_extra_specs_fails_match_one_with_op_allin(self):
values = ['aes', 'mmx', 'aux']
self._do_extra_specs_ops_test(
value=str(values),
req='<all-in> txt aes',
matches=False)