add colorful cmd for test scripts

pull/62/head
qiang0723 2017-06-14 13:30:12 +08:00
parent 9f0b6625c9
commit a83a419258
3 changed files with 66 additions and 56 deletions

View File

@ -6,6 +6,8 @@ echo " ==========initialize businesschannel========== "
echo " ============================================== " echo " ============================================== "
echo echo
source scripts/header.sh
CHANNEL_NAME="$1" CHANNEL_NAME="$1"
: ${CHANNEL_NAME:="businesschannel"} : ${CHANNEL_NAME:="businesschannel"}
: ${TIMEOUT:="60"} : ${TIMEOUT:="60"}
@ -13,12 +15,12 @@ COUNTER=1
MAX_RETRY=5 MAX_RETRY=5
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem
echo "Channel name : "$CHANNEL_NAME echo_b "Channel name : "$CHANNEL_NAME
verifyResult () { verifyResult () {
if [ $1 -ne 0 ] ; then if [ $1 -ne 0 ] ; then
echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" echo_b "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!"
echo "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" echo_r "================== ERROR !!! FAILED to execute End-2-End Scenario =================="
echo echo
exit 1 exit 1
fi fi
@ -61,7 +63,7 @@ createChannel() {
res=$? res=$?
cat log.txt cat log.txt
verifyResult $res "Channel creation failed" verifyResult $res "Channel creation failed"
echo "===================== Channel \"$CHANNEL_NAME\" is created successfully ===================== " echo_g "===================== Channel \"$CHANNEL_NAME\" is created successfully ===================== "
echo echo
} }
@ -77,7 +79,7 @@ updateAnchorPeers() {
res=$? res=$?
cat log.txt cat log.txt
verifyResult $res "Anchor peer update failed" verifyResult $res "Anchor peer update failed"
echo "===================== Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on \"$CHANNEL_NAME\" is updated successfully ===================== " echo_g "===================== Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on \"$CHANNEL_NAME\" is updated successfully ===================== "
echo echo
} }
@ -88,7 +90,7 @@ joinWithRetry () {
cat log.txt cat log.txt
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then
COUNTER=` expr $COUNTER + 1` COUNTER=` expr $COUNTER + 1`
echo "PEER$1 failed to join the channel, Retry after 2 seconds" echo_b "PEER$1 failed to join the channel, Retry after 2 seconds"
sleep 2 sleep 2
joinWithRetry $1 joinWithRetry $1
else else
@ -101,7 +103,7 @@ joinChannel () {
for ch in 0 1 2 3; do for ch in 0 1 2 3; do
setGlobals $ch setGlobals $ch
joinWithRetry $ch joinWithRetry $ch
echo "===================== PEER$ch joined on the channel \"$CHANNEL_NAME\" ===================== " echo_g "===================== PEER$ch joined on the channel \"$CHANNEL_NAME\" ===================== "
sleep 2 sleep 2
echo echo
done done
@ -114,7 +116,7 @@ installChaincode () {
res=$? res=$?
cat log.txt cat log.txt
verifyResult $res "Chaincode installation on remote peer PEER$PEER has Failed" verifyResult $res "Chaincode installation on remote peer PEER$PEER has Failed"
echo "===================== Chaincode is installed on remote peer PEER$PEER ===================== " echo_g "===================== Chaincode is installed on remote peer PEER$PEER ===================== "
echo echo
} }
@ -131,46 +133,46 @@ instantiateChaincode () {
res=$? res=$?
cat log.txt cat log.txt
verifyResult $res "Chaincode instantiation on PEER$PEER on channel '$CHANNEL_NAME' failed" verifyResult $res "Chaincode instantiation on PEER$PEER on channel '$CHANNEL_NAME' failed"
echo "===================== Chaincode Instantiation on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== " echo_g "===================== Chaincode Instantiation on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== "
echo echo
} }
## Create channel ## Create channel
echo "Creating channel..." echo_b "Creating channel..."
createChannel createChannel
## Join all the peers to the channel ## Join all the peers to the channel
echo "Having all peers join the channel..." echo_b "Having all peers join the channel..."
joinChannel joinChannel
## Set the anchor peers for each org in the channel ## Set the anchor peers for each org in the channel
echo "Updating anchor peers for org1..." echo_b "Updating anchor peers for org1..."
updateAnchorPeers 0 updateAnchorPeers 0
echo "Updating anchor peers for org2..." echo_b "Updating anchor peers for org2..."
updateAnchorPeers 2 updateAnchorPeers 2
## Install chaincode on Peer0/Org1 and Peer2/Org2 ## Install chaincode on Peer0/Org1 and Peer2/Org2
echo "Installing chaincode on org1/peer0..." echo_b "Installing chaincode on org1/peer0..."
installChaincode 0 installChaincode 0
echo "Install chaincode on org1/peer1..." echo_b "Install chaincode on org1/peer1..."
installChaincode 1 installChaincode 1
echo "Install chaincode on org2/peer0..." echo_b "Install chaincode on org2/peer0..."
installChaincode 2 installChaincode 2
echo "Install chaincode on org2/peer1..." echo_b "Install chaincode on org2/peer1..."
installChaincode 3 installChaincode 3
# Instantiate chaincode on Peer0/Org2 # Instantiate chaincode on Peer0/Org2
# Instantiate can only be executed once on any node # Instantiate can only be executed once on any node
echo "Instantiating chaincode on peer0/org2..." echo_b "Instantiating chaincode on peer0/org2..."
instantiateChaincode 2 instantiateChaincode 2
echo echo
echo "===================== All GOOD, initialization completed ===================== " echo_g "===================== All GOOD, initialization completed ===================== "
echo echo
echo echo

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
source scripts/header.sh
CHANNEL_NAME="$1" CHANNEL_NAME="$1"
: ${CHANNEL_NAME:="businesschannel"} : ${CHANNEL_NAME:="businesschannel"}
: ${TIMEOUT:="60"} : ${TIMEOUT:="60"}
@ -7,12 +9,12 @@ COUNTER=0
MAX_RETRY=5 MAX_RETRY=5
CC_PATH=github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 CC_PATH=github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
echo "Channel name : "$CHANNEL_NAME echo_b "Channel name : "$CHANNEL_NAME
verifyResult () { verifyResult () {
if [ $1 -ne 0 ] ; then if [ $1 -ne 0 ] ; then
echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" echo_b "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!"
echo "================== ERROR !!! FAILED to execute MVE ==================" echo_r "================== ERROR !!! FAILED to execute MVE =================="
echo echo
exit 1 exit 1
fi fi
@ -31,19 +33,19 @@ createChannel() {
res=$? res=$?
verifyResult $res "Channel created failed" verifyResult $res "Channel created failed"
fi fi
echo "================channel \"$CHANNEL_NAME\" is created successfully ===============" echo_g "================channel \"$CHANNEL_NAME\" is created successfully ==============="
} }
## Sometimes Join takes time hence RETRY atleast for 5 times ## Sometimes Join takes time hence RETRY atleast for 5 times
joinChannel () { joinChannel () {
echo "===================== PEER0 joined on the channel \"$CHANNEL_NAME\" ===================== " echo_b "===================== PEER0 joined on the channel \"$CHANNEL_NAME\" ===================== "
peer channel join -b ${CHANNEL_NAME}.block -o orderer.example.com:7050 >&log.txt peer channel join -b ${CHANNEL_NAME}.block -o orderer.example.com:7050 >&log.txt
res=$? res=$?
cat log.txt cat log.txt
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then
COUNTER=` expr $COUNTER + 1` COUNTER=` expr $COUNTER + 1`
echo "PEER0 failed to join the channel, Retry after 2 seconds" echo_r "PEER0 failed to join the channel, Retry after 2 seconds"
sleep 2 sleep 2
joinWithRetry joinWithRetry
else else
@ -57,7 +59,7 @@ updateAnchorPeers() {
res=$? res=$?
cat log.txt cat log.txt
verifyResult $res "Anchor peer update failed" verifyResult $res "Anchor peer update failed"
echo "==== Anchor peers for org1 on mychannel is updated successfully======" echo_g "==== Anchor peers for org1 on mychannel is updated successfully======"
echo echo
} }
@ -66,7 +68,7 @@ installChaincode () {
res=$? res=$?
cat log.txt cat log.txt
verifyResult $res "Chaincode installation on remote peer0 has Failed" verifyResult $res "Chaincode installation on remote peer0 has Failed"
echo "===================== Chaincode is installed success on remote peer0===================== " echo_g "===================== Chaincode is installed success on remote peer0===================== "
echo echo
} }
@ -76,8 +78,8 @@ instantiateChaincode () {
res=$? res=$?
cat log.txt cat log.txt
verifyResult $res "Chaincode instantiation on pee0.org1 on channel '$CHANNEL_NAME' failed" verifyResult $res "Chaincode instantiation on pee0.org1 on channel '$CHANNEL_NAME' failed"
echo "=========== Chaincode Instantiation on peer0.org1 on channel '$CHANNEL_NAME' is successful ========== " echo_g "=========== Chaincode Instantiation on peer0.org1 on channel '$CHANNEL_NAME' is successful ========== "
echo "Instantiate spent $(($(date +%s)-starttime)) secs" echo_b "Instantiate spent $(($(date +%s)-starttime)) secs"
echo echo
} }
@ -88,7 +90,7 @@ chaincodeQuery () {
while test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0 while test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0
do do
sleep 3 sleep 3
echo "Attempting to Query peer0.org1 ...$(($(date +%s)-starttime)) secs" echo_b "Attempting to Query peer0.org1 ...$(($(date +%s)-starttime)) secs"
peer chaincode query -C ${CHANNEL_NAME} -n mycc -c '{"Args":["query","a"]}' >&log.txt peer chaincode query -C ${CHANNEL_NAME} -n mycc -c '{"Args":["query","a"]}' >&log.txt
test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}') test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}')
test "$VALUE" = "$1" && let rc=0 test "$VALUE" = "$1" && let rc=0
@ -96,11 +98,11 @@ chaincodeQuery () {
echo echo
cat log.txt cat log.txt
if test $rc -eq 0 ; then if test $rc -eq 0 ; then
echo "===================== Query on peer0.org1 on channel '$CHANNEL_NAME' is successful ===================== " echo_g "===================== Query on peer0.org1 on channel '$CHANNEL_NAME' is successful ===================== "
else else
echo "!!!!!!!!!!!!!!! Query result on peer0.org1 is INVALID !!!!!!!!!!!!!!!!" echo_r "!!!!!!!!!!!!!!! Query result on peer0.org1 is INVALID !!!!!!!!!!!!!!!!"
echo "================== ERROR !!! FAILED to execute MVE test ==================" echo_r "================== ERROR !!! FAILED to execute MVE test =================="
echo echo
fi fi
} }
@ -110,35 +112,35 @@ chaincodeInvoke () {
res=$? res=$?
cat log.txt cat log.txt
verifyResult $res "Invoke execution on peer0.org1 failed " verifyResult $res "Invoke execution on peer0.org1 failed "
echo "========= Invoke transaction on peer0.org1 on channel '$CHANNEL_NAME' is successful ===== " echo_g "========= Invoke transaction on peer0.org1 on channel '$CHANNEL_NAME' is successful ===== "
echo echo
} }
echo "====================1.Create channel(default newchannel) =============================" echo_b "====================1.Create channel(default newchannel) ============================="
createChannel createChannel
echo "====================2.Join pee0 to the channel ======================================" echo_b "====================2.Join pee0 to the channel ======================================"
joinChannel joinChannel
echo "====================3.set anchor peers for org1 in the channel===========================" echo_b "====================3.set anchor peers for org1 in the channel==========================="
updateAnchorPeers updateAnchorPeers
echo "=====================4.Install chaincode test_cc on Peer0/Org0========================" echo_b "=====================4.Install chaincode test_cc on Peer0/Org0========================"
installChaincode installChaincode
echo "=====================5.Instantiate chaincode, this will take a while, pls waiting...===" echo_b "=====================5.Instantiate chaincode, this will take a while, pls waiting...==="
instantiateChaincode instantiateChaincode
echo "====================6.Query the existing value of a====================================" echo_b "====================6.Query the existing value of a===================================="
chaincodeQuery 100 chaincodeQuery 100
echo "=====================7.Invoke a transaction to transfer 10 from a to b==================" echo_b "=====================7.Invoke a transaction to transfer 10 from a to b=================="
chaincodeInvoke chaincodeInvoke
echo "=====================8.Check if the result of a is 90===================================" echo_b "=====================8.Check if the result of a is 90==================================="
chaincodeQuery 90 chaincodeQuery 90
echo echo
echo "=====================9.All GOOD, MVE Test completed ===================== " echo_g "=====================9.All GOOD, MVE Test completed ===================== "
echo echo
exit 0 exit 0

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
source scripts/header.sh
echo echo
echo " ______ __ __ _ _____ ____ _ ______ ______ ______ _____ " echo " ______ __ __ _ _____ ____ _ ______ ______ ______ _____ "
echo " / _____| | | | | / \ |_ _| | |\ \ | | / _____| / ______ \ | ___\ \ | ____|" echo " / _____| | | | | / \ |_ _| | |\ \ | | / _____| / ______ \ | ___\ \ | ____|"
@ -16,12 +18,12 @@ COUNTER=1
MAX_RETRY=5 MAX_RETRY=5
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem
echo "Channel name : "$CHANNEL_NAME echo_b "Channel name : "$CHANNEL_NAME
verifyResult () { verifyResult () {
if [ $1 -ne 0 ] ; then if [ $1 -ne 0 ] ; then
echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" echo_b "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!"
echo "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" echo_r "================== ERROR !!! FAILED to execute End-2-End Scenario =================="
echo echo
exit 1 exit 1
fi fi
@ -55,7 +57,7 @@ setGlobals () {
chaincodeQuery () { chaincodeQuery () {
PEER=$1 PEER=$1
echo "===================== Querying on PEER$PEER on channel '$CHANNEL_NAME'... ===================== " echo_b "===================== Querying on PEER$PEER on channel '$CHANNEL_NAME'... ===================== "
setGlobals $PEER setGlobals $PEER
local rc=1 local rc=1
local starttime=$(date +%s) local starttime=$(date +%s)
@ -65,7 +67,7 @@ chaincodeQuery () {
while test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0 while test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0
do do
sleep 3 sleep 3
echo "Attempting to Query PEER$PEER ...$(($(date +%s)-starttime)) secs" echo_b "Attempting to Query PEER$PEER ...$(($(date +%s)-starttime)) secs"
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' >&log.txt peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' >&log.txt
test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}') test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}')
test "$VALUE" = "$2" && let rc=0 test "$VALUE" = "$2" && let rc=0
@ -73,10 +75,10 @@ chaincodeQuery () {
echo echo
cat log.txt cat log.txt
if test $rc -eq 0 ; then if test $rc -eq 0 ; then
echo "===================== Query on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== " echo_g "===================== Query on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== "
else else
echo "!!!!!!!!!!!!!!! Query result on PEER$PEER is INVALID !!!!!!!!!!!!!!!!" echo_r "!!!!!!!!!!!!!!! Query result on PEER$PEER is INVALID !!!!!!!!!!!!!!!!"
echo "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" echo_r "================== ERROR !!! FAILED to execute End-2-End Scenario =================="
echo echo
exit 1 exit 1
fi fi
@ -95,29 +97,33 @@ chaincodeInvoke () {
res=$? res=$?
cat log.txt cat log.txt
verifyResult $res "Invoke execution on PEER$PEER failed " verifyResult $res "Invoke execution on PEER$PEER failed "
echo "===================== Invoke transaction on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== " echo_g "===================== Invoke transaction on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== "
echo echo
} }
#Query on chaincode on Peer0/Org1 #Query on chaincode on Peer0/Org1
echo "Querying chaincode on org1/peer0..." echo_b "Querying chaincode on org1/peer0..."
chaincodeQuery 2 100 chaincodeQuery 2 100
#Invoke on chaincode on Peer0/Org1 #Invoke on chaincode on Peer0/Org1
echo "Sending invoke transaction on org1/peer0..." echo_b "Sending invoke transaction on org1/peer0..."
chaincodeInvoke 1 chaincodeInvoke 1
#Query on chaincode on Peer1/Org2, check if the result is 90 #Query on chaincode on Peer1/Org2, check if the result is 90
echo "Querying chaincode on org2/peer1..." echo_b "Querying chaincode on org2/peer1..."
chaincodeQuery 3 90 chaincodeQuery 3 90
#Invoke on chaincode on Peer1/Org2
echo_b "Sending invoke transaction on org2/peer1..."
chaincodeInvoke 3 chaincodeInvoke 3
#Query on chaincode on Peer1/Org2, check if the result is 80
echo_b "Querying chaincode on org2/peer1..."
chaincodeQuery 3 80 chaincodeQuery 3 80
echo echo
echo "===================== All GOOD, End-2-End execution completed ===================== " echo_g "===================== All GOOD, End-2-End execution completed ===================== "
echo echo
echo echo