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 ##############################################################################
13 import yardstick.ssh as ssh
14 from yardstick.benchmark.scenarios import base
16 LOG = logging.getLogger(__name__)
19 class StorageCapacity(base.Scenario):
20 """Measure storage capacity and scale.
23 test_type - specified whether to measure.
24 valid test type are disk_size, block_size, disk_utilization
28 interval - specified how ofter to stat disk utilization
32 count - specified how many times to stat disk utilization
37 This scenario reads hardware specification,
38 disk size, block size and disk utilization.
40 __scenario_type__ = "StorageCapacity"
41 TARGET_SCRIPT = "storagecapacity.bash"
43 def __init__(self, scenario_cfg, context_cfg):
44 self.scenario_cfg = scenario_cfg
45 self.context_cfg = context_cfg
46 self.setup_done = False
50 self.target_script = pkg_resources.resource_filename(
51 "yardstick.benchmark.scenarios.storage",
52 StorageCapacity.TARGET_SCRIPT)
53 host = self.context_cfg['host']
55 raise RuntimeError('No right node.Please check the configuration')
56 host_user = host.get('user', 'ubuntu')
57 ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
58 host_ip = host.get('ip', None)
59 host_pwd = host.get('password', 'root')
60 LOG.debug("user:%s, host:%s", host_user, host_ip)
62 self.client = ssh.SSH(host_user, host_ip, password=host_pwd,
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(json.loads(stdout))