summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvishay Traeger <avishay@il.ibm.com>2013-03-06 12:21:31 +0200
committerAvishay Traeger <avishay@il.ibm.com>2013-03-07 18:25:08 +0200
commit2e8b5e8446432542901b3c814670a4c67e629137 (patch)
treef2ba2b1ca36f18eeeba9301c151a3270e65ac906
parent2cb8e4557b05f92fbd9f56b7a6a6d4f35c8a883a (diff)
downloadoslo-2e8b5e8446432542901b3c814670a4c67e629137.tar.gz
oslo-2e8b5e8446432542901b3c814670a4c67e629137.tar.xz
oslo-2e8b5e8446432542901b3c814670a4c67e629137.zip
Add 'is' operator to extra specs ops.
Boolean values for capabilities don't work because extra_specs are all converted to unicode. The scheduler will then check, for example, if the boolean 'True' is equal to the unicode string 'True', and will always return False. This patch allows admins to specify '<is> True' in extra_specs, which will compare successfully to boolean True. Fixes bug: 1146306 Change-Id: Id0e6dcfb71eb0943a16bba551ec23c4d57206550
-rw-r--r--openstack/common/scheduler/filters/extra_specs_ops.py6
-rw-r--r--tests/unit/scheduler/test_host_filters.py30
2 files changed, 35 insertions, 1 deletions
diff --git a/openstack/common/scheduler/filters/extra_specs_ops.py b/openstack/common/scheduler/filters/extra_specs_ops.py
index f4d4ff4..9537e28 100644
--- a/openstack/common/scheduler/filters/extra_specs_ops.py
+++ b/openstack/common/scheduler/filters/extra_specs_ops.py
@@ -15,13 +15,17 @@
import operator
+from openstack.common import strutils
+
# 1. The following operations are supported:
-# =, s==, s!=, s>=, s>, s<=, s<, <in>, <or>, ==, !=, >=, <=
+# =, s==, s!=, s>=, s>, s<=, s<, <in>, <is>, <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,
+ '<is>': lambda x, y: (strutils.bool_from_string(x) is
+ strutils.bool_from_string(y)),
'==': lambda x, y: float(x) == float(y),
'!=': lambda x, y: float(x) != float(y),
'>=': lambda x, y: float(x) >= float(y),
diff --git a/tests/unit/scheduler/test_host_filters.py b/tests/unit/scheduler/test_host_filters.py
index 7d3a0e4..566a9fb 100644
--- a/tests/unit/scheduler/test_host_filters.py
+++ b/tests/unit/scheduler/test_host_filters.py
@@ -169,6 +169,36 @@ class ExtraSpecsOpsTestCase(utils.BaseTestCase):
req='<in> 11 <in>',
matches=False)
+ def test_extra_specs_matches_with_op_is(self):
+ self._do_extra_specs_ops_test(
+ value=True,
+ req='<is> True',
+ matches=True)
+
+ def test_extra_specs_matches_with_op_is2(self):
+ self._do_extra_specs_ops_test(
+ value=False,
+ req='<is> False',
+ matches=True)
+
+ def test_extra_specs_matches_with_op_is3(self):
+ self._do_extra_specs_ops_test(
+ value=False,
+ req='<is> Nonsense',
+ matches=True)
+
+ def test_extra_specs_fails_with_op_is(self):
+ self._do_extra_specs_ops_test(
+ value=True,
+ req='<is> False',
+ matches=False)
+
+ def test_extra_specs_fails_with_op_is2(self):
+ self._do_extra_specs_ops_test(
+ value=False,
+ req='<is> True',
+ matches=False)
+
def test_extra_specs_matches_with_op_or(self):
self._do_extra_specs_ops_test(
value='12',