blob: 4be7eede9776ffd0ad79fb8b7c963fbeb397e8f5 [file] [log] [blame]
koder aka kdanilov4643fd62015-02-10 16:20:13 -08001import abc
koder aka kdanilov4643fd62015-02-10 16:20:13 -08002import os.path
koder aka kdanilov652cd802015-04-13 12:21:07 +03003
koder aka kdanilov4643fd62015-02-10 16:20:13 -08004
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +03005from wally.ssh_utils import run_over_ssh, copy_paths
6
7
8class TestResults(object):
9 def __init__(self, config, params, results,
koder aka kdanilovbb5fe072015-05-21 02:50:23 +030010 raw_result, run_interval, vm_count, test_name=None):
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030011 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 kdanilovbb5fe072015-05-21 02:50:23 +030017 self.test_name = test_name
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030018
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 kdanilove21d7472015-02-14 19:02:04 -080041
42
koder aka kdanilov4643fd62015-02-10 16:20:13 -080043class IPerfTest(object):
koder aka kdanilovabd6ead2015-04-24 02:03:07 +030044 def __init__(self, options, is_primary, on_result_cb, test_uuid, node,
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030045 total_nodes_count,
koder aka kdanilov2066daf2015-04-23 21:05:41 +030046 log_directory=None,
47 coordination_queue=None,
48 remote_dir="/tmp/wally"):
koder aka kdanilovabd6ead2015-04-24 02:03:07 +030049 self.options = options
koder aka kdanilov4643fd62015-02-10 16:20:13 -080050 self.on_result_cb = on_result_cb
koder aka kdanilov4500a5f2015-04-17 16:55:17 +030051 self.log_directory = log_directory
52 self.node = node
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030053 self.test_uuid = test_uuid
koder aka kdanilovec1b9732015-04-23 20:43:29 +030054 self.coordination_queue = coordination_queue
koder aka kdanilov2066daf2015-04-23 21:05:41 +030055 self.remote_dir = remote_dir
koder aka kdanilovabd6ead2015-04-24 02:03:07 +030056 self.is_primary = is_primary
koder aka kdanilove2de58c2015-04-24 22:59:36 +030057 self.stop_requested = False
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030058 self.total_nodes_count = total_nodes_count
koder aka kdanilove2de58c2015-04-24 22:59:36 +030059
60 def request_stop(self):
61 self.stop_requested = True
koder aka kdanilov2066daf2015-04-23 21:05:41 +030062
63 def join_remote(self, path):
64 return os.path.join(self.remote_dir, path)
koder aka kdanilovec1b9732015-04-23 20:43:29 +030065
66 def coordinate(self, data):
67 if self.coordination_queue is not None:
koder aka kdanilove2de58c2015-04-24 22:59:36 +030068 self.coordination_queue.put((self.node.get_conn_id(), data))
koder aka kdanilov4643fd62015-02-10 16:20:13 -080069
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030070 def pre_run(self):
koder aka kdanilov4643fd62015-02-10 16:20:13 -080071 pass
72
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030073 def cleanup(self):
koder aka kdanilov4500a5f2015-04-17 16:55:17 +030074 pass
75
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030076 @classmethod
77 @abc.abstractmethod
78 def load(cls, data):
79 pass
80
koder aka kdanilov4643fd62015-02-10 16:20:13 -080081 @abc.abstractmethod
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030082 def run(self, barrier):
koder aka kdanilov4643fd62015-02-10 16:20:13 -080083 pass
84
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030085 @classmethod
86 def format_for_console(cls, data):
87 msg = "{0}.format_for_console".format(cls.__name__)
88 raise NotImplementedError(msg)
89
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030090 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 kdanilovec1b9732015-04-23 20:43:29 +030094 @classmethod
95 def coordination_th(cls, coord_q, barrier, num_threads):
96 pass
97
koder aka kdanilov4643fd62015-02-10 16:20:13 -080098
Yulia Portnova7ddfa732015-02-24 17:32:58 +020099class TwoScriptTest(IPerfTest):
koder aka kdanilovabd6ead2015-04-24 02:03:07 +0300100 def __init__(self, *dt, **mp):
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300101 IPerfTest.__init__(self, *dt, **mp)
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200102
Yulia Portnovab1a15072015-05-06 14:59:25 +0300103 if 'scripts_path' in self.options:
104 self.root = self.options['scripts_path']
koder aka kdanilovabd6ead2015-04-24 02:03:07 +0300105 self.run_script = self.options['run_script']
Yulia Portnovab1a15072015-05-06 14:59:25 +0300106 self.prerun_script = self.options['prerun_script']
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200107
108 def get_remote_for_script(self, script):
Yulia Portnovab1a15072015-05-06 14:59:25 +0300109 return os.path.join(self.remote_dir, script.rpartition('/')[2])
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200110
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300111 def pre_run(self):
Yulia Portnovab1a15072015-05-06 14:59:25 +0300112 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 Portnova7ddfa732015-02-24 17:32:58 +0200115
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300116 def run(self, barrier):
Yulia Portnovab1a15072015-05-06 14:59:25 +0300117 remote_script = self.get_remote_for_script(self.run_script)
Yulia Portnova886a2562015-04-07 11:16:13 +0300118 cmd_opts = ' '.join(["%s %s" % (key, val) for key, val
koder aka kdanilovabd6ead2015-04-24 02:03:07 +0300119 in self.options.items()])
Yulia Portnova886a2562015-04-07 11:16:13 +0300120 cmd = remote_script + ' ' + cmd_opts
Yulia Portnovab1a15072015-05-06 14:59:25 +0300121 out_err = self.run_over_ssh(cmd, timeout=6000)
koder aka kdanilov66839a92015-04-11 13:22:31 +0300122 self.on_result(out_err, cmd)
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200123
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 kdanilov66839a92015-04-11 13:22:31 +0300130 def on_result(self, out_err, cmd):
131 try:
132 self.parse_results(out_err)
133 except Exception as exc:
koder aka kdanilovec1b9732015-04-23 20:43:29 +0300134 msg_templ = "Error during postprocessing results: {0!s}. {1}"
135 raise RuntimeError(msg_templ.format(exc, out_err))
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200136
Yulia Portnovab1a15072015-05-06 14:59:25 +0300137 def merge_results(self, results):
138 tpcm = sum([val[1] for val in results])
139 return {"res": {"TpmC": tpcm}}