Merge "Cleanup unittests for test_lmbench"
[yardstick.git] / yardstick / cmd / NSBperf.py
index dd96b7f..5d0aa74 100755 (executable)
@@ -24,28 +24,19 @@ 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 """
@@ -115,22 +106,24 @@ 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.
-"""
+        """
 
+        tc_name = os.path.splitext(test_case)[0]
         report_caption = '{}\n{} ({})\n{}\n\n'.format(
             '================================================================',
-            'Performance report for',
-            os.path.splitext(test_case)[0].upper(),
+            'Performance report for', tc_name.upper(),
             '================================================================')
         print(report_caption)
         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))
-                for key, value in tc_res["benchmark"]["data"].items():
+                lines = \
+                    lines['result']["testcases"][tc_name]["tc_data"]
+                tc_res = lines.pop(len(lines) - 1)
+                for key, value in tc_res["data"].items():
                     self.generate_kpi_results(key, value)
                     self.generate_nfvi_results(value)
 
@@ -157,8 +150,24 @@ class YardstickNSCli(object):
                 testcases = os.listdir(test_path + vnf)
                 print(("VNF :(%s)" % vnf))
                 print("================")
-                for testcase in [tc for tc in testcases if "tc" in tc]:
-                    print('%s' % testcase)
+                test_cases = [tc for tc in testcases if "tc_" in tc and "template" not in tc]
+
+                print("\tBareMetal Testcase:")
+                print("\t===================")
+                for testcase in [tc for tc in test_cases if "baremetal" in tc]:
+                    print("\t%s" % testcase)
+
+                print(os.linesep)
+                print("\tStandalone Virtualization Testcase:")
+                print("\t===================================")
+                for testcase in [tc for tc in test_cases if "ovs" in tc or "sriov" in tc]:
+                    print("\t%s" % testcase)
+
+                print(os.linesep)
+                print("\tOpenstack Testcase:")
+                print("\t===================")
+                for testcase in [tc for tc in test_cases if "heat" in tc]:
+                    print("\t%s" % testcase)
                 print(os.linesep)
             raise SystemExit(0)
 
@@ -213,5 +222,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()