Merge "Move "read_yaml_file" to common.yaml_loader"
[yardstick.git] / yardstick / benchmark / scenarios / compute / ramspeed.py
index db70af9..4daf776 100644 (file)
@@ -6,11 +6,15 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
-import pkg_resources
+from __future__ import absolute_import
+
 import logging
-import json
+
+import pkg_resources
+from oslo_serialization import jsonutils
 
 import yardstick.ssh as ssh
+from yardstick.common import utils
 from yardstick.benchmark.scenarios import base
 
 LOG = logging.getLogger(__name__)
@@ -86,14 +90,8 @@ class Ramspeed(base.Scenario):
             Ramspeed.RAMSPEED_MEM_SCRIPT)
 
         host = self.context_cfg["host"]
-        user = host.get("user", "ubuntu")
-        ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
-        ip = host.get("ip", None)
-        key_filename = host.get('key_filename', "~/.ssh/id_rsa")
-
-        LOG.info("user:%s, host:%s", user, ip)
-        self.client = ssh.SSH(user, ip, key_filename=key_filename,
-                              port=ssh_port)
+
+        self.client = ssh.SSH.from_node(host, defaults={"user": "ubuntu"})
         self.client.wait(timeout=600)
 
         # copy scripts to host
@@ -123,22 +121,23 @@ class Ramspeed(base.Scenario):
                   (test_id, load, block_size)
         # only the test_id 1-6 will be used in this scenario
         else:
-            raise RuntimeError("No such type_id: %s for Ramspeed scenario",
-                               test_id)
+            raise RuntimeError("No such type_id: %s for Ramspeed scenario"
+                               test_id)
 
         LOG.debug("Executing command: %s", cmd)
         status, stdout, stderr = self.client.execute(cmd)
         if status:
             raise RuntimeError(stderr)
 
-        result.update(json.loads(stdout))
+        ramspeed_result = jsonutils.loads(stdout)
+        result.update(utils.flatten_dict_key(ramspeed_result))
 
         if "sla" in self.scenario_cfg:
             sla_error = ""
             sla_min_bw = int(self.scenario_cfg['sla']['min_bandwidth'])
-            for i in result["Result"]:
+            for i in ramspeed_result["Result"]:
                 bw = i["Bandwidth(MBps)"]
                 if bw < sla_min_bw:
                     sla_error += "Bandwidth %f < " \
                         "sla:min_bandwidth(%f)" % (bw, sla_min_bw)
-            assert sla_error == "", sla_error
+            self.verify_SLA(sla_error == "", sla_error)