2011-06-03 21:47:44 +00:00
|
|
|
import argparse
|
2011-06-15 19:10:27 +00:00
|
|
|
import os
|
2011-06-03 21:47:44 +00:00
|
|
|
import yaml
|
|
|
|
|
|
|
|
def config_file(string):
|
|
|
|
config = {}
|
|
|
|
try:
|
|
|
|
with file(string) as f:
|
|
|
|
g = yaml.safe_load_all(f)
|
|
|
|
for new in g:
|
|
|
|
config.update(new)
|
|
|
|
except IOError, e:
|
|
|
|
raise argparse.ArgumentTypeError(str(e))
|
|
|
|
return config
|
|
|
|
|
|
|
|
class MergeConfig(argparse.Action):
|
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
|
|
|
config = getattr(namespace, self.dest)
|
|
|
|
for new in values:
|
|
|
|
config.update(new)
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
parser = argparse.ArgumentParser(description='Run ceph integration tests')
|
|
|
|
parser.add_argument(
|
|
|
|
'-v', '--verbose',
|
|
|
|
action='store_true', default=None,
|
|
|
|
help='be more verbose',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'config',
|
|
|
|
metavar='CONFFILE',
|
|
|
|
nargs='+',
|
|
|
|
type=config_file,
|
|
|
|
action=MergeConfig,
|
|
|
|
default={},
|
|
|
|
help='config file to read',
|
|
|
|
)
|
2011-06-07 21:47:30 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--archive',
|
|
|
|
metavar='DIR',
|
|
|
|
help='path to archive results in',
|
|
|
|
)
|
2011-06-28 21:15:19 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--description',
|
|
|
|
help='job description'
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--owner',
|
|
|
|
help='job owner'
|
|
|
|
)
|
2011-07-06 21:22:43 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--lock',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='lock machines for the duration of the run',
|
|
|
|
)
|
2011-07-07 23:15:18 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--block',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='block until locking machines succeeds (use with --lock)',
|
|
|
|
)
|
2011-07-11 22:48:42 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--keep-locked-on-error',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='unlock machines only if the test succeeds (use with --lock)',
|
|
|
|
)
|
2011-06-03 21:47:44 +00:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
return args
|
|
|
|
|
|
|
|
def main():
|
|
|
|
from gevent import monkey; monkey.patch_all()
|
|
|
|
from orchestra import monkey; monkey.patch_all()
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
ctx = parse_args()
|
|
|
|
|
|
|
|
loglevel = logging.INFO
|
|
|
|
if ctx.verbose:
|
|
|
|
loglevel = logging.DEBUG
|
|
|
|
|
|
|
|
logging.basicConfig(
|
|
|
|
level=loglevel,
|
|
|
|
)
|
|
|
|
|
2011-07-07 23:15:18 +00:00
|
|
|
if ctx.block:
|
|
|
|
assert ctx.lock, \
|
|
|
|
'the --block option is only supported with the --lock option'
|
2011-07-11 22:48:42 +00:00
|
|
|
if ctx.keep_locked_on_error:
|
|
|
|
assert ctx.lock, \
|
|
|
|
'the --keep_locked_on_error option is only supported with the --lock option'
|
2011-07-07 23:15:18 +00:00
|
|
|
|
2011-07-07 18:43:35 +00:00
|
|
|
from teuthology.misc import read_config
|
|
|
|
read_config(ctx)
|
|
|
|
|
2011-06-15 19:10:27 +00:00
|
|
|
if ctx.archive is not None:
|
|
|
|
os.mkdir(ctx.archive)
|
|
|
|
|
2011-06-15 19:32:22 +00:00
|
|
|
handler = logging.FileHandler(
|
|
|
|
filename=os.path.join(ctx.archive, 'teuthology.log'),
|
|
|
|
)
|
|
|
|
formatter = logging.Formatter(
|
|
|
|
fmt='%(asctime)s.%(msecs)03d %(levelname)s:%(name)s:%(message)s',
|
|
|
|
datefmt='%Y-%m-%dT%H:%M:%S',
|
|
|
|
)
|
|
|
|
handler.setFormatter(formatter)
|
|
|
|
logging.getLogger().addHandler(handler)
|
|
|
|
|
|
|
|
|
2011-06-15 19:10:27 +00:00
|
|
|
with file(os.path.join(ctx.archive, 'config.yaml'), 'w') as f:
|
|
|
|
yaml.safe_dump(ctx.config, f, default_flow_style=False)
|
|
|
|
|
2011-06-03 21:47:58 +00:00
|
|
|
log.debug('\n '.join(['Config:', ] + yaml.safe_dump(ctx.config, default_flow_style=False).splitlines()))
|
2011-06-03 21:47:44 +00:00
|
|
|
|
2011-06-16 20:01:09 +00:00
|
|
|
ctx.summary = {}
|
|
|
|
|
2011-07-06 21:22:43 +00:00
|
|
|
if ctx.owner is None:
|
2011-07-02 01:15:52 +00:00
|
|
|
from teuthology.misc import get_user
|
2011-07-06 21:22:43 +00:00
|
|
|
ctx.owner = get_user()
|
|
|
|
ctx.summary['owner'] = ctx.owner
|
2011-06-28 21:15:19 +00:00
|
|
|
|
|
|
|
if ctx.description is not None:
|
|
|
|
ctx.summary['description'] = ctx.description
|
|
|
|
|
2011-06-30 22:53:42 +00:00
|
|
|
for task in ctx.config['tasks']:
|
|
|
|
assert 'kernel' not in task, \
|
|
|
|
'kernel installation shouldn be a base-level item, not part of the tasks list'
|
|
|
|
|
2011-07-06 21:22:43 +00:00
|
|
|
init_tasks = []
|
|
|
|
if ctx.lock:
|
|
|
|
assert 'targets' not in ctx.config, \
|
|
|
|
'You cannot specify targets in a config file when using the --lock option'
|
|
|
|
init_tasks.append({'internal.lock_machines': len(ctx.config['roles'])})
|
|
|
|
|
|
|
|
init_tasks.extend([
|
|
|
|
{'internal.check_lock': None},
|
|
|
|
{'internal.connect': None},
|
|
|
|
{'internal.check_conflict': None},
|
|
|
|
])
|
2011-06-30 22:53:42 +00:00
|
|
|
if 'kernel' in ctx.config:
|
|
|
|
init_tasks.append({'kernel': ctx.config['kernel']})
|
|
|
|
init_tasks.extend([
|
|
|
|
{'internal.base': None},
|
|
|
|
{'internal.archive': None},
|
|
|
|
{'internal.coredump': None},
|
|
|
|
{'internal.syslog': None},
|
|
|
|
])
|
|
|
|
|
|
|
|
ctx.config['tasks'][:0] = init_tasks
|
2011-06-16 21:17:14 +00:00
|
|
|
|
2011-06-16 20:01:09 +00:00
|
|
|
from teuthology.run_tasks import run_tasks
|
2011-06-15 22:52:30 +00:00
|
|
|
try:
|
2011-06-16 20:01:09 +00:00
|
|
|
run_tasks(tasks=ctx.config['tasks'], ctx=ctx)
|
2011-06-15 22:52:30 +00:00
|
|
|
finally:
|
|
|
|
if ctx.archive is not None:
|
|
|
|
with file(os.path.join(ctx.archive, 'summary.yaml'), 'w') as f:
|
2011-06-16 20:01:09 +00:00
|
|
|
yaml.safe_dump(ctx.summary, f, default_flow_style=False)
|
2011-06-29 19:23:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
def nuke():
|
|
|
|
from gevent import monkey; monkey.patch_all()
|
|
|
|
from orchestra import monkey; monkey.patch_all()
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
ctx = parse_args()
|
|
|
|
|
|
|
|
loglevel = logging.INFO
|
|
|
|
if ctx.verbose:
|
|
|
|
loglevel = logging.DEBUG
|
|
|
|
|
|
|
|
logging.basicConfig(
|
|
|
|
level=loglevel,
|
|
|
|
)
|
|
|
|
|
2011-07-07 18:43:35 +00:00
|
|
|
from teuthology.misc import read_config
|
|
|
|
read_config(ctx)
|
|
|
|
|
2011-06-29 19:23:44 +00:00
|
|
|
log.info('\n '.join(['targets:', ] + yaml.safe_dump(ctx.config['targets'], default_flow_style=False).splitlines()))
|
|
|
|
|
2011-07-11 21:39:04 +00:00
|
|
|
if ctx.owner is None:
|
|
|
|
from teuthology.misc import get_user
|
|
|
|
ctx.owner = get_user()
|
|
|
|
|
2011-07-06 22:55:17 +00:00
|
|
|
from teuthology.task.internal import check_lock, connect
|
|
|
|
check_lock(ctx, None)
|
|
|
|
connect(ctx, None)
|
2011-06-29 19:23:44 +00:00
|
|
|
|
|
|
|
log.info('Killing daemons, unmounting, and removing data...')
|
|
|
|
|
2011-07-06 22:55:17 +00:00
|
|
|
from orchestra import run
|
2011-06-29 19:23:44 +00:00
|
|
|
ctx.cluster.run(
|
|
|
|
args=[
|
|
|
|
'killall',
|
|
|
|
'--quiet',
|
|
|
|
'/tmp/cephtest/binary/usr/local/bin/cmon',
|
|
|
|
'/tmp/cephtest/binary/usr/local/bin/cosd',
|
|
|
|
'/tmp/cephtest/binary/usr/local/bin/cmds',
|
|
|
|
'/tmp/cephtest/binary/usr/local/bin/cfuse',
|
|
|
|
run.Raw(';'),
|
2011-07-01 06:13:35 +00:00
|
|
|
'fusermount', '-u', run.Raw('/tmp/cephtest/mnt.*'),
|
2011-06-29 19:23:44 +00:00
|
|
|
run.Raw(';'),
|
2011-06-30 22:54:12 +00:00
|
|
|
'sudo', 'rm', '-rf', '/tmp/cephtest'
|
2011-06-29 19:23:44 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
log.info('Done.')
|
2011-07-08 18:37:20 +00:00
|
|
|
|
|
|
|
def schedule():
|
|
|
|
parser = argparse.ArgumentParser(description='Schedule ceph integration tests')
|
|
|
|
parser.add_argument(
|
|
|
|
'config',
|
|
|
|
metavar='CONFFILE',
|
|
|
|
nargs='+',
|
|
|
|
type=config_file,
|
|
|
|
action=MergeConfig,
|
|
|
|
default={},
|
|
|
|
help='config file to read',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--name',
|
|
|
|
required=True,
|
|
|
|
help='job name',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--description',
|
|
|
|
help='job description',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--owner',
|
|
|
|
help='job owner',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'-v', '--verbose',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='be more verbose',
|
|
|
|
)
|
|
|
|
|
|
|
|
ctx = parser.parse_args()
|
|
|
|
|
|
|
|
from teuthology.misc import read_config, get_user
|
|
|
|
if ctx.owner is None:
|
|
|
|
ctx.owner = get_user()
|
|
|
|
read_config(ctx)
|
|
|
|
|
|
|
|
import teuthology.queue
|
|
|
|
beanstalk = teuthology.queue.connect(ctx)
|
|
|
|
|
|
|
|
beanstalk.use('teuthology')
|
|
|
|
job = yaml.safe_dump(dict(
|
|
|
|
config=ctx.config,
|
|
|
|
name=ctx.name,
|
|
|
|
description=ctx.description,
|
|
|
|
owner=ctx.owner,
|
|
|
|
verbose=ctx.verbose,
|
|
|
|
))
|
|
|
|
jid = beanstalk.put(job, ttr=60*60*24)
|
|
|
|
print 'Job scheduled with ID {jid}'.format(jid=jid)
|