Commit f2c6673d authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Add unittest for cli.FormatResultError



Also make the parameter for verbosity mandatory.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 6b9b18a2
......@@ -2413,13 +2413,15 @@ class _QueryColumnFormatter:
assert value is None, \
"Found value %r for abnormal status %s" % (value, status)
return FormatResultError(status, verbose=self._verbose)
return FormatResultError(status, self._verbose)
def FormatResultError(status, verbose=True):
def FormatResultError(status, verbose):
"""Formats result status other than L{constants.RS_NORMAL}.
@param status: The result status
@type verbose: boolean
@param verbose: Whether to return the verbose text
@return: Text of result status
"""
......
......@@ -551,7 +551,7 @@ def PowerNode(opts, args):
data.append([node_name, "invoked"])
else:
errs += 1
data.append([node_name, cli.FormatResultError(data_status)])
data.append([node_name, cli.FormatResultError(data_status, True)])
data = GenerateTable(separator=opts.separator, headers=headers,
fields=["node", "status"], data=data)
......@@ -597,7 +597,7 @@ def Health(opts, args):
data.append(["", "%s=%s" % (item, status)])
else:
errs += 1
data.append([node_name, cli.FormatResultError(data_status)])
data.append([node_name, cli.FormatResultError(data_status, True)])
data = GenerateTable(separator=opts.separator, headers=headers,
fields=["node", "status"], data=data)
......
......@@ -729,5 +729,29 @@ class TestParseNicOption(unittest.TestCase):
[(3, { "mode": [], })])
class TestFormatResultError(unittest.TestCase):
def testNormal(self):
for verbose in [False, True]:
self.assertRaises(AssertionError, cli.FormatResultError,
constants.RS_NORMAL, verbose)
def testUnknown(self):
for verbose in [False, True]:
self.assertRaises(NotImplementedError, cli.FormatResultError,
"#some!other!status#", verbose)
def test(self):
for status in constants.RS_ALL:
if status == constants.RS_NORMAL:
continue
self.assertNotEqual(cli.FormatResultError(status, False),
cli.FormatResultError(status, True))
result = cli.FormatResultError(status, True)
self.assertTrue(result.startswith("("))
self.assertTrue(result.endswith(")"))
if __name__ == '__main__':
testutils.GanetiTestProgram()
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