2011-06-16 01:07:18 +00:00
|
|
|
import contextlib
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
from teuthology import misc as teuthology
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def task(ctx, config):
|
|
|
|
"""
|
|
|
|
Mount/unmount a ``kernel`` client.
|
|
|
|
|
2011-06-16 23:07:59 +00:00
|
|
|
The config is optional and defaults to mounting on all clients. If
|
|
|
|
a config is given, it is expected to be a list of clients to do
|
|
|
|
this operation on. This lets you e.g. set up one client with
|
2011-09-23 15:57:18 +00:00
|
|
|
``ceph-fuse`` and another with ``kclient``.
|
2011-06-16 01:07:18 +00:00
|
|
|
|
2011-06-16 23:51:57 +00:00
|
|
|
Example that mounts all clients::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- kclient:
|
|
|
|
- interactive:
|
|
|
|
|
2012-10-09 00:08:41 +00:00
|
|
|
Example that uses both ``kclient` and ``ceph-fuse``::
|
2011-06-16 23:51:57 +00:00
|
|
|
|
2011-06-16 01:07:18 +00:00
|
|
|
tasks:
|
|
|
|
- ceph:
|
2012-10-09 00:08:41 +00:00
|
|
|
- ceph-fuse: [client.0]
|
2011-06-16 01:07:18 +00:00
|
|
|
- kclient: [client.1]
|
|
|
|
- interactive:
|
|
|
|
"""
|
|
|
|
log.info('Mounting kernel clients...')
|
2011-06-16 23:07:59 +00:00
|
|
|
assert config is None or isinstance(config, list), \
|
|
|
|
"task kclient got invalid config"
|
2011-06-16 01:07:18 +00:00
|
|
|
|
2011-06-16 23:07:59 +00:00
|
|
|
if config is None:
|
|
|
|
config = ['client.{id}'.format(id=id_)
|
|
|
|
for id_ in teuthology.all_roles_of_type(ctx.cluster, 'client')]
|
2011-08-09 20:23:58 +00:00
|
|
|
clients = list(teuthology.get_clients(ctx=ctx, roles=config))
|
2011-06-16 23:07:59 +00:00
|
|
|
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
|
|
|
|
2011-06-16 23:07:59 +00:00
|
|
|
for id_, remote in clients:
|
2013-01-23 20:37:39 +00:00
|
|
|
mnt = os.path.join(testdir, 'mnt.{id}'.format(id=id_))
|
2011-08-04 22:03:05 +00:00
|
|
|
log.info('Mounting kclient client.{id} at {remote} {mnt}...'.format(
|
|
|
|
id=id_, remote=remote, mnt=mnt))
|
|
|
|
|
|
|
|
# figure mon ips
|
2011-06-16 01:07:18 +00:00
|
|
|
remotes_and_roles = ctx.cluster.remotes.items()
|
2011-08-04 17:41:50 +00:00
|
|
|
roles = [roles for (remote_, roles) in remotes_and_roles]
|
|
|
|
ips = [host for (host, port) in (remote_.ssh.get_transport().getpeername() for (remote_, roles) in remotes_and_roles)]
|
2011-06-16 01:07:18 +00:00
|
|
|
mons = teuthology.get_mons(roles, ips).values()
|
2011-08-04 22:03:05 +00:00
|
|
|
|
2013-02-17 05:30:57 +00:00
|
|
|
keyring = '/etc/ceph/ceph.client.{id}.keyring'.format(id=id_)
|
2013-01-23 20:37:39 +00:00
|
|
|
secret = '{tdir}/data/client.{id}.secret'.format(tdir=testdir, id=id_)
|
2013-02-17 05:30:57 +00:00
|
|
|
teuthology.write_secret_file(ctx, remote, 'client.{id}'.format(id=id_),
|
|
|
|
keyring, secret)
|
2011-06-16 01:07:18 +00:00
|
|
|
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'mkdir',
|
|
|
|
'--',
|
|
|
|
mnt,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'sudo',
|
2013-01-23 20:37:39 +00:00
|
|
|
'{tdir}/enable-coredump'.format(tdir=testdir),
|
2013-02-06 19:16:52 +00:00
|
|
|
'ceph-coverage',
|
2013-01-23 20:37:39 +00:00
|
|
|
'{tdir}/archive/coverage'.format(tdir=testdir),
|
2013-02-06 19:16:52 +00:00
|
|
|
'/sbin/mount.ceph',
|
2011-06-16 01:07:18 +00:00
|
|
|
'{mons}:/'.format(mons=','.join(mons)),
|
|
|
|
mnt,
|
|
|
|
'-v',
|
|
|
|
'-o',
|
|
|
|
'name={id},secretfile={secret}'.format(id=id_,
|
|
|
|
secret=secret),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
log.info('Unmounting kernel clients...')
|
2011-06-16 23:07:59 +00:00
|
|
|
for id_, remote in clients:
|
|
|
|
log.debug('Unmounting client client.{id}...'.format(id=id_))
|
2013-01-23 20:37:39 +00:00
|
|
|
mnt = os.path.join(testdir, 'mnt.{id}'.format(id=id_))
|
2011-06-16 01:07:18 +00:00
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'sudo',
|
|
|
|
'umount',
|
|
|
|
mnt,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'rmdir',
|
|
|
|
'--',
|
|
|
|
mnt,
|
|
|
|
],
|
|
|
|
)
|