test: create /tmp/cephtest/mnt.{id}

The workunit task assumes that a mount exists
at /tmp/cephtest/mnt.{id}
This patch creates the path if it doesn't
exist, enabling workunits to run in the absense
of kclient or ceph-fuse tasks.

Signed-off-by: Joe Buck <jbbuck@gmail.com>
Reviewed-by:  Sam Lang <sam.lang@inktank.com>
This commit is contained in:
Joe Buck 2013-01-14 12:09:56 -08:00
parent 98cc1b835c
commit b6e3edc6d8

View File

@ -66,6 +66,8 @@ def task(ctx, config):
log.info('Pulling workunits from ref %s', refspec)
created_dir_dict = {}
if config.get('env') is not None:
assert isinstance(config['env'], dict), 'env must be a dictionary'
clients = config['clients']
@ -76,7 +78,9 @@ def task(ctx, config):
continue
PREFIX = 'client.'
assert role.startswith(PREFIX)
_make_scratch_dir(ctx, role, config.get('subdir'))
created_mnt_dir = _make_scratch_dir(ctx, role, config.get('subdir'))
created_dir_dict[role] = created_mnt_dir
all_spec = False #is there an all grouping?
with parallel() as p:
for role, tests in clients.iteritems():
@ -89,32 +93,110 @@ def task(ctx, config):
all_tasks = clients["all"]
_spawn_on_all_clients(ctx, refspec, all_tasks, config.get('env'), config.get('subdir'))
for role in clients.iterkeys():
assert isinstance(role, basestring)
if role == "all":
continue
PREFIX = 'client.'
assert role.startswith(PREFIX)
if created_dir_dict[role]:
_delete_dir(ctx, role, config.get('subdir'))
def _delete_dir(ctx, role, subdir):
PREFIX = 'client.'
id_ = role[len(PREFIX):]
(remote,) = ctx.cluster.only(role).remotes.iterkeys()
mnt = os.path.join('/tmp/cephtest', 'mnt.{id}'.format(id=id_))
client = os.path.join(mnt, 'client.{id}'.format(id=id_))
try:
remote.run(
args=[
'rm',
'-rf',
'--',
client,
],
)
log.info("Deleted dir {dir}".format(dir=client))
except:
log.debug("Caught an execption deleting dir {dir}".format(dir=client))
try:
remote.run(
args=[
'rmdir',
'--',
mnt,
],
)
log.info("Deleted dir {dir}".format(dir=mnt))
except:
log.debug("Caught an execption deleting dir {dir}".format(dir=mnt))
def _make_scratch_dir(ctx, role, subdir):
retVal = False
PREFIX = 'client.'
id_ = role[len(PREFIX):]
log.debug("getting remote for {id} role {role_}".format(id=id_, role_=role))
(remote,) = ctx.cluster.only(role).remotes.iterkeys()
dir_owner = remote.shortname.split('@', 1)[0]
mnt = os.path.join('/tmp/cephtest', 'mnt.{id}'.format(id=id_))
# if neither kclient nor ceph-fuse are required for a workunit,
# mnt may not exist. Stat and create the directory if it doesn't.
try:
proc = remote.run(
args=[
'stat',
'--',
mnt,
],
)
log.info('Did not need to create dir {dir}'.format(dir=mnt))
except:
proc = remote.run(
args=[
'mkdir',
'--',
mnt,
],
)
log.info('Created dir {dir}'.format(dir=mnt))
retVal = True
if not subdir: subdir = 'client.{id}'.format(id=id_)
remote.run(
args=[
# cd first so this will fail if the mount point does
# not exist; pure install -d will silently do the
# wrong thing
'cd',
'--',
mnt,
run.Raw('&&'),
'sudo',
'install',
'-d',
'-m', '0755',
'--owner={user}'.format(user=dir_owner),
'--',
subdir,
],
)
if retVal:
remote.run(
args=[
'cd',
'--',
mnt,
run.Raw('&&'),
'mkdir',
'--',
subdir,
],
)
else:
remote.run(
args=[
# cd first so this will fail if the mount point does
# not exist; pure install -d will silently do the
# wrong thing
'cd',
'--',
mnt,
run.Raw('&&'),
'sudo',
'install',
'-d',
'-m', '0755',
'--owner={user}'.format(user=dir_owner),
'--',
subdir,
],
)
return retVal
def _spawn_on_all_clients(ctx, refspec, tests, env, subdir):
client_generator = teuthology.all_roles_of_type(ctx.cluster, 'client')