aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/scenarios/storage/storagecapacity.bash
blob: 6ed4b281170623354cf4f2fadf3ec749611fe1eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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