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 host_ip = host.get('ip', None)
58 host_pwd = host.get('password', 'root')
59 LOG.debug("user:%s, host:%s", host_user, host_ip)
61 self.client = ssh.SSH(host_user, host_ip, password=host_pwd)
62 self.client.wait(timeout=600)
65 self.client.run("cat > ~/storagecapacity.sh",
66 stdin=open(self.target_script, 'rb'))
68 self.setup_done = True
70 def _get_disk_utilization(self):
71 """Get disk utilization using iostat."""
72 options = self.scenario_cfg["options"]
73 interval = options.get('interval', 1)
74 count = options.get('count', 15)
76 cmd = "sudo iostat -dx %d %d | awk 'NF==14 && \
77 $1 !~ /Device/ {print $1,$14}'" % (interval, count)
79 LOG.debug("Executing command: %s", cmd)
80 status, stdout, stderr = self.client.execute(cmd)
82 raise RuntimeError(stderr)
88 for row in stdout.split('\n'):
94 if name not in device_name_arr:
95 device_name_arr.append(name)
96 min_util_arr.append(util)
97 max_util_arr.append(util)
98 avg_util_arr.append(util)
100 i = device_name_arr.index(name)
101 min_util_arr[i] = min_util_arr[i] \
102 if min_util_arr[i] < util else util
103 max_util_arr[i] = max_util_arr[i] \
104 if max_util_arr[i] > util else util
105 avg_util_arr[i] += util
107 for i in range(len(device_name_arr)):
108 r[device_name_arr[i]] = {"min_util": min_util_arr[i],
109 "max_util": max_util_arr[i],
110 "avg_util": avg_util_arr[i]/count}
113 def run(self, result):
114 """execute the benchmark"""
116 if not self.setup_done:
119 options = self.scenario_cfg["options"]
120 test_type = options.get('test_type', 'disk_size')
122 if test_type == "disk_utilization":
123 r = self._get_disk_utilization()
126 cmd = "sudo bash storagecapacity.sh " + test_type
128 LOG.debug("Executing command: %s", cmd)
129 status, stdout, stderr = self.client.execute(cmd)
131 raise RuntimeError(stderr)
133 result.update(json.loads(stdout))