1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and other.
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
14 from oslo_serialization import jsonutils
15 from six.moves import range
17 import yardstick.ssh as ssh
18 from yardstick.benchmark.scenarios import base
20 LOG = logging.getLogger(__name__)
23 class StorageCapacity(base.Scenario):
24 """Measure storage capacity and scale.
27 test_type - specified whether to measure.
28 valid test type are disk_size, block_size, disk_utilization
32 interval - specified how ofter to stat disk utilization
36 count - specified how many times to stat disk utilization
41 This scenario reads hardware specification,
42 disk size, block size and disk utilization.
44 __scenario_type__ = "StorageCapacity"
45 TARGET_SCRIPT = "storagecapacity.bash"
47 def __init__(self, scenario_cfg, context_cfg):
48 self.scenario_cfg = scenario_cfg
49 self.context_cfg = context_cfg
50 self.setup_done = False
54 self.target_script = pkg_resources.resource_filename(
55 "yardstick.benchmark.scenarios.storage",
56 StorageCapacity.TARGET_SCRIPT)
57 host = self.context_cfg['host']
59 raise RuntimeError('No right node.Please check the configuration')
61 self.client = ssh.SSH.from_node(host, defaults={
62 "user": "ubuntu", "password": "root"
64 self.client.wait(timeout=600)
67 self.client._put_file_shell(self.target_script, '~/storagecapacity.sh')
69 self.setup_done = True
71 def _get_disk_utilization(self):
72 """Get disk utilization using iostat."""
73 options = self.scenario_cfg["options"]
74 interval = options.get('interval', 1)
75 count = options.get('count', 15)
77 cmd = "sudo iostat -dx %d %d | awk 'NF==14 && \
78 $1 !~ /Device/ {print $1,$14}'" % (interval, count)
80 LOG.debug("Executing command: %s", cmd)
81 status, stdout, stderr = self.client.execute(cmd)
83 raise RuntimeError(stderr)
89 for row in stdout.split('\n'):
95 if name not in device_name_arr:
96 device_name_arr.append(name)
97 min_util_arr.append(util)
98 max_util_arr.append(util)
99 avg_util_arr.append(util)
101 i = device_name_arr.index(name)
102 min_util_arr[i] = min_util_arr[i] \
103 if min_util_arr[i] < util else util
104 max_util_arr[i] = max_util_arr[i] \
105 if max_util_arr[i] > util else util
106 avg_util_arr[i] += util
108 for i in range(len(device_name_arr)):
109 r[device_name_arr[i]] = {"min_util": min_util_arr[i],
110 "max_util": max_util_arr[i],
111 "avg_util": avg_util_arr[i] / count}
114 def run(self, result):
115 """execute the benchmark"""
117 if not self.setup_done:
120 options = self.scenario_cfg["options"]
121 test_type = options.get('test_type', 'disk_size')
123 if test_type == "disk_utilization":
124 r = self._get_disk_utilization()
127 cmd = "sudo bash storagecapacity.sh " + test_type
129 LOG.debug("Executing command: %s", cmd)
130 status, stdout, stderr = self.client.execute(cmd)
132 raise RuntimeError(stderr)
134 result.update(jsonutils.loads(stdout))