From: Josh Durgin Date: Thu, 16 Jun 2011 23:41:29 +0000 (-0700) Subject: Add rbd.mount method. X-Git-Tag: v0.94.10~27^2^2~364^2~1693 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=789de09f8b0b9349da489a2f8f2ffaaaefdf6920;p=ceph.git Add rbd.mount method. --- diff --git a/teuthology/task/rbd.py b/teuthology/task/rbd.py index 479d4fd6c982..06995acf530b 100644 --- a/teuthology/task/rbd.py +++ b/teuthology/task/rbd.py @@ -243,6 +243,76 @@ def mkfs(ctx, config): ) yield +@contextlib.contextmanager +def mount(ctx, config): + """ + Mount an rbd image. + + For example:: + + tasks: + - ceph: + - rbd.create_image: [client.0] + - rbd.modprobe: [client.0] + - rbd.mkfs: [client.0] + - rbd.mount: + client.0: testimage.client.0 + """ + assert isinstance(config, list) or isinstance(config, dict), \ + "task mount must be configured with a list or dictionary" + if isinstance(config, dict): + role_images = config.items() + else: + role_images = [(role, None) for role in config] + + mnt_template = '/tmp/cephtest/mnt.{role}' + for role, image in role_images: + if image is None: + image = default_image_name(role) + (remote,) = ctx.cluster.only(role).remotes.keys() + mnt = mnt_template.format(role=role) + remote.run( + args=[ + 'mkdir', + '--', + mnt, + ] + ) + + remote.run( + args=[ + 'sudo', + 'mount', + '/dev/rbd/rbd/{image}'.format(image=image), + mnt, + ], + ) + + try: + yield + finally: + log.info("Unmounting rbd images...") + for role, image in role_images: + if image is None: + image = default_image_name(role) + (remote,) = ctx.cluster.only(role).remotes.keys() + mnt = mnt_template.format(role=role) + remote.run( + args=[ + 'sudo', + 'umount', + mnt, + ], + ) + + remote.run( + args=[ + 'rmdir', + '--', + mnt, + ] + ) + @contextlib.contextmanager def task(ctx, config): create_image(ctx, config)