Merge "HA testcase containerized Compass support"
[yardstick.git] / yardstick / cmd / NSBperf.py
index 7be44ee..011990a 100755 (executable)
@@ -24,24 +24,26 @@ import argparse
 import json
 import subprocess
 import signal
+from oslo_serialization import jsonutils
+
+from six.moves import input
 
 CLI_PATH = os.path.dirname(os.path.realpath(__file__))
 REPO_PATH = os.path.abspath(os.path.join(CLI_PATH, os.pardir))
 PYTHONPATH = os.environ.get("PYTHONPATH", False)
 VIRTUAL_ENV = os.environ.get("VIRTUAL_ENV", False)
 
+
 if not PYTHONPATH or not VIRTUAL_ENV:
     print("Please setup env PYTHONPATH & VIRTUAL_ENV environment varaible.")
     raise SystemExit(1)
 
 
-def handler():
+def sigint_handler(*args, **kwargs):
     """ Capture ctrl+c and exit cli """
     subprocess.call(["pkill", "-9", "yardstick"])
     raise SystemExit(1)
 
-signal.signal(signal.SIGINT, handler)
-
 
 class YardstickNSCli(object):
     """ This class handles yardstick network serivce testing """
@@ -58,7 +60,7 @@ class YardstickNSCli(object):
         choice = int(choice)
         if not 1 <= choice <= choice_len:
             print("\nInvalid wrong choice...")
-            raw_input("Press Enter to continue...")
+            input("Press Enter to continue...")
             return 1
         subprocess.call(['clear'])
         return 0
@@ -111,7 +113,7 @@ class YardstickNSCli(object):
     def generate_final_report(self, test_case):
         """ Function will check if partial test results are available
         and generates final report in rst format.
-"""
+        """
 
         report_caption = '{}\n{} ({})\n{}\n\n'.format(
             '================================================================',
@@ -122,10 +124,11 @@ class YardstickNSCli(object):
         if os.path.isfile("/tmp/yardstick.out"):
             lines = []
             with open("/tmp/yardstick.out") as infile:
-                lines = infile.readlines()
+                lines = jsonutils.load(infile)
 
             if lines:
-                tc_res = json.loads(lines.pop(len(lines) - 1))
+                lines = lines['result']
+                tc_res = lines.pop(len(lines) - 1)
                 for key, value in tc_res["benchmark"]["data"].items():
                     self.generate_kpi_results(key, value)
                     self.generate_nfvi_results(value)
@@ -209,5 +212,6 @@ class YardstickNSCli(object):
         self.run_test(args, test_path)
 
 if __name__ == "__main__":
+    signal.signal(signal.SIGINT, sigint_handler)
     NS_CLI = YardstickNSCli()
     NS_CLI.main()