Update the api-test script with optional way to enable REST mode

This commit is contained in:
Kris Moore
2016-05-09 11:31:52 -04:00
parent 9287390e54
commit 2e4c3d8068

View File

@@ -14,6 +14,8 @@ DEFUSER="root"
DEFNAMESPACE="sysadm"
DEFCLASS="systemmanager"
DEFACTION="{\"action\":\"procinfo\"}"
RESTMODE="no"
RESTIP="127.0.0.1"
# Set variable to call jsawk utility
JSAWK="./utils/jsawk -j js24"
@@ -105,31 +107,34 @@ if [ -z "$APITESTPAYLOAD" ] ; then
echo ""
fi
# Source our resty functions
. ./utils/resty -W "https://127.0.0.1:12151" -H "Accept: application/json" -H "Content-Type: application/json" -u ${APITESTUSER}:${APITESTPASS}
# If the user wanted to do RESTMODE
if [ "$RESTMODE" = "yes" ] ; then
# Source our resty functions
. ./utils/resty -W "https://${RESTIP}:12151" -H "Accept: application/json" -H "Content-Type: application/json" -u ${APITESTUSER}:${APITESTPASS}
# Save output to a file in addition to stdout
ofile="/tmp/api-response"
echo "" > /tmp/api-response
# Save output to a file in addition to stdout
ofile="/tmp/api-response"
echo "" > /tmp/api-response
# Check the reply of this REST query
echo "" | tee -a $ofile
echo "REST Request:" | tee -a $ofile
echo "-------------------------------" | tee -a $ofile
echo "PUT /${APITESTNAMESPACE}/${APITESTCLASS}" | tee -a $ofile
echo "${APITESTPAYLOAD}" | perl -0007 -MJSON -ne'print to_json(from_json($_, {allow_nonref=>1}),{pretty=>1})."\n"' | tee -a $ofile
# Check the reply of this REST query
echo "" | tee -a $ofile
echo "REST Request:" | tee -a $ofile
echo "-------------------------------" | tee -a $ofile
echo "PUT /${APITESTNAMESPACE}/${APITESTCLASS}" | tee -a $ofile
echo "${APITESTPAYLOAD}" | perl -0007 -MJSON -ne'print to_json(from_json($_, {allow_nonref=>1}),{pretty=>1})."\n"' | tee -a $ofile
echo "" | tee -a $ofile
echo "REST Response:" | tee -a $ofile
echo "-------------------------------" | tee -a $ofile
PUT /${APITESTNAMESPACE}/${APITESTCLASS} "${APITESTPAYLOAD}" -v -k #2>/tmp/.rstErr | tee -a $ofile
if [ $? -ne 0 ] ; then
echo "Failed.. Error output:"
cat /tmp/.rstErr
echo "" | tee -a $ofile
echo "REST Response:" | tee -a $ofile
echo "-------------------------------" | tee -a $ofile
PUT /${APITESTNAMESPACE}/${APITESTCLASS} "${APITESTPAYLOAD}" -v -k 2>/tmp/.rstErr | tee -a $ofile
if [ $? -ne 0 ] ; then
echo "Failed.. Error output:"
cat /tmp/.rstErr
fi
rm $ofile
rm /tmp/.rstErr
exit 0
fi
rm $ofile
rm /tmp/.rstErr
exit 0;
# Now check the response via WebSockets