Devin Lim | e95b3f1 | 2017-12-01 10:46:55 -0800 | [diff] [blame] | 1 | #!groovy |
| 2 | import groovy.time.* |
| 3 | def init( type ){ |
| 4 | machineType = [ "FUNC" : "VM", |
| 5 | "HA" : "VM", |
| 6 | "SCPF" : "BM", |
| 7 | "USECASE" : "BM" ] |
| 8 | testType = type; |
| 9 | testMachine = "TestStation-" + machineType[ type ] + "s"; |
| 10 | } |
| 11 | def printType(){ |
| 12 | echo testType; |
| 13 | echo testMachine; |
| 14 | } |
| 15 | def getProperties(){ |
| 16 | node( testMachine ){ |
| 17 | return readProperties(file:'/var/jenkins/TestONOS.property'); |
| 18 | } |
| 19 | } |
| 20 | def getTestsToRun( testList ){ |
| 21 | testList.tokenize("\n;, ") |
| 22 | } |
| 23 | def getCurrentTime(){ |
| 24 | return new Date(); |
| 25 | } |
| 26 | def getTotalTime( start, end ){ |
| 27 | return TimeCategory.minus( end, start ); |
| 28 | } |
| 29 | def printTestToRun( testList ){ |
| 30 | for ( String test : testList ) { |
| 31 | println test; |
| 32 | } |
| 33 | } |
| 34 | def sendResultToSlack( start, isManualRun ){ |
| 35 | try{ |
| 36 | if( isManualRun == "false" ){ |
| 37 | end = getCurrentTime(); |
| 38 | TimeDuration duration = TimeCategory.minus( end , start ); |
| 39 | slackSend( color:"#5816EE", message: testType + " tests ended at: " + end.toString() + "\nTime took : " + duration ) |
| 40 | } |
| 41 | } |
| 42 | catch(all){} |
| 43 | } |
| 44 | def initAndRunTest( testName ){ |
| 45 | return '''#!/bin/bash -l |
| 46 | set -i # interactive |
| 47 | set +e |
| 48 | shopt -s expand_aliases # expand alias in non-interactive mode |
| 49 | export PYTHONUNBUFFERED=1 |
| 50 | |
| 51 | ifconfig |
| 52 | |
| 53 | echo "ONOS Branch is: $ONOSBranch" |
| 54 | echo "TestON Branch is: $TestONBranch" |
| 55 | echo "Test date: " |
| 56 | date |
| 57 | |
| 58 | cd ~ |
| 59 | export PATH=$PATH:onos/tools/test/bin |
| 60 | |
| 61 | timeout 240 stc shutdown | head -100 |
| 62 | timeout 240 stc teardown | head -100 |
| 63 | timeout 240 stc shutdown | head -100 |
| 64 | |
| 65 | cd ~/OnosSystemTest/TestON/bin |
| 66 | git log |head |
| 67 | ./cleanup.sh -f |
| 68 | ''' + "./cli.py run " + testName + ''' |
| 69 | ./cleanup.sh -f |
| 70 | # cleanup config changes |
| 71 | cd ~/onos/tools/package/config |
| 72 | git clean -df''' |
| 73 | } |
| 74 | def cleanAndCopyFiles( testName ){ |
| 75 | return '''#!/bin/bash -i |
| 76 | set +e |
| 77 | echo "ONOS Branch is: ${ONOSBranch}" |
| 78 | echo "TestON Branch is: ${TestONBranch}" |
| 79 | |
| 80 | echo "Job name is: "''' + testName + ''' |
| 81 | echo "Workspace is: ${WORKSPACE}/" |
| 82 | |
| 83 | echo "Wiki page to post is: ${WikiPrefix}-" |
| 84 | |
| 85 | # remove any leftover files from previous tests |
| 86 | sudo rm ${WORKSPACE}/*Wiki.txt |
| 87 | sudo rm ${WORKSPACE}/*Summary.txt |
| 88 | sudo rm ${WORKSPACE}/*Result.txt |
| 89 | sudo rm ${WORKSPACE}/*.csv |
| 90 | |
| 91 | #copy files to workspace |
| 92 | cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'` |
| 93 | sudo cp *.txt ${WORKSPACE}/ |
| 94 | sudo cp *.csv ${WORKSPACE}/ |
| 95 | cd ${WORKSPACE}/ |
| 96 | for i in *.csv |
| 97 | do mv "$i" "$WikiPrefix"-"$i" |
| 98 | done |
| 99 | ls -al |
| 100 | cd ''' |
| 101 | } |
| 102 | def fetchLogs( testName ){ |
| 103 | return '''#!/bin/bash |
| 104 | set +e |
| 105 | cd ~/OnosSystemTest/TestON/logs |
| 106 | echo "Job Name is: " + ''' + testName + ''' |
| 107 | TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1) |
| 108 | echo "########################################################################################" |
| 109 | echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}" |
| 110 | echo "########################################################################################" |
| 111 | cd $TestONlogDir |
| 112 | if [ $? -eq 1 ] |
| 113 | then |
| 114 | echo "Job name does not match any test suite name to move log!" |
| 115 | else |
| 116 | pwd |
| 117 | for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done |
| 118 | fi |
| 119 | cd''' |
| 120 | } |
| 121 | def postResult( prop, params ){ |
| 122 | if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){ |
| 123 | def post = build job: "Pipeline_postjob_" + machineType[ testType ], propagate: false, parameters: params |
| 124 | } |
| 125 | } |
| 126 | def analyzeResult( prop, workSpace, testName, otherTestName ){ |
| 127 | node( testMachine ){ |
| 128 | resultContents = readFile workSpace + "/" + testName + "Result.txt" |
| 129 | resultContents = resultContents.split("\n") |
| 130 | if( resultContents[ 0 ] == "1" ){ |
| 131 | print "All passed" |
| 132 | }else{ |
| 133 | print "Failed" |
| 134 | if( prop["manualRun"] == "false" ) |
| 135 | slackSend(color:"FF0000", message: "[" + prop["ONOSBranch"] + "]" + otherTestName + " : Failed!\n" |
| 136 | + resultContents[ 1 ] + "\n" |
| 137 | + "https://onos-jenkins.onlab.us/blue/organizations/jenkins/${env.JOB_NAME}/detail/${env.JOB_NAME}/${env.BUILD_NUMBER}/pipeline" ) |
| 138 | Failed |
| 139 | } |
| 140 | } |
| 141 | } |