1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from __future__ import absolute_import
10 from __future__ import print_function
15 import yardstick.ssh as ssh
16 from yardstick.benchmark.scenarios import base
18 LOG = logging.getLogger(__name__)
21 class Bonnie(base.Scenario):
22 """Execute bonnie benchmark in a host
25 file_size - size fo the test file in MB. File size should be double RAM for good results.
29 ram_size - specify RAM size in MB to use, this is used to reduce testing time.
33 test_dir - this directory is where bonnie++ will create the benchmark operations.
37 test_user - the user who should perform the test. This is not required if you are not running
42 concurrency - number of thread to perform test
47 __scenario_type__ = "Bonnie++"
49 def __init__(self, scenario_cfg, context_cfg):
50 self.scenario_cfg = scenario_cfg
51 self.context_cfg = context_cfg
52 self.setup_done = False
56 host = self.context_cfg["host"]
58 self.client = ssh.SSH.from_node(host, defaults={"user": "root"})
59 self.client.wait(timeout=600)
61 self.setup_done = True
63 def run(self, result): # pragma: no cover
64 """execute the benchmark"""
65 if not self.setup_done:
70 options = self.scenario_cfg["options"]
71 file_size = options.get("file_size", 2048)
72 test_dir = options.get("test_dir", "/tmp")
74 if "ram_size" in options:
75 cmd_args += " -r %s" % options["ram_size"]
77 if "test_user" in options:
78 cmd_args += " -u %s" % options["test_user"]
80 if "concurrency" in options:
81 cmd_args += " -c %s" % options["concurrency"]
83 cmd = "bonnie++ -d %s -s %s %s" % (test_dir, file_size, cmd_args)
85 LOG.debug("Executing command: %s", cmd)
86 status, stdout, stderr = self.client.execute(cmd)
88 raise RuntimeError(stderr)
90 raw_data = stdout.split('\n')[-2]
91 result.update({"raw_data": raw_data})
93 LOG.debug("Generating Bonnie++ HTML report...")
94 with open("/tmp/bonnie.html", "w") as bon_file:
95 p = subprocess.Popen(["bon_csv2html"], stdout=bon_file, stdin=subprocess.PIPE)
96 p.communicate(raw_data)
97 LOG.info('Bonnie++ benchmark completed, please find benchmark report at /tmp/bonnie.html')