Merge "run ipv6 test case on more pods"
[yardstick.git] / yardstick / benchmark / scenarios / networking / ping.py
index ae21666..54c1922 100644 (file)
@@ -41,11 +41,17 @@ class Ping(base.Scenario):
         user = host.get('user', 'ubuntu')
         ip = host.get('ip', None)
         key_filename = host.get('key_filename', '/root/.ssh/id_rsa')
-        password = host.get('password', 'root')
+        password = host.get('password', None)
+
+        if password is not None:
+            LOG.info("Log in via pw, user:%s, host:%s, pw:%s",
+                     user, ip, password)
+            self.connection = ssh.SSH(user, ip, password=password)
+        else:
+            LOG.info("Log in via key, user:%s, host:%s, key_filename:%s",
+                     user, ip, key_filename)
+            self.connection = ssh.SSH(user, ip, key_filename=key_filename)
 
-        LOG.info("user:%s, host:%s, key_filename:%s", user, ip, key_filename)
-        self.connection = ssh.SSH(user, ip, key_filename=key_filename,
-                                  password=password)
         self.connection.wait()
 
     def run(self, result):
@@ -57,29 +63,39 @@ class Ping(base.Scenario):
         else:
             options = ""
 
-        destination = self.context_cfg['target'].get("ipaddr", '127.0.0.1')
+        destination = self.context_cfg['target'].get('ipaddr', '127.0.0.1')
+        dest_list = [s.strip() for s in destination.split(',')]
 
-        LOG.debug("ping '%s' '%s'", options, destination)
+        result["rtt"] = {}
+        rtt_result = result["rtt"]
 
-        exit_status, stdout, stderr = self.connection.execute(
-            "/bin/sh -s {0} {1}".format(destination, options),
-            stdin=open(self.target_script, "r"))
+        for pos, dest in enumerate(dest_list):
+            if 'targets' in self.scenario_cfg:
+                target_vm = self.scenario_cfg['targets'][pos]
+            else:
+                target_vm = self.scenario_cfg['target']
 
-        if exit_status != 0:
-            raise RuntimeError(stderr)
+            LOG.debug("ping '%s' '%s'", options, dest)
+            exit_status, stdout, stderr = self.connection.execute(
+                "/bin/sh -s {0} {1}".format(dest, options),
+                stdin=open(self.target_script, "r"))
 
-        if stdout:
-            result["rtt"] = float(stdout)
+            if exit_status != 0:
+                raise RuntimeError(stderr)
 
-            if "sla" in self.scenario_cfg:
-                sla_max_rtt = int(self.scenario_cfg["sla"]["max_rtt"])
-                assert result["rtt"] <= sla_max_rtt, \
-                    "rtt %f > sla:max_rtt(%f); " % (result["rtt"], sla_max_rtt)
-        else:
-            LOG.error("ping '%s' '%s' timeout", options, destination)
+            if stdout:
+                target_vm_name = target_vm.split('.')[0]
+                rtt_result[target_vm_name] = float(stdout)
+                if "sla" in self.scenario_cfg:
+                    sla_max_rtt = int(self.scenario_cfg["sla"]["max_rtt"])
+                    assert rtt_result[target_vm_name] <= sla_max_rtt,\
+                        "rtt %f > sla: max_rtt(%f); " % \
+                        (rtt_result[target_vm_name], sla_max_rtt)
+            else:
+                LOG.error("ping '%s' '%s' timeout", options, target_vm)
 
 
-def _test():
+def _test():    # pragma: no cover
     '''internal test function'''
     key_filename = pkg_resources.resource_filename("yardstick.resources",
                                                    "files/yardstick_key")
@@ -104,5 +120,5 @@ def _test():
     p.run(result)
     print result
 
-if __name__ == '__main__':
+if __name__ == '__main__':    # pragma: no cover
     _test()