bugfix: fix bugs for running 'teststory run'
[bottlenecks.git] / utils / parser.py
index 7b1f4e2..48f705b 100644 (file)
@@ -14,6 +14,9 @@ Second is reading config file.'''
 
 import os
 import yaml
+import json
+import time
+from pyroute2 import IPDB
 
 
 class Parser():
@@ -50,7 +53,7 @@ class Parser():
         with open(story_dir) as file:
             story_parser = yaml.load(file)
         for case_name in story_parser['testcase']:
-            Parser.testcase_read(cls, testcase, case_name)
+            Parser.testcase_read(testcase, case_name)
 
         return cls.bottlenecks_test
 
@@ -75,6 +78,13 @@ class Parser():
         if not os.path.exists(dirname):
             os.makedirs(dirname)
 
+    @classmethod
+    def testcase_out_dir(cls, testcase):
+        file_time = time.strftime('%H_%M', time.localtime(time.time()))
+        out_name = cls.bottlenecks_config["log_dir"] + testcase + file_time
+        outfile_name = out_name + ".out"
+        return outfile_name
+
     @staticmethod
     def config_parser(testcase_cfg, parameters):
         test_cfg = testcase_cfg['test_config']
@@ -82,6 +92,22 @@ class Parser():
         # TO-DO add cli parameters to stack_config.
         return test_cfg, stack_cfg
 
+    @staticmethod
+    def ip_parser(ip_type):
+        with IPDB() as ip:
+            GATEWAY_IP = ip.routes['default'].gateway
+        if ip_type is "dashboard":
+            TEST_IP = GATEWAY_IP + ":9200"
+        elif ip_type is "yardstick_test_ip":
+            TEST_IP = GATEWAY_IP + ":8888"
+        return TEST_IP
+
+    @staticmethod
+    def result_to_file(data, file_name):
+        with open(file_name, "a") as f:
+            f.write(json.dumps(data, f))
+            f.write("\n")
+
 
 class HeatTemplate_Parser():
     """parser a Heat template and a method to deploy template to a stack"""
@@ -282,4 +308,3 @@ class HeatTemplate_Parser():
 
     def get_template_date(self):
         return self.heat_date
-