start:reg_linux_statelite_installation_hierarchy_by_nfs
os:Linux
label:others,provision,statelite
#stop:yes
cmd:xdsh $$SN fdisk -l
cmd:xdsh $$SN df -T
cmd:xdsh $$SN "echo "test"> /test.hierarchy"
check:rc==0
cmd:xdsh $$SN cat /test.hierarchy
check:rc==0
check:output=~test
cmd:output=$(xdsh $$SN ls -al / |grep test.hierarchy);if [[ $? -eq 0 ]];then  xdsh $$SN rm -rf /test.hierarchy;fi
cmd:chdef -t node -o $$CN servicenode=$$SN monserver=$$SN nfsserver=$$SN tftpserver=$$SN  xcatmaster=$$SN
check:rc==0
cmd:chdef -t node $$SN groups=service,all
check:rc==0

cmd:makedns -n
check:rc==0
cmd:if [ -x /usr/bin/goconserver ]; then makegocons $$CN; else makeconservercf $$CN; fi
check:rc==0
cmd:sleep 20
cmd:if [[ "__GETNODEATTR($$CN,arch)__" = "ppc64" ]]; then getmacs -D $$CN; fi
check:rc==0
cmd:makedhcp -n
check:rc==0
cmd:makedhcp -a
check:rc==0
cmd:copycds $$ISO
check:rc==0
cmd:xdsh $$SN df|grep /install;if [ $? -eq 0 ] ;then xdsh $$SN umount /install;fi
check:rc==0
cmd:xdsh $$SN 'cat /etc/exports|grep install; if [ "$?" -ne "0" ]; then echo "/install *(rw,no_root_squash,sync,no_subtree_check)" >> /etc/exports; fi'
check:rc==0

cmd:xdsh $$SN "mkdir -p /nodedata"
check:rc==0
cmd:xdsh $$SN "chmod 755 /etc/exports"
check:rc==0
cmd:xdsh $$SN 'cat /etc/exports|grep nodedata; if [ "$?" -ne "0" ]; then echo "/nodedata *(rw,no_root_squash,sync,no_subtree_check)" >> /etc/exports; fi'
check:rc==0
cmd:xdsh $$SN 'cd /etc; export exports;cd -'
check:rc==0
cmd:if cat /etc/*release |grep SUSE >/dev/null;then xdsh $$SN 'service nfsserver restart'; elif cat /etc/*release |grep "Red Hat\|Rocky\|Alma" >/dev/null;then xdsh $$SN 'if [ -f /usr/lib/systemd/system/nfs-server.service ]; then service nfs-server restart; else service nfs restart;fi'; fi
check:rc==0

cmd:xdsh $$SN 'showmount -e'

cmd:chtab node=$$CN statelite.statemnt="$$SN:/nodedata"
check:rc==0

cmd:if cat /etc/*release |grep SUSE >/dev/null; then cp /opt/xcat/share/xcat/tools/autotest/testcase/installation/litefile_sles.csv /tmp/litefile.csv; tabrestore /tmp/litefile.csv; elif cat /etc/*release |grep "Red Hat\|Rocky\|Alma" >/dev/null; then  tabrestore /opt/xcat/share/xcat/tools/autotest/testcase/installation/litefile.csv; fi
check:rc==0
cmd:tabdump litefile
check:rc==0

cmd:chtab priority=4.7 policy.commands=litefile policy.rule=allow
check:rc==0
cmd:chtab priority=4.8 policy.commands=litetree policy.rule=allow
check:rc==0

cmd:rootimgdir=`lsdef -t osimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-statelite-compute|grep rootimgdir|awk -F'=' '{print $2}'`; if [ -d $rootimgdir ]; then rm -rf $rootimgdir.regbak; mv $rootimgdir $rootimgdir.regbak;fi
check:rc==0

cmd:lsdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-statelite-compute
check:rc==0

cmd:chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-statelite-compute rootfstype=nfs
check:rc==0

cmd:genimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-statelite-compute
check:rc==0
cmd:liteimg __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-statelite-compute
check:rc==0
#Before doing prsync of /install to the service node, check if there is enough space there
cmd:du -sh /install
cmd:xdsh $$SN df -H
cmd:prsync /install $$SN:/
check:rc==0
check:output=~$$SN: done
check:output!~write failed

cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/retry_install.sh  $$CN __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-statelite-compute 1
check:rc==0
check:output=~Provision node\(s\)\: $$CN

cmd:xdsh $$SN "if [[ -f /var/lib/dhcp/db/dhcpd.leases ]]; then cat /var/lib/dhcp/db/dhcpd.leases; elif [[ -f /var/lib/dhcpd/dhcpd.leases ]];then cat /var/lib/dhcpd/dhcpd.leases;elif [[ -f /var/lib/dhcp/dhcpd.leases ]];then cat /var/lib/dhcp/dhcpd.leases; fi"

cmd:ping $$CN -c 3
check:rc==0
check:output=~64 bytes from $$CN
cmd:lsdef -l $$CN | grep status
check:rc==0
check:output=~booted
cmd:xdsh $$CN date
check:rc==0
check:output=~\d\d:\d\d:\d\d
cmd:xdsh $$CN mount
check:rc==0
check:output=~/nodedata/$$CN on /.statelite/persistent
check:output=~compute/rootimg on / type nfs
cmd:xdsh $$CN hostname
check:rc==0
check:output=~$$CN: $$CN
cmd:xdsh $$CN  "cat /var/log/xcat/xcat.log"
cmd:xdsh $$CN "echo "test"> /test.statelite"
check:rc!=0

# Check there are no load host key warnings
cmd:xdsh $$CN "grep 'load host key' /var/log/xcat/xcat.log || echo 'No load hostkey warning' >&2"
check:output=~No load hostkey warning

cmd:if [ -x /usr/bin/goconserver ]; then makegocons -d $$CN; else makeconservercf -d $$CN; fi
cmd:output=$(xdsh $$CN ls -al / |grep test.statelite);if [[ $? -eq 0 ]];then  xdsh $$CN rm -rf /test.statelite;fi
cmd:rootimgdir=`lsdef -t osimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-statelite-compute|grep rootimgdir|awk -F'=' '{print $2}'`; if [ -d $rootimgdir ]; then rm -rf $rootimgdir;fi
check:rc==0
end
