run ha test case in compass pod
[yardstick.git] / yardstick / benchmark / scenarios / networking / iperf3.py
index 13fa015..334f3a9 100644 (file)
 # iperf3 scenario
 # iperf3 homepage at: http://software.es.net/iperf/
 
+from __future__ import absolute_import
+from __future__ import print_function
+
 import logging
-import json
+
 import pkg_resources
+from oslo_serialization import jsonutils
 
 import yardstick.ssh as ssh
 from yardstick.benchmark.scenarios import base
@@ -55,25 +59,14 @@ For more info see http://software.es.net/iperf
 
     def setup(self):
         host = self.context_cfg['host']
-        host_user = host.get('user', 'ubuntu')
-        host_ssh_port = host.get('ssh_port', ssh.DEFAULT_PORT)
-        host_ip = host.get('ip', None)
-        host_key_filename = host.get('key_filename', '~/.ssh/id_rsa')
         target = self.context_cfg['target']
-        target_user = target.get('user', 'ubuntu')
-        target_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
-        target_ip = target.get('ip', None)
-        target_key_filename = target.get('key_filename', '~/.ssh/id_rsa')
-
-        LOG.info("user:%s, target:%s", target_user, target_ip)
-        self.target = ssh.SSH(target_user, target_ip,
-                              key_filename=target_key_filename,
-                              port=target_ssh_port)
+
+        LOG.info("user:%s, target:%s", target['user'], target['ip'])
+        self.target = ssh.SSH.from_node(target, defaults={"user": "ubuntu"})
         self.target.wait(timeout=600)
 
-        LOG.info("user:%s, host:%s", host_user, host_ip)
-        self.host = ssh.SSH(host_user, host_ip,
-                            key_filename=host_key_filename, port=host_ssh_port)
+        LOG.info("user:%s, host:%s", host['user'], host['ip'])
+        self.host = ssh.SSH.from_node(host, defaults={"user": "ubuntu"})
         self.host.wait(timeout=600)
 
         cmd = "iperf3 -s -D"
@@ -89,7 +82,7 @@ For more info see http://software.es.net/iperf
         self.host.close()
         status, stdout, stderr = self.target.execute("pkill iperf3")
         if status:
-            LOG.warn(stderr)
+            LOG.warning(stderr)
         self.target.close()
 
     def run(self, result):
@@ -138,7 +131,8 @@ For more info see http://software.es.net/iperf
         # Note: convert all ints to floats in order to avoid
         # schema conflicts in influxdb. We probably should add
         # a format func in the future.
-        result.update(json.loads(stdout, parse_int=float))
+        result.update(
+            jsonutils.loads(stdout, parse_int=float))
 
         if "sla" in self.scenario_cfg:
             sla_iperf = self.scenario_cfg["sla"]
@@ -162,7 +156,7 @@ For more info see http://software.es.net/iperf
 
 
 def _test():
-    '''internal test function'''
+    """internal test function"""
     key_filename = pkg_resources.resource_filename('yardstick.resources',
                                                    'files/yardstick_key')
     ctx = {
@@ -188,7 +182,8 @@ def _test():
 
     p = Iperf(args, ctx)
     p.run(result)
-    print result
+    print(result)
+
 
 if __name__ == '__main__':
     _test()