]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Add rbd task with create_image function.
authorJosh Durgin <josh.durgin@dreamhost.com>
Thu, 9 Jun 2011 18:46:04 +0000 (11:46 -0700)
committerTommi Virtanen <tommi.virtanen@dreamhost.com>
Wed, 22 Jun 2011 23:03:56 +0000 (16:03 -0700)
teuthology/ceph.conf
teuthology/task/rbd.py [new file with mode: 0644]

index 0b25a7f95853f847ab9da884ff4f3906b8e588e6..851530325b1cff44d38d0d59ca8b80792535fb34 100644 (file)
@@ -27,6 +27,7 @@
         osd journal = /tmp/cephtest/data/osd.$id.journal
         osd journal size = 100
         keyring = /tmp/cephtest/data/osd.$id.keyring
+        osd class dir = /tmp/cephtest/binary/usr/local/lib/rados-classes
 
 [mds]
         lockdep = 1
diff --git a/teuthology/task/rbd.py b/teuthology/task/rbd.py
new file mode 100644 (file)
index 0000000..5c9289b
--- /dev/null
@@ -0,0 +1,77 @@
+import contextlib
+import logging
+
+log = logging.getLogger(__name__)
+
+def default_image_name(role):
+    return 'testimage.{role}'.format(role=role)
+
+@contextlib.contextmanager
+def create_image(ctx, config):
+    """
+    Create an rbd image.
+
+    For example::
+
+        tasks:
+        - ceph:
+        - rbd.create_image:
+            client.0:
+                image_name: testimage
+                image_size: 100
+            client.1:
+    """
+    assert isinstance(config, dict) or isinstance(config, list), \
+        "task create_image only supports a list or dictionary for configuration"
+
+    if isinstance(config, dict):
+        images = config.items()
+    else:
+        images = [(role, None) for role in config]
+
+    for role, properties in images:
+        if properties is None:
+            properties = {}
+        name = properties.get('image_name', default_image_name(role))
+        size = properties.get('image_size', 1024)
+        (remote,) = ctx.cluster.only(role).remotes.keys()
+        log.info('Creating image {name} with size {size}'.format(name=name,
+                                                                 size=size))
+        remote.run(
+            args=[
+                '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',
+                'create',
+                '-s', str(size),
+                name,
+                ],
+            )
+    try:
+        yield
+    finally:
+        log.info('Deleting rbd images...')
+        for role, properties in images:
+            if properties is None:
+                properties = {}
+            name = properties.get('image_name', default_image_name(role))
+            (remote,) = ctx.cluster.only(role).remotes.keys()
+            remote.run(
+                args=[
+                    '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',
+                    'rm',
+                    name,
+                    ],
+                )
+
+@contextlib.contextmanager
+def task(ctx, config):
+    create_image(ctx, config)