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