- Implement colours in qa_utils.
- Print warning for cron script.
Reviewed-by: iustinp
if qa_config.TestEnabled('instance-info'):
RunTest(qa_instance.TestInstanceInfo, instance)
- if qa_config.TestEnabled('instance-automatic-restart'):
- RunTest(qa_daemon.TestInstanceAutomaticRestart, node, instance)
+ automatic_restart = \
+ qa_config.TestEnabled('instance-automatic-restart')
+ consecutive_failures = \
+ qa_config.TestEnabled('instance-consecutive-failures')
- if qa_config.TestEnabled('instance-consecutive-failures'):
- RunTest(qa_daemon.TestInstanceConsecutiveFailures, node, instance)
+ if automatic_restart or consecutive_failures:
+ qa_daemon.PrintCronWarning()
+
+ if automatic_restart:
+ RunTest(qa_daemon.TestInstanceAutomaticRestart, node, instance)
+
+ if consecutive_failures:
+ RunTest(qa_daemon.TestInstanceConsecutiveFailures, node, instance)
if qa_config.TestEnabled('instance-export'):
expnode = qa_config.AcquireNode(exclude=node)
utils.ShellQuoteArgs(cmd)).wait(), 0)
+def PrintCronWarning():
+ """Shows a warning about the required cron job.
+
+ """
+ print
+ qa_utils.PrintWarning("The following tests require the cron script for"
+ " ganeti-watcher to be set up.")
+
+
def TestInstanceAutomaticRestart(node, instance):
"""Test automatic restart of instance by ganeti-watcher.
"""
import os
+import sys
import subprocess
from ganeti import utils
import qa_error
+_INFO_SEQ = None
+_WARNING_SEQ = None
+_ERROR_SEQ = None
+_RESET_SEQ = None
+
+
+def _SetupColours():
+ """Initializes the colour constants.
+
+ """
+ global _INFO_SEQ, _WARNING_SEQ, _ERROR_SEQ, _RESET_SEQ
+
+ try:
+ import curses
+ except ImportError:
+ # Don't use colours if curses module can't be imported
+ return
+
+ curses.setupterm()
+
+ _RESET_SEQ = curses.tigetstr("op")
+
+ setaf = curses.tigetstr("setaf")
+ _INFO_SEQ = curses.tparm(setaf, curses.COLOR_GREEN)
+ _WARNING_SEQ = curses.tparm(setaf, curses.COLOR_YELLOW)
+ _ERROR_SEQ = curses.tparm(setaf, curses.COLOR_RED)
+
+
+_SetupColours()
+
+
def AssertEqual(first, second, msg=None):
"""Raises an error when values aren't equal.
AssertEqual(p.wait(), 0)
return p.stdout.read().strip()
+
+
+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(f, text):
+ return _PrintWithColor(text, _ERROR_SEQ)
+
+
+def PrintInfo(f, text):
+ return _PrintWithColor(text, _INFO_SEQ)