Commit 31554d0a authored by Michael Hanselmann's avatar Michael Hanselmann

qlang: Remove unused ReadSimpleFilter

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 9026e935
...@@ -54,55 +54,8 @@ OP_REGEXP = "=~" ...@@ -54,55 +54,8 @@ OP_REGEXP = "=~"
OP_CONTAINS = "=[]" OP_CONTAINS = "=[]"
def ReadSimpleFilter(namefield, filter_):
"""Function extracting wanted names from restricted filter.
This should only be used until proper filtering is implemented. The filter
must either be empty or of the format C{["|", ["=", field, "name1"], ["=",
field, "name2"], ...]}.
"""
if filter_ is None:
return []
if not isinstance(filter_, list):
raise errors.ParameterError("Filter should be list")
if not filter_ or filter_[0] != OP_OR:
raise errors.ParameterError("Filter should start with OR operator")
if len(filter_) < 2:
raise errors.ParameterError("Invalid filter, OR operator should have"
" operands")
result = []
for idx, item in enumerate(filter_[1:]):
if not isinstance(item, list):
raise errors.ParameterError("Invalid OR operator, operand %s not a"
" list" % idx)
if len(item) != 3 or item[0] != OP_EQUAL:
raise errors.ParameterError("Invalid OR operator, operand %s is not an"
" equality filter" % idx)
(_, name, value) = item
if not isinstance(value, basestring):
raise errors.ParameterError("Operand %s for OR should compare against a"
" string" % idx)
if name != namefield:
raise errors.ParameterError("Operand %s for OR should filter field '%s',"
" not '%s'" % (idx, namefield, name))
result.append(value)
return result
def MakeSimpleFilter(namefield, values): def MakeSimpleFilter(namefield, values):
"""Builds a filter for use with L{ReadSimpleFilter}. """Builds simple a filter.
@param namefield: Name of field containing item name @param namefield: Name of field containing item name
@param values: List of names @param values: List of names
......
...@@ -30,32 +30,6 @@ from ganeti import qlang ...@@ -30,32 +30,6 @@ from ganeti import qlang
import testutils import testutils
class TestReadSimpleFilter(unittest.TestCase):
def _Test(self, filter_, expected):
self.assertEqual(qlang.ReadSimpleFilter("name", filter_), expected)
def test(self):
self._Test(None, [])
self._Test(["|", ["=", "name", "xyz"]], ["xyz"])
for i in [1, 3, 10, 25, 140]:
self._Test(["|"] + [["=", "name", "node%s" % j] for j in range(i)],
["node%s" % j for j in range(i)])
def testErrors(self):
for i in [123, True, False, "", "Hello World", "a==b",
[], ["x"], ["x", "y", "z"], ["|"],
["|", ["="]], ["|", "x"], ["|", 123],
["|", ["=", "otherfield", "xyz"]],
["|", ["=", "name", "xyz"], "abc"],
["|", ["=", "name", "xyz", "too", "long"]],
["|", ["=", "name", []]],
["|", ["=", "name", 999]],
["|", ["=", "name", "abc"], ["=", "otherfield", "xyz"]]]:
self.assertRaises(errors.ParameterError, qlang.ReadSimpleFilter,
"name", i)
class TestMakeSimpleFilter(unittest.TestCase): class TestMakeSimpleFilter(unittest.TestCase):
def _Test(self, field, names, expected, parse_exp=None): def _Test(self, field, names, expected, parse_exp=None):
if parse_exp is None: if parse_exp is None:
...@@ -63,7 +37,6 @@ class TestMakeSimpleFilter(unittest.TestCase): ...@@ -63,7 +37,6 @@ class TestMakeSimpleFilter(unittest.TestCase):
filter_ = qlang.MakeSimpleFilter(field, names) filter_ = qlang.MakeSimpleFilter(field, names)
self.assertEqual(filter_, expected) self.assertEqual(filter_, expected)
self.assertEqual(qlang.ReadSimpleFilter(field, filter_), parse_exp)
def test(self): def test(self):
self._Test("name", None, None, parse_exp=[]) self._Test("name", None, None, parse_exp=[])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment