Make the code somewhat smaller. Disable disk failure test for master for now.
Reviewed-by: schreiberal
"""
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):
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):
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)
"""
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:
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)