Two scripts, pgbench tests
diff --git a/itest.py b/itest.py
index 018a11b..d63a9b4 100644
--- a/itest.py
+++ b/itest.py
@@ -4,7 +4,6 @@
 import os.path
 import logging
 
-
 from io_scenario import io
 from ssh_copy_directory import copy_paths
 from utils import run_over_ssh
@@ -31,6 +30,70 @@
         pass
 
 
+class TwoScriptTest(IPerfTest):
+    def __init__(self, opts, testtool, on_result_cb, keep_tmp_files):
+        super(TwoScriptTest, self).__init__(on_result_cb)
+        self.opts = opts
+        self.pre_run_script = None
+        self.run_script = None
+        self.tmp_dir = "/tmp/"
+        self.set_run_script()
+        self.set_pre_run_script()
+
+    def set_run_script(self):
+        self.pre_run_script = self.opts.pre_run_script
+
+    def set_pre_run_script(self):
+        self.run_script = self.opts.run_script
+
+    def get_remote_for_script(self, script):
+        return os.path.join(self.tmp_dir, script.rpartition('/')[2])
+
+    def copy_script(self, conn, src):
+        remote_path = self.get_remote_for_script(src)
+        copy_paths(conn, {src: remote_path})
+        return remote_path
+
+    def pre_run(self, conn):
+        remote_script = self.copy_script(conn, self.pre_run_script)
+        cmd = remote_script
+        code, out, err = run_over_ssh(conn, cmd)
+        if code != 0:
+            raise Exception("Pre run failed. %s" % err)
+
+    def run(self, conn):
+        remote_script = self.copy_script(conn, self.run_script)
+        cmd = remote_script
+        code, out, err = run_over_ssh(conn, cmd)
+        self.on_result(code, out, err, cmd)
+
+    def parse_results(self, out):
+        for line in out.split("\n"):
+            key, separator, value = line.partition(":")
+            if key and value:
+                self.on_result_cb((key, float(value)))
+
+    def on_result(self, code, out, err, cmd):
+        if 0 == code:
+            try:
+                self.parse_results(out)
+            except Exception as err:
+                msg_templ = "Error during postprocessing results: {0!r}"
+                raise RuntimeError(msg_templ.format(err.message))
+        else:
+            templ = "Command {0!r} failed with code {1}. Error output is:\n{2}"
+            logger.error(templ.format(cmd, code, err))
+
+
+class PgBenchTest(TwoScriptTest):
+
+    def set_run_script(self):
+        self.pre_run_script = "hl_tests/postgres/prepare.sh"
+
+    def set_pre_run_script(self):
+        self.run_script = "hl_tests/postgres/run.sh"
+
+
 def run_test_iter(obj, conn):
     yield obj.pre_run(conn)
     res = obj.run(conn)