#!/bin/bash
# 检查nvme盘的容量

_install() {
    return 0
}

_check() {
    _check="PASS"

    nvmesize_conf=$(/usr/bin/python $BASEDIR/utils/GetApolloConf.py "nvmesize" "$MachineType")
    if [[ -z $nvmesize_conf ]];then
        return 0
    fi

    nvmesize_real=$(/usr/bin/python $BASEDIR/utils/disk_subete.py -i|jq -r '.[]|select(.type=="nvme")|.pd|.[]|.size')
    wild_size=$nvmesize_real

    IFS='+' read -ra NVMESIZE <<< "$nvmesize_conf"
    for i in ${NVMESIZE[@]};
    do
        size=${i%\**}
        count=${i#*\*}
        if [[ -z $size || -z $count ]];then
            _check="FAIL"
            PRINT_ERR "[ERROR get nvmesize uconf failed"
        fi
        real_count=$(echo "$nvmesize_real"|grep -c $size)
        if [[ $real_count -ne $count ]];then
            _check="FAIL"
            PRINT_ERR "[ERROR] NVME Disk $i, real count is $real_count"
        fi
        wild_size=$(echo $wild_size|grep -v $size)
    done

    if [[ -n $wild_size ]];then
        _check="FAIL"
        wild_size=$(echo $wild_size|tr -s "\n" " ")
        PRINT_ERR "[ERROR] NVME Disk size $wild_size not in uconf"
    fi

}
