#!/bin/bash
set +x
G_INSPECT_MMLPATH="/opt/huawei/snas/script/inspect_mml"
source ${G_INSPECT_MMLPATH}/CheckItems
source ${G_INSPECT_MMLPATH}/CommonFunc.sh

function CheckSSDCPartitionCapacity()
{
    local isPass=0
    local iRet=0
    local curInspectNum="303"
    local curInspectFun="$(GetInspectType $curInspectNum)"
    local resultFile="/tmp/tmpResult${curInspectFun}"
    local chinaAreaKey="false"
    local tmpInfo=""
    local recommendCapPercent=100
    local recommendDataSwitch=0
    local recommendMetaDataSwitch=0
    local ssdcCfgFile="/opt/huawei/snas/etc/ssdc.ini"
    local Repeat=(1 2 3)
    
    [ -f ${resultFile} ] && rm -f ${resultFile}
    >${resultFile}

    #7.1.1/7.1.1.SPC1
    local productVersion=$(grep ProductVersion /opt/huawei/deploy/package/version | awk -F= '{print $2}')
    if [ "${productVersion}" != "V500R007C10SPC300" ] && [ "${productVersion}" != "V500R007C10SPC400" ];then
        isPass=3
        echo "CapPercent:Does not involve||DataSwitch:--||MetaDataSwitch:--" >> ${resultFile}  2>&1
        echo "${curInspectFun}_Pass $isPass" >>${resultFile}
        return
    fi

    if [ -f /opt/huawei/snas/etc/ssdc_inspect_flag ];then
        #Ҫ飬ͨ
        echo "CapPercent:Does not involve||DataSwitch:--||MetaDataSwitch:--" >> ${resultFile}  2>&1
        echo "${curInspectFun}_Pass $isPass" >>${resultFile}
        return
    fi

    tmpInfo=$(/usr/local/bin/MmlBatch 988 "ssdc show pt 1")
    iRet=$?
    if [[ ${iRet} -ne 0 ]];then
        isPass=$(check_pass ${isPass} 1)
        echo "[ERR]INFO:MML command execution failed (MmlBatch 988 'ssdc show pt 1')!" >> ${resultFile} 2>&1
        echo "${curInspectFun}_Pass $isPass" >>${resultFile}
        LOG "[$LINENO]ERR: ${curInspectFun} MML command execution failed!"
        return
    fi
    tmpInfo=$(echo "${tmpInfo}" | sed -e 's/\x1B\[0;[3-4][0-9]m//g' -e 's/\x0D//g' -e 's/\x00//g')
    local CapPercent=$(echo "${tmpInfo}" | grep "PartitionID" | grep -Po '(?<=CapPercent: )[0-9]+')

    #ûssdͨ, ûͨ
    if [ "${CapPercent}" == "" ];then
        echo "CapPercent:no SSD||DataSwitch:--||MetaDataSwitch:--" >> ${resultFile}  2>&1
        echo "${curInspectFun}_Pass $isPass" >>${resultFile}
        return
    fi

    local metadata_switch=$(grep ^metadata_switch "${ssdcCfgFile}" | awk -F'=' '{print $2}')
    local data_switch=$(grep ^data_switch "${ssdcCfgFile}" | awk -F'=' '{print $2}')

    if [[ "${CapPercent}" != "${recommendCapPercent}" ]] || [[ "${data_switch}" != "${recommendDataSwitch}" ]] || [[ "${metadata_switch}" != "${recommendMetaDataSwitch}" ]]  ;then
        isPass=$(check_pass ${isPass} 1)
        echo "[ERR]INFO:CapPercent of SSDC Partition 1 is not 100 or data_switch is not 0 or matedata_switch is not 0!" >> ${resultFile} 2>&1
    fi

    echo "CapPercent:$CapPercent||DataSwitch:${data_switch}||MetaDataSwitch:${metadata_switch}" >> ${resultFile}  2>&1
    echo "${curInspectFun}_Pass ${isPass}" >>${resultFile} 2>&1

}

CheckSSDCPartitionCapacity

#Ƿسɹ[ERR]ʶǷ
exit 0

