Merge "NSB Topology fix for Prox 4 port test case"
[yardstick.git] / yardstick / benchmark / scenarios / networking / iperf3.py
index a3d2737..51e044e 100644 (file)
@@ -92,7 +92,7 @@ For more info see http://software.es.net/iperf
     def teardown(self):
         LOG.debug("teardown")
         self.host.close()
-        status, stdout, stderr = self.target.execute("pkill iperf3")
+        status, _, stderr = self.target.execute("pkill iperf3")
         if status:
             LOG.warning(stderr)
         self.target.close()
@@ -111,18 +111,22 @@ For more info see http://software.es.net/iperf
 
         # If there are no options specified
         if not options:
-            options = ""
+            options = {}
 
         use_UDP = False
-        if "udp" in options:
-            cmd += " --udp"
-            use_UDP = True
-            if "bandwidth" in options:
-                cmd += " --bandwidth %s" % options["bandwidth"]
-        else:
-            # tcp obviously
+        try:
+            protocol = options.get("protocol")
+            bandwidth = options.get('bandwidth')
+            use_UDP = protocol == 'udp'
+            if protocol:
+                cmd += " --" + protocol
+            if use_UDP and bandwidth:
+                cmd += " --bandwidth " + bandwidth
+            # if nodelay in the option, protocal maybe null or 'tcp'
             if "nodelay" in options:
                 cmd += " --nodelay"
+        except AttributeError:
+            LOG.warning("Can't parser the options in your config file!!!")
 
         # these options are mutually exclusive in iperf3
         if time:
@@ -141,7 +145,7 @@ For more info see http://software.es.net/iperf
 
         LOG.debug("Executing command: %s", cmd)
 
-        status, stdout, stderr = self.host.execute(cmd)
+        status, stdout, _ = self.host.execute(cmd)
         if status:
             # error cause in json dict on stdout
             raise RuntimeError(stdout)
@@ -161,16 +165,17 @@ For more info see http://software.es.net/iperf
                 bit_per_second = \
                     int(iperf_result["end"]["sum_received"]["bits_per_second"])
                 bytes_per_second = bit_per_second / 8
-                assert bytes_per_second >= sla_bytes_per_second, \
-                    "bytes_per_second %d < sla:bytes_per_second (%d); " % \
-                    (bytes_per_second, sla_bytes_per_second)
+                self.verify_SLA(
+                    bytes_per_second >= sla_bytes_per_second,
+                    "bytes_per_second %d < sla:bytes_per_second (%d); "
+                    % (bytes_per_second, sla_bytes_per_second))
             else:
                 sla_jitter = float(sla_iperf["jitter"])
 
                 jitter_ms = float(iperf_result["end"]["sum"]["jitter_ms"])
-                assert jitter_ms <= sla_jitter, \
-                    "jitter_ms  %f > sla:jitter %f; " % \
-                    (jitter_ms, sla_jitter)
+                self.verify_SLA(jitter_ms <= sla_jitter,
+                                "jitter_ms  %f > sla:jitter %f; "
+                                % (jitter_ms, sla_jitter))
 
 
 def _test():