summaryrefslogtreecommitdiffstats
path: root/yardstick
diff options
context:
space:
mode:
authorliang gao <jean.gaoliang@huawei.com>2016-08-04 06:27:09 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-08-04 06:27:09 +0000
commit545ac267f0080a456984f7975febff28ef4c61c7 (patch)
tree44e5014e8b764ad954c03889af1e93c7c806e81f /yardstick
parent248836fe41a16a705752c6f84553d1026a67c806 (diff)
parent8c1d4554ae60aad799826f1d8967a69bdf3fd017 (diff)
Merge "Support Storage Capacity Test"
Diffstat (limited to 'yardstick')
-rw-r--r--yardstick/benchmark/scenarios/storage/storagecapacity.bash69
-rw-r--r--yardstick/benchmark/scenarios/storage/storagecapacity.py133
2 files changed, 202 insertions, 0 deletions
diff --git a/yardstick/benchmark/scenarios/storage/storagecapacity.bash b/yardstick/benchmark/scenarios/storage/storagecapacity.bash
new file mode 100644
index 000000000..6ed4b2811
--- /dev/null
+++ b/yardstick/benchmark/scenarios/storage/storagecapacity.bash
@@ -0,0 +1,69 @@
+#!/bin/bash
+
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Measure storage capacity and scale of a host
+
+set -e
+OUTPUT_FILE=/tmp/storagecapacity-out.log
+
+# run disk_size test
+run_disk_size()
+{
+ fdisk -l | grep '^Disk.*bytes$' | awk -F [:,\ ] '{print $2,$7}' > $OUTPUT_FILE
+}
+
+# write the disk size to stdout in json format
+output_disk_size()
+{
+ DEVICENUM=`awk 'END{print NR}' $OUTPUT_FILE`
+ DISKSIZE=`awk 'BEGIN{cnt=0;} {cnt=cnt+$2} END{print cnt}' $OUTPUT_FILE`
+ echo -e "{\
+ \"Number of devices\":\"$DEVICENUM\", \
+ \"Total disk size\":\"$DISKSIZE bytes\" \
+ }"
+}
+
+# run block_size test
+run_block_size()
+{
+ echo -n "" > $OUTPUT_FILE
+ blkdevices=`fdisk -l | grep '^Disk.*bytes$' | awk -F [:,\ ] '{print $2}'`
+ blkdevices=($blkdevices)
+ for bd in "${blkdevices[@]}";do
+ blk_size=`blockdev --getbsz $bd`
+ echo '"'$bd'" '$blk_size >> $OUTPUT_FILE
+ done
+}
+
+# write the block size to stdout in json format
+output_block_size()
+{
+ BLK_SIZE_STR=`awk 'BEGIN{r="{";} {r=r""$1":"$2","} END{print r}' $OUTPUT_FILE`
+ BLK_SIZE_STR=${BLK_SIZE_STR%,}"}"
+ echo $BLK_SIZE_STR
+}
+
+main()
+{
+ test_type=$1
+ case $test_type in
+ "disk_size" )
+ run_disk_size
+ output_disk_size
+ ;;
+ "block_size" )
+ run_block_size
+ output_block_size
+ ;;
+ esac
+}
+
+main $1
diff --git a/yardstick/benchmark/scenarios/storage/storagecapacity.py b/yardstick/benchmark/scenarios/storage/storagecapacity.py
new file mode 100644
index 000000000..49e3a0339
--- /dev/null
+++ b/yardstick/benchmark/scenarios/storage/storagecapacity.py
@@ -0,0 +1,133 @@
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and other.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import pkg_resources
+import logging
+import json
+
+import yardstick.ssh as ssh
+from yardstick.benchmark.scenarios import base
+
+LOG = logging.getLogger(__name__)
+
+
+class StorageCapacity(base.Scenario):
+ """Measure storage capacity and scale.
+
+ Parameters:
+ test_type - specified whether to measure.
+ valid test type are disk_size, block_size, disk_utilization
+ type: string
+ unit: na
+ default: "disk_size"
+ interval - specified how ofter to stat disk utilization
+ type: int
+ unit: seconds
+ default: 1
+ count - specified how many times to stat disk utilization
+ type: int
+ unit: na
+ default: 15
+
+ This scenario reads hardware specification,
+ disk size, block size and disk utilization.
+ """
+ __scenario_type__ = "StorageCapacity"
+ TARGET_SCRIPT = "storagecapacity.bash"
+
+ def __init__(self, scenario_cfg, context_cfg):
+ self.scenario_cfg = scenario_cfg
+ self.context_cfg = context_cfg
+ self.setup_done = False
+
+ def setup(self):
+ """scenario setup"""
+ self.target_script = pkg_resources.resource_filename(
+ "yardstick.benchmark.scenarios.storage",
+ StorageCapacity.TARGET_SCRIPT)
+ host = self.context_cfg['host']
+ if host is None:
+ raise RuntimeError('No right node.Please check the configuration')
+ host_user = host.get('user', 'ubuntu')
+ host_ip = host.get('ip', None)
+ host_pwd = host.get('password', 'root')
+ LOG.debug("user:%s, host:%s", host_user, host_ip)
+
+ self.client = ssh.SSH(host_user, host_ip, password=host_pwd)
+ self.client.wait(timeout=600)
+
+ # copy script to host
+ self.client.run("cat > ~/storagecapacity.sh",
+ stdin=open(self.target_script, 'rb'))
+
+ self.setup_done = True
+
+ def _get_disk_utilization(self):
+ """Get disk utilization using iostat."""
+ options = self.scenario_cfg["options"]
+ interval = options.get('interval', 1)
+ count = options.get('count', 15)
+
+ cmd = "sudo iostat -dx %d %d | awk 'NF==14 && \
+ $1 !~ /Device/ {print $1,$14}'" % (interval, count)
+
+ LOG.debug("Executing command: %s", cmd)
+ status, stdout, stderr = self.client.execute(cmd)
+ if status:
+ raise RuntimeError(stderr)
+
+ device_name_arr = []
+ min_util_arr = []
+ max_util_arr = []
+ avg_util_arr = []
+ for row in stdout.split('\n'):
+ kv = row.split(' ')
+ if len(kv) != 2:
+ continue
+ name = kv[0]
+ util = float(kv[1])
+ if name not in device_name_arr:
+ device_name_arr.append(name)
+ min_util_arr.append(util)
+ max_util_arr.append(util)
+ avg_util_arr.append(util)
+ else:
+ i = device_name_arr.index(name)
+ min_util_arr[i] = min_util_arr[i] \
+ if min_util_arr[i] < util else util
+ max_util_arr[i] = max_util_arr[i] \
+ if max_util_arr[i] > util else util
+ avg_util_arr[i] += util
+ r = {}
+ for i in range(len(device_name_arr)):
+ r[device_name_arr[i]] = {"min_util": min_util_arr[i],
+ "max_util": max_util_arr[i],
+ "avg_util": avg_util_arr[i]/count}
+ return r
+
+ def run(self, result):
+ """execute the benchmark"""
+
+ if not self.setup_done:
+ self.setup()
+
+ options = self.scenario_cfg["options"]
+ test_type = options.get('test_type', 'disk_size')
+
+ if test_type == "disk_utilization":
+ r = self._get_disk_utilization()
+ result.update(r)
+ else:
+ cmd = "sudo bash storagecapacity.sh " + test_type
+
+ LOG.debug("Executing command: %s", cmd)
+ status, stdout, stderr = self.client.execute(cmd)
+ if status:
+ raise RuntimeError(stderr)
+
+ result.update(json.loads(stdout))