Skip to content

Commit 928b72b

Browse files
author
Simon Stone
committed
[FAB-12875] Add automated tests for fabcar sample
Introduce automated tests for the fabcar sample, that deploy the new sample contracts and submit the initLedger transaction using the "peer" CLI. Additional changes will follow to drive the new sample apps to ensure that they work as well (but the apps aren't there yet!). Change-Id: Ie42d139eb1dc1cf0f7c16f41f54bb5f40309921c Signed-off-by: Simon Stone <sstone1@uk.ibm.com>
1 parent 5c087f1 commit 928b72b

File tree

5 files changed

+93
-28
lines changed

5 files changed

+93
-28
lines changed

Jenkinsfile

+21-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ node ('hyp-x') { // trigger build on x86_64 node
99
timestamps {
1010
try {
1111
def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name>
12-
env.NODE_VER = "8.11.3" // NodeJs version
12+
def nodeHome = tool 'nodejs-8.11.3'
1313
env.ARCH = "amd64"
1414
env.VERSION = sh(returnStdout: true, script: 'curl -O https://raw.githubusercontent.com/hyperledger/fabric/master/Makefile && cat Makefile | grep "BASE_VERSION =" | cut -d "=" -f2').trim()
1515
env.VERSION = "$VERSION" // BASE_VERSION from fabric Makefile
@@ -19,7 +19,7 @@ node ('hyp-x') { // trigger build on x86_64 node
1919
env.BASE_IMAGE_TAG = "${ARCH}-${BASE_IMAGE_VER}" //fabric baseimage version
2020
env.PROJECT_DIR = "gopath/src/github.com/hyperledger"
2121
env.GOPATH = "$WORKSPACE/gopath"
22-
env.PATH = "$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:~/npm/bin:/home/jenkins/.nvm/versions/node/v${NODE_VER}/bin:$PATH"
22+
env.PATH = "$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:${nodeHome}/bin:$PATH"
2323

2424
def failure_stage = "none"
2525
// delete working directory
@@ -105,13 +105,30 @@ node ('hyp-x') { // trigger build on x86_64 node
105105
}
106106
}
107107
}
108+
109+
// Run fabcar tests
110+
stage("Run FabCar Tests") {
111+
// making the output color coded
112+
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
113+
try {
114+
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
115+
sh './CI_Script.sh --fabcar_Tests'
116+
}
117+
}
118+
catch (err) {
119+
failure_stage = "fabcar_Tests"
120+
currentBuild.result = 'FAILURE'
121+
throw err
122+
}
123+
}
124+
}
108125
} finally {
109126
// Archive the artifacts
110127
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log'
111128
// Sends notification to Rocket.Chat jenkins-robot channel
112-
if (env.GERRIT_EVENT_TYPE == 'change-merged') {
129+
if (env.JOB_NAME == "fabric-samples-merge-byfn") {
113130
if (currentBuild.result == 'FAILURE') { // Other values: SUCCESS, UNSTABLE
114-
rocketSend channel: 'jenkins-robot', message: "Build Notification - STATUS: ${currentBuild.result} - BRANCH: ${env.GERRIT_BRANCH} - PROJECT: ${env.PROJECT} - (<${env.BUILD_URL}|Open>)"
131+
rocketSend message: "Build Notification - STATUS: *${currentBuild.result}* - BRANCH: *${env.GERRIT_BRANCH}* - PROJECT: *${env.PROJECT}* - (<${env.BUILD_URL}|Open>)"
115132
}
116133
}
117134
}

fabcar/startFabric.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ cd ../basic-network
4646
docker-compose -f ./docker-compose.yml up -d cli
4747

4848
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode install -n fabcar -v 1.0 -p "$CC_SRC_PATH" -l "$CC_RUNTIME_LANGUAGE"
49-
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n fabcar -l "$CC_RUNTIME_LANGUAGE" -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
49+
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n fabcar -l "$CC_RUNTIME_LANGUAGE" -v 1.0 -c '{"Args":[]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
5050
sleep 10
51-
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n fabcar -c '{"function":"initLedger","Args":[""]}'
51+
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n fabcar -c '{"function":"initLedger","Args":[]}'
5252

5353
printf "\nTotal setup execution time : $(($(date +%s) - starttime)) secs ...\n\n\n"
5454
printf "Start by installing required packages run 'npm install'\n"

scripts/Jenkins_Scripts/CI_Script.sh

+27-22
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ Parse_Arguments() {
1717
--env_Info)
1818
env_Info
1919
;;
20-
--SetGopath)
21-
setGopath
22-
;;
2320
--pull_Docker_Images)
2421
pull_Docker_Images
2522
;;
@@ -29,9 +26,12 @@ Parse_Arguments() {
2926
--clean_Environment)
3027
clean_Environment
3128
;;
32-
--byfn_eyfn_Tests)
29+
--byfn_eyfn_Tests)
3330
byfn_eyfn_Tests
3431
;;
32+
--fabcar_Tests)
33+
fabcar_Tests
34+
;;
3535
--pull_Thirdparty_Images)
3636
pull_Thirdparty_Images
3737
;;
@@ -54,23 +54,19 @@ function clearContainers () {
5454
}
5555

5656
function removeUnwantedImages() {
57-
DOCKER_IMAGES_SNAPSHOTS=$(docker images | grep snapshot | grep -v grep | awk '{print $1":" $2}')
5857

59-
if [ -z "$DOCKER_IMAGES_SNAPSHOTS" ] || [ "$DOCKER_IMAGES_SNAPSHOTS" = " " ]; then
60-
echo "---- No snapshot images available for deletion ----"
61-
else
62-
docker rmi -f $DOCKER_IMAGES_SNAPSHOTS || true
63-
fi
64-
DOCKER_IMAGE_IDS=$(docker images | grep -v 'base*\|couchdb\|kafka\|zookeeper\|cello' | awk '{print $3}')
58+
for i in $(docker images | grep none | awk '{print $3}'); do
59+
docker rmi ${i};
60+
done
6561

66-
if [ -z "$DOCKER_IMAGE_IDS" ] || [ "$DOCKER_IMAGE_IDS" = " " ]; then
67-
echo "---- No images available for deletion ----"
68-
else
69-
docker rmi -f $DOCKER_IMAGE_IDS || true
70-
docker images
71-
fi
62+
for i in $(docker images | grep -vE ".*baseimage.*(0.4.13|0.4.14)" | grep -vE ".*baseos.*(0.4.13|0.4.14)" | grep -vE ".*couchdb.*(0.4.13|0.4.14)" | grep -vE ".*zoo.*(0.4.13|0.4.14)" | grep -vE ".*kafka.*(0.4.13|0.4.14)" | grep -v "REPOSITORY" | awk '{print $1":" $2}'); do
63+
docker rmi ${i};
64+
done
7265
}
7366

67+
# Remove /tmp/fabric-shim
68+
docker run -v /tmp:/tmp library/alpine rm -rf /tmp/fabric-shim || true
69+
7470
# remove tmp/hfc and hfc-key-store data
7571
rm -rf /home/jenkins/.nvm /home/jenkins/npm /tmp/fabric-shim /tmp/hfc* /tmp/npm* /home/jenkins/kvsTemp /home/jenkins/.hfc-key-store
7672

@@ -128,7 +124,7 @@ pull_Docker_Images() {
128124
exit 1
129125
fi
130126
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES
131-
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES:$IMAGE_TAG
127+
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES:$ARCH-$VERSION
132128
docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG
133129
done
134130
echo
@@ -146,16 +142,25 @@ pull_Fabric_CA_Image() {
146142
exit 1
147143
fi
148144
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES
149-
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES:$IMAGE_TAG
145+
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES:$ARCH-$VERSION
150146
docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG
151147
done
152148
echo
153149
docker images | grep hyperledger/fabric-ca
154150
}
151+
155152
# run byfn,eyfn tests
156153
byfn_eyfn_Tests() {
157-
echo
158-
echo "-----------> Execute Byfn and Eyfn Tests"
159-
./byfn_eyfn.sh
154+
echo
155+
echo "-----------> Execute Byfn and Eyfn Tests"
156+
./byfn_eyfn.sh
157+
}
158+
# run fabcar tests
159+
fabcar_Tests() {
160+
echo
161+
echo "npm version ------> $(npm -v)"
162+
echo "node version ------> $(node -v)"
163+
echo "-----------> Execute FabCar Tests"
164+
./fabcar.sh
160165
}
161166
Parse_Arguments $@

scripts/Jenkins_Scripts/byfn_eyfn.sh

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ COUCHDB_CONTAINER_LIST=(couchdb0 couchdb1 couchdb2 couchdb3 couchdb4 couchdb5)
1212
MARCH=$(uname -s|tr '[:upper:]' '[:lower:]')
1313
echo "-----------> MARCH" $MARCH
1414
echo "-----------> PROJECT_VERSION:" $PROJECT_VERSION
15+
# Download latest binaries from nexus2
1516
MVN_METADATA=$(echo "https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric-$PROJECT_VERSION/maven-metadata.xml")
1617
curl -L "$MVN_METADATA" > maven-metadata.xml
1718
RELEASE_TAG=$(cat maven-metadata.xml | grep release)

scripts/Jenkins_Scripts/fabcar.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
# docker container list - Check these from basic-network/docker-compose.yaml
7+
CONTAINER_LIST=(peer0.org1 orderer ca)
8+
9+
logs() {
10+
11+
for CONTAINER in ${CONTAINER_LIST[*]}; do
12+
docker logs $CONTAINER.example.com >& $WORKSPACE/$CONTAINER-$1.log
13+
echo
14+
done
15+
# Write couchdb container logs into couchdb.log file
16+
docker logs couchdb >& couchdb.log
17+
18+
}
19+
20+
copy_logs() {
21+
22+
# Call logs function
23+
logs $2 $3
24+
25+
if [ $1 != 0 ]; then
26+
echo -e "\033[31m $2 test case is FAILED" "\033[0m"
27+
exit 1
28+
fi
29+
}
30+
31+
cd $BASE_FOLDER/fabric-samples/fabcar || exit
32+
export PATH=gopath/src/github.com/hyperledger/fabric-samples/bin:$PATH
33+
34+
LANGUAGES="go javascript typescript"
35+
for LANGUAGE in ${LANGUAGES}; do
36+
echo -e "\033[32m starting fabcar test (${LANGUAGE})" "\033[0m"
37+
./startFabric.sh ${LANGUAGE}
38+
copy_logs $? fabcar-${LANGUAGE}
39+
docker ps -aq | xargs docker rm -f
40+
docker rmi -f $(docker images -aq dev-*)
41+
echo -e "\033[32m finished fabcar test (${LANGUAGE})" "\033[0m"
42+
done

0 commit comments

Comments
 (0)