blob: 04176b683815c531d76b824597f4f955a2f31383 [file] [log] [blame]
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -08001import os
2import sys
3import json
4import time
5import pprint
6import os.path
7import argparse
8
9import io_scenario
10from itest import IOPerfTest
11from log import setlogger
12
13import ssh_runner
14import rally_runner
15
16from starts_vms import nova_connect, create_vms_mt, clear_all
17
18
19def run_io_test(tool,
20 script_args,
21 test_runner,
22 keep_temp_files=False):
23
24 files_dir = os.path.dirname(io_scenario.__file__)
25
26 path = 'iozone' if 'iozone' == tool else 'fio'
27 src_testtool_path = os.path.join(files_dir, path)
28
29 obj = IOPerfTest(script_args,
30 src_testtool_path,
31 None,
32 keep_temp_files)
33
34 return test_runner(obj)
35
36
37def parse_args(argv):
38 parser = argparse.ArgumentParser(
39 description="Run disk io performance test")
40
41 parser.add_argument("tool_type", help="test tool type",
42 choices=['iozone', 'fio'])
43
44 parser.add_argument("-l", dest='extra_logs',
45 action='store_true', default=False,
46 help="print some extra log info")
47
48 parser.add_argument("-o", "--io-opts", dest='io_opts',
49 required=True,
50 help="cmd line options for io.py")
51
52 parser.add_argument("-t", "--test-directory", help="directory with test",
53 dest="test_directory", required=True)
54
55 parser.add_argument("--max-preparation-time", default=300,
56 type=int, dest="max_preparation_time")
57
58 parser.add_argument("-k", "--keep", default=False,
59 help="keep temporary files",
60 dest="keep_temp_files", action='store_true')
61
62 parser.add_argument("--runner", required=True,
63 choices=["ssh", "rally"],
64 help="runner type")
65
66 parser.add_argument("--runner-extra-opts", default="",
67 dest="runner_opts", help="runner extra options")
68
69 return parser.parse_args(argv)
70
71
72def main(argv):
73 opts = parse_args(argv)
74
75 if not opts.extra_logs:
76 def nolog(x):
77 pass
78
79 setlogger(nolog)
80
81 script_args = [opt.strip()
82 for opt in opts.io_opts.split(" ")
83 if opt.strip() != ""]
84
85 if opts.runner == "rally":
86 runner = rally_runner.get_rally_runner(
87 files_dir=os.path.dirname(io_scenario.__file__),
88 rally_extra_opts=opts.runner_opts.split(" "),
89 max_preparation_time=opts.max_preparation_time,
90 keep_temp_files=opts.keep_temp_files)
91 res = run_io_test(opts.tool_type,
92 script_args,
93 runner,
94 opts.keep_temp_files)
95 elif opts.runner == "ssh":
96 user, key_file = opts.runner_opts.split(" ", 1)
97
98 latest_start_time = opts.max_preparation_time + time.time()
99
100 nova = nova_connect()
101
102 # nova, amount, keypair_name, img_name,
103 # flavor_name, vol_sz=None, network_zone_name=None,
104 # flt_ip_pool=None, name_templ='ceph-test-{}',
105 # scheduler_hints=None
106
107 try:
108 ips = [i[0] for i in create_vms_mt(nova, 3,
109 keypair_name='ceph',
110 img_name='ubuntu',
111 flavor_name='ceph.512',
112 network_zone_name='net04',
113 flt_ip_pool='net04_ext')]
114
115 uris = ["{0}@{1}::{2}".format(user, ip, key_file) for ip in ips]
116
117 runner = ssh_runner.get_ssh_runner(uris,
118 latest_start_time,
119 opts.keep_temp_files)
120 res = run_io_test(opts.tool_type,
121 script_args,
122 runner,
123 opts.keep_temp_files)
124 finally:
125 clear_all(nova)
126
127 print "=" * 80
128 print pprint.pformat(res)
129 print "=" * 80
130
131 if len(res) != 0:
132 bw_mean = 0.0
133 for measurement in res:
134 bw_mean += measurement["bw_mean"]
135
136 bw_mean /= len(res)
137
138 it = ((bw_mean - measurement["bw_mean"]) ** 2 for measurement in res)
139 bw_dev = sum(it) ** 0.5
140
141 meta = res[0]['__meta__']
142 key = "{0} {1} {2}k".format(meta['action'],
143 's' if meta['sync'] else 'a',
144 meta['blocksize'])
145
146 print
147 print "====> " + json.dumps({key: (int(bw_mean), int(bw_dev))})
148 print
149 print "=" * 80
150
151 return 0
152
153
154ostack_prepare = """
155glance image-create --name 'ubuntu' --disk-format qcow2
156--container-format bare --is-public true --copy-from
157https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
158
159nova flavor-create ceph.512 ceph.512 512 50 1
160nova server-group-create --policy anti-affinity ceph
161"""
162
163
164if __name__ == '__main__':
165 exit(main(sys.argv[1:]))