From ad40e29ebbf31677871620d71f4f05c148bec2c9 Mon Sep 17 00:00:00 2001 From: Naga Pemmara Date: Wed, 20 Jun 2018 10:12:04 -0400 Subject: [PATCH] [FAB-10732] BYFN upgrade to v1.2 This patch set includes changes for demonstrating byfn network sample upgrade from v1.1 to v1.2 Change-Id: Ib0e5243e7ec280861c13feab0a23dc3566674f4c Signed-off-by: Naga Pemmara --- first-network/byfn.sh | 25 ++-- first-network/scripts/capabilities.json | 4 +- first-network/scripts/upgrade_to_v11.sh | 174 ------------------------ first-network/scripts/upgrade_to_v12.sh | 126 +++++++++++++++++ scripts/Jenkins_Scripts/byfn_eyfn.sh | 8 +- 5 files changed, 145 insertions(+), 192 deletions(-) delete mode 100755 first-network/scripts/upgrade_to_v11.sh create mode 100755 first-network/scripts/upgrade_to_v12.sh diff --git a/first-network/byfn.sh b/first-network/byfn.sh index 9737326b7a..044390461d 100755 --- a/first-network/byfn.sh +++ b/first-network/byfn.sh @@ -41,7 +41,7 @@ function printHelp() { echo " - 'down' - clear the network with docker-compose down" echo " - 'restart' - restart the network" echo " - 'generate' - generate required certificates and genesis block" - echo " - 'upgrade' - upgrade the network from v1.0.x to v1.1" + echo " - 'upgrade' - upgrade the network from version 1.1.x to 1.2.x" echo " -c - channel name to use (defaults to \"mychannel\")" echo " -t - CLI timeout duration in seconds (defaults to 10)" echo " -d - delay duration in seconds (defaults to 3)" @@ -57,7 +57,7 @@ function printHelp() { echo echo " byfn.sh generate -c mychannel" echo " byfn.sh up -c mychannel -s couchdb" - echo " byfn.sh up -c mychannel -s couchdb -i 1.1.0-alpha" + echo " byfn.sh up -c mychannel -s couchdb -i 1.2.x" echo " byfn.sh up -l node" echo " byfn.sh down -c mychannel" echo " byfn.sh upgrade -c mychannel" @@ -172,13 +172,13 @@ function networkUp() { fi } -# Upgrade the network from v1.0.x to v1.1 -# Stop the orderer and peers, backup the ledger from orderer and peers, cleanup chaincode containers and images +# Upgrade the network components which are at version 1.1.x to 1.2.x +# Stop the orderer and peers, backup the ledger for orderer and peers, cleanup chaincode containers and images # and relaunch the orderer and peers with latest tag function upgradeNetwork() { docker inspect -f '{{.Config.Volumes}}' orderer.example.com | grep -q '/var/hyperledger/production/orderer' if [ $? -ne 0 ]; then - echo "ERROR !!!! This network does not appear to be using volumes for its ledgers, did you start from fabric-samples >= v1.0.6?" + echo "ERROR !!!! This network does not appear to be using volumes for its ledgers, did you start from fabric-samples >= v1.1.x?" exit 1 fi @@ -224,7 +224,7 @@ function upgradeNetwork() { docker-compose $COMPOSE_FILES up -d --no-deps $PEER done - docker exec cli scripts/upgrade_to_v11.sh $CHANNEL_NAME $CLI_DELAY $LANGUAGE $CLI_TIMEOUT $VERBOSE + docker exec cli scripts/upgrade_to_v12.sh $CHANNEL_NAME $CLI_DELAY $LANGUAGE $CLI_TIMEOUT $VERBOSE if [ $? -ne 0 ]; then echo "ERROR !!!! Test failed" exit 1 @@ -429,7 +429,7 @@ function generateChannelArtifacts() { } # Obtain the OS and Architecture string that will be used to select the correct -# native binaries for your platform +# native binaries for your platform, e.g., darwin-amd64 or linux-amd64 OS_ARCH=$(echo "$(uname -s | tr '[:upper:]' '[:lower:]' | sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}') # timeout duration - the duration the CLI should wait for a response from # another container before giving up @@ -463,7 +463,7 @@ elif [ "$MODE" == "down" ]; then elif [ "$MODE" == "restart" ]; then EXPMODE="Restarting" elif [ "$MODE" == "generate" ]; then - EXPMODE="Generating certs and genesis block for" + EXPMODE="Generating certs and genesis block" elif [ "$MODE" == "upgrade" ]; then EXPMODE="Upgrading the network" else @@ -496,7 +496,7 @@ while getopts "h?c:t:d:f:s:l:i:v" opt; do LANGUAGE=$OPTARG ;; i) - IMAGETAG=$(uname -m)"-"$OPTARG + IMAGETAG=$(go env GOARCH)"-"$OPTARG ;; v) VERBOSE=true @@ -504,13 +504,14 @@ while getopts "h?c:t:d:f:s:l:i:v" opt; do esac done + # Announce what was requested if [ "${IF_COUCHDB}" == "couchdb" ]; then echo - echo "${EXPMODE} with channel '${CHANNEL_NAME}' and CLI timeout of '${CLI_TIMEOUT}' seconds and CLI delay of '${CLI_DELAY}' seconds and using database '${IF_COUCHDB}'" + echo "${EXPMODE} for channel '${CHANNEL_NAME}' with CLI timeout of '${CLI_TIMEOUT}' seconds and CLI delay of '${CLI_DELAY}' seconds and using database '${IF_COUCHDB}'" else - echo "${EXPMODE} with channel '${CHANNEL_NAME}' and CLI timeout of '${CLI_TIMEOUT}' seconds and CLI delay of '${CLI_DELAY}' seconds" + echo "${EXPMODE} for channel '${CHANNEL_NAME}' with CLI timeout of '${CLI_TIMEOUT}' seconds and CLI delay of '${CLI_DELAY}' seconds" fi # ask for confirmation to proceed askProceed @@ -527,7 +528,7 @@ elif [ "${MODE}" == "generate" ]; then ## Generate Artifacts elif [ "${MODE}" == "restart" ]; then ## Restart the network networkDown networkUp -elif [ "${MODE}" == "upgrade" ]; then ## Upgrade the network from v1.0.x to v1.1 +elif [ "${MODE}" == "upgrade" ]; then ## Upgrade the network from version 1.1.x to 1.2.x upgradeNetwork else printHelp diff --git a/first-network/scripts/capabilities.json b/first-network/scripts/capabilities.json index f6120bbf5d..3acfab9908 100644 --- a/first-network/scripts/capabilities.json +++ b/first-network/scripts/capabilities.json @@ -2,8 +2,8 @@ "mod_policy": "Admins", "value": { "capabilities": { - "V1_1": {} + "V1_2": {} } }, "version": "0" -} +} \ No newline at end of file diff --git a/first-network/scripts/upgrade_to_v11.sh b/first-network/scripts/upgrade_to_v11.sh deleted file mode 100755 index 93ab6f61eb..0000000000 --- a/first-network/scripts/upgrade_to_v11.sh +++ /dev/null @@ -1,174 +0,0 @@ -#!/bin/bash - -echo -echo " ____ _____ _ ____ _____ " -echo "/ ___| |_ _| / \ | _ \ |_ _|" -echo "\___ \ | | / _ \ | |_) | | | " -echo " ___) | | | / ___ \ | _ < | | " -echo "|____/ |_| /_/ \_\ |_| \_\ |_| " -echo -echo "Upgrade your first network (BYFN) from v1.0.x to v1.1 end-to-end test" -echo -CHANNEL_NAME="$1" -DELAY="$2" -LANGUAGE="$3" -TIMEOUT="$4" -VERBOSE="$5" -: ${CHANNEL_NAME:="mychannel"} -: ${DELAY:="5"} -: ${LANGUAGE:="golang"} -: ${TIMEOUT:="10"} -: ${VERBOSE:="false"} -LANGUAGE=`echo "$LANGUAGE" | tr [:upper:] [:lower:]` -COUNTER=1 -MAX_RETRY=5 - -CC_SRC_PATH="github.com/chaincode/chaincode_example02/go/" -if [ "$LANGUAGE" = "node" ]; then - CC_SRC_PATH="/opt/gopath/src/github.com/chaincode/chaincode_example02/node/" -fi - -echo "Channel name : "$CHANNEL_NAME - -# import utils -. scripts/utils.sh - -# addCapabilityToChannel -# This function pulls the current channel config, modifies it with capabilities -# for the specified group, computes the config update, signs, and submits it. -addCapabilityToChannel() { - CH_NAME=$1 - GROUP=$2 - - setOrdererGlobals - - # Get the current channel config, decode and write it to config.json - fetchChannelConfig $CH_NAME config.json - - # Modify the correct section of the config based on capabilities group - if [ $GROUP == "orderer" ]; then - jq -s '.[0] * {"channel_group":{"groups":{"Orderer": {"values": {"Capabilities": .[1]}}}}}' config.json ./scripts/capabilities.json > modified_config.json - elif [ $GROUP == "channel" ]; then - jq -s '.[0] * {"channel_group":{"values": {"Capabilities": .[1]}}}' config.json ./scripts/capabilities.json > modified_config.json - elif [ $GROUP == "application" ]; then - jq -s '.[0] * {"channel_group":{"groups":{"Application": {"values": {"Capabilities": .[1]}}}}}' config.json ./scripts/capabilities.json > modified_config.json - fi - - # Create a config updated for this channel based on the differences between config.json and modified_config.json - # write the output to config_update_in_envelope.pb - createConfigUpdate "$CH_NAME" config.json modified_config.json config_update_in_envelope.pb - - # Sign, and set the correct identity for submission. - if [ $CH_NAME != "testchainid" ] ; then - if [ $GROUP == "orderer" ]; then - # Modifying the orderer group requires only the Orderer admin to sign. - # Prepare to sign the update as the OrdererOrg.Admin - setOrdererGlobals - elif [ $GROUP == "channel" ]; then - # Modifying the channel group requires a majority of application admins and the orderer admin to sign. - # Sign with PeerOrg1.Admin - signConfigtxAsPeerOrg 1 config_update_in_envelope.pb - # Sign with PeerOrg2.Admin - signConfigtxAsPeerOrg 2 config_update_in_envelope.pb - # Prepare to sign the update as the OrdererOrg.Admin - setOrdererGlobals - elif [ $GROUP == "application" ]; then - # Modifying the application group requires a majority of application admins to sign. - # Sign with PeerOrg1.Admin - signConfigtxAsPeerOrg 1 config_update_in_envelope.pb - # Prepare to sign the update as the PeerOrg2.Admin - setGlobals 0 2 - fi - else - # For the orderer system channel, only the orderer admin needs sign - # which will be attached during the update - setOrdererGlobals - fi - - if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then - set -x - peer channel update -f config_update_in_envelope.pb -c $CH_NAME -o orderer.example.com:7050 --cafile $ORDERER_CA - res=$? - set +x - else - set -x - peer channel update -f config_update_in_envelope.pb -c $CH_NAME -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA - res=$? - set +x - fi - verifyResult $res "Config update for \"$GROUP\" on \"$CH_NAME\" failed" - echo "===================== Config update for \"$GROUP\" on \"$CH_NAME\" is completed ===================== " - -} - -echo "Installing jq" -apt-get update -apt-get install -y jq - -sleep $DELAY - -#Config update for /Channel/Orderer on testchainid -echo "Config update for /Channel/Orderer on testchainid" -addCapabilityToChannel testchainid orderer - -sleep $DELAY - -#Config update for /Channel on testchainid -echo "Config update for /Channel on testchainid" -addCapabilityToChannel testchainid channel - -sleep $DELAY - -#Config update for /Channel/Orderer -echo "Config update for /Channel/Orderer on \"$CHANNEL_NAME\"" -addCapabilityToChannel $CHANNEL_NAME orderer - -sleep $DELAY - -#Config update for /Channel/Application -echo "Config update for /Channel/Application on \"$CHANNEL_NAME\"" -addCapabilityToChannel $CHANNEL_NAME application - -sleep $DELAY - -#Config update for /Channel -echo "Config update for /Channel on \"$CHANNEL_NAME\"" -addCapabilityToChannel $CHANNEL_NAME channel - -#Query on chaincode on Peer0/Org1 -echo "Querying chaincode on org1/peer0..." -chaincodeQuery 0 1 90 - -#Invoke on chaincode on Peer0/Org1 -echo "Sending invoke transaction on org1/peer0..." -chaincodeInvoke 0 1 - -sleep $DELAY - -#Query on chaincode on Peer0/Org1 -echo "Querying chaincode on org1/peer0..." -chaincodeQuery 0 1 80 - -##Invoke on chaincode on Peer0/Org2 -echo "Sending invoke transaction on org2/peer0..." -chaincodeInvoke 0 2 - -sleep $DELAY - -#Query on chaincode on Peer0/Org2 -echo "Querying chaincode on org2/peer0..." -chaincodeQuery 0 2 70 - -echo -echo "===================== All GOOD, End-2-End UPGRADE Scenario execution completed ===================== " -echo - -echo -echo " _____ _ _ ____ _____ ____ _____ " -echo "| ____| | \ | | | _ \ | ____| |___ \ | ____|" -echo "| _| | \| | | | | | _____ | _| __) | | _| " -echo "| |___ | |\ | | |_| | |_____| | |___ / __/ | |___ " -echo "|_____| |_| \_| |____/ |_____| |_____| |_____|" -echo - -exit 0 diff --git a/first-network/scripts/upgrade_to_v12.sh b/first-network/scripts/upgrade_to_v12.sh new file mode 100755 index 0000000000..79d4600afd --- /dev/null +++ b/first-network/scripts/upgrade_to_v12.sh @@ -0,0 +1,126 @@ +#!/bin/bash + +echo +echo " ____ _____ _ ____ _____ " +echo "/ ___| |_ _| / \ | _ \ |_ _|" +echo "\___ \ | | / _ \ | |_) | | | " +echo " ___) | | | / ___ \ | _ < | | " +echo "|____/ |_| /_/ \_\ |_| \_\ |_| " +echo +echo "Upgrade your first network (BYFN) from v1.1.x to v1.2.x end-to-end test" +echo +CHANNEL_NAME="$1" +DELAY="$2" +LANGUAGE="$3" +TIMEOUT="$4" +VERBOSE="$5" +: ${CHANNEL_NAME:="mychannel"} +: ${DELAY:="5"} +: ${LANGUAGE:="golang"} +: ${TIMEOUT:="10"} +: ${VERBOSE:="false"} +LANGUAGE=$(echo "$LANGUAGE" | tr [:upper:] [:lower:]) +COUNTER=1 +MAX_RETRY=5 + +CC_SRC_PATH="github.com/chaincode/chaincode_example02/go/" +if [ "$LANGUAGE" = "node" ]; then + CC_SRC_PATH="/opt/gopath/src/github.com/chaincode/chaincode_example02/node/" +fi + +echo "Channel name : "$CHANNEL_NAME + +# import utils +. scripts/utils.sh + +# addCapabilityToChannel +# This function pulls the current channel config, modifies it with capabilities +# for the specified group, computes the config update, signs, and submits it. +addCapabilityToChannel() { + CH_NAME="$1" + GROUP=$2 + + setOrdererGlobals + + # Get the current channel config, decode and write it to config.json + fetchChannelConfig "$CH_NAME" config.json + + # Modify the correct section of the config based on capabilities group + if [ $GROUP == "application" ]; then + jq -s '.[0] * {"channel_group":{"groups":{"Application": {"values": {"Capabilities": .[1]}}}}}' config.json ./scripts/capabilities.json >modified_config.json + fi + + # Create a config updated for this channel based on the differences between config.json and modified_config.json + # write the output to config_update_in_envelope.pb + createConfigUpdate "$CH_NAME" config.json modified_config.json config_update_in_envelope.pb + + # Sign, and set the correct identity for submission. + if [ $GROUP == "application" ]; then + # Modifying the application group requires a majority of application admins to sign. + # Sign with PeerOrg1.Admin + signConfigtxAsPeerOrg 1 config_update_in_envelope.pb + # Prepare to sign the update as the PeerOrg2.Admin + setGlobals 0 2 + fi + + if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then + set -x + peer channel update -f config_update_in_envelope.pb -c $CH_NAME -o orderer.example.com:7050 --cafile $ORDERER_CA + res=$? + set +x + else + set -x + peer channel update -f config_update_in_envelope.pb -c $CH_NAME -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA + res=$? + set +x + fi + verifyResult $res "Config update for \"$GROUP\" on \"$CH_NAME\" failed" + echo "===================== Config update for \"$GROUP\" on \"$CH_NAME\" is completed ===================== " +} + + +sleep $DELAY + +#Config update for /Channel/Application +echo "Config update for /Channel/Application on \"$CHANNEL_NAME\"" +addCapabilityToChannel "$CHANNEL_NAME" application + +sleep $DELAY + +#Query on chaincode on Peer0/Org1 +echo "Querying chaincode on org1/peer0..." +chaincodeQuery 0 1 90 + +#Invoke on chaincode on Peer0/Org1 +echo "Sending invoke transaction on org1/peer0..." +chaincodeInvoke 0 1 + +sleep $DELAY + +#Query on chaincode on Peer0/Org1 +echo "Querying chaincode on org1/peer0..." +chaincodeQuery 0 1 80 + +##Invoke on chaincode on Peer0/Org2 +echo "Sending invoke transaction on org2/peer0..." +chaincodeInvoke 0 2 + +sleep $DELAY + +#Query on chaincode on Peer0/Org2 +echo "Querying chaincode on org2/peer0..." +chaincodeQuery 0 2 70 + +echo +echo "===================== All GOOD, End-2-End UPGRADE Scenario execution completed ===================== " +echo + +echo +echo " _____ _ _ ____ _____ ____ _____ " +echo "| ____| | \ | | | _ \ | ____| |___ \ | ____|" +echo "| _| | \| | | | | | _____ | _| __) | | _| " +echo "| |___ | |\ | | |_| | |_____| | |___ / __/ | |___ " +echo "|_____| |_| \_| |____/ |_____| |_____| |_____|" +echo + +exit 0 diff --git a/scripts/Jenkins_Scripts/byfn_eyfn.sh b/scripts/Jenkins_Scripts/byfn_eyfn.sh index 15fedb3d22..fea4fc1e56 100755 --- a/scripts/Jenkins_Scripts/byfn_eyfn.sh +++ b/scripts/Jenkins_Scripts/byfn_eyfn.sh @@ -41,18 +41,18 @@ fi echo "############### BYFN,EYFN CUSTOM CHANNEL WITH COUCHDB TEST ##############" echo "#########################################################################" echo y | ./byfn.sh -m up -c custom-channel-couchdb -s couchdb -t 60 - err_check $? custom-channel-couch couchdb + err_Check $? custom-channel-couch couchdb echo y | ./eyfn.sh -m up -c custom-channel-couchdb -s couchdb -t 60 - err_check $? custom-channel-couch + err_Check $? custom-channel-couch echo y | ./eyfn.sh -m down echo echo "############### BYFN,EYFN WITH NODE Chaincode. TEST ################" echo "####################################################################" echo y | ./byfn.sh -m up -l node -t 60 - err_check $? default-channel-node + err_Check $? default-channel-node echo y | ./eyfn.sh -m up -l node -t 60 - err_check $? default-channel-node + err_Check $? default-channel-node echo y | ./eyfn.sh -m down echo "############### FABRIC-CA SAMPLES TEST ########################"