Merge "Add host&targer in scenario['options']['server_name'] support"
[yardstick.git] / yardstick / benchmark / scenarios / networking / pktgen.py
index 8ca1ca6..a9e7aa6 100644 (file)
@@ -11,6 +11,7 @@ from __future__ import print_function
 
 import os
 import logging
+import math
 
 import pkg_resources
 from oslo_serialization import jsonutils
@@ -20,6 +21,7 @@ from yardstick.benchmark.scenarios import base
 
 LOG = logging.getLogger(__name__)
 
+SSH_TIMEOUT = 60
 VNIC_TYPE_LIST = ["ovs", "sriov"]
 SRIOV_DRIVER_LIST = ["ixgbevf", "i40evf"]
 
@@ -287,7 +289,7 @@ class Pktgen(base.Scenario):
               "sudo iptables -A INPUT -p udp --dport 1000:%s -j DROP" \
               % (1000 + self.number_of_ports)
         LOG.debug("Executing command: %s", cmd)
-        status, _, stderr = self.server.execute(cmd)
+        status, _, stderr = self.server.execute(cmd, timeout=SSH_TIMEOUT)
         if status:
             raise RuntimeError(stderr)
 
@@ -349,22 +351,22 @@ class Pktgen(base.Scenario):
                duration, queue_number, pps)
 
         LOG.debug("Executing command: %s", cmd)
-        status, stdout, stderr = self.client.execute(cmd)
+        status, stdout, stderr = self.client.execute(cmd, timeout=SSH_TIMEOUT)
 
         if status:
             raise RuntimeError(stderr)
 
         result.update(jsonutils.loads(stdout))
 
-        result['packets_received'] = self._iptables_get_result()
+        received = result['packets_received'] = self._iptables_get_result()
+        sent = result['packets_sent']
         result['packetsize'] = packetsize
+        # compatible with python3 /
+        ppm = math.ceil(1000000.0 * (sent - received) / sent)
+
+        result['ppm'] = ppm
 
         if "sla" in self.scenario_cfg:
-            sent = result['packets_sent']
-            received = result['packets_received']
-            ppm = 1000000 * (sent - received) / sent
-            # if ppm is 1, then 11 out of 10 million is no pass
-            ppm += (sent - received) % sent > 0
             LOG.debug("Lost packets %d - Lost ppm %d", (sent - received), ppm)
             sla_max_ppm = int(self.scenario_cfg["sla"]["max_ppm"])
             assert ppm <= sla_max_ppm, "ppm %d > sla_max_ppm %d; " \