#!/bin/bash
set +x

G_MML_FILE_PATH="/opt/huawei/snas/script/inspect_mml"
source $G_MML_FILE_PATH/CheckItems
. /opt/node_type_recognize.sh
CurInspectNum="317"
CurInspectFun="$(GetInspectType $CurInspectNum)"
RESULTFILE="/tmp/tmpResult${CurInspectFun}"
LOG_FILE="/var/log/inspect.log"
>${RESULTFILE}

G_ISPASS=0

function LOG
{
   time=$(date)
   echo [${time}][$$][${CurInspectFun}]$@ >> ${LOG_FILE}
}

function CheckNuma()
{
    local status=""
    local available_nodes_num=0
    local iRet=0
    local isTs=0
    IsTSNode
    isTs=$?
    if [ ${isTs} -ne 0 ];then
        echo "INFO:It is not TaiShan server. No need to check." >>${RESULTFILE}
        return
    fi
    #ARM鵽available nodesΪ1ʾNumaΪأNumaʵʲЧ
    available_nodes_num=$(numactl --hardware |grep available |head -n1 |awk '{print $2}')
    iRet=$?
    if [ ${iRet} -ne 0 ];then
        G_ISPASS=1
        echo "[ERR]INFO:Failed to get information from command(numactl --hardware)." >>${RESULTFILE}
        LOG "[$LINENO]Failed to get information,iRet=${iRet}"
        return
    fi

    if [ ${available_nodes_num} -ne 1 ];then
        status="OPEN"
    else
        G_ISPASS=1
        status="CLOSE"
        LOG "[$LINENO]NumaEn switch is off,available_nodes_num=${available_nodes_num}"
        echo "[ERR]INFO:NumaEn switch is off." >>${RESULTFILE}
    fi
    echo "INFO:${status}" >>${RESULTFILE}
}

CheckNuma
echo "${CurInspectFun}_Pass ${G_ISPASS}" >>${RESULTFILE}
exit 0

