2011-12-22 01:36:26 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
'''
|
|
|
|
Discover all instances of unittest.TestCase in this directory.
|
|
|
|
'''
|
2012-02-12 08:24:20 +00:00
|
|
|
# Import python libs
|
2012-05-05 11:53:39 +00:00
|
|
|
import sys
|
2012-02-12 08:24:20 +00:00
|
|
|
import os
|
2012-04-04 17:49:28 +00:00
|
|
|
import optparse
|
2012-05-05 22:27:16 +00:00
|
|
|
|
2012-02-12 09:58:15 +00:00
|
|
|
# Import salt libs
|
2012-02-12 23:03:31 +00:00
|
|
|
import saltunittest
|
2012-02-20 12:18:13 +00:00
|
|
|
from integration import TestDaemon
|
2012-02-12 09:58:15 +00:00
|
|
|
|
2012-05-05 22:27:16 +00:00
|
|
|
try:
|
|
|
|
import xmlrunner
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
2012-02-12 23:03:31 +00:00
|
|
|
TEST_DIR = os.path.dirname(os.path.normpath(os.path.abspath(__file__)))
|
2011-12-22 01:36:26 +00:00
|
|
|
|
2012-04-04 16:58:11 +00:00
|
|
|
PNUM = 50
|
|
|
|
|
2012-04-04 17:49:28 +00:00
|
|
|
|
2012-05-30 02:56:47 +00:00
|
|
|
def run_suite(opts, path, display_name, suffix='[!_]*.py'):
|
2012-05-30 23:10:48 +00:00
|
|
|
'''
|
|
|
|
Execute a unit test suite
|
|
|
|
'''
|
2012-05-30 02:56:47 +00:00
|
|
|
loader = saltunittest.TestLoader()
|
|
|
|
if opts.name:
|
|
|
|
tests = loader.loadTestsFromName(opts.name)
|
|
|
|
else:
|
|
|
|
tests = loader.discover(path, suffix, TEST_DIR)
|
|
|
|
print('~' * PNUM)
|
|
|
|
print('Starting {0} Tests'.format(display_name))
|
|
|
|
print('~' * PNUM)
|
|
|
|
if opts.xmlout:
|
|
|
|
runner = xmlrunner.XMLTestRunner(output='test-reports').run(tests)
|
|
|
|
else:
|
|
|
|
runner = saltunittest.TextTestRunner(
|
|
|
|
verbosity=opts.verbosity).run(tests)
|
|
|
|
return runner.wasSuccessful()
|
|
|
|
|
|
|
|
|
|
|
|
def run_integration_suite(opts, suite_folder, display_name):
|
2012-05-30 23:10:48 +00:00
|
|
|
'''
|
|
|
|
Run an integration test suite
|
|
|
|
'''
|
2012-05-30 02:56:47 +00:00
|
|
|
path = os.path.join(TEST_DIR, 'integration', suite_folder)
|
|
|
|
return run_suite(opts, path, display_name)
|
|
|
|
|
|
|
|
|
2012-05-05 20:42:47 +00:00
|
|
|
def run_integration_tests(opts):
|
2012-04-04 17:49:28 +00:00
|
|
|
'''
|
|
|
|
Execute the integration tests suite
|
|
|
|
'''
|
2012-04-20 19:13:02 +00:00
|
|
|
print('~' * PNUM)
|
|
|
|
print('Setting up Salt daemons to execute tests')
|
|
|
|
print('~' * PNUM)
|
2012-05-05 11:53:39 +00:00
|
|
|
status = []
|
2012-05-30 02:56:47 +00:00
|
|
|
if not any([opts.client, opts.module, opts.runner,
|
|
|
|
opts.shell, opts.state, opts.name]):
|
|
|
|
return status
|
2012-02-20 12:18:13 +00:00
|
|
|
with TestDaemon():
|
2012-05-30 02:56:47 +00:00
|
|
|
if opts.name:
|
|
|
|
results = run_suite(opts, '', opts.name)
|
|
|
|
status.append(results)
|
2012-05-30 23:10:48 +00:00
|
|
|
if opts.runner:
|
|
|
|
status.append(run_integration_suite(opts, 'runners', 'Runner'))
|
2012-05-05 20:42:47 +00:00
|
|
|
if opts.module:
|
2012-05-30 02:56:47 +00:00
|
|
|
status.append(run_integration_suite(opts, 'modules', 'Module'))
|
2012-05-13 04:27:30 +00:00
|
|
|
if opts.state:
|
2012-05-30 02:56:47 +00:00
|
|
|
status.append(run_integration_suite(opts, 'states', 'State'))
|
2012-05-05 20:42:47 +00:00
|
|
|
if opts.client:
|
2012-05-30 02:56:47 +00:00
|
|
|
status.append(run_integration_suite(opts, 'client', 'Client'))
|
2012-05-05 20:42:47 +00:00
|
|
|
if opts.shell:
|
2012-05-30 02:56:47 +00:00
|
|
|
status.append(run_integration_suite(opts, 'shell', 'Shell'))
|
2012-05-05 11:53:39 +00:00
|
|
|
return status
|
2012-04-04 17:49:28 +00:00
|
|
|
|
|
|
|
|
2012-05-05 20:42:47 +00:00
|
|
|
def run_unit_tests(opts):
|
2012-04-04 17:49:28 +00:00
|
|
|
'''
|
|
|
|
Execute the unit tests
|
|
|
|
'''
|
2012-05-05 20:42:47 +00:00
|
|
|
if not opts.unit:
|
2012-05-05 12:37:39 +00:00
|
|
|
return [True]
|
2012-05-05 11:53:39 +00:00
|
|
|
status = []
|
2012-05-30 02:56:47 +00:00
|
|
|
results = run_suite(
|
|
|
|
opts, os.path.join(TEST_DIR, 'unit'), 'Unit', '*_test.py')
|
|
|
|
status.append(results)
|
2012-05-05 11:53:39 +00:00
|
|
|
return status
|
2012-02-20 12:18:13 +00:00
|
|
|
|
2012-02-12 08:24:20 +00:00
|
|
|
|
2012-04-04 17:49:28 +00:00
|
|
|
def parse_opts():
|
|
|
|
'''
|
|
|
|
Parse command line options for running specific tests
|
|
|
|
'''
|
|
|
|
parser = optparse.OptionParser()
|
|
|
|
parser.add_option('-m',
|
|
|
|
'--module',
|
|
|
|
'--module-tests',
|
|
|
|
dest='module',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run tests for modules')
|
2012-05-13 02:55:56 +00:00
|
|
|
parser.add_option('-S',
|
|
|
|
'--state',
|
|
|
|
'--state-tests',
|
|
|
|
dest='state',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run tests for states')
|
2012-04-04 17:49:28 +00:00
|
|
|
parser.add_option('-c',
|
|
|
|
'--client',
|
|
|
|
'--client-tests',
|
|
|
|
dest='client',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run tests for client')
|
2012-05-05 20:42:47 +00:00
|
|
|
parser.add_option('-s',
|
|
|
|
'--shell',
|
|
|
|
dest='shell',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run shell tests')
|
2012-05-28 03:01:08 +00:00
|
|
|
parser.add_option('-r',
|
|
|
|
'--runner',
|
|
|
|
dest='runner',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run runner tests')
|
2012-04-04 17:49:28 +00:00
|
|
|
parser.add_option('-u',
|
|
|
|
'--unit',
|
|
|
|
'--unit-tests',
|
|
|
|
dest='unit',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run unit tests')
|
2012-05-05 20:42:47 +00:00
|
|
|
parser.add_option('-v',
|
|
|
|
'--verbose',
|
|
|
|
dest='verbosity',
|
|
|
|
default=1,
|
|
|
|
action='count',
|
|
|
|
help='Verbose test runner output')
|
2012-05-05 22:27:16 +00:00
|
|
|
parser.add_option('-x',
|
|
|
|
'--xml',
|
|
|
|
dest='xmlout',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
2012-05-30 02:56:47 +00:00
|
|
|
help='XML test runner output')
|
|
|
|
parser.add_option('-n',
|
|
|
|
'--name',
|
|
|
|
dest='name',
|
|
|
|
default='',
|
|
|
|
help='Specific test name to run')
|
2012-05-05 22:27:16 +00:00
|
|
|
|
2012-05-30 02:56:47 +00:00
|
|
|
options, _ = parser.parse_args()
|
|
|
|
if not any((options.module, options.client,
|
|
|
|
options.shell, options.unit,
|
|
|
|
options.state, options.runner,
|
|
|
|
options.name)):
|
2012-05-05 20:42:47 +00:00
|
|
|
options.module = True
|
|
|
|
options.client = True
|
|
|
|
options.shell = True
|
|
|
|
options.unit = True
|
2012-05-28 03:01:08 +00:00
|
|
|
options.runner = True
|
2012-06-30 16:40:00 +00:00
|
|
|
options.state = True
|
2012-05-05 20:42:47 +00:00
|
|
|
return options
|
2012-04-04 17:49:28 +00:00
|
|
|
|
|
|
|
|
2012-05-28 03:01:08 +00:00
|
|
|
if __name__ == '__main__':
|
2012-04-04 17:49:28 +00:00
|
|
|
opts = parse_opts()
|
2012-05-05 11:53:39 +00:00
|
|
|
overall_status = []
|
|
|
|
status = run_integration_tests(opts)
|
|
|
|
overall_status.extend(status)
|
|
|
|
status = run_unit_tests(opts)
|
|
|
|
overall_status.extend(status)
|
|
|
|
false_count = overall_status.count(False)
|
|
|
|
if false_count > 0:
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
sys.exit(0)
|