summaryrefslogtreecommitdiff
path: root/scripts/scalability/test_controller/server/blobs.py
blob: 2e68a12ee1b81f7cc46166b4233d9fb2a8398ff8 (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
#!/usr/bin/env python

import shutil
import os
from argparse import ArgumentParser
from twisted.logger import Logger
from test_controller.utils import mkdir_p, payload

logger = Logger()


def _create_blob(path, data):
    with open(path, 'w') as f:
        logger.info('Creating %s' % path)
        f.write(data)


def create_blobs(target_dir, amount, size):
    delete_blobs(target_dir)
    data = payload(size * 1000)
    for i in xrange(amount):
        istr = str(i)
        blob_dir = '%s/%s/%s' % (istr[0], istr[0:3], istr[0:6])
        basedir = os.path.join(target_dir, '0/default/%s' % blob_dir)
        mkdir_p(basedir)
        _create_blob(os.path.join(basedir, str(i)), data)


def delete_blobs(target_dir):
    if not os.path.isdir(target_dir):
        return
    for f in os.listdir(target_dir):
        if f.isdigit():
            directory = os.path.join(target_dir, f)
            logger.info('Deleting %s' % directory)
            shutil.rmtree(directory)


def parse_args():
    parser = ArgumentParser()
    parser.add_argument(
        'target_dir',
        help='The target directory where templates will be written to.')
    parser.add_argument(
        '--amount', default=1000, type=int,
        help='The amount of users to create blobs to.')
    parser.add_argument(
        '--size', default=1000, type=int,
        help='The size of each template in KB.')
    return parser.parse_args()


if __name__ == '__main__':
    args = parse_args()
    create_blobs(args.target_dir, args.amount, args.size * 1000)