Merge "Raise Exception if HA test case failed"
[yardstick.git] / yardstick / benchmark / scenarios / storage / fio.py
index 4e00423..b99e342 100644 (file)
@@ -6,9 +6,13 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
-import pkg_resources
+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
@@ -36,10 +40,26 @@ class Fio(base.Scenario):
         type:    string
         unit:    na
         default: write
+    rwmixwrite - percentage of a mixed workload that should be writes
+        type: int
+        unit: percentage
+        default: 50
     ramp_time - run time before logging any performance
         type:    int
         unit:    seconds
         default: 20
+    direct - whether use non-buffered I/O or not
+        type:    boolean
+        unit:    na
+        default: 1
+    size - total size of I/O for this job.
+        type:    string
+        unit:    na
+        default: 1g
+    numjobs - number of clones (processes/threads performing the same workload) of this job
+        type:    int
+        unit:    na
+        default: 1
 
     Read link below for more fio args description:
         http://www.bluestop.org/fio/HOWTO.txt
@@ -54,19 +74,13 @@ class Fio(base.Scenario):
         self.setup_done = False
 
     def setup(self):
-        '''scenario setup'''
+        """scenario setup"""
         self.target_script = pkg_resources.resource_filename(
             "yardstick.benchmark.scenarios.storage",
             Fio.TARGET_SCRIPT)
         host = self.context_cfg["host"]
-        user = host.get("user", "root")
-        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": "root"})
         self.client.wait(timeout=600)
 
         # copy script to host
@@ -76,8 +90,8 @@ class Fio(base.Scenario):
 
     def run(self, result):
         """execute the benchmark"""
-        default_args = "-ioengine=libaio -direct=1 -group_reporting " \
-            "-numjobs=1 -time_based --output-format=json"
+        default_args = "-ioengine=libaio -group_reporting -time_based -time_based " \
+            "--output-format=json"
 
         if not self.setup_done:
             self.setup()
@@ -88,6 +102,10 @@ class Fio(base.Scenario):
         iodepth = options.get("iodepth", "1")
         rw = options.get("rw", "write")
         ramp_time = options.get("ramp_time", 20)
+        size = options.get("size", "1g")
+        direct = options.get("direct", "1")
+        numjobs = options.get("numjobs", "1")
+        rwmixwrite = options.get("rwmixwrite", 50)
         name = "yardstick-fio"
         # if run by a duration runner
         duration_time = self.scenario_cfg["runner"].get("duration", None) \
@@ -101,10 +119,10 @@ class Fio(base.Scenario):
         else:
             runtime = 30
 
-        cmd_args = "-filename=%s -bs=%s -iodepth=%s -rw=%s -ramp_time=%s " \
-                   "-runtime=%s -name=%s %s" \
-                   % (filename, bs, iodepth, rw, ramp_time, runtime, name,
-                      default_args)
+        cmd_args = "-filename=%s -direct=%s -bs=%s -iodepth=%s -rw=%s -rwmixwrite=%s " \
+                   "-size=%s -ramp_time=%s -numjobs=%s -runtime=%s -name=%s %s" \
+                   % (filename, direct, bs, iodepth, rw, rwmixwrite, size, ramp_time, numjobs,
+                      runtime, name, default_args)
         cmd = "sudo bash fio.sh %s %s" % (filename, cmd_args)
         LOG.debug("Executing command: %s", cmd)
         # Set timeout, so that the cmd execution does not exit incorrectly
@@ -114,7 +132,7 @@ class Fio(base.Scenario):
         if status:
             raise RuntimeError(stderr)
 
-        raw_data = json.loads(stdout)
+        raw_data = jsonutils.loads(stdout)
 
         # The bandwidth unit is KB/s, and latency unit is us
         if rw in ["read", "randread", "rw", "randrw"]:
@@ -148,7 +166,7 @@ class Fio(base.Scenario):
 
 
 def _test():
-    '''internal test function'''
+    """internal test function"""
     key_filename = pkg_resources.resource_filename("yardstick.resources",
                                                    "files/yardstick_key")
     ctx = {
@@ -175,7 +193,8 @@ def _test():
 
     fio = Fio(args, ctx)
     fio.run(result)
-    print result
+    print(result)
+
 
 if __name__ == '__main__':
     _test()