blob: 7b2c3e3e5ed7542ed44256eff90352a2277dead3 [file] [log] [blame]
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +02001import array
koder aka kdanilovbc2c8982015-06-13 02:50:43 +03002import os.path
3import logging
koder aka kdanilov7f59d562016-12-26 01:34:23 +02004from typing import cast, Any
koder aka kdanilovbc2c8982015-06-13 02:50:43 +03005
koder aka kdanilov6ab4d432015-06-22 00:26:28 +03006import wally
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +03007
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +02008from ...utils import StopTestError, get_os, ssize2b
koder aka kdanilov70227062016-11-26 23:23:21 +02009from ...node_interfaces import IRPCNode
koder aka kdanilovf2865172016-12-30 03:35:11 +020010from ..itest import ThreadedTest
11from ...result_classes import TimeSeries, JobMetrics
12from .fio_task_parser import execution_time, fio_cfg_compile, FioJobConfig, FioParams, get_log_files
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +020013from . import rpc_plugin
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +020014from .fio_hist import expected_lat_bins
koder aka kdanilov7f59d562016-12-26 01:34:23 +020015
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030016
17logger = logging.getLogger("wally")
18
19
koder aka kdanilov70227062016-11-26 23:23:21 +020020class IOPerfTest(ThreadedTest):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030021 soft_runcycle = 5 * 60
Michael Semenov8ba6e232015-08-28 10:57:18 +000022 retry_time = 30
koder aka kdanilov70227062016-11-26 23:23:21 +020023 configs_dir = os.path.dirname(__file__) # type: str
koder aka kdanilov7f59d562016-12-26 01:34:23 +020024 name = 'fio'
koder aka kdanilovf2865172016-12-30 03:35:11 +020025 job_config_cls = FioJobConfig
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030026
koder aka kdanilov70227062016-11-26 23:23:21 +020027 def __init__(self, *args, **kwargs) -> None:
28 super().__init__(*args, **kwargs)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030029
30 get = self.config.params.get
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030031
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +020032 self.remote_task_file = self.join_remote("task.fio")
33 self.remote_output_file = self.join_remote("fio_result.json")
34 self.use_system_fio = get('use_system_fio', False) # type: bool
35 self.use_sudo = get("use_sudo", True) # type: bool
36 self.force_prefill = get('force_prefill', False) # type: bool
37
koder aka kdanilov70227062016-11-26 23:23:21 +020038 self.load_profile_name = self.config.params['load'] # type: str
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030039
koder aka kdanilov70227062016-11-26 23:23:21 +020040 if os.path.isfile(self.load_profile_name):
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +020041 self.load_profile_path = self.load_profile_name # type: str
koder aka kdanilov6ab4d432015-06-22 00:26:28 +030042 else:
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +020043 self.load_profile_path = os.path.join(self.configs_dir, self.load_profile_name+ '.cfg')
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030044
koder aka kdanilov70227062016-11-26 23:23:21 +020045 self.load_profile = open(self.load_profile_path, 'rt').read() # type: str
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030046
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030047 if self.use_system_fio:
koder aka kdanilov70227062016-11-26 23:23:21 +020048 self.fio_path = "fio" # type: str
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030049 else:
koder aka kdanilov70227062016-11-26 23:23:21 +020050 self.fio_path = os.path.join(self.config.remote_dir, "fio")
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030051
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +020052 self.load_params = self.config.params['params']
53 self.file_name = self.load_params['FILENAME']
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030054
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +020055 if 'FILESIZE' not in self.load_params:
56 logger.debug("Getting test file sizes on all nodes")
57 try:
58 sizes = {node.conn.fs.file_stat(self.file_name)['size']
59 for node in self.config.nodes}
60 except Exception:
61 logger.exception("FILESIZE is not set in config file and fail to detect it." +
62 "Set FILESIZE or fix error and rerun test")
63 raise StopTestError()
koder aka kdanilova94dfe12015-08-19 13:04:51 +030064
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +020065 if len(sizes) != 1:
66 logger.error("IO target file %r has different sizes on test nodes - %r",
67 self.file_name, sizes)
68 raise StopTestError()
koder aka kdanilova94dfe12015-08-19 13:04:51 +030069
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +020070 self.file_size = list(sizes)[0]
71 logger.info("Detected test file size is %s", self.file_size)
72 self.load_params['FILESIZE'] = self.file_size
73 else:
74 self.file_size = ssize2b(self.load_params['FILESIZE'])
koder aka kdanilov70227062016-11-26 23:23:21 +020075
koder aka kdanilovf2865172016-12-30 03:35:11 +020076 self.job_configs = list(fio_cfg_compile(self.load_profile, self.load_profile_path,
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +020077 cast(FioParams, self.load_params)))
koder aka kdanilov70227062016-11-26 23:23:21 +020078
koder aka kdanilovf2865172016-12-30 03:35:11 +020079 if len(self.job_configs) == 0:
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +020080 logger.error("Empty fio config provided")
81 raise StopTestError()
koder aka kdanilov70227062016-11-26 23:23:21 +020082
koder aka kdanilov70227062016-11-26 23:23:21 +020083 self.exec_folder = self.config.remote_dir
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030084
koder aka kdanilov70227062016-11-26 23:23:21 +020085 def config_node(self, node: IRPCNode) -> None:
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +020086 plugin_code = open(rpc_plugin.__file__.rsplit(".", 1)[0] + ".py", "rb").read() # type: bytes
87 node.upload_plugin("fio", plugin_code)
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +020088
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030089 try:
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +020090 node.conn.fs.rmtree(self.config.remote_dir)
91 except Exception:
92 pass
93
94 try:
95 node.conn.fs.makedirs(self.config.remote_dir)
96 except Exception:
97 msg = "Failed to recreate folder {} on remote {}.".format(self.config.remote_dir, node)
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +030098 logger.exception(msg)
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +020099 raise StopTestError()
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300100
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +0300101 self.install_utils(node)
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +0200102
103 mb = int(self.file_size / 1024 ** 2)
104 logger.info("Filling test file %s with %sMiB of random data", self.file_name, mb)
105 fill_bw = node.conn.fio.fill_file(self.file_name, mb, force=self.force_prefill, fio_path=self.fio_path)
koder aka kdanilov70227062016-11-26 23:23:21 +0200106 if fill_bw is not None:
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +0200107 logger.info("Initial fio fill bw is {} MiBps for {}".format(fill_bw, node))
108
koder aka kdanilov70227062016-11-26 23:23:21 +0200109 def install_utils(self, node: IRPCNode) -> None:
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +0200110 os_info = get_os(node)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300111 if self.use_system_fio:
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +0200112 if os_info.distro != 'ubuntu':
113 logger.error("Only ubuntu supported on test VM")
114 raise StopTestError()
115 node.conn.fio.install('fio', binary='fio')
116 else:
117 node.conn.fio.install('bzip2', binary='bzip2')
koder aka kdanilov70227062016-11-26 23:23:21 +0200118 fio_dir = os.path.dirname(os.path.dirname(wally.__file__)) # type: str
119 fio_dir = os.path.join(os.getcwd(), fio_dir)
120 fio_dir = os.path.join(fio_dir, 'fio_binaries')
121 fname = 'fio_{0.release}_{0.arch}.bz2'.format(os_info)
122 fio_path = os.path.join(fio_dir, fname) # type: str
123
124 if not os.path.exists(fio_path):
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +0200125 logger.error("No prebuild fio binary available for {0}".format(os_info))
126 raise StopTestError()
koder aka kdanilov70227062016-11-26 23:23:21 +0200127
128 bz_dest = self.join_remote('fio.bz2') # type: str
129 node.copy_file(fio_path, bz_dest)
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +0200130 node.run("bzip2 --decompress {} ; chmod a+x {}".format(bz_dest, self.join_remote("fio")))
koder aka kdanilov70227062016-11-26 23:23:21 +0200131
koder aka kdanilovf2865172016-12-30 03:35:11 +0200132 def get_expected_runtime(self, job_config: FioJobConfig) -> int:
133 return execution_time(cast(FioJobConfig, job_config))
koder aka kdanilov70227062016-11-26 23:23:21 +0200134
koder aka kdanilovf2865172016-12-30 03:35:11 +0200135 def prepare_iteration(self, node: IRPCNode, job_config: FioJobConfig) -> None:
136 node.put_to_file(self.remote_task_file, str(job_config).encode("utf8"))
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +0200137
138 # TODO: get a link to substorage as a parameter
koder aka kdanilovf2865172016-12-30 03:35:11 +0200139 def run_iteration(self, node: IRPCNode, iter_config: FioJobConfig, job_root: str) -> JobMetrics:
140 f_iter_config = cast(FioJobConfig, iter_config)
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200141 exec_time = execution_time(f_iter_config)
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +0200142
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +0200143 fio_cmd_templ = "cd {exec_folder}; " + \
144 "{fio_path} --output-format=json --output={out_file} --alloc-size=262144 {job_file}"
145
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +0200146 cmd = fio_cmd_templ.format(exec_folder=self.exec_folder,
147 fio_path=self.fio_path,
148 out_file=self.remote_output_file,
149 job_file=self.remote_task_file)
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +0200150 must_be_empty = node.run(cmd, timeout=exec_time + max(300, exec_time), check_timeout=1).strip()
koder aka kdanilovbbbe1dc2016-12-20 01:19:56 +0200151
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +0200152 if must_be_empty:
153 logger.error("Unexpected fio output: %r", must_be_empty)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300154
koder aka kdanilovf2865172016-12-30 03:35:11 +0200155 res = {} # type: JobMetrics
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +0200156
koder aka kdanilovf2865172016-12-30 03:35:11 +0200157 # put fio output into storage
158 fio_out = node.get_file_content(self.remote_output_file)
159 self.rstorage.put_extra(job_root, node.info.node_id(), "fio_raw", fio_out)
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +0200160 node.conn.fs.unlink(self.remote_output_file)
161
162 files = [name for name in node.conn.fs.listdir(self.exec_folder)]
163
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200164 for name, path in get_log_files(f_iter_config):
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +0200165 log_files = [fname for fname in files if fname.startswith(path)]
166 if len(log_files) != 1:
167 logger.error("Found %s files, match log pattern %s(%s) - %s",
168 len(log_files), path, name, ",".join(log_files[10:]))
169 raise StopTestError()
170
171 fname = os.path.join(self.exec_folder, log_files[0])
172 raw_result = node.get_file_content(fname) # type: bytes
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +0200173 node.conn.fs.unlink(fname)
174
175 try:
176 log_data = raw_result.decode("utf8").split("\n")
177 except UnicodeEncodeError:
178 logger.exception("Error during parse %s fio log file - can't decode usint UTF8", name)
179 raise StopTestError()
180
181 parsed = array.array('L' if name == 'lat' else 'Q')
koder aka kdanilovf2865172016-12-30 03:35:11 +0200182 times = array.array('Q')
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +0200183
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +0200184 for idx, line in enumerate(log_data):
185 line = line.strip()
186 if line:
187 try:
188 time_ms_s, val_s, _, *rest = line.split(",")
koder aka kdanilovf2865172016-12-30 03:35:11 +0200189 times.append(int(time_ms_s.strip()))
koder aka kdanilovffaf48d2016-12-27 02:25:29 +0200190
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +0200191 if name == 'lat':
192 vals = [int(i.strip()) for i in rest]
193
194 if len(vals) != expected_lat_bins:
195 logger.error("Expect {} bins in latency histogram, but found {} at time {}"
196 .format(expected_lat_bins, len(vals), time_ms_s))
197 raise StopTestError()
198
199 parsed.extend(vals)
200 else:
201 parsed.append(int(val_s.strip()))
202 except ValueError:
203 logger.exception("Error during parse %s fio log file in line %s: %r", name, idx, line)
204 raise StopTestError()
koder aka kdanilovffaf48d2016-12-27 02:25:29 +0200205
koder aka kdanilovf2865172016-12-30 03:35:11 +0200206 ts = TimeSeries(name=name,
207 raw=raw_result,
208 second_axis_size=expected_lat_bins if name == 'lat' else 1,
209 data=parsed,
210 times=times)
211 res[(node.info.node_id(), 'fio', name)] = ts
koder aka kdanilov23e6bdf2016-12-24 02:18:54 +0200212
213 return res
koder aka kdanilov7f59d562016-12-26 01:34:23 +0200214
215 def format_for_console(self, data: Any) -> str:
216 raise NotImplementedError()