start:makehosts_h
label:mn_only,dns
description:makehosts -h
cmd:makehosts -h
check:rc==0
check:output=~Usage
end

start:makehosts_help
label:mn_only,dns
description:makehosts --help
cmd:makehosts --help
check:rc==0
check:output=~Usage
end

start:makehosts_null
description:makehosts
label:mn_only,dns
cmd:cp -f /etc/hosts /etc/hosts.xcatbakautotest
cmd:chtab node=nouse_compute hosts.ip="|node(\d+)|1.2.3.(\$1+0)|" hosts.hostnames="|(.*)|(\$1).cluster.net|"
check:rc==0
cmd:mkdef -t node -o node01,node02 groups="nouse_compute"
check:rc==0
cmd:sleep 30
cmd:XCATBYPASS=1 makehosts
check:rc==0
cmd:sleep 30
cmd:cat /etc/hosts
check:output=~1.2.3.2
check:output=~1.2.3.1
check:output=~node01
check:output=~node02
cmd:chtab -d node=nouse_compute hosts
cmd:rmdef node01
cmd:rmdef node02
cmd:mv -f /etc/hosts.xcatbakautotest /etc/hosts
end

start:makehosts_l
label:mn_only,dns,wait_fix
cmd:cp -f /etc/hosts /etc/hosts.xcatbakautotest
cmd:cat /etc/hosts
cmd:chtab node=nouse_compute hosts.ip="|node(\d+)|1.2.3.(\$1+0)|" hosts.hostnames="|(.*)|(\$1).cluster.net|"
check:rc==0
cmd:chdef -t node -o node01,node02 groups="nouse_compute"
check:rc==0
cmd:sleep 30
cmd:lsdef -l nouse_compute
cmd:XCATBYPASS=1 makehosts -l
check:rc==0
cmd:sleep 30
cmd:cat /etc/hosts
cmd:cat /etc/hosts |awk '{print $2}'
check:output=~node01.cluster.net
check:output=~node02.cluster.net
cmd:rmdef node01
cmd:rmdef node02
cmd:chtab -d node=nouse_compute hosts
cmd:mv -f /etc/hosts.xcatbakautotest /etc/hosts
end

start:makehosts_d
label:mn_only,dns,wait_fix
cmd:cp -f /etc/hosts /etc/hosts.xcatbakautotest
cmd:chtab node=compute hosts.ip="|node(\d+)|1.2.3.(\$1+0)|" hosts.hostnames="|(.*)|(\$1).cluster.net|"
check:rc==0
cmd:chdef -t node -o node01 groups="compute"
check:rc==0
cmd:lsdef  -l node01
cmd:sleep 30
cmd:cat /etc/hosts
cmd:makehosts node01
check:rc==0
cmd:sleep 30
cmd:cat /etc/hosts |tee /tmp/1
cmd:grep "node01" /etc/hosts
check:rc==0
cmd:XCATBYPASS=1 makehosts -d node01
check:rc==0
cmd:cat /etc/hosts |tee /tmp/2
cmd:diff /tmp/1 /tmp/2
check:output=~node01.cluster.net
cmd:chtab -d node=compute hosts
cmd:rmdef node01
cmd:mv -f /etc/hosts.xcatbakautotest /etc/hosts
cmd:rm -f /tmp/1 /tmp/2
end

start:makehosts_n
label:mn_only,dns
cmd:cp -f /etc/hosts /etc/hosts.xcatbakautotest
cmd:chtab node=nouse_compute hosts.ip="|node(\d+)|1.2.3.(\$1+0)|" hosts.hostnames="|(.*)|(\$1).cluster.net|"
check:rc==0
cmd:chdef -t node -o node01 groups="nouse_compute"
check:rc==0
cmd:sleep 30
cmd:XCATBYPASS=1 makehosts -n
check:rc==0
cmd:sleep 30
cmd:cat /etc/hosts
cmd:sleep 30
cmd:cp -f /etc/hosts /tmp/hosts
cmd:cat /tmp/hosts |wc -l
check:rc==0
cmd:cat /tmp/hosts
check:output=~node01.cluster.net
cmd:chtab -d node=nouse_compute hosts
cmd:rmdef node01
cmd:cp /etc/hosts /hosts
cmd:mv -f /etc/hosts.xcatbakautotest /etc/hosts
cmd:rm -rf /tmp/hosts
end

start:makehosts_n_noderange
label:mn_only,dns
cmd:cp -f /etc/hosts /etc/hosts.xcatbakautotest
cmd:chtab node=compute hosts.ip="|node(\d+)|1.2.3.(\$1+0)|" hosts.hostnames="|(.*)|(\$1).cluster.net|"
check:rc==0
cmd:chdef -t node -o node01 groups="compute"
check:rc==0
cmd:sleep 30
cmd:XCATBYPASS=1 makehosts -n node01
check:rc==0
cmd:sleep 30
cmd:cp /etc/hosts /tmp/hosts -f
cmd:cat /tmp/hosts |wc -l
check:rc==0
check:output==2
cmd:cat /tmp/hosts
check:output=~node01.cluster.net
cmd:chtab -d node=compute hosts
cmd:rmdef node01
cmd:mv -f /etc/hosts.xcatbakautotest /etc/hosts
cmd:cat /etc/hosts| grep -v node01 > /tmp/1
cmd:mv -f /tmp/1 /etc/hosts
cmd:rm -rf /tmp/hosts
end

start:makehost_n_r
label:mn_only,dns,wait_fix
descriptions:modify makehosts testcases according to special node name eg:s01 and s01r* . for issue #2717 and #2683
cmd:cp -f /etc/hosts /etc/hosts.xcatbakautotest
cmd:cat /etc/hosts
cmd:lsdef s01;if [ $? -eq 0 ]; then lsdef -l s01 -z >/tmp/s01.standa ;rmdef s01;fi
check:rc==0
cmd:lsdef s01r1b01;if [ $? -eq 0 ]; then lsdef -l s01r1b01 -z >/tmp/s01r1b01.standa ;rmdef s01r1b01;fi
check:rc==0
cmd:nodeadd s01 groups=service; chdef s01 ip=70.2.0.254;nodeadd s01r1b01 groups=compute; chdef s01r1b01 ip=80.2.0.254
check:rc==0
cmd:lsdef -l s01,s01r1b01
cmd:makehosts
check:rc==0
cmd:cat /etc/hosts
cmd:#!/bin/bash
file="/etc/hosts"
for i in {1..5}; do
    if (grep "70.2.0.254 s01" $file >/dev/null 2>&1) && (grep "80.2.0.254 s01r1b01" $file >/dev/null 2>&1); then
        exit 0;
    else
        echo "Do not find s01 and s01r1b01 in $file, sleep $[i*2] seconds and try again"
        sleep $[i*2]
    fi
done
exit 1
check:rc==0
cmd:cp -f /etc/hosts.xcatbakautotest /etc/hosts
cmd:makehosts s01
check:rc==0
cmd:cat /etc/hosts
cmd:#!/bin/bash
file="/etc/hosts"
for i in {1..5}; do
    if (grep "70.2.0.254 s01" $file >/dev/null 2>&1) && ( ! grep "80.2.0.254 s01r1b01" $file >/dev/null 2>&1); then
        exit 0;
    else
        echo "sleep $[i*2] seconds and try again"
        sleep $[i*2]
    fi
done
exit 1
check:rc==0
cmd:cp -f /etc/hosts.xcatbakautotest /etc/hosts
cmd:makehosts service
check:rc==0
cmd:cat /etc/hosts
cmd:#!/bin/bash
file="/etc/hosts"
for i in {1..5}; do
    if (grep "70.2.0.254 s01" $file >/dev/null 2>&1) && (! grep "80.2.0.254 s01r1b01" $file >/dev/null 2>&1); then
        exit 0;
    else
        echo "sleep $[i*2] seconds and try again"
        sleep $[i*2]
    fi
done
exit 1
check:rc==0
cmd:makehosts -d s01
check:rc==0
cmd:cat /etc/hosts
cmd:#!/bin/bash
file="/etc/hosts"
for i in {1..5}; do
    if (! grep "70.2.0.254 s01" $file >/dev/null 2>&1) && (! grep "80.2.0.254 s01r1b01" $file >/dev/null 2>&1); then
        exit 0;
    else
        echo "sleep $[i*2] seconds and try again"
        sleep $[i*2]
    fi
done
exit 1
check:rc==0
cmd:cp -f /etc/hosts.xcatbakautotest /etc/hosts
cmd:makehosts
check:rc==0
cmd:cat /etc/hosts
cmd:makehosts -d service
check:rc==0
cmd:cat /etc/hosts
cmd:#!/bin/bash
file="/etc/hosts"
for i in {1..5}; do
    if (! grep "70.2.0.254 s01" $file >/dev/null 2>&1) && (grep "80.2.0.254 s01r1b01" $file >/dev/null 2>&1); then
        exit 0;
    else
        echo "sleep $[i*2] seconds and try again"
        sleep $[i*2]
    fi
done
exit 1
check:rc==0
cmd:cp -f /etc/hosts.xcatbakautotest /etc/hosts
cmd:makehosts
check:rc==0
cmd:cat /etc/hosts
cmd:makehosts -d s01r1b01
check:rc==0
cmd:cat /etc/hosts
cmd:#!/bin/bash
file="/etc/hosts"
for i in {1..5}; do
    if (grep "70.2.0.254 s01" $file >/dev/null 2>&1) && (! grep "80.2.0.254 s01r1b01" $file >/dev/null 2>&1); then
        exit 0;
    else
        echo "sleep $[i*2] seconds and try again"
        sleep $[i*2]
    fi
done
exit 1
check:rc==0
cmd:if [ -e /tmp/s01.standa ]; then rmdef s01; cat /tmp/s01.standa | mkdef -z; rm -rf /tmp/s01.standa; else rmdef s01;fi
check:rc==0
cmd:if [ -e /tmp/s01r1b01.standa ]; then rmdef s01r1b01; cat /tmp/s01r1b01.standa | mkdef -z; rm -rf /tmp/s01r1b01.standa;else rmdef s01r1b01; fi
check:rc==0
cmd:mv -f /etc/hosts.xcatbakautotest /etc/hosts
end

start:makehosts_regex
label:mn_only,dns
description:this case is to test if makehosts support regex. This case is for bug 2578.
cmd:cp /etc/hosts /etc/hosts.bak
cmd:if lsdef -z sn4b;then lsdef -z sn4b|tee /tmp/sn4bdef;noderm sn4b;fi
cmd:if lsdef -t group -z regextest;then lsdef -t group -z regextest |tee /tmp/regextestdef;rmdef -t group -o regextest;fi
cmd:if grep sn4b /etc/hosts;then sed -i '/sn4b/d' /etc/hosts;fi
check:rc==0
cmd:cat /etc/hosts
cmd:mkdef -t node sn4b groups=compute
check:rc==0
cmd:mkdef -t group regextest ip="|\D+(\d+)\D+|20.80.1.($1*2+103)|" members=sn4b nichostnamesuffixes.eth0=-eth0 nicips.eth0="|\D+(\d+)\D+|10.80.1.($1*2+103)|" nicnetworks.eth0=10_0_0_0-255_0_0_0
check:rc==0
cmd:lsdef -t group regextest
check:rc==0
cmd:makehosts sn4b
check:rc==0
cmd:cat /etc/hosts
cmd:sn4bip=`lsdef sn4b |grep -w ip|awk -F= '{print $2}'`;grep $sn4bip /etc/hosts
check:rc==0
cmd:sn4beth0ip=`lsdef sn4b |grep -w nicips.eth0|awk -F= '{print $2}'`;grep $sn4beth0ip /etc/hosts
check:rc==0
cmd:cp -f /etc/hosts.bak /etc/hosts
cmd:noderm sn4b;if [ -e /tmp/sn4bdef ]; then cat /tmp/sn4bdef |mkdef -z;fi
cmd:rmdef -t group -o regextest;if [ -e /tmp/regextestdef ]; then cat /tmp/regextestdef |mkdef -z;fi
end
