f963782d89ab83cce3f075f4246c45a574d848b2
[yardstick.git] / yardstick / benchmark / scenarios / storage / storagecapacity.bash
1 #!/bin/bash
2
3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # Measure storage capacity and scale of a host
13
14 set -e
15 OUTPUT_FILE=/tmp/storagecapacity-out.log
16
17 # run disk_size test
18 run_disk_size()
19 {
20     fdisk -l | grep '^Disk.*bytes$' | awk -F [:,\ ] '{print $2,$7}' > $OUTPUT_FILE
21 }
22
23 # write the disk size to stdout in json format
24 output_disk_size()
25 {
26     DEVICENUM=`awk 'END{print NR}' $OUTPUT_FILE`
27     DISKSIZE=`awk 'BEGIN{cnt=0;} {cnt=cnt+$2} END{print cnt}' $OUTPUT_FILE`
28     echo -e "{\
29          \"Number of devices\":\"$DEVICENUM\", \
30          \"Total disk size in bytes\":\"$DISKSIZE\" \
31     }"
32 }
33
34 # run block_size test
35 run_block_size()
36 {
37     echo -n "" > $OUTPUT_FILE
38     blkdevices=`fdisk -l | grep '^Disk.*bytes$' | awk -F [:,\ ] '{print $2}'`
39     blkdevices=($blkdevices)
40     for bd in "${blkdevices[@]}";do
41         blk_size=`blockdev --getbsz $bd`
42         echo '"'$bd'" '$blk_size >> $OUTPUT_FILE
43     done
44 }
45
46 # write the block size to stdout in json format
47 output_block_size()
48 {
49     BLK_SIZE_STR=`awk 'BEGIN{r="{";} {r=r""$1":"$2","} END{print r}' $OUTPUT_FILE`
50     BLK_SIZE_STR=${BLK_SIZE_STR%,}"}"
51     echo $BLK_SIZE_STR
52 }
53
54 main()
55 {
56     test_type=$1
57     case $test_type in
58         "disk_size" )
59             run_disk_size
60             output_disk_size
61         ;;
62         "block_size" )
63             run_block_size
64             output_block_size
65         ;;
66     esac
67 }
68
69 main $1