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 | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 3 | |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 4 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 5 | from wally.ssh_utils import run_over_ssh, copy_paths |
| 6 | |
| 7 | |
| 8 | class TestResults(object): |
| 9 | def __init__(self, config, params, results, |
koder aka kdanilov | bb5fe07 | 2015-05-21 02:50:23 +0300 | [diff] [blame^] | 10 | raw_result, run_interval, vm_count, test_name=None): |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 11 | self.config = config |
| 12 | self.params = params |
| 13 | self.results = results |
| 14 | self.raw_result = raw_result |
| 15 | self.run_interval = run_interval |
| 16 | self.vm_count = vm_count |
koder aka kdanilov | bb5fe07 | 2015-05-21 02:50:23 +0300 | [diff] [blame^] | 17 | self.test_name = test_name |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 18 | |
| 19 | def __str__(self): |
| 20 | res = "{0}({1}):\n results:\n".format( |
| 21 | self.__class__.__name__, |
| 22 | self.summary()) |
| 23 | |
| 24 | for name, val in self.results.items(): |
| 25 | res += " {0}={1}\n".format(name, val) |
| 26 | |
| 27 | res += " params:\n" |
| 28 | |
| 29 | for name, val in self.params.items(): |
| 30 | res += " {0}={1}\n".format(name, val) |
| 31 | |
| 32 | return res |
| 33 | |
| 34 | @abc.abstractmethod |
| 35 | def summary(self): |
| 36 | pass |
| 37 | |
| 38 | @abc.abstractmethod |
| 39 | def get_yamable(self): |
| 40 | pass |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 41 | |
| 42 | |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 43 | class IPerfTest(object): |
koder aka kdanilov | abd6ead | 2015-04-24 02:03:07 +0300 | [diff] [blame] | 44 | 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] | 45 | total_nodes_count, |
koder aka kdanilov | 2066daf | 2015-04-23 21:05:41 +0300 | [diff] [blame] | 46 | log_directory=None, |
| 47 | coordination_queue=None, |
| 48 | remote_dir="/tmp/wally"): |
koder aka kdanilov | abd6ead | 2015-04-24 02:03:07 +0300 | [diff] [blame] | 49 | self.options = options |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 50 | self.on_result_cb = on_result_cb |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 51 | self.log_directory = log_directory |
| 52 | self.node = node |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 53 | self.test_uuid = test_uuid |
koder aka kdanilov | ec1b973 | 2015-04-23 20:43:29 +0300 | [diff] [blame] | 54 | self.coordination_queue = coordination_queue |
koder aka kdanilov | 2066daf | 2015-04-23 21:05:41 +0300 | [diff] [blame] | 55 | self.remote_dir = remote_dir |
koder aka kdanilov | abd6ead | 2015-04-24 02:03:07 +0300 | [diff] [blame] | 56 | self.is_primary = is_primary |
koder aka kdanilov | e2de58c | 2015-04-24 22:59:36 +0300 | [diff] [blame] | 57 | self.stop_requested = False |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 58 | self.total_nodes_count = total_nodes_count |
koder aka kdanilov | e2de58c | 2015-04-24 22:59:36 +0300 | [diff] [blame] | 59 | |
| 60 | def request_stop(self): |
| 61 | self.stop_requested = True |
koder aka kdanilov | 2066daf | 2015-04-23 21:05:41 +0300 | [diff] [blame] | 62 | |
| 63 | def join_remote(self, path): |
| 64 | return os.path.join(self.remote_dir, path) |
koder aka kdanilov | ec1b973 | 2015-04-23 20:43:29 +0300 | [diff] [blame] | 65 | |
| 66 | def coordinate(self, data): |
| 67 | if self.coordination_queue is not None: |
koder aka kdanilov | e2de58c | 2015-04-24 22:59:36 +0300 | [diff] [blame] | 68 | self.coordination_queue.put((self.node.get_conn_id(), data)) |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 69 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 70 | def pre_run(self): |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 71 | pass |
| 72 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 73 | def cleanup(self): |
koder aka kdanilov | 4500a5f | 2015-04-17 16:55:17 +0300 | [diff] [blame] | 74 | pass |
| 75 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 76 | @classmethod |
| 77 | @abc.abstractmethod |
| 78 | def load(cls, data): |
| 79 | pass |
| 80 | |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 81 | @abc.abstractmethod |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 82 | def run(self, barrier): |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 83 | pass |
| 84 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 85 | @classmethod |
| 86 | def format_for_console(cls, data): |
| 87 | msg = "{0}.format_for_console".format(cls.__name__) |
| 88 | raise NotImplementedError(msg) |
| 89 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 90 | def run_over_ssh(self, cmd, **kwargs): |
| 91 | return run_over_ssh(self.node.connection, cmd, |
| 92 | node=self.node.get_conn_id(), **kwargs) |
| 93 | |
koder aka kdanilov | ec1b973 | 2015-04-23 20:43:29 +0300 | [diff] [blame] | 94 | @classmethod |
| 95 | def coordination_th(cls, coord_q, barrier, num_threads): |
| 96 | pass |
| 97 | |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 98 | |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 99 | class TwoScriptTest(IPerfTest): |
koder aka kdanilov | abd6ead | 2015-04-24 02:03:07 +0300 | [diff] [blame] | 100 | def __init__(self, *dt, **mp): |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 101 | IPerfTest.__init__(self, *dt, **mp) |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 102 | |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 103 | if 'scripts_path' in self.options: |
| 104 | self.root = self.options['scripts_path'] |
koder aka kdanilov | abd6ead | 2015-04-24 02:03:07 +0300 | [diff] [blame] | 105 | self.run_script = self.options['run_script'] |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 106 | self.prerun_script = self.options['prerun_script'] |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 107 | |
| 108 | def get_remote_for_script(self, script): |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 109 | return os.path.join(self.remote_dir, script.rpartition('/')[2]) |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 110 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 111 | def pre_run(self): |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 112 | copy_paths(self.node.connection, {self.root: self.remote_dir}) |
| 113 | cmd = self.get_remote_for_script(self.pre_run_script) |
| 114 | self.run_over_ssh(cmd, timeout=2000) |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 115 | |
koder aka kdanilov | 4d4771c | 2015-04-23 01:32:02 +0300 | [diff] [blame] | 116 | def run(self, barrier): |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 117 | remote_script = self.get_remote_for_script(self.run_script) |
Yulia Portnova | 886a256 | 2015-04-07 11:16:13 +0300 | [diff] [blame] | 118 | cmd_opts = ' '.join(["%s %s" % (key, val) for key, val |
koder aka kdanilov | abd6ead | 2015-04-24 02:03:07 +0300 | [diff] [blame] | 119 | in self.options.items()]) |
Yulia Portnova | 886a256 | 2015-04-07 11:16:13 +0300 | [diff] [blame] | 120 | cmd = remote_script + ' ' + cmd_opts |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 121 | out_err = self.run_over_ssh(cmd, timeout=6000) |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 122 | self.on_result(out_err, cmd) |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 123 | |
| 124 | def parse_results(self, out): |
| 125 | for line in out.split("\n"): |
| 126 | key, separator, value = line.partition(":") |
| 127 | if key and value: |
| 128 | self.on_result_cb((key, float(value))) |
| 129 | |
koder aka kdanilov | 66839a9 | 2015-04-11 13:22:31 +0300 | [diff] [blame] | 130 | def on_result(self, out_err, cmd): |
| 131 | try: |
| 132 | self.parse_results(out_err) |
| 133 | except Exception as exc: |
koder aka kdanilov | ec1b973 | 2015-04-23 20:43:29 +0300 | [diff] [blame] | 134 | msg_templ = "Error during postprocessing results: {0!s}. {1}" |
| 135 | raise RuntimeError(msg_templ.format(exc, out_err)) |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 136 | |
Yulia Portnova | b1a1507 | 2015-05-06 14:59:25 +0300 | [diff] [blame] | 137 | def merge_results(self, results): |
| 138 | tpcm = sum([val[1] for val in results]) |
| 139 | return {"res": {"TpmC": tpcm}} |