#!/bin/bash

group=$1
testName="SAPCON"
testSummary="halib configured in sap profiles and sidadm is part of haclient group"

source ../get_test_values --group=$group


function test()
{
    local system=$1
    timeout 10 ssh -T root@$system <<EOF
        grep -q halib /sapmnt/${mySID}/profile/${mySID}_ASCS${ascsINST}_${ascsVNAME} && \
        grep -q halib /sapmnt/${mySID}/profile/${mySID}_ERS${ersINST}_${ersVNAME} && \
        id ${mySID,,}adm | grep -q haclient
EOF
    return $?
}

#
# TODO: correct filter for all cluster nodes in the use case.
#       currently we just take the first two as cluster nodes - that's a hack
#
read sys1 sys2 X <<< $allSystems
for system in $sys1 $sys2; do
    test $system; rc=$?
    logger -t $LandscapeUseCase -s "Test $testName for $group on node $system rc:  $rc"
    case $rc in 
        124 | 255 ) # test timeout - set N/A
             rm -f $STATUS_BASE_DIR/.status/${group}_${testName}_OK
             rm -f $STATUS_BASE_DIR/.status/${group}_${testName}_FAIL
             res="NA";
             ;;
        0  )
             touch $STATUS_BASE_DIR/.status/${group}_${testName}_OK
             rm -f $STATUS_BASE_DIR/.status/${group}_${testName}_FAIL
             # do not break, we need all clusternodes to be 'correct'
             ;;
        104| 1 | * )  rm -f $STATUS_BASE_DIR/.status/${group}_${testName}_OK
             touch $STATUS_BASE_DIR/.status/${group}_${testName}_FAIL
             ;;
    esac
done
