#!/usr/bin/env python import sys import os import os.path import re import lxml.etree as et from argparse import ArgumentParser from argparse import FileType from pprint import pprint from subprocess import check_call from subprocess import Popen from subprocess import PIPE from subprocess import CalledProcessError from datetime import datetime from time import sleep from errno import ESRCH if sys.stdout.isatty(): COLORS = { "COLOR_RESET": "\033[0m", "COLOR_WHITE": "\033[1;37m", "COLOR_FAIL": "\033[1;31m", "COLOR_UNKNOWN": "\033[1;30m", "COLOR_OK": "\033[1;32m", "COLOR_SKIPPED": "\033[1;34m" } else: COLORS = { "COLOR_RESET": "", "COLOR_WHITE": "", "COLOR_FAIL": "", "COLOR_UNKNOWN": "", "COLOR_OK": "", "COLOR_SKIPPED": "" } MSG_FAIL = "{COLOR_WHITE}[ {COLOR_FAIL}FAIL{COLOR_WHITE} ]{COLOR_RESET}".format(**COLORS) MSG_UNKNOWN = "{COLOR_WHITE}[ {COLOR_UNKNOWN}UNKNOWN{COLOR_WHITE} ]{COLOR_RESET}".format(**COLORS) MSG_OK = "{COLOR_WHITE}[ {COLOR_OK}OK{COLOR_WHITE} ]{COLOR_RESET}".format(**COLORS) MSG_SKIPPED = "{COLOR_WHITE}[ {COLOR_SKIPPED}SKIPPED{COLOR_WHITE} ]{COLOR_RESET}".format(**COLORS) def main(args): SERVER_DIED = False def is_data_present(): proc = Popen(args.client, stdin=PIPE, stdout=PIPE, stderr=PIPE) (stdout, stderr) = proc.communicate("EXISTS TABLE test.hits") if proc.returncode != 0: raise CalledProcessError(proc.returncode, args.client, stderr) return stdout.startswith('1') def dump_report(destination, suite, test_case, report): if destination is not None: destination_file = os.path.join(destination, suite, test_case + ".xml") destination_dir = os.path.dirname(destination_file) if not os.path.exists(destination_dir): os.makedirs(destination_dir) with open(destination_file, 'w') as report_file: report_root = et.Element("testsuites", attrib = {'name': 'ClickHouse Tests'}) report_suite = et.Element("testsuite", attrib = {"name": suite}) report_suite.append(report) report_root.append(report_suite) report_file.write(et.tostring(report_root, encoding = "UTF-8", xml_declaration=True, pretty_print=True)) if args.zookeeper is None: try: check_call(['grep', '-q', ' 0: print("\n{COLOR_FAIL}Having {0} errors!{COLOR_RESET}".format(failures_total, **COLORS)) sys.exit(1) else: print("\n{COLOR_OK}All tests passed.{COLOR_RESET}".format(**COLORS)) sys.exit(0) if __name__ == '__main__': parser = ArgumentParser(description = 'ClickHouse functional tests') parser.add_argument('-q', '--queries', default = 'queries', help = 'Path to queries dir') parser.add_argument('-c', '--client', default = 'clickhouse-client', help = 'Client program') parser.add_argument('-o', '--output', help = 'Output xUnit compliant test report directory') parser.add_argument('-t', '--timeout', type = int, default = 600, help = 'Timeout for each test case in seconds') parser.add_argument('test', nargs = '?', help = 'Optional test case name regex') group = parser.add_mutually_exclusive_group(required = False) group.add_argument('--zookeeper', action = 'store_true', default = None, dest = 'zookeeper', help = 'Run zookeeper related tests') group.add_argument('--no-zookeeper', action = 'store_false', default = None, dest = 'zookeeper', help = 'Do not run zookeeper related tests') args = parser.parse_args() main(args)