mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 07:25:10 +00:00
[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>
This commit is contained in:
parent
5c087f1443
commit
928b72b60a
5 changed files with 93 additions and 28 deletions
25
Jenkinsfile
vendored
25
Jenkinsfile
vendored
|
|
@ -9,7 +9,7 @@ node ('hyp-x') { // trigger build on x86_64 node
|
|||
timestamps {
|
||||
try {
|
||||
def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name>
|
||||
env.NODE_VER = "8.11.3" // NodeJs version
|
||||
def nodeHome = tool 'nodejs-8.11.3'
|
||||
env.ARCH = "amd64"
|
||||
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()
|
||||
env.VERSION = "$VERSION" // BASE_VERSION from fabric Makefile
|
||||
|
|
@ -19,7 +19,7 @@ node ('hyp-x') { // trigger build on x86_64 node
|
|||
env.BASE_IMAGE_TAG = "${ARCH}-${BASE_IMAGE_VER}" //fabric baseimage version
|
||||
env.PROJECT_DIR = "gopath/src/github.com/hyperledger"
|
||||
env.GOPATH = "$WORKSPACE/gopath"
|
||||
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"
|
||||
env.PATH = "$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:${nodeHome}/bin:$PATH"
|
||||
|
||||
def failure_stage = "none"
|
||||
// delete working directory
|
||||
|
|
@ -105,13 +105,30 @@ node ('hyp-x') { // trigger build on x86_64 node
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run fabcar tests
|
||||
stage("Run FabCar Tests") {
|
||||
// making the output color coded
|
||||
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
|
||||
try {
|
||||
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
|
||||
sh './CI_Script.sh --fabcar_Tests'
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
failure_stage = "fabcar_Tests"
|
||||
currentBuild.result = 'FAILURE'
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
// Archive the artifacts
|
||||
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log'
|
||||
// Sends notification to Rocket.Chat jenkins-robot channel
|
||||
if (env.GERRIT_EVENT_TYPE == 'change-merged') {
|
||||
if (env.JOB_NAME == "fabric-samples-merge-byfn") {
|
||||
if (currentBuild.result == 'FAILURE') { // Other values: SUCCESS, UNSTABLE
|
||||
rocketSend channel: 'jenkins-robot', message: "Build Notification - STATUS: ${currentBuild.result} - BRANCH: ${env.GERRIT_BRANCH} - PROJECT: ${env.PROJECT} - (<${env.BUILD_URL}|Open>)"
|
||||
rocketSend message: "Build Notification - STATUS: *${currentBuild.result}* - BRANCH: *${env.GERRIT_BRANCH}* - PROJECT: *${env.PROJECT}* - (<${env.BUILD_URL}|Open>)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ cd ../basic-network
|
|||
docker-compose -f ./docker-compose.yml up -d cli
|
||||
|
||||
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"
|
||||
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')"
|
||||
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')"
|
||||
sleep 10
|
||||
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":[""]}'
|
||||
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":[]}'
|
||||
|
||||
printf "\nTotal setup execution time : $(($(date +%s) - starttime)) secs ...\n\n\n"
|
||||
printf "Start by installing required packages run 'npm install'\n"
|
||||
|
|
|
|||
|
|
@ -17,9 +17,6 @@ Parse_Arguments() {
|
|||
--env_Info)
|
||||
env_Info
|
||||
;;
|
||||
--SetGopath)
|
||||
setGopath
|
||||
;;
|
||||
--pull_Docker_Images)
|
||||
pull_Docker_Images
|
||||
;;
|
||||
|
|
@ -29,9 +26,12 @@ Parse_Arguments() {
|
|||
--clean_Environment)
|
||||
clean_Environment
|
||||
;;
|
||||
--byfn_eyfn_Tests)
|
||||
--byfn_eyfn_Tests)
|
||||
byfn_eyfn_Tests
|
||||
;;
|
||||
--fabcar_Tests)
|
||||
fabcar_Tests
|
||||
;;
|
||||
--pull_Thirdparty_Images)
|
||||
pull_Thirdparty_Images
|
||||
;;
|
||||
|
|
@ -54,23 +54,19 @@ function clearContainers () {
|
|||
}
|
||||
|
||||
function removeUnwantedImages() {
|
||||
DOCKER_IMAGES_SNAPSHOTS=$(docker images | grep snapshot | grep -v grep | awk '{print $1":" $2}')
|
||||
|
||||
if [ -z "$DOCKER_IMAGES_SNAPSHOTS" ] || [ "$DOCKER_IMAGES_SNAPSHOTS" = " " ]; then
|
||||
echo "---- No snapshot images available for deletion ----"
|
||||
else
|
||||
docker rmi -f $DOCKER_IMAGES_SNAPSHOTS || true
|
||||
fi
|
||||
DOCKER_IMAGE_IDS=$(docker images | grep -v 'base*\|couchdb\|kafka\|zookeeper\|cello' | awk '{print $3}')
|
||||
for i in $(docker images | grep none | awk '{print $3}'); do
|
||||
docker rmi ${i};
|
||||
done
|
||||
|
||||
if [ -z "$DOCKER_IMAGE_IDS" ] || [ "$DOCKER_IMAGE_IDS" = " " ]; then
|
||||
echo "---- No images available for deletion ----"
|
||||
else
|
||||
docker rmi -f $DOCKER_IMAGE_IDS || true
|
||||
docker images
|
||||
fi
|
||||
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
|
||||
docker rmi ${i};
|
||||
done
|
||||
}
|
||||
|
||||
# Remove /tmp/fabric-shim
|
||||
docker run -v /tmp:/tmp library/alpine rm -rf /tmp/fabric-shim || true
|
||||
|
||||
# remove tmp/hfc and hfc-key-store data
|
||||
rm -rf /home/jenkins/.nvm /home/jenkins/npm /tmp/fabric-shim /tmp/hfc* /tmp/npm* /home/jenkins/kvsTemp /home/jenkins/.hfc-key-store
|
||||
|
||||
|
|
@ -128,7 +124,7 @@ pull_Docker_Images() {
|
|||
exit 1
|
||||
fi
|
||||
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES
|
||||
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES:$IMAGE_TAG
|
||||
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES:$ARCH-$VERSION
|
||||
docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG
|
||||
done
|
||||
echo
|
||||
|
|
@ -146,16 +142,25 @@ pull_Fabric_CA_Image() {
|
|||
exit 1
|
||||
fi
|
||||
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES
|
||||
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES:$IMAGE_TAG
|
||||
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES:$ARCH-$VERSION
|
||||
docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG
|
||||
done
|
||||
echo
|
||||
docker images | grep hyperledger/fabric-ca
|
||||
}
|
||||
|
||||
# run byfn,eyfn tests
|
||||
byfn_eyfn_Tests() {
|
||||
echo
|
||||
echo "-----------> Execute Byfn and Eyfn Tests"
|
||||
./byfn_eyfn.sh
|
||||
echo
|
||||
echo "-----------> Execute Byfn and Eyfn Tests"
|
||||
./byfn_eyfn.sh
|
||||
}
|
||||
# run fabcar tests
|
||||
fabcar_Tests() {
|
||||
echo
|
||||
echo "npm version ------> $(npm -v)"
|
||||
echo "node version ------> $(node -v)"
|
||||
echo "-----------> Execute FabCar Tests"
|
||||
./fabcar.sh
|
||||
}
|
||||
Parse_Arguments $@
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ COUCHDB_CONTAINER_LIST=(couchdb0 couchdb1 couchdb2 couchdb3 couchdb4 couchdb5)
|
|||
MARCH=$(uname -s|tr '[:upper:]' '[:lower:]')
|
||||
echo "-----------> MARCH" $MARCH
|
||||
echo "-----------> PROJECT_VERSION:" $PROJECT_VERSION
|
||||
# Download latest binaries from nexus2
|
||||
MVN_METADATA=$(echo "https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric-$PROJECT_VERSION/maven-metadata.xml")
|
||||
curl -L "$MVN_METADATA" > maven-metadata.xml
|
||||
RELEASE_TAG=$(cat maven-metadata.xml | grep release)
|
||||
|
|
|
|||
42
scripts/Jenkins_Scripts/fabcar.sh
Executable file
42
scripts/Jenkins_Scripts/fabcar.sh
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# docker container list - Check these from basic-network/docker-compose.yaml
|
||||
CONTAINER_LIST=(peer0.org1 orderer ca)
|
||||
|
||||
logs() {
|
||||
|
||||
for CONTAINER in ${CONTAINER_LIST[*]}; do
|
||||
docker logs $CONTAINER.example.com >& $WORKSPACE/$CONTAINER-$1.log
|
||||
echo
|
||||
done
|
||||
# Write couchdb container logs into couchdb.log file
|
||||
docker logs couchdb >& couchdb.log
|
||||
|
||||
}
|
||||
|
||||
copy_logs() {
|
||||
|
||||
# Call logs function
|
||||
logs $2 $3
|
||||
|
||||
if [ $1 != 0 ]; then
|
||||
echo -e "\033[31m $2 test case is FAILED" "\033[0m"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
cd $BASE_FOLDER/fabric-samples/fabcar || exit
|
||||
export PATH=gopath/src/github.com/hyperledger/fabric-samples/bin:$PATH
|
||||
|
||||
LANGUAGES="go javascript typescript"
|
||||
for LANGUAGE in ${LANGUAGES}; do
|
||||
echo -e "\033[32m starting fabcar test (${LANGUAGE})" "\033[0m"
|
||||
./startFabric.sh ${LANGUAGE}
|
||||
copy_logs $? fabcar-${LANGUAGE}
|
||||
docker ps -aq | xargs docker rm -f
|
||||
docker rmi -f $(docker images -aq dev-*)
|
||||
echo -e "\033[32m finished fabcar test (${LANGUAGE})" "\033[0m"
|
||||
done
|
||||
Loading…
Reference in a new issue