~andrewjbeach/juju-ci-tools/make-local-patcher

1657.2.1 by Christopher Lee
Add mass model destruction test.
1
#!/usr/bin/env python
2
"""Perfscale test measuring adding and destroying a large number of models.
3
4
Steps taken in this test:
5
  - Bootstraps a provider
6
  - Creates x amount of models and waits for them to be ready
7
  - Delete all the models at once.
8
"""
9
10
import argparse
11
from datetime import datetime
12
import logging
13
import sys
1657.2.3 by Christopher Lee
Add work around for destroying models too quickly.
14
from time import sleep
1657.2.1 by Christopher Lee
Add mass model destruction test.
15
16
from deploy_stack import (
17
    BootstrapManager,
18
)
19
from generate_perfscale_results import (
1686.1.2 by Christopher Lee
Update deploy testing.
20
    add_basic_perfscale_arguments,
1657.2.1 by Christopher Lee
Add mass model destruction test.
21
    DeployDetails,
22
    TimingData,
23
    run_perfscale_test,
24
)
25
from utility import (
26
    configure_logging,
27
)
28
29
30
log = logging.getLogger("perfscale_mass_model_destruction")
31
32
__metaclass__ = type
33
34
35
def perfscale_assess_model_destruction(client, args):
36
    """Create a bunch of models and then destroy them all."""
37
    model_count = args.model_count
38
39
    all_models = []
40
    for item in xrange(0, model_count):
41
        model_name = 'model{}'.format(item)
42
        log.info('Creating model: {}'.format(model_name))
43
        new_model = client.add_model(client.env.clone(model_name))
44
        all_models.append(new_model)
45
1657.2.3 by Christopher Lee
Add work around for destroying models too quickly.
46
    # Workaround for bug: https://bugs.launchpad.net/juju/+bug/1635052
47
    # Noted here: https://bugs.launchpad.net/juju-ci-tools/+bug/1635109
48
    sleep(10)
1657.2.1 by Christopher Lee
Add mass model destruction test.
49
    destruction_start = datetime.utcnow()
50
    for doomed in all_models:
51
        doomed.destroy_model()
52
    destruction_end = datetime.utcnow()
53
54
    destruction_timing = TimingData(destruction_start, destruction_end)
55
    return DeployDetails(
56
        'Destroy {} models'.format(model_count),
57
        {'Model Count': model_count},
58
        destruction_timing)
59
60
61
def parse_args(argv):
62
    """Parse all arguments."""
63
    parser = argparse.ArgumentParser(
64
        description="Perfscale bundle deployment test.")
1686.1.2 by Christopher Lee
Update deploy testing.
65
    add_basic_perfscale_arguments(parser)
1657.2.1 by Christopher Lee
Add mass model destruction test.
66
    parser.add_argument(
67
        '--model-count',
1657.2.2 by Christopher Lee
Fix argument type.
68
        type=int,
1657.2.1 by Christopher Lee
Add mass model destruction test.
69
        help='Number of models to create.',
70
        default=100)
71
    return parser.parse_args(argv)
72
73
74
def main(argv=None):
75
    args = parse_args(argv)
76
    configure_logging(args.verbose)
77
    bs_manager = BootstrapManager.from_args(args)
78
    run_perfscale_test(perfscale_assess_model_destruction, bs_manager, args)
79
80
    return 0
81
82
83
if __name__ == '__main__':
84
    sys.exit(main())