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-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-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-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-02-20 12:18:13 +00:00
|
|
|
with TestDaemon():
|
2012-05-05 20:42:47 +00:00
|
|
|
if opts.module:
|
2012-04-04 17:49:28 +00:00
|
|
|
moduleloader = saltunittest.TestLoader()
|
|
|
|
moduletests = moduleloader.discover(
|
|
|
|
os.path.join(TEST_DIR, 'integration', 'modules'),
|
|
|
|
'*.py'
|
|
|
|
)
|
2012-04-20 19:13:02 +00:00
|
|
|
print('~' * PNUM)
|
|
|
|
print('Starting Module Tests')
|
|
|
|
print('~' * PNUM)
|
2012-05-05 20:42:47 +00:00
|
|
|
runner = saltunittest.TextTestRunner(verbosity=opts.verbosity).run(moduletests)
|
2012-05-05 11:53:39 +00:00
|
|
|
status.append(runner.wasSuccessful())
|
2012-05-05 20:42:47 +00:00
|
|
|
if opts.client:
|
2012-04-04 17:49:28 +00:00
|
|
|
clientloader = saltunittest.TestLoader()
|
2012-04-21 23:27:59 +00:00
|
|
|
clienttests = clientloader.discover(
|
|
|
|
os.path.join(TEST_DIR, 'integration', 'client'),
|
|
|
|
'*.py'
|
|
|
|
)
|
2012-04-20 19:13:02 +00:00
|
|
|
print('~' * PNUM)
|
|
|
|
print('Starting Client Tests')
|
|
|
|
print('~' * PNUM)
|
2012-05-05 20:42:47 +00:00
|
|
|
runner = saltunittest.TextTestRunner(verbosity=opts.verbosity).run(clienttests)
|
2012-05-05 11:53:39 +00:00
|
|
|
status.append(runner.wasSuccessful())
|
2012-05-05 20:42:47 +00:00
|
|
|
if opts.shell:
|
2012-04-21 23:27:59 +00:00
|
|
|
shellloader = saltunittest.TestLoader()
|
|
|
|
shelltests = shellloader.discover(
|
|
|
|
os.path.join(TEST_DIR, 'integration', 'shell'),
|
|
|
|
'*.py'
|
|
|
|
)
|
|
|
|
print('~' * PNUM)
|
|
|
|
print('Starting Shell Tests')
|
|
|
|
print('~' * PNUM)
|
2012-05-05 20:42:47 +00:00
|
|
|
runner = saltunittest.TextTestRunner(verbosity=opts.verbosity).run(shelltests)
|
2012-05-05 11:53:39 +00:00
|
|
|
status.append(runner.wasSuccessful())
|
|
|
|
|
|
|
|
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-02-20 12:18:13 +00:00
|
|
|
loader = saltunittest.TestLoader()
|
2012-05-02 07:42:01 +00:00
|
|
|
tests = loader.discover(os.path.join(TEST_DIR, 'unit'), '*_test.py')
|
2012-04-20 19:13:02 +00:00
|
|
|
print('~' * PNUM)
|
|
|
|
print('Starting Unit Tests')
|
|
|
|
print('~' * PNUM)
|
2012-05-05 20:42:47 +00:00
|
|
|
runner = saltunittest.TextTestRunner(verbosity=opts.verbosity).run(tests)
|
2012-05-05 11:53:39 +00:00
|
|
|
status.append(runner.wasSuccessful())
|
|
|
|
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')
|
|
|
|
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-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-04-04 17:49:28 +00:00
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
2012-05-05 20:42:47 +00:00
|
|
|
if all((not options.module, not options.client,
|
|
|
|
not options.shell, not options.unit)):
|
|
|
|
options.module = True
|
|
|
|
options.client = True
|
|
|
|
options.shell = True
|
|
|
|
options.unit = True
|
|
|
|
return options
|
2012-04-04 17:49:28 +00:00
|
|
|
|
|
|
|
|
2011-12-22 01:36:26 +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)
|