xcat-core/xCAT-server/xCAT-wsapi/xcatws-test.sh

136 lines
5.5 KiB
Bash
Raw Normal View History

2014-02-03 20:58:15 +00:00
#!/bin/bash
# IBM(c) 2014 EPL license http://www.eclipse.org/legal/epl-v10.html
2014-01-31 13:26:55 +00:00
2014-02-27 00:34:16 +00:00
# Test driver for xcatws.cgi, pass 3 arguments to it: user, password, noderange
# This test driver will create to dummy nodes, wstest1 and wstest2, so make sure those
# names don't conflict with your nodes on this MN.
# You also have to pass in a noderange of 2 real system x nodes that can be used
# to test some of the r cmds, xdsh, xdcp, nodestat.
user=$1
pw=$2
2014-02-27 00:34:16 +00:00
nr=$3
if [ -z "$3" ]; then
echo "Usage: chkrc <user> <pw> <noderange>"
exit
fi
format='format=json&pretty=1'
2014-02-27 00:34:16 +00:00
ctype='-H Content-Type:application/json'
function chkrc
{
rc=$?
{ set +x; } 2>/dev/null
if [[ $1 == "not" ]]; then
if [[ $rc -eq 0 ]]; then
echo "Test failed!"
exit
fi
else
if [[ $rc -gt 0 ]]; then
echo "Test failed!"
exit
fi
fi
echo ''
set -x
}
# pcregrep -M 'abc.*(\n|.)*efg' test.txt
2014-02-03 20:58:15 +00:00
#todo: add a test case for every api call that is documented
2014-02-27 00:34:16 +00:00
set -x
# clean up from last time
2014-03-16 23:54:00 +00:00
curl -# -X DELETE -k "https://127.0.0.1/xcatws/node/wstest?userName=$user&password=$pw" >/dev/null; echo ''
2014-02-27 00:34:16 +00:00
# create test nodes
2014-03-16 23:54:00 +00:00
curl -# -X POST -k "https://127.0.0.1/xcatws/node/wstest1-wstest2?userName=$user&password=$pw&$format" $ctype --data '{"groups":"wstest","netboot":"xnba"}' \
2014-02-27 00:34:16 +00:00
| grep -q '2 object definitions have been created'; chkrc
# list all nodes and make sure they are in the list
2014-03-16 23:54:00 +00:00
curl -# -X GET -k "https://127.0.0.1/xcatws/node?userName=$user&password=$pw&$format" \
2014-02-27 00:34:16 +00:00
| pcregrep -qM '"wstest1",\n\s*"wstest2"'; chkrc
# list all node's group and netboot attributes
2014-03-16 23:54:00 +00:00
curl -# -X GET -k "https://127.0.0.1/xcatws/node?userName=$user&password=$pw&field=groups&field=netboot" \
2014-02-27 00:34:16 +00:00
| grep -qE '"nodename":"wstest1".*"groups":"wstest"'; chkrc
# list all attributes of all nodes
2014-03-16 23:54:00 +00:00
curl -# -X GET -k "https://127.0.0.1/xcatws/node?userName=$user&password=$pw&field=ALL" \
2014-02-27 00:34:16 +00:00
| grep -qE '"nodename":"wstest1".*"groups":"wstest"'; chkrc
# list the noderange and make sure they are in the list
2014-03-16 23:54:00 +00:00
curl -# -X GET -k "https://127.0.0.1/xcatws/node/wstest?userName=$user&password=$pw&$format" \
2014-02-27 00:34:16 +00:00
| pcregrep -qM '"wstest1",\n\s*"wstest2"'; chkrc
# list all node's group and netboot attributes
2014-03-16 23:54:00 +00:00
curl -# -X GET -k "https://127.0.0.1/xcatws/node/wstest?userName=$user&password=$pw&field=groups&field=netboot" \
2014-02-27 00:34:16 +00:00
| grep -qE '"nodename":"wstest1".*"groups":"wstest"'; chkrc
# list all attributes of all nodes
2014-03-16 23:54:00 +00:00
curl -# -X GET -k "https://127.0.0.1/xcatws/node/wstest?userName=$user&password=$pw&field=ALL" \
2014-02-27 00:34:16 +00:00
| grep -qE '"nodename":"wstest1".*"groups":"wstest"'; chkrc
# change some attributes
2014-03-16 23:54:00 +00:00
curl -# -X PUT -k "https://127.0.0.1/xcatws/node/wstest?userName=$user&password=$pw&$format" $ctype --data '{"room":"222","netboot":"pxe"}' \
2014-02-27 00:34:16 +00:00
| grep -q '2 object definitions have been created or modified'; chkrc
# verify they got the new values
2014-03-16 23:54:00 +00:00
curl -# -X GET -k "https://127.0.0.1/xcatws/node/wstest?userName=$user&password=$pw&field=room&field=netboot" \
2014-02-27 00:34:16 +00:00
| grep -qE '"nodename":"wstest1".*"room":"222"'; chkrc
# delete the nodes
2014-03-16 23:54:00 +00:00
curl -# -X DELETE -k "https://127.0.0.1/xcatws/node/wstest?userName=$user&password=$pw&$format" \
2014-02-27 00:34:16 +00:00
| grep -q '2 object definitions have been removed'; chkrc
# list all nodes and make sure they are not in the list
2014-03-16 23:54:00 +00:00
curl -# -X GET -k "https://127.0.0.1/xcatws/node?userName=$user&password=$pw&$format" \
2014-02-27 00:34:16 +00:00
| pcregrep -qM '"wstest1",\n\s*"wstest2"'; chkrc not
# list the power state of the noderange
2014-03-16 23:54:00 +00:00
curl -# -X GET -k "https://127.0.0.1/xcatws/node/$nr/power?userName=$user&password=$pw&$format" \
2014-02-27 00:34:16 +00:00
| grep -q '"power":"on"'; chkrc
# list the nodestat state of the noderange
2014-03-16 23:54:00 +00:00
curl -# -X GET -k "https://127.0.0.1/xcatws/node/$nr/status?userName=$user&password=$pw&$format" \
2014-02-27 00:34:16 +00:00
| grep -q '":"sshd"'; chkrc
# list the node inventory of the noderange
2014-03-16 23:54:00 +00:00
curl -# -X GET -k "https://127.0.0.1/xcatws/node/$nr/inventory?userName=$user&password=$pw&$format" \
2014-02-27 00:34:16 +00:00
| grep -q '"Board manufacturer":"IBM"'; chkrc
# list the node vitals of the noderange
2014-03-16 23:54:00 +00:00
curl -# -X GET -k "https://127.0.0.1/xcatws/node/$nr/vitals?userName=$user&password=$pw&$format" \
2014-02-27 00:34:16 +00:00
| grep -q '"Cooling Fault":"false"'; chkrc
# list the node energy settings of the noderange
2014-03-16 23:54:00 +00:00
curl -# -X GET -k "https://127.0.0.1/xcatws/node/$nr/energy?userName=$user&password=$pw&$format&field=cappingstatus&field=cappingmaxmin" \
2014-02-27 00:34:16 +00:00
| grep -q '"cappingstatus":"off"'; chkrc
# run a cmd on the noderange
2014-03-16 23:54:00 +00:00
curl -# -X POST -k "https://127.0.0.1/xcatws/node/$nr/dsh?userName=$user&password=$pw&$format" $ctype --data '{"command":"pwd"}' \
2014-02-27 00:34:16 +00:00
| grep -q '"/root"'; chkrc
# copy a file to the noderange
2014-03-16 23:54:00 +00:00
curl -# -X POST -k "https://127.0.0.1/xcatws/node/$nr/dcp?userName=$user&password=$pw&$format" $ctype --data '{"source":"/root/.bashrc","target":"/tmp/"}' \
2014-02-27 00:34:16 +00:00
| grep -q '"errorcode":"0"'; chkrc
2014-03-16 23:54:00 +00:00
# test the table calls
#curl -# -X GET -k "https://127.0.0.1/xcatws/table/nodelist/test001?userName=$user&password=$pw&$format"
2014-02-27 00:34:16 +00:00
exit
#curl -X GET -k "https://127.0.0.1/xcatws/groups?userName=$user&password=$pw&$format"
#curl -X GET -k "https://127.0.0.1/xcatws/images?userName=$user&password=$pw&$format"
#curl -X GET -k "https://127.0.0.1/xcatws/images?userName=$user&password=$pw&$format&field=osvers"
#curl -X GET -k "https://127.0.0.1/xcatws/images/bp-netboot?userName=$user&password=$pw&$format"
#curl -X GET -k "https://127.0.0.1/xcatws/images/bp-netboot?userName=$user&password=$pw&$format&field=osvers"
#todo: remove when these test cases are in xcatws-test.pl
2014-03-16 23:54:00 +00:00
#./xcatws-test.pl -u "https://127.0.0.1/xcatws/node/test001?userName=$user&password=$pw" -m GET
#./xcatws-test.pl -u "https://127.0.0.1/xcatws/node/test001?userName=$user&password=$pw" -m PUT "nodepos.room=foo"