2011-06-21 17:00:16 +00:00
|
|
|
import argparse
|
2011-08-26 00:11:33 +00:00
|
|
|
import copy
|
2011-07-01 16:32:30 +00:00
|
|
|
import errno
|
2011-06-21 17:00:16 +00:00
|
|
|
import itertools
|
|
|
|
import logging
|
|
|
|
import os
|
2012-11-15 01:24:50 +00:00
|
|
|
|
|
|
|
# this file is responsible for submitting tests into the queue
|
|
|
|
# by generating combinations of facets found in
|
|
|
|
# https://github.com/ceph/ceph-qa-suite.git
|
|
|
|
|
2011-06-21 17:00:16 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2011-08-26 00:11:33 +00:00
|
|
|
import time
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
from teuthology import misc as teuthology
|
2011-11-18 01:14:05 +00:00
|
|
|
from teuthology import safepath
|
2011-06-21 17:00:16 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="""
|
|
|
|
Run a suite of ceph integration tests.
|
|
|
|
|
2011-11-18 01:14:05 +00:00
|
|
|
A suite is a set of collections.
|
2011-08-10 20:34:38 +00:00
|
|
|
|
|
|
|
A collection is a directory containing facets.
|
2011-06-21 17:00:16 +00:00
|
|
|
|
|
|
|
A facet is a directory containing config snippets.
|
|
|
|
|
2011-08-10 20:34:38 +00:00
|
|
|
Running a collection means running teuthology for every configuration
|
2011-06-21 17:00:16 +00:00
|
|
|
combination generated by taking one config snippet from each facet.
|
|
|
|
|
|
|
|
Any config files passed on the command line will be used for every
|
2011-07-07 23:19:26 +00:00
|
|
|
combination, and will override anything in the suite.
|
2011-06-21 17:00:16 +00:00
|
|
|
""")
|
|
|
|
parser.add_argument(
|
|
|
|
'-v', '--verbose',
|
|
|
|
action='store_true', default=None,
|
|
|
|
help='be more verbose',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2011-11-18 01:14:05 +00:00
|
|
|
'--name',
|
|
|
|
help='name for this suite',
|
|
|
|
required=True,
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--collections',
|
2011-06-21 17:00:16 +00:00
|
|
|
metavar='DIR',
|
2011-11-18 01:14:05 +00:00
|
|
|
nargs='+',
|
2011-06-21 17:00:16 +00:00
|
|
|
required=True,
|
2011-11-18 01:14:05 +00:00
|
|
|
help='the collections to run',
|
2011-06-21 17:00:16 +00:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
2011-07-11 19:52:07 +00:00
|
|
|
'--owner',
|
|
|
|
help='job owner',
|
|
|
|
)
|
2011-08-26 00:11:33 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--email',
|
|
|
|
help='address to email test failures to',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--timeout',
|
|
|
|
help='how many seconds to wait for jobs to finish before emailing results',
|
|
|
|
)
|
2012-07-14 20:02:04 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'-n', '--num',
|
|
|
|
default=1,
|
|
|
|
type=int,
|
|
|
|
help='number of times to run/queue each job'
|
|
|
|
)
|
2012-09-21 21:54:19 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'-b', '--branch',
|
|
|
|
default='master',
|
|
|
|
help='which branch of teuthology to use',
|
|
|
|
)
|
2011-06-21 17:00:16 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'config',
|
|
|
|
metavar='CONFFILE',
|
|
|
|
nargs='*',
|
|
|
|
default=[],
|
|
|
|
help='config file to read',
|
|
|
|
)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
loglevel = logging.INFO
|
|
|
|
if args.verbose:
|
|
|
|
loglevel = logging.DEBUG
|
|
|
|
|
|
|
|
logging.basicConfig(
|
|
|
|
level=loglevel,
|
|
|
|
)
|
|
|
|
|
2011-08-26 00:11:33 +00:00
|
|
|
base_arg = [
|
|
|
|
os.path.join(os.path.dirname(sys.argv[0]), 'teuthology-schedule'),
|
|
|
|
'--name', args.name,
|
2012-07-14 20:02:04 +00:00
|
|
|
'--num', str(args.num),
|
2012-09-21 21:54:19 +00:00
|
|
|
'--branch', args.branch,
|
2011-08-26 00:11:33 +00:00
|
|
|
]
|
|
|
|
if args.verbose:
|
|
|
|
base_arg.append('-v')
|
|
|
|
if args.owner:
|
|
|
|
base_arg.extend(['--owner', args.owner])
|
|
|
|
|
2011-11-18 01:14:05 +00:00
|
|
|
for collection in args.collections:
|
|
|
|
if not os.path.isdir(collection):
|
|
|
|
print >>sys.stderr, 'Collection %s is not a directory' % collection
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
collections = [
|
|
|
|
(collection,
|
|
|
|
os.path.basename(safepath.munge(collection)))
|
|
|
|
for collection in args.collections
|
|
|
|
]
|
|
|
|
|
2011-08-10 20:34:38 +00:00
|
|
|
for collection, collection_name in sorted(collections):
|
|
|
|
log.info('Collection %s in %s' % (collection_name, collection))
|
|
|
|
facets = [
|
|
|
|
f for f in sorted(os.listdir(collection))
|
|
|
|
if not f.startswith('.')
|
|
|
|
and os.path.isdir(os.path.join(collection, f))
|
|
|
|
]
|
|
|
|
facet_configs = (
|
|
|
|
[(f, name, os.path.join(collection, f, name))
|
|
|
|
for name in sorted(os.listdir(os.path.join(collection, f)))
|
|
|
|
if not name.startswith('.')
|
|
|
|
and name.endswith('.yaml')
|
|
|
|
]
|
|
|
|
for f in facets
|
|
|
|
)
|
|
|
|
for configs in itertools.product(*facet_configs):
|
|
|
|
description = 'collection:%s ' % (collection_name);
|
|
|
|
description += ' '.join('{facet}:{name}'.format(
|
|
|
|
facet=facet, name=name)
|
|
|
|
for facet, name, path in configs)
|
|
|
|
log.info(
|
|
|
|
'Running teuthology-schedule with facets %s', description
|
|
|
|
)
|
2011-08-26 00:11:33 +00:00
|
|
|
arg = copy.deepcopy(base_arg)
|
2011-08-10 20:34:38 +00:00
|
|
|
arg.extend([
|
|
|
|
'--description', description,
|
|
|
|
'--',
|
|
|
|
])
|
|
|
|
arg.extend(args.config)
|
2011-11-18 01:26:21 +00:00
|
|
|
arg.extend(path for facet, name, path in configs)
|
2011-08-10 20:34:38 +00:00
|
|
|
subprocess.check_call(
|
|
|
|
args=arg,
|
|
|
|
)
|
2011-06-29 19:54:53 +00:00
|
|
|
|
2011-08-26 00:11:33 +00:00
|
|
|
arg = copy.deepcopy(base_arg)
|
|
|
|
arg.append('--last-in-suite')
|
|
|
|
if args.email:
|
|
|
|
arg.extend(['--email', args.email])
|
|
|
|
if args.timeout:
|
|
|
|
arg.extend(['--timeout', args.timeout])
|
|
|
|
subprocess.check_call(
|
2011-11-18 01:14:05 +00:00
|
|
|
args=arg,
|
2011-08-26 00:11:33 +00:00
|
|
|
)
|
|
|
|
|
2011-06-29 19:54:53 +00:00
|
|
|
def ls():
|
|
|
|
parser = argparse.ArgumentParser(description='List teuthology job results')
|
|
|
|
parser.add_argument(
|
|
|
|
'--archive-dir',
|
|
|
|
metavar='DIR',
|
|
|
|
help='path under which to archive results',
|
|
|
|
required=True,
|
|
|
|
)
|
2011-10-03 23:32:42 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'-v', '--verbose',
|
|
|
|
action='store_true', default=False,
|
|
|
|
help='show reasons tests failed',
|
|
|
|
)
|
2011-06-29 19:54:53 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
for j in sorted(os.listdir(args.archive_dir)):
|
2012-03-19 21:16:14 +00:00
|
|
|
job_dir = os.path.join(args.archive_dir, j)
|
|
|
|
if j.startswith('.') or not os.path.isdir(job_dir):
|
2011-06-29 19:54:53 +00:00
|
|
|
continue
|
2011-07-01 16:29:19 +00:00
|
|
|
|
2011-07-01 16:33:06 +00:00
|
|
|
summary = {}
|
2011-06-29 19:54:53 +00:00
|
|
|
try:
|
2012-03-19 21:16:14 +00:00
|
|
|
with file(os.path.join(job_dir, 'summary.yaml')) as f:
|
2011-06-29 19:54:53 +00:00
|
|
|
g = yaml.safe_load_all(f)
|
|
|
|
for new in g:
|
2011-06-30 18:25:15 +00:00
|
|
|
summary.update(new)
|
2011-06-29 19:54:53 +00:00
|
|
|
except IOError, e:
|
2011-07-01 16:32:30 +00:00
|
|
|
if e.errno == errno.ENOENT:
|
2012-04-10 15:57:19 +00:00
|
|
|
print '%s ' % j,
|
2012-01-14 06:08:33 +00:00
|
|
|
|
|
|
|
# pid
|
|
|
|
try:
|
2012-03-19 21:16:14 +00:00
|
|
|
pidfile = os.path.join(job_dir, 'pid')
|
2012-01-16 21:18:49 +00:00
|
|
|
found = False
|
2012-01-14 06:08:33 +00:00
|
|
|
if os.path.isfile(pidfile):
|
|
|
|
pid = open(pidfile, 'r').read()
|
|
|
|
if os.path.isdir("/proc/%s" % pid):
|
|
|
|
cmdline = open('/proc/%s/cmdline' % pid, 'r').read()
|
|
|
|
if cmdline.find(args.archive_dir) >= 0:
|
2012-01-16 21:18:49 +00:00
|
|
|
print '(pid %s)' % pid,
|
|
|
|
found = True
|
|
|
|
if not found:
|
2012-04-10 15:59:47 +00:00
|
|
|
print '(no process or summary.yaml)',
|
2012-01-14 06:08:33 +00:00
|
|
|
# tail
|
|
|
|
tail = os.popen(
|
|
|
|
'tail -1 %s/%s/teuthology.log' % (args.archive_dir, j)
|
|
|
|
).read().rstrip()
|
2012-01-16 21:18:49 +00:00
|
|
|
print tail,
|
2012-01-14 06:08:33 +00:00
|
|
|
except IOError, e:
|
|
|
|
continue
|
|
|
|
print ''
|
2011-07-01 16:32:30 +00:00
|
|
|
continue
|
|
|
|
else:
|
|
|
|
raise
|
2011-06-29 19:54:53 +00:00
|
|
|
|
2012-01-16 21:18:49 +00:00
|
|
|
print "{job} {success} {owner} {desc} {duration}s".format(
|
2011-06-29 19:54:53 +00:00
|
|
|
job=j,
|
2011-07-01 16:34:08 +00:00
|
|
|
owner=summary.get('owner', '-'),
|
|
|
|
desc=summary.get('description', '-'),
|
2012-06-20 17:13:48 +00:00
|
|
|
success='pass' if summary.get('success', False) else 'FAIL',
|
2012-03-20 14:48:45 +00:00
|
|
|
duration=int(summary.get('duration', 0)),
|
2011-06-29 19:54:53 +00:00
|
|
|
)
|
2011-10-03 23:32:42 +00:00
|
|
|
if args.verbose and 'failure_reason' in summary:
|
|
|
|
print ' {reason}'.format(reason=summary['failure_reason'])
|
2011-08-26 00:11:33 +00:00
|
|
|
|
2012-03-15 23:21:33 +00:00
|
|
|
def generate_coverage(args):
|
2012-03-16 18:40:17 +00:00
|
|
|
log.info('starting coverage generation')
|
2012-03-15 23:21:33 +00:00
|
|
|
subprocess.Popen(
|
|
|
|
args=[
|
|
|
|
os.path.join(os.path.dirname(sys.argv[0]), 'teuthology-coverage'),
|
|
|
|
'-v',
|
|
|
|
'-o',
|
|
|
|
os.path.join(args.teuthology_config['coverage_output_dir'], args.name),
|
|
|
|
'--html-output',
|
|
|
|
os.path.join(args.teuthology_config['coverage_html_dir'], args.name),
|
|
|
|
'--cov-tools-dir',
|
|
|
|
args.teuthology_config['coverage_tools_dir'],
|
|
|
|
args.archive_dir,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
def email_results(subject, from_, to, body):
|
2012-03-16 18:40:17 +00:00
|
|
|
log.info('Sending results to {to}: {body}'.format(to=to, body=body))
|
2012-03-15 23:21:33 +00:00
|
|
|
import smtplib
|
|
|
|
from email.mime.text import MIMEText
|
|
|
|
msg = MIMEText(body)
|
|
|
|
msg['Subject'] = subject
|
|
|
|
msg['From'] = from_
|
|
|
|
msg['To'] = to
|
|
|
|
log.debug('sending email %s', msg.as_string())
|
|
|
|
smtp = smtplib.SMTP('localhost')
|
|
|
|
smtp.sendmail(msg['From'], [msg['To']], msg.as_string())
|
|
|
|
smtp.quit()
|
|
|
|
|
2011-08-26 00:11:33 +00:00
|
|
|
def results():
|
|
|
|
parser = argparse.ArgumentParser(description='Email teuthology suite results')
|
|
|
|
parser.add_argument(
|
|
|
|
'--email',
|
|
|
|
help='address to email test failures to',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--timeout',
|
|
|
|
help='how many seconds to wait for all tests to finish (default no wait)',
|
|
|
|
type=int,
|
|
|
|
default=0,
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--archive-dir',
|
|
|
|
metavar='DIR',
|
|
|
|
help='path under which results for the suite are stored',
|
|
|
|
required=True,
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--name',
|
|
|
|
help='name of the suite',
|
|
|
|
required=True,
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'-v', '--verbose',
|
|
|
|
action='store_true', default=False,
|
|
|
|
help='be more verbose',
|
|
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
loglevel = logging.INFO
|
|
|
|
if args.verbose:
|
|
|
|
loglevel = logging.DEBUG
|
|
|
|
|
|
|
|
logging.basicConfig(
|
|
|
|
level=loglevel,
|
|
|
|
)
|
|
|
|
|
|
|
|
teuthology.read_config(args)
|
|
|
|
|
2012-03-16 18:40:17 +00:00
|
|
|
handler = logging.FileHandler(
|
|
|
|
filename=os.path.join(args.archive_dir, 'results.log'),
|
|
|
|
)
|
|
|
|
formatter = logging.Formatter(
|
|
|
|
fmt='%(asctime)s.%(msecs)03d %(levelname)s:%(message)s',
|
|
|
|
datefmt='%Y-%m-%dT%H:%M:%S',
|
|
|
|
)
|
|
|
|
handler.setFormatter(formatter)
|
|
|
|
logging.getLogger().addHandler(handler)
|
|
|
|
|
|
|
|
try:
|
|
|
|
_results(args)
|
|
|
|
except:
|
|
|
|
log.exception('error generating results')
|
|
|
|
raise
|
|
|
|
|
|
|
|
def _results(args):
|
2011-08-26 00:11:33 +00:00
|
|
|
running_tests = [
|
|
|
|
f for f in sorted(os.listdir(args.archive_dir))
|
2012-03-19 21:16:14 +00:00
|
|
|
if not f.startswith('.')
|
|
|
|
and os.path.isdir(os.path.join(args.archive_dir, f))
|
2011-08-26 00:11:33 +00:00
|
|
|
and not os.path.exists(os.path.join(args.archive_dir, f, 'summary.yaml'))
|
|
|
|
]
|
|
|
|
starttime = time.time()
|
2012-03-19 18:31:33 +00:00
|
|
|
log.info('Waiting up to %d seconds for tests to finish...', args.timeout)
|
2011-08-26 00:11:33 +00:00
|
|
|
while running_tests and args.timeout > 0:
|
|
|
|
if os.path.exists(os.path.join(
|
|
|
|
args.archive_dir,
|
|
|
|
running_tests[-1], 'summary.yaml')):
|
|
|
|
running_tests.pop()
|
|
|
|
else:
|
|
|
|
if time.time() - starttime > args.timeout:
|
|
|
|
log.warn('test(s) did not finish before timeout of %d seconds',
|
|
|
|
args.timeout)
|
|
|
|
break
|
|
|
|
time.sleep(10)
|
2012-03-19 18:31:33 +00:00
|
|
|
log.info('Tests finished! gathering results...')
|
2011-08-26 00:11:33 +00:00
|
|
|
|
2011-08-29 19:42:45 +00:00
|
|
|
descriptions = []
|
2011-08-26 00:11:33 +00:00
|
|
|
failures = []
|
2011-10-04 00:00:45 +00:00
|
|
|
num_failures = 0
|
2011-08-26 00:11:33 +00:00
|
|
|
unfinished = []
|
2011-10-04 00:05:33 +00:00
|
|
|
passed = []
|
|
|
|
all_jobs = sorted(os.listdir(args.archive_dir))
|
|
|
|
for j in all_jobs:
|
2012-03-19 21:16:14 +00:00
|
|
|
job_dir = os.path.join(args.archive_dir, j)
|
|
|
|
if j.startswith('.') or not os.path.isdir(job_dir):
|
2011-08-26 00:11:33 +00:00
|
|
|
continue
|
2012-03-19 21:16:14 +00:00
|
|
|
summary_fn = os.path.join(job_dir, 'summary.yaml')
|
2011-08-26 00:11:33 +00:00
|
|
|
if not os.path.exists(summary_fn):
|
|
|
|
unfinished.append(j)
|
|
|
|
continue
|
|
|
|
summary = {}
|
|
|
|
with file(summary_fn) as f:
|
|
|
|
g = yaml.safe_load_all(f)
|
|
|
|
for new in g:
|
|
|
|
summary.update(new)
|
2012-02-20 21:38:06 +00:00
|
|
|
desc = '{test}: ({duration}s) {desc}'.format(
|
2012-03-20 14:48:45 +00:00
|
|
|
duration=int(summary.get('duration', 0)),
|
2011-08-29 19:42:45 +00:00
|
|
|
desc=summary['description'],
|
|
|
|
test=j,
|
|
|
|
)
|
|
|
|
descriptions.append(desc)
|
2011-10-04 00:05:33 +00:00
|
|
|
if summary['success']:
|
|
|
|
passed.append(desc)
|
|
|
|
else:
|
2011-08-29 19:42:45 +00:00
|
|
|
failures.append(desc)
|
2011-10-04 00:00:45 +00:00
|
|
|
num_failures += 1
|
|
|
|
if 'failure_reason' in summary:
|
|
|
|
failures.append(' {reason}'.format(
|
|
|
|
reason=summary['failure_reason'],
|
|
|
|
))
|
2011-08-29 19:42:45 +00:00
|
|
|
|
|
|
|
if failures or unfinished:
|
2011-10-04 00:05:33 +00:00
|
|
|
subject = ('{num_failed} failed, {num_hung} possibly hung, '
|
|
|
|
'and {num_passed} passed tests in {suite}'.format(
|
|
|
|
num_failed=num_failures,
|
|
|
|
num_hung=len(unfinished),
|
|
|
|
num_passed=len(passed),
|
|
|
|
suite=args.name,
|
|
|
|
))
|
2011-08-29 19:42:45 +00:00
|
|
|
body = """
|
2011-08-26 00:11:33 +00:00
|
|
|
The following tests failed:
|
|
|
|
|
|
|
|
{failures}
|
|
|
|
|
|
|
|
These tests may be hung (did not finish in {timeout} seconds after the last test in the suite):
|
2011-10-04 00:05:33 +00:00
|
|
|
{unfinished}
|
|
|
|
|
|
|
|
These tests passed:
|
|
|
|
{passed}""".format(
|
2011-08-26 00:11:33 +00:00
|
|
|
failures='\n'.join(failures),
|
|
|
|
unfinished='\n'.join(unfinished),
|
2011-10-04 00:05:33 +00:00
|
|
|
passed='\n'.join(passed),
|
2011-08-26 00:11:33 +00:00
|
|
|
timeout=args.timeout,
|
2011-08-29 19:42:45 +00:00
|
|
|
)
|
|
|
|
else:
|
2012-10-06 00:33:57 +00:00
|
|
|
subject = 'All {num_passed} tests passed in {suite}!'.format(suite=args.name, num_passed=len(passed))
|
2011-08-29 19:42:45 +00:00
|
|
|
body = '\n'.join(descriptions)
|
|
|
|
|
2012-03-15 23:21:33 +00:00
|
|
|
try:
|
|
|
|
if args.email:
|
|
|
|
email_results(
|
|
|
|
subject=subject,
|
|
|
|
from_=args.teuthology_config['results_sending_email'],
|
|
|
|
to=args.email,
|
|
|
|
body=body,
|
|
|
|
)
|
|
|
|
finally:
|
|
|
|
generate_coverage(args)
|