diff --git a/ci-scripts/Jenkinsfile-gitlab b/ci-scripts/Jenkinsfile-gitlab index ad97588d9b..d7d542f863 100644 --- a/ci-scripts/Jenkinsfile-gitlab +++ b/ci-scripts/Jenkinsfile-gitlab @@ -8,7 +8,7 @@ pipeline { disableConcurrentBuilds() timestamps() gitLabConnection('OAI GitLab') - gitlabBuilds(builds: ["Build eNb-USRP", "Build basic-sim", "Build phy-sim", "Analysis with cppcheck"]) + gitlabBuilds(builds: ["Build eNb-USRP", "Build basic-sim", "Build phy-sim", "Build eNb-ethernet", "Build UE-ethernet", "Analysis with cppcheck", "Test phy-sim"]) } stages { @@ -47,33 +47,83 @@ pipeline { } } + stage ("Start VM -- cppcheck") { + steps { + sh "./ci-scripts/createVM.sh --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID}" + } + } + + stage ("Start VM -- enb-usrp") { + steps { + sh "./ci-scripts/createVM.sh --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID}" + } + } + + stage ("Start VM -- basic-sim") { + steps { + sh "./ci-scripts/createVM.sh --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}" + } + } + + stage ("Start VM -- phy-sim") { + steps { + sh "./ci-scripts/createVM.sh --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}" + } + } + + stage ("Start VM -- enb-ethernet") { + steps { + sh "./ci-scripts/createVM.sh --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID}" + } + } + + stage ("Start VM -- ue-ethernet") { + steps { + sh "./ci-scripts/createVM.sh --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID}" + } + } + stage ("Variant Builds") { parallel { stage ("Analysis with cppcheck") { steps { gitlabCommitStatus(name: "Analysis with cppcheck") { - sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant cppcheck" + sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive" } } } stage ("Build eNb-USRP") { steps { gitlabCommitStatus(name: "Build eNb-USRP") { - sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant enb-usrp" + sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive" } } } stage ("Build basic simulator") { steps { gitlabCommitStatus(name: "Build basic-sim") { - sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant basic-sim" + sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive" } } } stage ("Build physical simulators") { steps { gitlabCommitStatus(name: "Build phy-sim") { - sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant phy-sim" + sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive" + } + } + } + stage ("Build eNb-ethernet") { + steps { + gitlabCommitStatus(name: "Build eNb-ethernet") { + sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive" + } + } + } + stage ("Build UE-ethernet") { + steps { + gitlabCommitStatus(name: "Build UE-ethernet") { + sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive" } } } @@ -82,7 +132,7 @@ pipeline { always { script { dir ('archives') { - sh "zip -r vm_build_logs.zip basic_sim enb_usrp phy_sim cppcheck" + sh "zip -r -qq vm_build_logs.zip basic_sim enb_usrp phy_sim cppcheck enb_eth ue_eth" } if(fileExists('archives/vm_build_logs.zip')) { archiveArtifacts artifacts: 'archives/vm_build_logs.zip' @@ -99,11 +149,49 @@ pipeline { } } } + + stage ("Variant Tests") { + parallel { + stage ("Test physical simulators") { + steps { + gitlabCommitStatus(name: "Test phy-sim") { + sh "./ci-scripts/runTestOnVM.sh --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive" + } + } + } + stage ("Test basic simulator") { + steps { + //gitlabCommitStatus(name: "Test basic-sim") { + sh "./ci-scripts/runTestOnVM.sh --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive" + //} + } + } + } + post { + always { + script { + dir ('archives') { + sh "if [ -d */test ]; then zip -r -qq vm_tests_logs.zip */test ; fi" + } + if(fileExists('archives/vm_tests_logs.zip')) { + archiveArtifacts artifacts: 'archives/vm_tests_logs.zip' + archiveArtifacts artifacts: 'archives/*/test/results_autotests*.xml' + } + } + } + } + } + stage ("Destroy all Virtual Machines") { + steps { + sh "./ci-scripts/destroyAllRunningVM.sh --job-name ${JOB_NAME} --build-id ${BUILD_ID}" + } + } } post { always { script { - echo "End of script" + // Stage destroy may not be run if error in previous stage + sh "./ci-scripts/destroyAllRunningVM.sh --job-name ${JOB_NAME} --build-id ${BUILD_ID}" } } success { diff --git a/ci-scripts/buildOnVM.sh b/ci-scripts/buildOnVM.sh index b5fef44ba6..c8ff90c11e 100755 --- a/ci-scripts/buildOnVM.sh +++ b/ci-scripts/buildOnVM.sh @@ -15,13 +15,21 @@ function usage { echo "" echo "Options:" echo "--------" + echo " --job-name #### OR -jn ####" + echo " Specify the name of the Jenkins job." + echo "" + echo " --build-id #### OR -id ####" + echo " Specify the build ID of the Jenkins job." + echo "" echo " --workspace #### OR -ws ####" echo " Specify the workspace." echo "" - echo " --variant enb-usrp OR -v1" - echo " --variant basic-sim OR -v2" - echo " --variant phy-sim OR -v3" - echo " --variant cppcheck OR -v4" + echo " --variant enb-usrp OR -v1" + echo " --variant basic-sim OR -v2" + echo " --variant phy-sim OR -v3" + echo " --variant cppcheck OR -v4" + echo " --variant enb-ethernet OR -v7" + echo " --variant ue-ethernet OR -v8" echo " Specify the variant to build." echo "" echo " --keep-vm-alive OR -k" @@ -36,14 +44,16 @@ function variant_usage { echo "OAI VM Build Check script" echo " Original Author: Raphael Defosseux" echo "" - echo " --variant enb-usrp OR -v1" - echo " --variant basic-sim OR -v2" - echo " --variant phy-sim OR -v3" - echo " --variant cppcheck OR -v4" + echo " --variant enb-usrp OR -v1" + echo " --variant basic-sim OR -v2" + echo " --variant phy-sim OR -v3" + echo " --variant cppcheck OR -v4" + echo " --variant enb-ethernet OR -v7" + echo " --variant ue-ethernet OR -v8" echo "" } -if [ $# -lt 1 ] || [ $# -gt 5 ] +if [ $# -lt 1 ] || [ $# -gt 9 ] then echo "Syntax Error: not the correct number of arguments" echo "" @@ -51,6 +61,9 @@ then exit 1 fi +VM_TEMPLATE=ci- +JOB_NAME=XX +BUILD_ID=XX VM_NAME=ci-enb-usrp ARCHIVES_LOC=enb_usrp LOG_PATTERN=.Rel14.txt @@ -68,6 +81,16 @@ case $key in usage exit 0 ;; + -jn|--job-name) + JOB_NAME="$2" + shift + shift + ;; + -id|--build-id) + BUILD_ID="$2" + shift + shift + ;; -ws|--workspace) JENKINS_WKSP="$2" shift @@ -109,6 +132,22 @@ case $key in BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2" shift ;; + -v7) + VM_NAME=ci-enb-ethernet + ARCHIVES_LOC=enb_eth + LOG_PATTERN=.Rel14.txt + NB_PATTERN_FILES=6 + BUILD_OPTIONS="--eNB -t ETHERNET --noS1" + shift + ;; + -v8) + VM_NAME=ci-ue-ethernet + ARCHIVES_LOC=ue_eth + LOG_PATTERN=.Rel14.txt + NB_PATTERN_FILES=6 + BUILD_OPTIONS="--UE -t ETHERNET --noS1" + shift + ;; --variant) variant="$2" case $variant in @@ -140,6 +179,20 @@ case $key in NB_PATTERN_FILES=1 BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2" ;; + enb-ethernet) + VM_NAME=ci-enb-ethernet + ARCHIVES_LOC=enb_eth + LOG_PATTERN=.Rel14.txt + NB_PATTERN_FILES=6 + BUILD_OPTIONS="--eNB -t ETHERNET --noS1" + ;; + ue-ethernet) + VM_NAME=ci-ue-ethernet + ARCHIVES_LOC=ue_eth + LOG_PATTERN=.Rel14.txt + NB_PATTERN_FILES=6 + BUILD_OPTIONS="--UE -t ETHERNET --noS1" + ;; *) echo "" echo "Syntax Error: Invalid Variant option -> $variant" @@ -170,6 +223,14 @@ then exit 1 fi +if [ "$JOB_NAME" == "XX" ] || [ "$BUILD_ID" == "XX" ] +then + VM_TEMPLATE=ci- +else + VM_TEMPLATE=${JOB_NAME}-b${BUILD_ID}- +fi + +VM_NAME=`echo $VM_NAME | sed -e "s#ci-#$VM_TEMPLATE#"` VM_CMDS=${VM_NAME}_cmds.txt ARCHIVES_LOC=${JENKINS_WKSP}/archives/${ARCHIVES_LOC} @@ -179,10 +240,16 @@ echo "JENKINS_WKSP = $JENKINS_WKSP" echo "ARCHIVES_LOC = $ARCHIVES_LOC" echo "BUILD_OPTIONS = $BUILD_OPTIONS" -echo "############################################################" -echo "Creating VM ($VM_NAME) on Ubuntu Cloud Image base" -echo "############################################################" -uvt-kvm create $VM_NAME release=xenial --memory 2048 --cpu 4 --unsafe-caching --template ci-scripts/template-host.xml +IS_VM_ALIVE=`uvt-kvm list | grep -c $VM_NAME` + +if [ $IS_VM_ALIVE -eq 0 ] +then + echo "############################################################" + echo "Creating VM ($VM_NAME) on Ubuntu Cloud Image base" + echo "############################################################" + uvt-kvm create $VM_NAME release=xenial --memory 2048 --cpu 4 --unsafe-caching --template ci-scripts/template-host.xml +fi + echo "Waiting for VM to be started" uvt-kvm wait $VM_NAME --insecure @@ -199,7 +266,7 @@ echo "############################################################" echo "Running install and build script on VM ($VM_NAME)" echo "############################################################" echo "sudo cp 01proxy /etc/apt/apt.conf.d/" > $VM_CMDS -if [ "$VM_NAME" == "ci-cppcheck" ] +if [[ "$VM_NAME" == *"-cppcheck"* ]] then echo "echo \"sudo apt-get --yes --quiet install zip cppcheck \"" >> $VM_CMDS echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS @@ -210,9 +277,9 @@ else fi echo "mkdir tmp" >> $VM_CMDS echo "cd tmp" >> $VM_CMDS -echo "echo \"unzip -qq ../localZip.zip\"" >> $VM_CMDS -echo "unzip -qq ../localZip.zip" >> $VM_CMDS -if [ "$VM_NAME" == "ci-cppcheck" ] +echo "echo \"unzip -qq -DD ../localZip.zip\"" >> $VM_CMDS +echo "unzip -qq -DD ../localZip.zip" >> $VM_CMDS +if [[ "$VM_NAME" == *"-cppcheck"* ]] then echo "mkdir cmake_targets/log" >> $VM_CMDS echo "cp /home/ubuntu/zip-install.txt cmake_targets/log" >> $VM_CMDS @@ -243,7 +310,7 @@ then fi scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/*.txt $ARCHIVES_LOC -if [ "$VM_NAME" == "ci-cppcheck" ] +if [[ "$VM_NAME" == *"-cppcheck"* ]] then scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/*.xml $ARCHIVES_LOC fi diff --git a/ci-scripts/createVM.sh b/ci-scripts/createVM.sh new file mode 100755 index 0000000000..02d9523d67 --- /dev/null +++ b/ci-scripts/createVM.sh @@ -0,0 +1,167 @@ +#!/bin/bash + +function usage { + echo "OAI VM Creation script" + echo " Original Author: Raphael Defosseux" + echo " Requirements:" + echo " -- uvtool uvtool-libvirt apt-cacher" + echo " -- xenial image already synced" + echo " Default:" + echo " -- eNB with USRP" + echo "" + echo "Usage:" + echo "------" + echo " createVM.sh [OPTIONS]" + echo "" + echo "Options:" + echo "--------" + echo " --job-name #### OR -jn ####" + echo " Specify the name of the Jenkins job." + echo "" + echo " --build-id #### OR -id ####" + echo " Specify the build ID of the Jenkins job." + echo "" + echo " --variant enb-usrp OR -v1" + echo " --variant basic-sim OR -v2" + echo " --variant phy-sim OR -v3" + echo " --variant cppcheck OR -v4" + echo " --variant enb-ethernet OR -v7" + echo " --variant ue-ethernet OR -v8" + echo " Specify the variant to build." + echo "" + echo " --help OR -h" + echo " Print this help message." + echo "" +} + +function variant_usage { + echo "OAI VM Build Check script" + echo " Original Author: Raphael Defosseux" + echo "" + echo " --variant enb-usrp OR -v1" + echo " --variant basic-sim OR -v2" + echo " --variant phy-sim OR -v3" + echo " --variant cppcheck OR -v4" + echo " --variant enb-ethernet OR -v7" + echo " --variant ue-ethernet OR -v8" + echo "" +} + +if [ $# -lt 1 ] || [ $# -gt 6 ] +then + echo "Syntax Error: not the correct number of arguments" + echo "" + usage + exit 1 +fi + +VM_TEMPLATE=ci- +JOB_NAME=XX +BUILD_ID=XX +VM_NAME=ci-enb-usrp + +while [[ $# -gt 0 ]] +do +key="$1" + +case $key in + -h|--help) + shift + usage + exit 0 + ;; + -jn|--job-name) + JOB_NAME="$2" + shift + shift + ;; + -id|--build-id) + BUILD_ID="$2" + shift + shift + ;; + -v1) + VM_NAME=ci-enb-usrp + shift + ;; + -v2) + VM_NAME=ci-basic-sim + shift + ;; + -v3) + VM_NAME=ci-phy-sim + shift + ;; + -v4) + VM_NAME=ci-cppcheck + shift + ;; + -v7) + VM_NAME=ci-enb-ethernet + shift + ;; + -v8) + VM_NAME=ci-ue-ethernet + shift + ;; + --variant) + variant="$2" + case $variant in + enb-usrp) + VM_NAME=ci-enb-usrp + ;; + basic-sim) + VM_NAME=ci-basic-sim + ;; + phy-sim) + VM_NAME=ci-phy-sim + ;; + cppcheck) + VM_NAME=ci-cppcheck + ;; + enb-ethernet) + VM_NAME=ci-enb-ethernet + ;; + ue-ethernet) + VM_NAME=ci-ue-ethernet + ;; + *) + echo "" + echo "Syntax Error: Invalid Variant option -> $variant" + echo "" + variant_usage + exit 1 + esac + shift + shift + ;; + *) + echo "Syntax Error: unknown option: $key" + echo "" + usage + exit 1 +esac +done + +if [ "$JOB_NAME" == "XX" ] || [ "$BUILD_ID" == "XX" ] +then + VM_TEMPLATE=ci- +else + VM_TEMPLATE=${JOB_NAME}-b${BUILD_ID}- +fi + +VM_NAME=`echo $VM_NAME | sed -e "s#ci-#$VM_TEMPLATE#"` +VM_CMDS=${VM_NAME}_cmds.txt + +echo "VM_NAME = $VM_NAME" + +echo "############################################################" +echo "Creating VM ($VM_NAME) on Ubuntu Cloud Image base" +echo "############################################################" +uvt-kvm create $VM_NAME release=xenial --memory 2048 --cpu 4 --unsafe-caching --template ci-scripts/template-host.xml +echo "Waiting for VM to be started" +uvt-kvm wait $VM_NAME --insecure + +VM_IP_ADDR=`uvt-kvm ip $VM_NAME` +echo "$VM_NAME has for IP addr = $VM_IP_ADDR" +exit 0 diff --git a/ci-scripts/destroyAllRunningVM.sh b/ci-scripts/destroyAllRunningVM.sh new file mode 100755 index 0000000000..c9eb43b4ef --- /dev/null +++ b/ci-scripts/destroyAllRunningVM.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +function usage { + echo "OAI VM Destroy script" + echo " Original Author: Raphael Defosseux" + echo "" + echo "Usage:" + echo "------" + echo " destroyAllRunningVM.sh [OPTIONS]" + echo "" + echo "Options:" + echo "--------" + echo " --job-name #### OR -jn ####" + echo " Specify the name of the Jenkins job." + echo "" + echo " --build-id #### OR -id ####" + echo " Specify the build ID of the Jenkins job." + echo "" + echo " --help OR -h" + echo " Print this help message." + echo "" +} + +if [ $# -gt 4 ] +then + echo "Syntax Error: not the correct number of arguments" + echo "" + usage + exit 1 +fi + +VM_TEMPLATE=ci- +JOB_NAME=XX +BUILD_ID=XX + +while [[ $# -gt 0 ]] +do +key="$1" +case $key in + -h|--help) + shift + usage + exit 0 + ;; + -jn|--job-name) + JOB_NAME="$2" + shift + shift + ;; + -id|--build-id) + BUILD_ID="$2" + shift + shift + ;; + *) + echo "Syntax Error: unknown option: $key" + echo "" + usage + exit 1 +esac +done + +if [ "$JOB_NAME" == "XX" ] || [ "$BUILD_ID" == "XX" ] +then + VM_TEMPLATE=ci- +else + VM_TEMPLATE=${JOB_NAME}-b${BUILD_ID}- +fi + +LIST_CI_VM=`uvt-kvm list | grep $VM_TEMPLATE` + +for CI_VM in $LIST_CI_VM +do + VM_IP_ADDR=`uvt-kvm ip $CI_VM` + echo "VM to destroy: $CI_VM -- IP $VM_IP_ADDR" + uvt-kvm destroy $CI_VM + ssh-keygen -R $VM_IP_ADDR +done + +exit 0 + diff --git a/ci-scripts/reportBuildLocally.sh b/ci-scripts/reportBuildLocally.sh index 3a19bae812..694e92e478 100755 --- a/ci-scripts/reportBuildLocally.sh +++ b/ci-scripts/reportBuildLocally.sh @@ -232,6 +232,10 @@ function sca_summary_table_footer { echo "