summaryrefslogtreecommitdiffstats
path: root/qa/tasks/populate_rbd_pool.py
blob: 76395eb688f16e120f6974c78bbb8e00568f814e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
Populate rbd pools
"""
import contextlib
import logging

log = logging.getLogger(__name__)

@contextlib.contextmanager
def task(ctx, config):
    """
    Populate <num_pools> pools with prefix <pool_prefix> with <num_images>
    rbd images at <num_snaps> snaps

    The config could be as follows::

        populate_rbd_pool:
          client: <client>
          pool_prefix: foo
          num_pools: 5
          num_images: 10
          num_snaps: 3
          image_size: 10737418240
    """
    if config is None:
        config = {}
    client = config.get("client", "client.0")
    pool_prefix = config.get("pool_prefix", "foo")
    num_pools = config.get("num_pools", 2)
    num_images = config.get("num_images", 20)
    num_snaps = config.get("num_snaps", 4)
    image_size = config.get("image_size", 100)
    write_size = config.get("write_size", 1024*1024)
    write_threads = config.get("write_threads", 10)
    write_total_per_snap = config.get("write_total_per_snap", 1024*1024*30)

    (remote,) = ctx.cluster.only(client).remotes.keys()

    for poolid in range(num_pools):
        poolname = "%s-%s" % (pool_prefix, str(poolid))
        log.info("Creating pool %s" % (poolname,))
        ctx.managers['ceph'].create_pool(poolname)
        for imageid in range(num_images):
            imagename = "rbd-%s" % (str(imageid),)
            log.info("Creating imagename %s" % (imagename,))
            remote.run(
                args = [
                    "rbd",
                    "create",
                    imagename,
                    "--image-format", "1",
                    "--size", str(image_size),
                    "--pool", str(poolname)])
            def bench_run():
                remote.run(
                    args = [
                        "rbd",
                        "bench-write",
                        imagename,
                        "--pool", poolname,
                        "--io-size", str(write_size),
                        "--io-threads", str(write_threads),
                        "--io-total", str(write_total_per_snap),
                        "--io-pattern", "rand"])
            log.info("imagename %s first bench" % (imagename,))
            bench_run()
            for snapid in range(num_snaps):
                snapname = "snap-%s" % (str(snapid),)
                log.info("imagename %s creating snap %s" % (imagename, snapname))
                remote.run(
                    args = [
                        "rbd", "snap", "create",
                        "--pool", poolname,
                        "--snap", snapname,
                        imagename
                        ])
                bench_run()

    try:
        yield
    finally:
        log.info('done')