Commit d5a9b556 authored by Petr Pudlak's avatar Petr Pudlak Committed by Jose A. Lopes

Add visual/color marks to the QA script

 * Use different visual marks at the beginning of lines (such as "<<<<" for
    starting a test and ">>>>" for finishing it)

 * Show more specifically if a test fails/passes.

 * If stdout is a terminal, use colors to distinguish different messages
Signed-off-by: default avatarPetr Pudlak <pudlak@google.com>
Reviewed-by: default avatarJose A. Lopes <jabolopes@google.com>
parent c5c8d092
#!/usr/bin/python -u
#
# Copyright (C) 2013 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""Script for adding colorized output to Ganeti.
Colors are enabled only if the standard output is a proper terminal.
"""
import os
import sys
DEFAULT = '\033[0m'
RED = '\033[91m'
GREEN = '\033[92m'
BLUE = '\033[94m'
CYAN = '\033[96m'
WHITE = '\033[97m'
YELLOW = '\033[93m'
MAGENTA = '\033[95m'
GREY = '\033[90m'
BLACK = '\033[90m'
_enabled = sys.stdout.isatty()
def colorize(line, color=None):
if _enabled and color is not None:
return color + line + DEFAULT
else:
return line
......@@ -31,6 +31,7 @@ import datetime
import optparse
import sys
import colors
import qa_cluster
import qa_config
import qa_daemon
......@@ -57,13 +58,14 @@ import ganeti.rapi.client # pylint: disable=W0611
from ganeti.rapi.client import UsesRapiClient
def _FormatHeader(line, end=72):
def _FormatHeader(line, end=72, mark="-", color=None):
"""Fill a line up to the end column.
"""
line = "---- " + line + " "
line = (mark * 4) + " " + line + " "
line += "-" * (end - len(line))
line = line.rstrip()
line = colors.colorize(line, color)
return line
......@@ -92,15 +94,21 @@ def RunTest(fn, *args, **kwargs):
desc = _DescriptionOf(fn)
print
print _FormatHeader("%s start %s" % (tstart, desc))
print _FormatHeader("%s start %s" % (tstart, desc),
color=colors.YELLOW, mark="<")
try:
retval = fn(*args, **kwargs)
print _FormatHeader("PASSED %s" % (desc, ), color=colors.GREEN)
return retval
except Exception, e:
print _FormatHeader("FAILED %s: %s" % (desc, e), color=colors.RED)
raise
finally:
tstop = datetime.datetime.now()
tdelta = tstop - tstart
print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc))
print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc),
color=colors.MAGENTA, mark=">")
def RunTestIf(testnames, fn, *args, **kwargs):
......@@ -117,7 +125,8 @@ def RunTestIf(testnames, fn, *args, **kwargs):
desc = _DescriptionOf(fn)
# TODO: Formatting test names when non-string names are involved
print _FormatHeader("%s skipping %s, test(s) %s disabled" %
(tstart, desc, testnames))
(tstart, desc, testnames),
color=colors.BLUE, mark="*")
def RunEnvTests():
......
......@@ -45,6 +45,7 @@ from ganeti import ht
from ganeti import pathutils
from ganeti import vcluster
import colors
import qa_config
import qa_error
......@@ -285,7 +286,8 @@ def StartLocalCommand(cmd, _nolog_opts=False, log_cmd=True, **kwargs):
pcmd = [i for i in cmd if not i.startswith("-")]
else:
pcmd = cmd
print "Command: %s" % utils.ShellQuoteArgs(pcmd)
print "%s %s" % (colors.colorize("Command:", colors.CYAN),
utils.ShellQuoteArgs(pcmd))
return subprocess.Popen(cmd, shell=False, **kwargs)
......
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