~ubuntu-branches/ubuntu/vivid/drizzle/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/kewpie.py

  • Committer: Package Import Robot
  • Author(s): Tobias Frost
  • Date: 2013-08-22 20:18:31 UTC
  • mto: (20.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20130822201831-gn3ozsh7o7wmc5tk
Tags: upstream-7.2.3
ImportĀ upstreamĀ versionĀ 7.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
# -*- mode: python; indent-tabs-mode: nil; -*-
 
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
4
#
 
5
# Copyright (C) 2010 Patrick Crews
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation; either version 2 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program; if not, write to the Free Software
 
19
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
20
 
 
21
 
 
22
""" kewpie.py
 
23
 
 
24
(DataBase) Quality Platform - system for executing various
 
25
testing systems and the helper code 
 
26
 
 
27
Designed to be a modular test-runner.  Different testing tools
 
28
and databases may be plugged into the system via hacking the
 
29
appropriate modules
 
30
 
 
31
Currently geared towards Drizzle and MySQL systems
 
32
Runs: Drizzle, MySQL, Percona Server, Galera dbms's
 
33
"""
 
34
 
 
35
# imports
 
36
import os
 
37
import imp
 
38
import sys
 
39
 
 
40
import lib.opts.test_run_options as test_run_options
 
41
from lib.opts.defaults import get_defaults
 
42
from lib.modes.test_mode import handle_mode
 
43
from lib.server_mgmt.server_management import serverManager
 
44
from lib.sys_mgmt.system_management import systemManager
 
45
from lib.test_mgmt.execution_management import executionManager
 
46
 
 
47
# functions
 
48
def handle_sys_config(input_args, defaults):
 
49
    """ Look for / update defaults based on sys_config file
 
50
        if specified
 
51
 
 
52
    """
 
53
    key_string = '--sys-config'
 
54
    module_file = None
 
55
    for input_arg in input_args:
 
56
        if input_arg.startswith(key_string):
 
57
            module_file = input_arg.split(key_string)[1].replace('=','').strip()
 
58
            module_file = os.path.abspath(module_file)
 
59
            break
 
60
    if module_file:
 
61
        module_parent = os.path.dirname(module_file)
 
62
        sys.path.append(module_parent) 
 
63
        module_name = os.path.basename(module_file).replace('.py','')
 
64
        project = imp.load_source(module_name, module_file)
 
65
        defaults = project.get_project_defaults(module_file, defaults)
 
66
    return defaults
 
67
 
 
68
# main
 
69
# We base / look for a lot of things based on the location of
 
70
# the kewpie.py file
 
71
qp_rootdir = os.path.dirname(os.path.abspath(sys.argv[0]))
 
72
project_name = None
 
73
defaults = get_defaults(qp_rootdir,project_name)
 
74
defaults = handle_sys_config(sys.argv, defaults)
 
75
 
 
76
variables = test_run_options.parse_qp_options(defaults)
 
77
variables['qp_root'] = qp_rootdir
 
78
 
 
79
system_manager = None
 
80
server_manager = None
 
81
test_manager = None
 
82
test_executor = None
 
83
execution_manager = None
 
84
 
 
85
try:
 
86
        # Some system-level work is constant regardless
 
87
        # of the test to be run
 
88
        system_manager = systemManager(variables)
 
89
 
 
90
        # Create our server_manager
 
91
        server_manager = serverManager(system_manager, variables)
 
92
 
 
93
        # Get our mode-specific test_manager and test_executor
 
94
        (test_manager,test_executor) = handle_mode(variables, system_manager)
 
95
 
 
96
        # Gather our tests for execution
 
97
        test_manager.gather_tests()
 
98
 
 
99
        # Initialize test execution manager
 
100
        execution_manager = executionManager(server_manager, system_manager
 
101
                                        , test_manager, test_executor
 
102
                                        , variables)
 
103
 
 
104
        # Execute our tests!
 
105
        execution_manager.execute_tests()
 
106
    
 
107
except Exception, e:
 
108
       print Exception, e
 
109
 
 
110
except KeyboardInterrupt:
 
111
      print "\n\nDetected <Ctrl>+c, shutting down and cleaning up..."
 
112
 
 
113
finally:
 
114
# TODO - make a more robust cleanup
 
115
# At the moment, runaway servers are our biggest concern
 
116
    if server_manager and not variables['startandexit']:
 
117
        if variables['gdb']:
 
118
            server_manager.cleanup_all_servers()
 
119
        else:
 
120
            server_manager.cleanup()
 
121
    if not variables['startandexit']:
 
122
        if test_manager:
 
123
            fail_count = test_manager.has_failing_tests()
 
124
            sys.exit(test_manager.has_failing_tests())
 
125
        else:
 
126
            # return 1 as we likely have a problem if we don't have a
 
127
            # test_manager
 
128
            sys.exit(1)
 
129