diff --git a/manila/scheduler/evaluator/evaluator.py b/manila/scheduler/evaluator/evaluator.py index e796e79ba4..88bfc3d765 100644 --- a/manila/scheduler/evaluator/evaluator.py +++ b/manila/scheduler/evaluator/evaluator.py @@ -56,9 +56,9 @@ class EvalConstant(object): except ValueError: try: result = float(result) - except ValueError as e: - msg = _("ValueError: %s") % e - raise exception.EvaluatorParseException(reason=msg) + except ValueError: + if isinstance(result, str): + result = result.replace('"', '').replace('\'', '') return result @@ -233,6 +233,7 @@ def _def_parser(): Combine = pyparsing.Combine Forward = pyparsing.Forward nums = pyparsing.nums + quoted_string = pyparsing.quotedString oneOf = pyparsing.oneOf opAssoc = pyparsing.opAssoc infixNotation = pyparsing.infixNotation @@ -244,7 +245,7 @@ def _def_parser(): number = real | integer expr = Forward() fn = Word(alphas + '_' + '.') - operand = number | variable | fn + operand = number | variable | fn | quoted_string signop = oneOf('+ -') addop = oneOf('+ -') diff --git a/manila/tests/scheduler/evaluator/test_evaluator.py b/manila/tests/scheduler/evaluator/test_evaluator.py index 44c5a47c23..3dae40b59d 100644 --- a/manila/tests/scheduler/evaluator/test_evaluator.py +++ b/manila/tests/scheduler/evaluator/test_evaluator.py @@ -128,11 +128,12 @@ class EvaluatorTestCase(test.TestCase): def test_nonnumber_comparison(self): nonnumber = {'test': 'foo'} request = {'test': 'bar'} - self.assertRaises( - exception.EvaluatorParseException, - evaluator.evaluate, - "nonnumber.test != request.test", - nonnumber=nonnumber, request=request) + self.assertTrue( + evaluator.evaluate("nonnumber.test != request.test", + nonnumber=nonnumber, request=request)) + self.assertFalse( + evaluator.evaluate("nonnumber.test == request.test", + nonnumber=nonnumber, request=request)) def test_div_zero(self): self.assertRaises(exception.EvaluatorParseException, diff --git a/releasenotes/notes/bug-1975715-fix-driverfilter-string-evaluations-3886a68d4d7fa3a1.yaml b/releasenotes/notes/bug-1975715-fix-driverfilter-string-evaluations-3886a68d4d7fa3a1.yaml new file mode 100644 index 0000000000..2223568be7 --- /dev/null +++ b/releasenotes/notes/bug-1975715-fix-driverfilter-string-evaluations-3886a68d4d7fa3a1.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Goodness_function expects integer or float else raise parseException. This + causes example such as "(share.share_proto == 'CIFS') ? 100 : 50" to fail + during evaluation. Fix it by adding support of string evalution.