diff --git a/qa/qa_daemon.py b/qa/qa_daemon.py index 8b40edf4823e4a090ecca7d038daa9a6f91bdb83..413e5d798aaec88225035aba7f9368ed354f7698 100644 --- a/qa/qa_daemon.py +++ b/qa/qa_daemon.py @@ -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): diff --git a/qa/qa_instance.py b/qa/qa_instance.py index 39a5e4ff41705621f776c9ff774cc6cebc9096f6..5d2601739a7ff9aaba7736ec8e2b44d5fa130a85 100644 --- a/qa/qa_instance.py +++ b/qa/qa_instance.py @@ -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): diff --git a/qa/qa_os.py b/qa/qa_os.py index 5383d07e59aa5131bf741259b4147fdebfc3aa82..957b97d18441ee07b6da6d23547ad1dfea5113c4 100644 --- a/qa/qa_os.py +++ b/qa/qa_os.py @@ -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) diff --git a/qa/qa_utils.py b/qa/qa_utils.py index f94aa6fda3f99e14a2709e84344de14da0190ad1..70650c1b953860d0ea481ad1dec8c46343225a98 100644 --- a/qa/qa_utils.py +++ b/qa/qa_utils.py @@ -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)