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

Cleanup colouring functions.

Make the code somewhat smaller. Disable disk failure test for master for now.

Reviewed-by: schreiberal
parent b1ffe1eb
......@@ -83,8 +83,8 @@ def PrintCronWarning():
"""
print
qa_utils.PrintWarning("The following tests require the cron script for"
" ganeti-watcher to be set up.")
print qa_utils.FormatWarning("The following tests require the cron script "
"for ganeti-watcher to be set up.")
def TestInstanceAutomaticRestart(node, instance):
......
......@@ -301,10 +301,10 @@ def _TestInstanceDiskFailure(instance, node, node2, onmaster):
def TestInstanceMasterDiskFailure(instance, node, node2):
"""Testing disk failure on master node."""
qa_utils.PrintError("Disk failure on primary node cannot be "
"tested due to potential crashes.")
print qa_utils.FormatError("Disk failure on primary node cannot be "
"tested due to potential crashes.")
# The following can cause crashes, thus it's disabled until fixed
return _TestInstanceDiskFailure(instance, node, node2, True)
#return _TestInstanceDiskFailure(instance, node, node2, True)
def TestInstanceSecondaryDiskFailure(instance, node, node2):
......
......@@ -74,8 +74,9 @@ def _SetupTempOs(node, dir, valid):
cmd = ' && '.join(parts)
qa_utils.PrintInfo("Setting up %s with %s OS definition" %
(node["primary"], ["an invalid", "a valid"][int(valid)]))
print qa_utils.FormatInfo("Setting up %s with %s OS definition" %
(node["primary"],
["an invalid", "a valid"][int(valid)]))
AssertEqual(StartSSH(node['primary'], cmd).wait(), 0)
......
......@@ -42,6 +42,10 @@ def _SetupColours():
"""
global _INFO_SEQ, _WARNING_SEQ, _ERROR_SEQ, _RESET_SEQ
# Don't use colours if stdout isn't a terminal
if not sys.stdout.isatty():
return
try:
import curses
except ImportError:
......@@ -201,29 +205,12 @@ def GetNodeInstances(node, secondaries=False):
return instances
def _PrintWithColor(text, seq):
f = sys.stdout
if not f.isatty():
seq = None
if seq:
f.write(seq)
f.write(text)
f.write("\n")
if seq:
f.write(_RESET_SEQ)
def PrintWarning(text):
return _PrintWithColor(text, _WARNING_SEQ)
def PrintError(text):
return _PrintWithColor(text, _ERROR_SEQ)
def _FormatWithColor(text, seq):
if not seq:
return text
return "%s%s%s" % (seq, text, _RESET_SEQ)
def PrintInfo(text):
return _PrintWithColor(text, _INFO_SEQ)
FormatWarning = lambda text: _FormatWithColor(text, _WARNING_SEQ)
FormatError = lambda text: _FormatWithColor(text, _ERROR_SEQ)
FormatInfo = lambda text: _FormatWithColor(text, _INFO_SEQ)
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