~juju-qa/juju-ci-tools/trunk

« back to all changes in this revision

Viewing changes to perfscale_longrunning.py

  • Committer: Christopher Lee
  • Date: 2016-10-26 04:59:52 UTC
  • mfrom: (1689 trunk)
  • mto: This revision was merged to the branch mainline in revision 1698.
  • Revision ID: chris.lee@canonical.com-20161026045952-g0l8ba05nmo5a638
Merge trunk. Fix conflict issues.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import argparse
 
4
from datetime import datetime
 
5
import sys
 
6
import time
 
7
import logging
 
8
 
 
9
from assess_recovery import deploy_stack
 
10
from deploy_stack import (
 
11
    BootstrapManager,
 
12
)
 
13
from generate_perfscale_results import (
 
14
    _convert_seconds_to_readable,
 
15
    DeployDetails,
 
16
    MINUTE,
 
17
    TimingData,
 
18
    run_perfscale_test,
 
19
)
 
20
from utility import (
 
21
    add_basic_testing_arguments,
 
22
    configure_logging,
 
23
    until_timeout,
 
24
)
 
25
 
 
26
 
 
27
__metaclass__ = type
 
28
 
 
29
 
 
30
total_new_models = 0
 
31
 
 
32
log = logging.getLogger("perfscale_longrunning")
 
33
 
 
34
 
 
35
class Rest:
 
36
    short = MINUTE * 1
 
37
    medium = MINUTE * 30
 
38
    long = MINUTE * 60
 
39
    really_long = MINUTE * 120
 
40
 
 
41
 
 
42
def perfscale_longrun_perf(client, args):
 
43
    test_length = args.run_length * (60 * MINUTE)
 
44
    longrun_start = datetime.utcnow()
 
45
    run_count = 0
 
46
    for _ in until_timeout(test_length):
 
47
        applications = ['dummy-sink']
 
48
        new_client = action_create(client)
 
49
        new_models = action_busy(new_client, applications)
 
50
        action_cleanup(new_client, new_models)
 
51
 
 
52
        action_rest(Rest.short/2)
 
53
        run_count += 1
 
54
 
 
55
    longrun_end = datetime.utcnow()
 
56
    timing_data = TimingData(longrun_start, longrun_end)
 
57
    return DeployDetails(
 
58
        'Longrun for {} Hours.'.format(test_length/60/60),
 
59
        {'Total action runs': run_count},
 
60
        timing_data
 
61
    )
 
62
 
 
63
 
 
64
def action_create(client, series='trusty'):
 
65
    start = datetime.utcnow()
 
66
    new_model = client.add_model(client.env.clone('newmodel'))
 
67
    deploy_stack(new_model, series)
 
68
    end = datetime.utcnow()
 
69
    log.info('Create action took: {}'.format(
 
70
        _convert_seconds_to_readable(int((end - start).total_seconds()))))
 
71
    return new_model
 
72
 
 
73
 
 
74
def action_busy(client, applications):
 
75
    start = datetime.utcnow()
 
76
 
 
77
    for app in applications:
 
78
        client.juju('add-unit', (app, '-n', '1'))
 
79
        client.wait_for_started(timeout=1200)
 
80
        client.wait_for_workloads(timeout=1200)
 
81
 
 
82
    global total_new_models
 
83
    new_models = []
 
84
    for i in range(0, 20):
 
85
        total_new_models += 1
 
86
        new_model_name = 'model{}'.format(total_new_models)
 
87
        new_model = client.add_model(client.env.clone(new_model_name))
 
88
        new_model.wait_for_started()
 
89
        log.info('Added model number {}'.format(total_new_models))
 
90
        new_models.append(new_model)
 
91
 
 
92
    for _ in until_timeout(MINUTE*2):
 
93
        log.info('Checking status ping.')
 
94
        client.show_status()
 
95
        log.info('Sleeping . . .')
 
96
        time.sleep(MINUTE/2)
 
97
    end = datetime.utcnow()
 
98
 
 
99
    log.info('Create action took: {}'.format(
 
100
        _convert_seconds_to_readable(int((end - start).total_seconds()))))
 
101
 
 
102
    return new_models
 
103
 
 
104
 
 
105
def action_cleanup(client, new_models):
 
106
    client.destroy_model()
 
107
    for model in new_models:
 
108
        model.destroy_model()
 
109
 
 
110
 
 
111
def action_rest(rest_length=Rest.short):
 
112
    log.info('Resting for {} seconds'.format(rest_length))
 
113
    time.sleep(rest_length)
 
114
 
 
115
 
 
116
def parse_args(argv):
 
117
    """Parse all arguments."""
 
118
    parser = argparse.ArgumentParser(
 
119
        description="Perfscale longrunning test.")
 
120
    add_basic_testing_arguments(parser)
 
121
    parser.add_argument(
 
122
        '--run-length',
 
123
        help='Length of time (in hours) to run the test',
 
124
        type=int,
 
125
        default=12)
 
126
    return parser.parse_args(argv)
 
127
 
 
128
 
 
129
def main(argv=None):
 
130
    args = parse_args(argv)
 
131
    configure_logging(args.verbose)
 
132
    bs_manager = BootstrapManager.from_args(args)
 
133
    run_perfscale_test(perfscale_longrun_perf, bs_manager, args)
 
134
 
 
135
    return 0
 
136
 
 
137
if __name__ == '__main__':
 
138
    sys.exit(main())