cfg-checker benchmark module part 2

 - fixes for fio-runner error handling
 - fixes for web-server error handling
 - proper handling of 'scheduled_to' option
 - cleanup procedure
 - kube can wait for specific phases of svc, pod, pvc, pv

Change-Id: I9b241597e6314fed1dbc3aba5e8dee1637eea1c7
diff --git a/cfg_checker/modules/ceph/bench.py b/cfg_checker/modules/ceph/bench.py
index 190076a..dd96a69 100644
--- a/cfg_checker/modules/ceph/bench.py
+++ b/cfg_checker/modules/ceph/bench.py
@@ -47,6 +47,8 @@
         if config.bench_mode == "tasks":
             self.load_tasks(config.bench_task_file)
 
+        self.cleanup_list = []
+
     def load_tasks(self, taskfile):
         # Load csv file
         logger_cli.info("-> Loading taskfile '{}'".format(taskfile))
@@ -63,6 +65,11 @@
                     "size": row[4]
                 })
 
+    def add_for_deletion(self, obj, typ):
+        _d = [typ, obj.metadata.namespace, obj.metadata.name]
+        self.cleanup_list.append(_d)
+        return
+
     def prepare_agents(self, options):
         logger_cli.info("# Preparing {} agents".format(self.agent_count))
         for idx in range(self.agent_count):
@@ -75,10 +82,15 @@
                 options['size'] + 'i',
                 self._agent_template
             )
-            # save it to list
+            # save it to lists
             self.agent_pods.append(_agent)
+            self.add_for_deletion(_pv, "pv")
+            self.add_for_deletion(_pvc, "pvc")
+            self.add_for_deletion(_agent, "pod")
+
             # expose it
             _svc = self.master.expose_benchmark_agent(_agent)
+            self.add_for_deletion(_svc, "svc")
             # Save service
             self.services.append(_svc)
 
@@ -203,7 +215,9 @@
         _runtime = _get_seconds(options["runtime"])
         _ramptime = _get_seconds(options["ramp_time"])
         _timeout = _runtime + _ramptime + 5
-        while _timeout > 0:
+        _end = datetime.now() + timedelta(seconds=_timeout)
+        while True:
+            # Print status
             _sts = get_status()
             _str = ""
             for _s in _sts:
@@ -212,17 +226,29 @@
                     _s["status"],
                     _s["progress"]
                 )
-            logger_cli.debug("... {}".format(_str))
-            sleep(1)
-            _timeout -= 1
+            # recalc how much is left
+            diff = (_end - datetime.now()).total_seconds()
+            logger_cli.debug("... [{}s]: {}".format(diff, _str))
+            # In case end_datetime was in past to begin with
+            if diff < 0:
+                break
+            logger_cli.info("-> Sleeping for {}s".format(diff/2))
+            sleep(diff/2)
+            if diff <= 0.1:
+                break
 
+        logger_cli.info("-> Done")
         return True
 
     def cleanup(self):
+        self.cleanup_list.reverse()
 
+        for _res in self.cleanup_list:
+            self.master.cleanup_resource_by_name(_res[0], _res[2], ns=_res[1])
+        logger_cli.info("# Done cleaning up")
         return
 
     # Create report
-    def create_report(self):
+    def create_report(self, filename):
 
         return