Rename to Constants.py
[csit.git] / resources / tools / wrk / wrk.py
index 33cfd08..43355b9 100644 (file)
 
 import re
 
 
 import re
 
+from copy import deepcopy
+from time import sleep
+
 from robot.api import logger
 
 from resources.libraries.python.ssh import SSH
 from resources.libraries.python.topology import NodeType
 from resources.libraries.python.CpuUtils import CpuUtils
 from robot.api import logger
 
 from resources.libraries.python.ssh import SSH
 from resources.libraries.python.topology import NodeType
 from resources.libraries.python.CpuUtils import CpuUtils
-from resources.libraries.python.constants import Constants
+from resources.libraries.python.Constants import Constants
 
 from resources.tools.wrk.wrk_traffic_profile_parser import WrkTrafficProfile
 from resources.tools.wrk.wrk_errors import WrkError
 
 from resources.tools.wrk.wrk_traffic_profile_parser import WrkTrafficProfile
 from resources.tools.wrk.wrk_errors import WrkError
@@ -100,17 +103,19 @@ def destroy_wrk(tg_node):
         raise RuntimeError('Removal of wrk from the TG node failed.')
 
 
         raise RuntimeError('Removal of wrk from the TG node failed.')
 
 
-def run_wrk(tg_node, profile_name, tg_numa, test_type):
+def run_wrk(tg_node, profile_name, tg_numa, test_type, warm_up=False):
     """Send the traffic as defined in the profile.
 
     :param tg_node: Traffic generator node.
     :param profile_name: The name of wrk traffic profile.
     :param tg_numa: Numa node on which wrk will run.
     :param test_type: The type of the tests: cps, rps, bw
     """Send the traffic as defined in the profile.
 
     :param tg_node: Traffic generator node.
     :param profile_name: The name of wrk traffic profile.
     :param tg_numa: Numa node on which wrk will run.
     :param test_type: The type of the tests: cps, rps, bw
+    :param warm_up: If True, warm-up traffic is generated before test traffic.
     :type profile_name: str
     :type tg_node: dict
     :type tg_numa: int
     :type test_type: str
     :type profile_name: str
     :type tg_node: dict
     :type tg_numa: int
     :type test_type: str
+    :type warm_up: bool
     :returns: Message with measured data.
     :rtype: str
     :raises: RuntimeError if node type is not a TG.
     :returns: Message with measured data.
     :rtype: str
     :raises: RuntimeError if node type is not a TG.
@@ -140,6 +145,9 @@ def run_wrk(tg_node, profile_name, tg_numa, test_type):
             str(profile["latency"]),
             "'{0}'".format(" ".join(profile["urls"]))
         ]
             str(profile["latency"]),
             "'{0}'".format(" ".join(profile["urls"]))
         ]
+        if warm_up:
+            warm_up_params = deepcopy(params)
+            warm_up_params[4] = "10s"
     elif len(profile["urls"]) == profile["cpus"]:
         params = [
             "traffic_n_urls_n_cores",
     elif len(profile["urls"]) == profile["cpus"]:
         params = [
             "traffic_n_urls_n_cores",
@@ -153,6 +161,9 @@ def run_wrk(tg_node, profile_name, tg_numa, test_type):
             str(profile["latency"]),
             "'{0}'".format(" ".join(profile["urls"]))
         ]
             str(profile["latency"]),
             "'{0}'".format(" ".join(profile["urls"]))
         ]
+        if warm_up:
+            warm_up_params = deepcopy(params)
+            warm_up_params[4] = "10s"
     else:
         params = [
             "traffic_n_urls_m_cores",
     else:
         params = [
             "traffic_n_urls_m_cores",
@@ -167,11 +178,24 @@ def run_wrk(tg_node, profile_name, tg_numa, test_type):
             str(profile["latency"]),
             "'{0}'".format(" ".join(profile["urls"]))
         ]
             str(profile["latency"]),
             "'{0}'".format(" ".join(profile["urls"]))
         ]
+        if warm_up:
+            warm_up_params = deepcopy(params)
+            warm_up_params[5] = "10s"
+
     args = " ".join(params)
 
     ssh = SSH()
     ssh.connect(tg_node)
 
     args = " ".join(params)
 
     ssh = SSH()
     ssh.connect(tg_node)
 
+    if warm_up:
+        warm_up_args = " ".join(warm_up_params)
+        ret, _, _ = ssh.exec_command(
+            "{0}/resources/tools/wrk/wrk_utils.sh {1}".
+            format(Constants.REMOTE_FW_DIR, warm_up_args), timeout=1800)
+        if int(ret) != 0:
+            raise RuntimeError('wrk runtime error.')
+        sleep(60)
+
     ret, stdout, _ = ssh.exec_command(
         "{0}/resources/tools/wrk/wrk_utils.sh {1}".
         format(Constants.REMOTE_FW_DIR, args), timeout=1800)
     ret, stdout, _ = ssh.exec_command(
         "{0}/resources/tools/wrk/wrk_utils.sh {1}".
         format(Constants.REMOTE_FW_DIR, args), timeout=1800)
@@ -190,7 +214,7 @@ def run_wrk(tg_node, profile_name, tg_numa, test_type):
         log_msg += "Requests/sec: Avg / Stdev / Max  / +/- Stdev\n"
         for item in stats["rps-stats-lst"]:
             log_msg += "{0} / {1} / {2} / {3}\n".format(*item)
         log_msg += "Requests/sec: Avg / Stdev / Max  / +/- Stdev\n"
         for item in stats["rps-stats-lst"]:
             log_msg += "{0} / {1} / {2} / {3}\n".format(*item)
-        log_msg += "Total rps: {0}cps\n".format(stats["rps-sum"])
+        log_msg += "Total rps: {0}rps\n".format(stats["rps-sum"])
     elif test_type == "bw":
         log_msg += "Transfer/sec: {0}Bps".format(stats["bw-sum"])
 
     elif test_type == "bw":
         log_msg += "Transfer/sec: {0}Bps".format(stats["bw-sum"])