koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 1 | import abc |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 2 | import os.path |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 3 | import functools |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 4 | |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 5 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 6 | from wally.ssh_utils import run_over_ssh, copy_paths |
| 7 | |
| 8 | |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 9 | def cached_prop(func): |
| 10 | @property |
| 11 | @functools.wraps(func) |
| 12 | def closure(self): |
| 13 | val = getattr(self, "_" + func.__name__) |
| 14 | if val is NoData: |
| 15 | val = func(self) |
| 16 | setattr(self, "_" + func.__name__, val) |
| 17 | return val |
| 18 | return closure |
| 19 | |
| 20 | |
| 21 | class NoData(object): |
| 22 | pass |
| 23 | |
| 24 | |
| 25 | class VMThData(object): |
| 26 | "store set of values for VM_COUNT * TH_COUNT" |
| 27 | |
| 28 | |
| 29 | class IOTestResult(object): |
| 30 | def __init__(self): |
| 31 | self.run_config = None |
| 32 | self.suite_config = None |
| 33 | self.run_interval = None |
| 34 | |
| 35 | self.bw = None |
| 36 | self.lat = None |
| 37 | self.iops = None |
| 38 | self.slat = None |
| 39 | self.clat = None |
| 40 | |
| 41 | self.fio_section = None |
| 42 | |
| 43 | self._lat_log = NoData |
| 44 | self._iops_log = NoData |
| 45 | self._bw_log = NoData |
| 46 | |
| 47 | self._sensors_data = NoData |
| 48 | self._raw_resuls = NoData |
| 49 | |
| 50 | def to_jsonable(self): |
| 51 | pass |
| 52 | |
| 53 | @property |
| 54 | def thread_count(self): |
| 55 | pass |
| 56 | |
| 57 | @property |
| 58 | def sync_mode(self): |
| 59 | pass |
| 60 | |
| 61 | @property |
| 62 | def abbrev_name(self): |
| 63 | pass |
| 64 | |
| 65 | @property |
| 66 | def full_name(self): |
| 67 | pass |
| 68 | |
| 69 | @cached_prop |
| 70 | def lat_log(self): |
| 71 | pass |
| 72 | |
| 73 | @cached_prop |
| 74 | def iops_log(self): |
| 75 | pass |
| 76 | |
| 77 | @cached_prop |
| 78 | def bw_log(self): |
| 79 | pass |
| 80 | |
| 81 | @cached_prop |
| 82 | def sensors_data(self): |
| 83 | pass |
| 84 | |
| 85 | @cached_prop |
| 86 | def raw_resuls(self): |
| 87 | pass |
| 88 | |
| 89 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 90 | class TestResults(object): |
| 91 | def __init__(self, config, params, results, |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 92 | raw_result, run_interval, vm_count, |
| 93 | test_name, **attrs): |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 94 | self.config = config |
| 95 | self.params = params |
| 96 | self.results = results |
| 97 | self.raw_result = raw_result |
| 98 | self.run_interval = run_interval |
| 99 | self.vm_count = vm_count |
koder aka kdanilov | bb5fe07 | 2015-05-21 02:50:23 +0300 | [diff] [blame] | 100 | self.test_name = test_name |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 101 | self.__dict__.update(attrs) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 102 | |
| 103 | def __str__(self): |
| 104 | res = "{0}({1}):\n results:\n".format( |
| 105 | self.__class__.__name__, |
| 106 | self.summary()) |
| 107 | |
| 108 | for name, val in self.results.items(): |
| 109 | res += " {0}={1}\n".format(name, val) |
| 110 | |
| 111 | res += " params:\n" |
| 112 | |
| 113 | for name, val in self.params.items(): |
| 114 | res += " {0}={1}\n".format(name, val) |
| 115 | |
| 116 | return res |
| 117 | |
| 118 | @abc.abstractmethod |
| 119 | def summary(self): |
| 120 | pass |
| 121 | |
| 122 | @abc.abstractmethod |
| 123 | def get_yamable(self): |
| 124 | pass |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 125 | |
| 126 | |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 127 | class IPerfTest(object): |
koder aka kdanilov | abd6ead | 2015-04-24 02:03:07 +0300 | [diff] [blame] | 128 | def __init__(self, options, is_primary, on_result_cb, test_uuid, node, |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 129 | total_nodes_count, |
koder aka kdanilov | 2066daf | 2015-04-23 21:05:41 +0300 | [diff] [blame] | 130 | log_directory=None, |
| 131 | coordination_queue=None, |
| 132 | remote_dir="/tmp/wally"): |
koder aka kdanilov | abd6ead | 2015-04-24 02:03:07 +0300 | [diff] [blame] | 133 | self.options = options |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 134 | self.on_result_cb = on_result_cb |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 135 | self.log_directory = log_directory |
| 136 | self.node = node |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 137 | self.test_uuid = test_uuid |
koder aka kdanilov | ec1b973 | 2015-04-23 20:43:29 +0300 | [diff] [blame] | 138 | self.coordination_queue = coordination_queue |
koder aka kdanilov | 2066daf | 2015-04-23 21:05:41 +0300 | [diff] [blame] | 139 | self.remote_dir = remote_dir |
koder aka kdanilov | abd6ead | 2015-04-24 02:03:07 +0300 | [diff] [blame] | 140 | self.is_primary = is_primary |
koder aka kdanilov | e2de58c | 2015-04-24 22:59:36 +0300 | [diff] [blame] | 141 | self.stop_requested = False |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 142 | self.total_nodes_count = total_nodes_count |
koder aka kdanilov | e2de58c | 2015-04-24 22:59:36 +0300 | [diff] [blame] | 143 | |
| 144 | def request_stop(self): |
| 145 | self.stop_requested = True |
koder aka kdanilov | 2066daf | 2015-04-23 21:05:41 +0300 | [diff] [blame] | 146 | |
| 147 | def join_remote(self, path): |
| 148 | return os.path.join(self.remote_dir, path) |
koder aka kdanilov | ec1b973 | 2015-04-23 20:43:29 +0300 | [diff] [blame] | 149 | |
| 150 | def coordinate(self, data): |
| 151 | if self.coordination_queue is not None: |
koder aka kdanilov | e2de58c | 2015-04-24 22:59:36 +0300 | [diff] [blame] | 152 | self.coordination_queue.put((self.node.get_conn_id(), data)) |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 153 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 154 | def pre_run(self): |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 155 | pass |
| 156 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 157 | def cleanup(self): |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 158 | pass |
| 159 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 160 | @classmethod |
| 161 | @abc.abstractmethod |
| 162 | def load(cls, data): |
| 163 | pass |
| 164 | |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 165 | @abc.abstractmethod |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 166 | def run(self, barrier): |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 167 | pass |
| 168 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 169 | @classmethod |
| 170 | def format_for_console(cls, data): |
| 171 | msg = "{0}.format_for_console".format(cls.__name__) |
| 172 | raise NotImplementedError(msg) |
| 173 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 174 | def run_over_ssh(self, cmd, **kwargs): |
| 175 | return run_over_ssh(self.node.connection, cmd, |
| 176 | node=self.node.get_conn_id(), **kwargs) |
| 177 | |
koder aka kdanilov | ec1b973 | 2015-04-23 20:43:29 +0300 | [diff] [blame] | 178 | @classmethod |
| 179 | def coordination_th(cls, coord_q, barrier, num_threads): |
| 180 | pass |
| 181 | |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 182 | |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 183 | class TwoScriptTest(IPerfTest): |
koder aka kdanilov | abd6ead | 2015-04-24 02:03:07 +0300 | [diff] [blame] | 184 | def __init__(self, *dt, **mp): |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 185 | IPerfTest.__init__(self, *dt, **mp) |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 186 | |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 187 | if 'scripts_path' in self.options: |
| 188 | self.root = self.options['scripts_path'] |
koder aka kdanilov | abd6ead | 2015-04-24 02:03:07 +0300 | [diff] [blame] | 189 | self.run_script = self.options['run_script'] |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 190 | self.prerun_script = self.options['prerun_script'] |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 191 | |
| 192 | def get_remote_for_script(self, script): |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 193 | return os.path.join(self.remote_dir, script.rpartition('/')[2]) |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 194 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 195 | def pre_run(self): |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 196 | copy_paths(self.node.connection, {self.root: self.remote_dir}) |
| 197 | cmd = self.get_remote_for_script(self.pre_run_script) |
| 198 | self.run_over_ssh(cmd, timeout=2000) |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 199 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 200 | def run(self, barrier): |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 201 | remote_script = self.get_remote_for_script(self.run_script) |
Yulia Portnova | 886a256 | 2015-04-07 11:16:13 +0300 | [diff] [blame] | 202 | cmd_opts = ' '.join(["%s %s" % (key, val) for key, val |
koder aka kdanilov | abd6ead | 2015-04-24 02:03:07 +0300 | [diff] [blame] | 203 | in self.options.items()]) |
Yulia Portnova | 886a256 | 2015-04-07 11:16:13 +0300 | [diff] [blame] | 204 | cmd = remote_script + ' ' + cmd_opts |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 205 | out_err = self.run_over_ssh(cmd, timeout=6000) |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 206 | self.on_result(out_err, cmd) |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 207 | |
| 208 | def parse_results(self, out): |
| 209 | for line in out.split("\n"): |
| 210 | key, separator, value = line.partition(":") |
| 211 | if key and value: |
| 212 | self.on_result_cb((key, float(value))) |
| 213 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 214 | def on_result(self, out_err, cmd): |
| 215 | try: |
| 216 | self.parse_results(out_err) |
| 217 | except Exception as exc: |
koder aka kdanilov | ec1b973 | 2015-04-23 20:43:29 +0300 | [diff] [blame] | 218 | msg_templ = "Error during postprocessing results: {0!s}. {1}" |
| 219 | raise RuntimeError(msg_templ.format(exc, out_err)) |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 220 | |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 221 | def merge_results(self, results): |
| 222 | tpcm = sum([val[1] for val in results]) |
| 223 | return {"res": {"TpmC": tpcm}} |