Skip to content

Commit 5b926ce

Browse files
committed
[FAB-3258] fwk test chaincode functionality Part1
Goal: 1. Test all examples under fabric/examples folder 2. Test custom chaincodes 3. Integrate tests into daily, weekly CI runs 4. Reporting ability on the test runs. "generateCfgTrx.sh" is used to create Org Certs(using cryptogen binary) and channel cfg trxns + orderer genesis block (using configtxgen) based on defaults ( base docker compose ) in examples/e2e_cli Note: All the artifcats are genreated during run time. Change-Id: Iddc0ac6fc1b119734e6f0b9c728b607c18e80eab Signed-off-by: nishi.nidamarty <[email protected]>
1 parent 154160e commit 5b926ce

File tree

5 files changed

+309
-0
lines changed

5 files changed

+309
-0
lines changed

test/regression/daily/chaincodeTests/envsetup/channel-artifacts/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
version: '2'
2+
3+
services:
4+
5+
orderer.example.com:
6+
extends:
7+
file: base/docker-compose-base.yaml
8+
service: orderer.example.com
9+
container_name: orderer.example.com
10+
11+
peer0.org1.example.com:
12+
container_name: peer0.org1.example.com
13+
extends:
14+
file: base/docker-compose-base.yaml
15+
service: peer0.org1.example.com
16+
17+
peer1.org1.example.com:
18+
container_name: peer1.org1.example.com
19+
extends:
20+
file: base/docker-compose-base.yaml
21+
service: peer1.org1.example.com
22+
23+
peer0.org2.example.com:
24+
container_name: peer0.org2.example.com
25+
extends:
26+
file: base/docker-compose-base.yaml
27+
service: peer0.org2.example.com
28+
29+
peer1.org2.example.com:
30+
container_name: peer1.org2.example.com
31+
extends:
32+
file: base/docker-compose-base.yaml
33+
service: peer1.org2.example.com
34+
35+
cli:
36+
container_name: cli
37+
image: hyperledger/fabric-testenv
38+
tty: true
39+
environment:
40+
- GOPATH=/opt/gopath
41+
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
42+
- CORE_LOGGING_LEVEL=DEBUG
43+
- CORE_PEER_ID=cli
44+
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
45+
- CORE_PEER_LOCALMSPID=Org1MSP
46+
- CORE_PEER_TLS_ENABLED=true
47+
- 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
48+
- 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
49+
- 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
50+
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
51+
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
52+
#command: /bin/bash -c 'apt-get update && apt-get install && scripts1/${SCRIPT_NAME} ${CHANNEL_NAME} ${CHANNELS_NUM} ${CHAINCODES_NUM} ${ENDORSERS_NUM}; sleep 60'
53+
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'
54+
#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'
55+
#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'
56+
volumes:
57+
- /var/run/:/host/var/run/
58+
- ../../../../../examples/chaincode/go:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
59+
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
60+
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto
61+
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts1
62+
- ../fabricFeatureChaincodes:/opt/gopath/src/github.com/hyperledger/fabric/peer/daily/fabricFeatureChaincodes
63+
depends_on:
64+
- orderer.example.com
65+
- peer0.org1.example.com
66+
- peer1.org1.example.com
67+
- peer0.org2.example.com
68+
- peer1.org2.example.com
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
CHANNEL_NAME=$1
6+
CHANNEL_COUNT=$2
7+
8+
echo "ch_name : $CHANNEL_NAME"
9+
echo "ch_count : $CHANNEL_COUNT"
10+
11+
: ${CHANNEL_NAME:="mychannel"}
12+
: ${CHANNEL_COUNT:="1"}
13+
14+
export FABRIC_ROOT=$GOPATH/src/github.com/hyperledger/fabric
15+
export E2E_CLI_PATH=$FABRIC_ROOT/examples/e2e_cli/
16+
cp $E2E_CLI_PATH/configtx.yaml $PWD
17+
cp $E2E_CLI_PATH/crypto-config.yaml ./crypto-config.yaml
18+
cp -r $E2E_CLI_PATH/base $PWD/
19+
sed -i 's/e2ecli/envsetup/g' base/peer-base.yaml
20+
export FABRIC_CFG_PATH=$PWD
21+
22+
ARTIFACTS=./channel-artifacts
23+
OS_ARCH=$(echo "$(uname -s)-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')
24+
25+
echo "Channel name - "$CHANNEL_NAME
26+
echo "Total channels - "$CHANNEL_COUNT
27+
echo
28+
29+
CONFIGTXGEN=`which configtxgen || /bin/true`
30+
31+
## Generates Org certs using cryptogen tool
32+
function generateCerts (){
33+
CRYPTOGEN=$FABRIC_ROOT/release/$OS_ARCH/bin/cryptogen
34+
35+
if [ -f "$CRYPTOGEN" ]; then
36+
echo "Using cryptogen -> $CRYPTOGEN"
37+
else
38+
echo "Building cryptogen"
39+
make -C $FABRIC_ROOT release-all
40+
fi
41+
42+
echo
43+
echo "**** Generate certificates using cryptogen tool ****"
44+
$CRYPTOGEN generate --config=./crypto-config.yaml
45+
echo
46+
}
47+
48+
## Generate orderer genesis block , channel configuration transaction and anchor peer update transactions
49+
function generateChannelArtifacts() {
50+
51+
CONFIGTXGEN=$FABRIC_ROOT/release/$OS_ARCH/bin/configtxgen
52+
if [ -f "$CONFIGTXGEN" ]; then
53+
echo "Using configtxgen -> $CONFIGTXGEN"
54+
else
55+
echo "Building configtxgen"
56+
make -C $FABRIC_ROOT release-all
57+
fi
58+
59+
echo "Generating genesis block"
60+
$CONFIGTXGEN -profile TwoOrgsOrdererGenesis -outputBlock $ARTIFACTS/orderer.genesis.block
61+
62+
for (( i=0; $i<$CHANNEL_COUNT; i++))
63+
do
64+
echo "Generating channel configuration transaction for channel '$CHANNEL_NAME$i'"
65+
$CONFIGTXGEN -profile TwoOrgsChannel -outputCreateChannelTx $ARTIFACTS/channel$i.tx -channelID $CHANNEL_NAME$i
66+
67+
echo "Generating anchor peer update for Org1MSP"
68+
$CONFIGTXGEN -profile TwoOrgsChannel -outputAnchorPeersUpdate $ARTIFACTS/Org1MSPanchors$i.tx -channelID $CHANNEL_NAME$i -asOrg Org1MSP
69+
70+
echo "Generating anchor peer update for Org2MSP"
71+
$CONFIGTXGEN -profile TwoOrgsChannel -outputAnchorPeersUpdate $ARTIFACTS/Org2MSPanchors$i.tx -channelID $CHANNEL_NAME$i -asOrg Org2MSP
72+
done
73+
}
74+
75+
generateCerts
76+
generateChannelArtifacts
77+
78+
echo "######################### DONE ######################"
79+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
3+
UP_DOWN=$1
4+
CH_NAME=$2
5+
CHANNELS=$3
6+
CHAINCODES=$4
7+
ENDORSERS=$5
8+
SCRIPT_NAME=$6
9+
10+
: ${CH_NAME:="mychannel"}
11+
: ${CHANNELS:="1"}
12+
: ${CHAINCODES:="1"}
13+
: ${ENDORSERS:="4"}
14+
COMPOSE_FILE=docker-compose.yaml
15+
16+
function printHelp () {
17+
echo "Usage: ./network_setup.sh <up|down|retstart> [channel-name] [total-channels [chaincodes] [endorsers count] [SCRIPT_NAME]"
18+
}
19+
20+
function validateArgs () {
21+
if [ -z "${UP_DOWN}" ]; then
22+
echo "Option up / down / restart not mentioned"
23+
printHelp
24+
exit 1
25+
fi
26+
}
27+
28+
function clearContainers () {
29+
CONTAINER_IDS=$(docker ps -aq)
30+
if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" = " " ]; then
31+
echo "---- No containers available for deletion ----"
32+
else
33+
docker rm -f $CONTAINER_IDS
34+
fi
35+
}
36+
37+
function removeUnwantedImages() {
38+
DOCKER_IMAGE_IDS=$(docker images | grep "dev\|none\|test-vp\|peer[0-9]-" | awk '{print $3}')
39+
if [ -z "$DOCKER_IMAGE_IDS" -o "$DOCKER_IMAGE_IDS" = " " ]; then
40+
echo "---- No images available for deletion ----"
41+
else
42+
docker rmi -f $DOCKER_IMAGE_IDS
43+
fi
44+
}
45+
46+
function networkUp () {
47+
CurrentDIR=$PWD
48+
cd ./configTx
49+
echo "ch_name $CH_NAME"
50+
echo "Num channels $CHANNELS"
51+
echo "Num chaincodes $CHAINCODES"
52+
echo "Num of endorsers/peers $ENDORSERS"
53+
echo "Running Script $SCRIPT_NAME"
54+
source generateCfgTrx.sh $CH_NAME $CHANNELS
55+
cd $CurrentDIR
56+
57+
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
58+
if [ $? -ne 0 ]; then
59+
echo "ERROR !!!! Unable to pull the images "
60+
exit 1
61+
fi
62+
docker logs -f cli
63+
}
64+
65+
function networkDown () {
66+
docker-compose -f $COMPOSE_FILE down
67+
#Cleanup the chaincode containers
68+
clearContainers
69+
#Cleanup images
70+
removeUnwantedImages
71+
#remove orderer and config txn
72+
rm -rf channel-artifacts/* crypto-config crypto-config.yaml configtx.yaml scripts/__pycache__ scripts/results.xml scripts/logs.txt scripts/.cache base
73+
}
74+
75+
validateArgs
76+
77+
#Create the network using docker compose
78+
if [ "${UP_DOWN}" == "up" ]; then
79+
networkUp
80+
elif [ "${UP_DOWN}" == "down" ]; then ## Clear the network
81+
networkDown
82+
elif [ "${UP_DOWN}" == "restart" ]; then ## Restart the network
83+
networkDown
84+
networkUp
85+
else
86+
printHelp
87+
exit 1
88+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/python2.7
2+
import shlex
3+
import sys
4+
import subprocess
5+
import xmlrunner
6+
import unittest
7+
from subprocess import Popen, PIPE
8+
from xmlrunner import XMLTestRunner
9+
10+
dailyRunsPath="/opt/gopath/src/github.com/hyperledger/fabric/peer/daily/chaincodeTests"
11+
12+
class TestDailyRuns(unittest.TestCase):
13+
14+
#def runIt(self, command, scriptName):
15+
# cmd = "/opt/gopath/src/github.com/hyperledger/fabric/peer/daily/%s %s %s %s %s %s"% (scriptName, CHANNEL_NAME, CHANNELS, CHAINCODES, ENDORSERS, command)
16+
# print cmd
17+
# p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
18+
# output = p.communicate()[0]
19+
# print output
20+
# self.assertEqual(p.returncode, 0)
21+
22+
def runIt(self, command, scriptName):
23+
cmd = "/opt/gopath/src/github.com/hyperledger/fabric/peer/daily/%s %s %s %s %s %s"% (scriptName, CHANNEL_NAME, CHANNELS, CHAINCODES, ENDORSERS, command)
24+
print cmd
25+
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
26+
output = p.communicate()[0]
27+
print output
28+
self.assertEqual(p.returncode, 0)
29+
30+
def createChannel(self, scriptName):
31+
self.runIt("create", scriptName)
32+
33+
def joinChannel(self, scriptName):
34+
self.runIt("join", scriptName)
35+
36+
def install(self, scriptName):
37+
self.runIt("install", scriptName)
38+
39+
def instantiate(self, scriptName):
40+
self.runIt("instantiate", scriptName)
41+
42+
def invokeQuery(self, scriptName):
43+
self.runIt("invokeQuery", scriptName)
44+
45+
#####Begin tests for different chaincode samples that exist in fabricExamples folder ###################
46+
def test_ACreate_Join_Channel(self):
47+
script_name = "fabricFeatureChaincodes/create_join_channel.sh"
48+
self.createChannel(script_name)
49+
self.joinChannel(script_name)
50+
def test_example02(self):
51+
script_name = "fabricFeatureChaincodes/e2e_test_example02.sh"
52+
self.install(script_name)
53+
self.instantiate(script_name)
54+
self.invokeQuery(script_name)
55+
56+
#####Begin tests for different chaincode samples that exist in fabricExamples folder ###################
57+
58+
59+
if __name__ == '__main__':
60+
CHANNEL_NAME = sys.argv[1]
61+
CHANNELS = sys.argv[2]
62+
CHAINCODES = sys.argv[3]
63+
ENDORSERS = sys.argv[4]
64+
sys.argv.pop()
65+
sys.argv.pop()
66+
sys.argv.pop()
67+
sys.argv.pop()
68+
print CHANNEL_NAME
69+
print CHANNELS
70+
print CHAINCODES
71+
print ENDORSERS
72+
73+
unittest.main(verbosity=2, testRunner=xmlrunner.XMLTestRunner(output='test-reports'))
74+

0 commit comments

Comments
 (0)