blob: 09e93f0d99b612cb1b25f4fb3bdfde967dfe1d8b [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,
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 kdanilove21d7472015-02-14 19:02:04 -080040
41
koder aka kdanilov4643fd62015-02-10 16:20:13 -080042class IPerfTest(object):
koder aka kdanilovabd6ead2015-04-24 02:03:07 +030043 def __init__(self, options, is_primary, on_result_cb, test_uuid, node,
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030044 total_nodes_count,
koder aka kdanilov2066daf2015-04-23 21:05:41 +030045 log_directory=None,
46 coordination_queue=None,
47 remote_dir="/tmp/wally"):
koder aka kdanilovabd6ead2015-04-24 02:03:07 +030048 self.options = options
koder aka kdanilov4643fd62015-02-10 16:20:13 -080049 self.on_result_cb = on_result_cb
koder aka kdanilov4500a5f2015-04-17 16:55:17 +030050 self.log_directory = log_directory
51 self.node = node
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030052 self.test_uuid = test_uuid
koder aka kdanilovec1b9732015-04-23 20:43:29 +030053 self.coordination_queue = coordination_queue
koder aka kdanilov2066daf2015-04-23 21:05:41 +030054 self.remote_dir = remote_dir
koder aka kdanilovabd6ead2015-04-24 02:03:07 +030055 self.is_primary = is_primary
koder aka kdanilove2de58c2015-04-24 22:59:36 +030056 self.stop_requested = False
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030057 self.total_nodes_count = total_nodes_count
koder aka kdanilove2de58c2015-04-24 22:59:36 +030058
59 def request_stop(self):
60 self.stop_requested = True
koder aka kdanilov2066daf2015-04-23 21:05:41 +030061
62 def join_remote(self, path):
63 return os.path.join(self.remote_dir, path)
koder aka kdanilovec1b9732015-04-23 20:43:29 +030064
65 def coordinate(self, data):
66 if self.coordination_queue is not None:
koder aka kdanilove2de58c2015-04-24 22:59:36 +030067 self.coordination_queue.put((self.node.get_conn_id(), data))
koder aka kdanilov4643fd62015-02-10 16:20:13 -080068
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030069 def pre_run(self):
koder aka kdanilov4643fd62015-02-10 16:20:13 -080070 pass
71
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030072 def cleanup(self):
koder aka kdanilov4500a5f2015-04-17 16:55:17 +030073 pass
74
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030075 @classmethod
76 @abc.abstractmethod
77 def load(cls, data):
78 pass
79
koder aka kdanilov4643fd62015-02-10 16:20:13 -080080 @abc.abstractmethod
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030081 def run(self, barrier):
koder aka kdanilov4643fd62015-02-10 16:20:13 -080082 pass
83
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030084 @classmethod
85 def format_for_console(cls, data):
86 msg = "{0}.format_for_console".format(cls.__name__)
87 raise NotImplementedError(msg)
88
koder aka kdanilov4d4771c2015-04-23 01:32:02 +030089 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 kdanilovec1b9732015-04-23 20:43:29 +030093 @classmethod
94 def coordination_th(cls, coord_q, barrier, num_threads):
95 pass
96
koder aka kdanilov4643fd62015-02-10 16:20:13 -080097
Yulia Portnova7ddfa732015-02-24 17:32:58 +020098class TwoScriptTest(IPerfTest):
koder aka kdanilovabd6ead2015-04-24 02:03:07 +030099 def __init__(self, *dt, **mp):
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300100 IPerfTest.__init__(self, *dt, **mp)
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200101
Yulia Portnovab1a15072015-05-06 14:59:25 +0300102 if 'scripts_path' in self.options:
103 self.root = self.options['scripts_path']
koder aka kdanilovabd6ead2015-04-24 02:03:07 +0300104 self.run_script = self.options['run_script']
Yulia Portnovab1a15072015-05-06 14:59:25 +0300105 self.prerun_script = self.options['prerun_script']
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200106
107 def get_remote_for_script(self, script):
Yulia Portnovab1a15072015-05-06 14:59:25 +0300108 return os.path.join(self.remote_dir, script.rpartition('/')[2])
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200109
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300110 def pre_run(self):
Yulia Portnovab1a15072015-05-06 14:59:25 +0300111 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 Portnova7ddfa732015-02-24 17:32:58 +0200114
koder aka kdanilov4d4771c2015-04-23 01:32:02 +0300115 def run(self, barrier):
Yulia Portnovab1a15072015-05-06 14:59:25 +0300116 remote_script = self.get_remote_for_script(self.run_script)
Yulia Portnova886a2562015-04-07 11:16:13 +0300117 cmd_opts = ' '.join(["%s %s" % (key, val) for key, val
koder aka kdanilovabd6ead2015-04-24 02:03:07 +0300118 in self.options.items()])
Yulia Portnova886a2562015-04-07 11:16:13 +0300119 cmd = remote_script + ' ' + cmd_opts
Yulia Portnovab1a15072015-05-06 14:59:25 +0300120 out_err = self.run_over_ssh(cmd, timeout=6000)
koder aka kdanilov66839a92015-04-11 13:22:31 +0300121 self.on_result(out_err, cmd)
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200122
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 kdanilov66839a92015-04-11 13:22:31 +0300129 def on_result(self, out_err, cmd):
130 try:
131 self.parse_results(out_err)
132 except Exception as exc:
koder aka kdanilovec1b9732015-04-23 20:43:29 +0300133 msg_templ = "Error during postprocessing results: {0!s}. {1}"
134 raise RuntimeError(msg_templ.format(exc, out_err))
Yulia Portnova7ddfa732015-02-24 17:32:58 +0200135
Yulia Portnovab1a15072015-05-06 14:59:25 +0300136 def merge_results(self, results):
137 tpcm = sum([val[1] for val in results])
138 return {"res": {"TpmC": tpcm}}