diff --git a/test/regression/daily/chaincodeTests/envsetup/channel-artifacts/.gitkeep b/test/regression/daily/chaincodeTests/envsetup/channel-artifacts/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/regression/daily/chaincodeTests/envsetup/docker-compose.yaml b/test/regression/daily/chaincodeTests/envsetup/docker-compose.yaml new file mode 100644 index 00000000000..3ed124e3966 --- /dev/null +++ b/test/regression/daily/chaincodeTests/envsetup/docker-compose.yaml @@ -0,0 +1,68 @@ +version: '2' + +services: + + orderer.example.com: + extends: + file: base/docker-compose-base.yaml + service: orderer.example.com + container_name: orderer.example.com + + peer0.org1.example.com: + container_name: peer0.org1.example.com + extends: + file: base/docker-compose-base.yaml + service: peer0.org1.example.com + + peer1.org1.example.com: + container_name: peer1.org1.example.com + extends: + file: base/docker-compose-base.yaml + service: peer1.org1.example.com + + peer0.org2.example.com: + container_name: peer0.org2.example.com + extends: + file: base/docker-compose-base.yaml + service: peer0.org2.example.com + + peer1.org2.example.com: + container_name: peer1.org2.example.com + extends: + file: base/docker-compose-base.yaml + service: peer1.org2.example.com + + cli: + container_name: cli + image: hyperledger/fabric-testenv + tty: true + environment: + - GOPATH=/opt/gopath + - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock + - CORE_LOGGING_LEVEL=DEBUG + - CORE_PEER_ID=cli + - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 + - CORE_PEER_LOCALMSPID=Org1MSP + - CORE_PEER_TLS_ENABLED=true + - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt + - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key + - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt + - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp + working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer + #command: /bin/bash -c 'apt-get update && apt-get install && scripts1/${SCRIPT_NAME} ${CHANNEL_NAME} ${CHANNELS_NUM} ${CHAINCODES_NUM} ${ENDORSERS_NUM}; sleep 60' + command: /bin/bash -c 'apt-get update && apt-get install -y python python-xmlrunner && scripts1/${SCRIPT_NAME} ${CHANNEL_NAME} ${CHANNELS_NUM} ${CHAINCODES_NUM} ${ENDORSERS_NUM}; sleep 60' + #command: /bin/bash -c ' echo "NOW RUN SCRIPT ${SCRIPT_NAME}" apt-get update && apt-get install -y python python-pytest python-xmlrunner && python -m py.test -v --junitxml scripts1/results.xml ./scripts1/${SCRIPT_NAME} ${CHANNEL_NAME} ${CHANNELS_NUM} ${CHAINCODES_NUM} ${ENDORSERS_NUM}; sleep 60' + #command: /bin/bash -c 'apt-get update && apt-get install -y python python-pytest python-xmlrunner && py.test -v --junitxml scripts1/results.xml scripts1/${SCRIPT_NAME}; sleep 60' + volumes: + - /var/run/:/host/var/run/ + - ../../../../../examples/chaincode/go:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go + - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts + - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto + - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts1 + - ../fabricFeatureChaincodes:/opt/gopath/src/github.com/hyperledger/fabric/peer/daily/fabricFeatureChaincodes + depends_on: + - orderer.example.com + - peer0.org1.example.com + - peer1.org1.example.com + - peer0.org2.example.com + - peer1.org2.example.com diff --git a/test/regression/daily/chaincodeTests/envsetup/generateCfgTrx.sh b/test/regression/daily/chaincodeTests/envsetup/generateCfgTrx.sh new file mode 100755 index 00000000000..5f99c96b629 --- /dev/null +++ b/test/regression/daily/chaincodeTests/envsetup/generateCfgTrx.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +set -e + +CHANNEL_NAME=$1 +CHANNEL_COUNT=$2 + +echo "ch_name : $CHANNEL_NAME" +echo "ch_count : $CHANNEL_COUNT" + +: ${CHANNEL_NAME:="mychannel"} +: ${CHANNEL_COUNT:="1"} + +export FABRIC_ROOT=$GOPATH/src/github.com/hyperledger/fabric +export E2E_CLI_PATH=$FABRIC_ROOT/examples/e2e_cli/ +cp $E2E_CLI_PATH/configtx.yaml $PWD +cp $E2E_CLI_PATH/crypto-config.yaml ./crypto-config.yaml +cp -r $E2E_CLI_PATH/base $PWD/ +sed -i 's/e2ecli/envsetup/g' base/peer-base.yaml +export FABRIC_CFG_PATH=$PWD + +ARTIFACTS=./channel-artifacts +OS_ARCH=$(echo "$(uname -s)-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}') + +echo "Channel name - "$CHANNEL_NAME +echo "Total channels - "$CHANNEL_COUNT +echo + +CONFIGTXGEN=`which configtxgen || /bin/true` + +## Generates Org certs using cryptogen tool +function generateCerts (){ + CRYPTOGEN=$FABRIC_ROOT/release/$OS_ARCH/bin/cryptogen + + if [ -f "$CRYPTOGEN" ]; then + echo "Using cryptogen -> $CRYPTOGEN" + else + echo "Building cryptogen" + make -C $FABRIC_ROOT release-all + fi + + echo + echo "**** Generate certificates using cryptogen tool ****" + $CRYPTOGEN generate --config=./crypto-config.yaml + echo +} + +## Generate orderer genesis block , channel configuration transaction and anchor peer update transactions +function generateChannelArtifacts() { + + CONFIGTXGEN=$FABRIC_ROOT/release/$OS_ARCH/bin/configtxgen + if [ -f "$CONFIGTXGEN" ]; then + echo "Using configtxgen -> $CONFIGTXGEN" + else + echo "Building configtxgen" + make -C $FABRIC_ROOT release-all + fi + + echo "Generating genesis block" + $CONFIGTXGEN -profile TwoOrgsOrdererGenesis -outputBlock $ARTIFACTS/orderer.genesis.block + + for (( i=0; $i<$CHANNEL_COUNT; i++)) + do + echo "Generating channel configuration transaction for channel '$CHANNEL_NAME$i'" + $CONFIGTXGEN -profile TwoOrgsChannel -outputCreateChannelTx $ARTIFACTS/channel$i.tx -channelID $CHANNEL_NAME$i + + echo "Generating anchor peer update for Org1MSP" + $CONFIGTXGEN -profile TwoOrgsChannel -outputAnchorPeersUpdate $ARTIFACTS/Org1MSPanchors$i.tx -channelID $CHANNEL_NAME$i -asOrg Org1MSP + + echo "Generating anchor peer update for Org2MSP" + $CONFIGTXGEN -profile TwoOrgsChannel -outputAnchorPeersUpdate $ARTIFACTS/Org2MSPanchors$i.tx -channelID $CHANNEL_NAME$i -asOrg Org2MSP + done +} + +generateCerts +generateChannelArtifacts + +echo "######################### DONE ######################" + diff --git a/test/regression/daily/chaincodeTests/envsetup/network_setup.sh b/test/regression/daily/chaincodeTests/envsetup/network_setup.sh new file mode 100755 index 00000000000..d8acadef9d6 --- /dev/null +++ b/test/regression/daily/chaincodeTests/envsetup/network_setup.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +UP_DOWN=$1 +CH_NAME=$2 +CHANNELS=$3 +CHAINCODES=$4 +ENDORSERS=$5 +SCRIPT_NAME=$6 + +: ${CH_NAME:="mychannel"} +: ${CHANNELS:="1"} +: ${CHAINCODES:="1"} +: ${ENDORSERS:="4"} +COMPOSE_FILE=docker-compose.yaml + +function printHelp () { + echo "Usage: ./network_setup.sh [channel-name] [total-channels [chaincodes] [endorsers count] [SCRIPT_NAME]" +} + +function validateArgs () { + if [ -z "${UP_DOWN}" ]; then + echo "Option up / down / restart not mentioned" + printHelp + exit 1 + fi +} + +function clearContainers () { + CONTAINER_IDS=$(docker ps -aq) + if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" = " " ]; then + echo "---- No containers available for deletion ----" + else + docker rm -f $CONTAINER_IDS + fi +} + +function removeUnwantedImages() { + DOCKER_IMAGE_IDS=$(docker images | grep "dev\|none\|test-vp\|peer[0-9]-" | awk '{print $3}') + if [ -z "$DOCKER_IMAGE_IDS" -o "$DOCKER_IMAGE_IDS" = " " ]; then + echo "---- No images available for deletion ----" + else + docker rmi -f $DOCKER_IMAGE_IDS + fi +} + +function networkUp () { + CurrentDIR=$PWD + cd ./configTx + echo "ch_name $CH_NAME" + echo "Num channels $CHANNELS" + echo "Num chaincodes $CHAINCODES" + echo "Num of endorsers/peers $ENDORSERS" + echo "Running Script $SCRIPT_NAME" + source generateCfgTrx.sh $CH_NAME $CHANNELS + cd $CurrentDIR + + CHANNEL_NAME=$CH_NAME CHANNELS_NUM=$CHANNELS CHAINCODES_NUM=$CHAINCODES ENDORSERS_NUM=$ENDORSERS SCRIPT_NAME=$SCRIPT_NAME docker-compose -f $COMPOSE_FILE up -d 2>&1 + if [ $? -ne 0 ]; then + echo "ERROR !!!! Unable to pull the images " + exit 1 + fi + docker logs -f cli +} + +function networkDown () { + docker-compose -f $COMPOSE_FILE down + #Cleanup the chaincode containers + clearContainers + #Cleanup images + removeUnwantedImages + #remove orderer and config txn + rm -rf channel-artifacts/* crypto-config crypto-config.yaml configtx.yaml scripts/__pycache__ scripts/results.xml scripts/logs.txt scripts/.cache base +} + +validateArgs + +#Create the network using docker compose +if [ "${UP_DOWN}" == "up" ]; then + networkUp +elif [ "${UP_DOWN}" == "down" ]; then ## Clear the network + networkDown +elif [ "${UP_DOWN}" == "restart" ]; then ## Restart the network + networkDown + networkUp +else + printHelp + exit 1 +fi diff --git a/test/regression/daily/chaincodeTests/envsetup/scripts/fabricFeatureChaincodeTestRuns.py b/test/regression/daily/chaincodeTests/envsetup/scripts/fabricFeatureChaincodeTestRuns.py new file mode 100755 index 00000000000..2b8c8d45eac --- /dev/null +++ b/test/regression/daily/chaincodeTests/envsetup/scripts/fabricFeatureChaincodeTestRuns.py @@ -0,0 +1,74 @@ +#!/usr/bin/python2.7 +import shlex +import sys +import subprocess +import xmlrunner +import unittest +from subprocess import Popen, PIPE +from xmlrunner import XMLTestRunner + +dailyRunsPath="/opt/gopath/src/github.com/hyperledger/fabric/peer/daily/chaincodeTests" + +class TestDailyRuns(unittest.TestCase): + + #def runIt(self, command, scriptName): + # cmd = "/opt/gopath/src/github.com/hyperledger/fabric/peer/daily/%s %s %s %s %s %s"% (scriptName, CHANNEL_NAME, CHANNELS, CHAINCODES, ENDORSERS, command) + # print cmd + # p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) + # output = p.communicate()[0] + # print output + # self.assertEqual(p.returncode, 0) + + def runIt(self, command, scriptName): + cmd = "/opt/gopath/src/github.com/hyperledger/fabric/peer/daily/%s %s %s %s %s %s"% (scriptName, CHANNEL_NAME, CHANNELS, CHAINCODES, ENDORSERS, command) + print cmd + p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) + output = p.communicate()[0] + print output + self.assertEqual(p.returncode, 0) + + def createChannel(self, scriptName): + self.runIt("create", scriptName) + + def joinChannel(self, scriptName): + self.runIt("join", scriptName) + + def install(self, scriptName): + self.runIt("install", scriptName) + + def instantiate(self, scriptName): + self.runIt("instantiate", scriptName) + + def invokeQuery(self, scriptName): + self.runIt("invokeQuery", scriptName) + +#####Begin tests for different chaincode samples that exist in fabricExamples folder ################### + def test_ACreate_Join_Channel(self): + script_name = "fabricFeatureChaincodes/create_join_channel.sh" + self.createChannel(script_name) + self.joinChannel(script_name) + def test_example02(self): + script_name = "fabricFeatureChaincodes/e2e_test_example02.sh" + self.install(script_name) + self.instantiate(script_name) + self.invokeQuery(script_name) + +#####Begin tests for different chaincode samples that exist in fabricExamples folder ################### + + +if __name__ == '__main__': + CHANNEL_NAME = sys.argv[1] + CHANNELS = sys.argv[2] + CHAINCODES = sys.argv[3] + ENDORSERS = sys.argv[4] + sys.argv.pop() + sys.argv.pop() + sys.argv.pop() + sys.argv.pop() + print CHANNEL_NAME + print CHANNELS + print CHAINCODES + print ENDORSERS + + unittest.main(verbosity=2, testRunner=xmlrunner.XMLTestRunner(output='test-reports')) +