From dfe11bad3ad2c306886c9cd86156178eccb8bd6b Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Thu, 1 Nov 2007 14:31:56 +0000 Subject: [PATCH] Cleanup colouring functions. Make the code somewhat smaller. Disable disk failure test for master for now. Reviewed-by: schreiberal --- qa/qa_daemon.py | 4 ++-- qa/qa_instance.py | 6 +++--- qa/qa_os.py | 5 +++-- qa/qa_utils.py | 35 +++++++++++------------------------ 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/qa/qa_daemon.py b/qa/qa_daemon.py index 8b40edf48..413e5d798 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 39a5e4ff4..5d2601739 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 5383d07e5..957b97d18 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 f94aa6fda..70650c1b9 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) -- GitLab