From 789de09f8b0b9349da489a2f8f2ffaaaefdf6920 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Thu, 16 Jun 2011 16:41:29 -0700 Subject: [PATCH] Add rbd.mount method. --- teuthology/task/rbd.py | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/teuthology/task/rbd.py b/teuthology/task/rbd.py index 479d4fd6c9825..06995acf530be 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) -- 2.39.5