]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Add rbd -> /dev mapping method.
authorJosh Durgin <josh.durgin@dreamhost.com>
Thu, 9 Jun 2011 18:47:52 +0000 (11:47 -0700)
committerTommi Virtanen <tommi.virtanen@dreamhost.com>
Wed, 22 Jun 2011 23:03:57 +0000 (16:03 -0700)
teuthology/task/rbd.py

index 0bae7f9accd49b2737ddbf86cf4cb78a267a3e3e..092e342eea7e37276db49e724038bec37e071328 100644 (file)
@@ -1,6 +1,9 @@
 import contextlib
 import logging
 
+from orchestra import run
+from teuthology import misc as teuthology
+
 log = logging.getLogger(__name__)
 
 def default_image_name(role):
@@ -108,6 +111,99 @@ def modprobe(ctx, config):
                     ],
                 )
 
+@contextlib.contextmanager
+def dev_create(ctx, config):
+    """
+    Map block devices to rbd images.
+
+    For example::
+
+        tasks:
+        - ceph:
+        - rbd.create_image: [client.0]
+        - rbd.modprobe: [client.0]
+        - rbd.dev_create:
+            client.0: testimage.client.0
+    """
+    assert isinstance(config, dict) or isinstance(config, list), \
+        "task dev_create only supports a list or dictionary for configuration"
+
+    if isinstance(config, dict):
+        role_images = config.items()
+    else:
+        role_images = [(role, None) for role in config]
+
+    for role, image in role_images:
+        if image is None:
+            image = default_image_name(role)
+        (remote,) = ctx.cluster.only(role).remotes.keys()
+
+        # add udev rule for creating /dev/rbd/pool/image
+        remote.run(
+            args=[
+                'echo',
+                'KERNEL=="rbd[0-9]*", PROGRAM="/tmp/cephtest/binary/usr/local/bin/crbdnamer %n", SYMLINK+="rbd/%c{1}/%c{2}"',
+                run.Raw('>'),
+                '/tmp/cephtest/51-rbd.rules',
+                ],
+            )
+        remote.run(
+            args=[
+                'sudo',
+                'mv',
+                '/tmp/cephtest/51-rbd.rules',
+                '/etc/udev/rules.d',
+                ],
+            )
+
+        secretfile = '/tmp/cephtest/data/{role}.secret'.format(role=role)
+        teuthology.write_secret_file(remote, role, secretfile)
+
+        remote.run(
+            args=[
+                'sudo',
+                'LD_LIBRARY_PATH=/tmp/cephtest/binary/usr/local/lib',
+                '/tmp/cephtest/binary/usr/local/bin/ceph-coverage',
+                '/tmp/cephtest/archive/coverage',
+                '/tmp/cephtest/binary/usr/local/bin/rbd',
+                '-c', '/tmp/cephtest/ceph.conf',
+                '--user', role.rsplit('.')[-1],
+                '--secret', secretfile,
+                '-p', 'rbd',
+                'map',
+                image,
+                ],
+            )
+    try:
+        yield
+    finally:
+        log.info('Unmapping rbd devices...')
+        for role, image in role_images:
+            if image is None:
+                image = default_image_name(role)
+            (remote,) = ctx.cluster.only(role).remotes.keys()
+            remote.run(
+                args=[
+                    'sudo',
+                    'LD_LIBRARY_PATH=/tmp/cephtest/binary/usr/local/lib',
+                    '/tmp/cephtest/binary/usr/local/bin/ceph-coverage',
+                    '/tmp/cephtest/archive/coverage',
+                    '/tmp/cephtest/binary/usr/local/bin/rbd',
+                    '-c', '/tmp/cephtest/ceph.conf',
+                    '-p', 'rbd',
+                    'unmap',
+                    '/dev/rbd/rbd/{imgname}'.format(imgname=image),
+                    ],
+                )
+            remote.run(
+                args=[
+                    'sudo',
+                    'rm',
+                    '/etc/udev/rules.d/51-rbd.rules',
+                    ],
+                wait=False,
+                )
+
 @contextlib.contextmanager
 def task(ctx, config):
     create_image(ctx, config)