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.run("cat > ~/storagecapacity.sh",
68 stdin=open(self.target_script, 'rb'))
70 self.setup_done = True
72 def _get_disk_utilization(self):
73 """Get disk utilization using iostat."""
74 options = self.scenario_cfg["options"]
75 interval = options.get('interval', 1)
76 count = options.get('count', 15)
78 cmd = "sudo iostat -dx %d %d | awk 'NF==14 && \
79 $1 !~ /Device/ {print $1,$14}'" % (interval, count)
81 LOG.debug("Executing command: %s", cmd)
82 status, stdout, stderr = self.client.execute(cmd)
84 raise RuntimeError(stderr)
90 for row in stdout.split('\n'):
96 if name not in device_name_arr:
97 device_name_arr.append(name)
98 min_util_arr.append(util)
99 max_util_arr.append(util)
100 avg_util_arr.append(util)
102 i = device_name_arr.index(name)
103 min_util_arr[i] = min_util_arr[i] \
104 if min_util_arr[i] < util else util
105 max_util_arr[i] = max_util_arr[i] \
106 if max_util_arr[i] > util else util
107 avg_util_arr[i] += util
109 for i in range(len(device_name_arr)):
110 r[device_name_arr[i]] = {"min_util": min_util_arr[i],
111 "max_util": max_util_arr[i],
112 "avg_util": avg_util_arr[i]/count}
115 def run(self, result):
116 """execute the benchmark"""
118 if not self.setup_done:
121 options = self.scenario_cfg["options"]
122 test_type = options.get('test_type', 'disk_size')
124 if test_type == "disk_utilization":
125 r = self._get_disk_utilization()
128 cmd = "sudo bash storagecapacity.sh " + test_type
130 LOG.debug("Executing command: %s", cmd)
131 status, stdout, stderr = self.client.execute(cmd)
133 raise RuntimeError(stderr)
135 result.update(json.loads(stdout))