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')
60 host_user = host.get('user', 'ubuntu')
61 ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
62 host_ip = host.get('ip', None)
63 host_pwd = host.get('password', 'root')
64 LOG.debug("user:%s, host:%s", host_user, host_ip)
66 self.client = ssh.SSH(host_user, host_ip, password=host_pwd,
68 self.client.wait(timeout=600)
71 self.client._put_file_shell(self.target_script, '~/storagecapacity.sh')
73 self.setup_done = True
75 def _get_disk_utilization(self):
76 """Get disk utilization using iostat."""
77 options = self.scenario_cfg["options"]
78 interval = options.get('interval', 1)
79 count = options.get('count', 15)
81 cmd = "sudo iostat -dx %d %d | awk 'NF==14 && \
82 $1 !~ /Device/ {print $1,$14}'" % (interval, count)
84 LOG.debug("Executing command: %s", cmd)
85 status, stdout, stderr = self.client.execute(cmd)
87 raise RuntimeError(stderr)
93 for row in stdout.split('\n'):
99 if name not in device_name_arr:
100 device_name_arr.append(name)
101 min_util_arr.append(util)
102 max_util_arr.append(util)
103 avg_util_arr.append(util)
105 i = device_name_arr.index(name)
106 min_util_arr[i] = min_util_arr[i] \
107 if min_util_arr[i] < util else util
108 max_util_arr[i] = max_util_arr[i] \
109 if max_util_arr[i] > util else util
110 avg_util_arr[i] += util
112 for i in range(len(device_name_arr)):
113 r[device_name_arr[i]] = {"min_util": min_util_arr[i],
114 "max_util": max_util_arr[i],
115 "avg_util": avg_util_arr[i] / count}
118 def run(self, result):
119 """execute the benchmark"""
121 if not self.setup_done:
124 options = self.scenario_cfg["options"]
125 test_type = options.get('test_type', 'disk_size')
127 if test_type == "disk_utilization":
128 r = self._get_disk_utilization()
131 cmd = "sudo bash storagecapacity.sh " + test_type
133 LOG.debug("Executing command: %s", cmd)
134 status, stdout, stderr = self.client.execute(cmd)
136 raise RuntimeError(stderr)
138 result.update(jsonutils.loads(stdout))