Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 1 | #!groovy |
Devin Lim | 61657e4 | 2017-10-09 17:24:40 -0700 | [diff] [blame] | 2 | import groovy.time.* |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 3 | // This is a Jenkinsfile for a scripted pipeline for the USECASETest tests |
| 4 | |
| 5 | // TODO: Exception handling around steps |
| 6 | |
| 7 | def prop = null |
| 8 | node("TestStation-BMs"){ |
| 9 | prop = readProperties(file:'/var/jenkins/TestONOS.property') |
| 10 | } |
| 11 | USECASE = [ |
| 12 | "FUNCvirNetNB" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCvirNetNB", wiki_file:"FUNCvirNetNBWiki.txt"], |
| 13 | "FUNCbgpls" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCbgpls", wiki_file:"FUNCbgplsWiki.txt"], |
| 14 | "VPLSBasic" : [wiki_link:prop["WikiPrefix"]+"-"+"VPLSBasic", wiki_file:"VPLSBasicWiki.txt"], |
| 15 | "VPLSfailsafe" : [wiki_link:prop["WikiPrefix"]+"-"+"VPLSfailsafe", wiki_file:"VPLSfailsafeWiki.txt"], |
| 16 | "PLATdockertest": [wiki_link:"Docker Images sanity test", wiki_file:"PLATdockertestTableWiki.txt"], |
| 17 | "SRSanity": [wiki_link:prop["WikiPrefix"]+"-"+"SR Sanity", wiki_file:"SRSanityWiki.txt"], |
| 18 | "SRSwitchFailure": [wiki_link:prop["WikiPrefix"]+"-"+"SR Switch Failure", wiki_file:"SRSwitchFailureWiki.txt"], |
| 19 | "SRLinkFailure": [wiki_link:prop["WikiPrefix"]+"-"+"SR Link Failure", wiki_file:"SRLinkFailureWiki.txt"], |
| 20 | "SROnosFailure": [wiki_link:prop["WikiPrefix"]+"-"+"SR Onos node Failure", wiki_file:"SROnosFailureWiki.txt"], |
| 21 | "SRClusterRestart": [wiki_link:prop["WikiPrefix"]+"-"+"SR Cluster Restart", wiki_file:"SRClusterRestartWiki.txt"], |
| 22 | "SRDynamic": [wiki_link:prop["WikiPrefix"]+"-"+"SR Dynamic Config", wiki_file:"SRDynamicWiki.txt"], |
Devin Lim | 61657e4 | 2017-10-09 17:24:40 -0700 | [diff] [blame] | 23 | "SRHighAvailability": [wiki_link:prop["WikiPrefix"]+"-"+"SR High Availability", wiki_file:"SRHighAvailabilityWiki.txt"], |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 24 | "USECASE_SdnipFunction": [wiki_link:prop["WikiPrefix"]+"-"+"SDNIP Function", wiki_file:"USECASE_SdnipFunctionWiki.txt"], |
| 25 | "USECASE_SdnipFunctionCluster": [wiki_link:prop["WikiPrefix"]+"-"+"SDNIP Function Cluster", wiki_file:"USECASE_SdnipFunctionClusterWiki.txt"] |
| 26 | ] |
| 27 | |
| 28 | table_name = "executed_test_tests" |
| 29 | result_name = "executed_test_results" |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 30 | graph_generator_file = "~/OnosSystemTest/TestON/JenkinsFile/scripts/testCaseGraphGenerator.R" |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 31 | graph_saved_directory = "/var/jenkins/workspace/Pipeline_postjob_BM/" |
| 32 | |
| 33 | echo("Testcases:") |
| 34 | testsToRun = prop["Tests"].tokenize("\n;, ") |
| 35 | for ( String test : testsToRun ) { |
| 36 | println test |
| 37 | } |
| 38 | |
| 39 | def tests = [:] |
| 40 | for( String test : USECASE.keySet() ){ |
| 41 | toBeRun = testsToRun.contains( test ) |
| 42 | def stepName = ( toBeRun ? "" : "Not " ) + "Running $test" |
| 43 | tests[stepName] = USECASETest(test, toBeRun, prop) |
| 44 | } |
| 45 | |
Devin Lim | 61657e4 | 2017-10-09 17:24:40 -0700 | [diff] [blame] | 46 | def now = new Date() |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 47 | // run the tests |
| 48 | for ( test in tests.keySet() ){ |
| 49 | tests[test].call() |
| 50 | } |
Devin Lim | 79af50f | 2017-10-26 14:26:47 -0700 | [diff] [blame] | 51 | try{ |
| 52 | if( prop["manualRun"] == "false" ){ |
| 53 | def end = new Date() |
| 54 | TimeDuration duration = TimeCategory.minus( end, now ) |
| 55 | slackSend( color:"#5816EE", message: "USECASE tests ended at: " + end.toString() + "\nTime took : " + duration ) |
| 56 | } |
Devin Lim | 61657e4 | 2017-10-09 17:24:40 -0700 | [diff] [blame] | 57 | } |
Devin Lim | 79af50f | 2017-10-26 14:26:47 -0700 | [diff] [blame] | 58 | catch(all){} |
| 59 | |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 60 | // The testName should be the key from the FUNC |
| 61 | def USECASETest( testName, toBeRun, prop ) { |
| 62 | return { |
Devin Lim | 79af50f | 2017-10-26 14:26:47 -0700 | [diff] [blame] | 63 | catchError{ |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 64 | stage(testName) { |
| 65 | if ( toBeRun ){ |
| 66 | workSpace = "/var/jenkins/workspace/"+testName |
| 67 | def fileContents = "" |
| 68 | node("TestStation-BMs"){ |
| 69 | withEnv(['ONOSBranch='+prop["ONOSBranch"], |
| 70 | 'ONOSJVMHeap='+prop["ONOSJVMHeap"], |
| 71 | 'TestONBranch='+prop["TestONBranch"], |
| 72 | 'ONOSTag='+prop["ONOSTag"], |
| 73 | 'WikiPrefix='+prop["WikiPrefix"], |
| 74 | 'WORKSPACE='+workSpace]){ |
| 75 | sh '''#!/bin/bash -l |
| 76 | set -i # interactive |
| 77 | set +e |
| 78 | shopt -s expand_aliases # expand alias in non-interactive mode |
| 79 | export PYTHONUNBUFFERED=1 |
| 80 | |
| 81 | ifconfig |
| 82 | |
| 83 | echo "ONOS Branch is: $ONOSBranch" |
| 84 | echo "TestON Branch is: $TestONBranch" |
| 85 | echo "Test date: " |
| 86 | date |
| 87 | |
| 88 | cd ~ |
| 89 | export PATH=$PATH:onos/tools/test/bin |
| 90 | |
| 91 | . .bash_killcmd |
| 92 | killTestONall |
| 93 | onos-group uninstall |
| 94 | timeout 240 stc teardown | head -100 |
| 95 | |
| 96 | cd ~/OnosSystemTest/TestON/bin |
| 97 | git log |head |
| 98 | ./cleanup.sh -f |
| 99 | ''' + "./cli.py run " + testName + ''' |
| 100 | ./cleanup.sh -f |
| 101 | cd ~/onos/tools/package/config |
| 102 | git clean -df''' |
| 103 | |
| 104 | // For the Wiki page |
| 105 | sh '''#!/bin/bash -i |
Devin Lim | a0e52eb | 2017-09-13 18:35:12 -0700 | [diff] [blame] | 106 | set +e |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 107 | echo "ONOS Branch is: ${ONOSBranch}" |
| 108 | echo "TestON Branch is: ${TestONBranch}" |
| 109 | |
| 110 | echo "Job name is: "''' + testName + ''' |
| 111 | echo "Workspace is: ${WORKSPACE}/" |
| 112 | |
| 113 | echo "Wiki page to post is: ${WikiPrefix}-" |
| 114 | |
| 115 | # remove any leftover files from previous tests |
| 116 | sudo rm ${WORKSPACE}/*Wiki.txt |
| 117 | sudo rm ${WORKSPACE}/*Summary.txt |
| 118 | sudo rm ${WORKSPACE}/*Result.txt |
| 119 | sudo rm ${WORKSPACE}/*.csv |
| 120 | |
| 121 | #copy files to workspace |
| 122 | cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'` |
| 123 | sudo cp *.txt ${WORKSPACE}/ |
| 124 | sudo cp *.csv ${WORKSPACE}/ |
| 125 | cd ${WORKSPACE}/ |
| 126 | for i in *.csv |
| 127 | do mv "$i" "$WikiPrefix"-"$i" |
| 128 | done |
| 129 | ls -al |
| 130 | cd ''' |
| 131 | |
Devin Lim | 61657e4 | 2017-10-09 17:24:40 -0700 | [diff] [blame] | 132 | if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){ |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 133 | // Post Results |
| 134 | withCredentials([ |
| 135 | string(credentialsId: 'db_pass', variable: 'pass'), |
| 136 | string(credentialsId: 'db_user', variable: 'user'), |
| 137 | string(credentialsId: 'db_host', variable: 'host'), |
| 138 | string(credentialsId: 'db_port', variable: 'port')]) { |
| 139 | def database_command = pass + "|psql --host=" + host + " --port=" + port + " --username=" + user + " --password --dbname onostest -c \"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" + testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\"" |
| 140 | |
| 141 | sh '''#!/bin/bash |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 142 | export DATE=\$(date +%F_%T) |
| 143 | cd ~ |
| 144 | pwd |
| 145 | sed 1d ''' + workSpace + "/" + prop["WikiPrefix"] + "-" + testName + '''.csv | while read line |
| 146 | do |
| 147 | echo \$line |
| 148 | echo ''' + database_command + ''' |
| 149 | |
| 150 | done |
| 151 | Rscript ''' + graph_generator_file + " " + host + " " + port + " " + user + " " + pass + " " + testName + " " + prop["ONOSBranch"] + " 20 " + graph_saved_directory |
| 152 | |
| 153 | } |
| 154 | } |
| 155 | // Fetch Logs |
| 156 | sh '''#!/bin/bash |
Devin Lim | a0e52eb | 2017-09-13 18:35:12 -0700 | [diff] [blame] | 157 | set +e |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 158 | cd ~/OnosSystemTest/TestON/logs |
| 159 | echo "Job Name is: " + ''' + testName + ''' |
| 160 | TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1) |
| 161 | echo "########################################################################################" |
| 162 | echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}" |
| 163 | echo "########################################################################################" |
| 164 | cd $TestONlogDir |
| 165 | if [ $? -eq 1 ] |
| 166 | then |
| 167 | echo "Job name does not match any test suite name to move log!" |
| 168 | else |
| 169 | pwd |
| 170 | for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done |
| 171 | fi |
| 172 | cd''' |
| 173 | fileContents = readFile workSpace+"/"+USECASE[testName]['wiki_file'] |
| 174 | |
| 175 | } |
| 176 | } |
Devin Lim | 61657e4 | 2017-10-09 17:24:40 -0700 | [diff] [blame] | 177 | if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){ |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 178 | def post = build job: "Pipeline_postjob_BM", propagate: false, |
| 179 | parameters: [ |
| 180 | string(name: 'Wiki_Contents', value: fileContents), |
| 181 | string(name: 'Wiki_Link', value: USECASE[testName]['wiki_link']) |
| 182 | ] |
| 183 | } |
| 184 | node("TestStation-BMs"){ |
Devin Lim | 79af50f | 2017-10-26 14:26:47 -0700 | [diff] [blame] | 185 | resultContents = readFile workSpace + "/" + testName + "Result.txt" |
| 186 | resultContents = resultContents.split("\n") |
| 187 | if( resultContents[ 0 ] == "1" ){ |
| 188 | print "All passed" |
| 189 | }else{ |
| 190 | print "Failed" |
| 191 | if( prop["manualRun"] == "false" ) |
| 192 | slackSend(color:"FF0000", message: "[" + prop["ONOSBranch"] + "]" + testName + " : Failed!\n" |
| 193 | + resultContents[ 1 ] + "\n" |
| 194 | + "https://onos-jenkins.onlab.us/blue/organizations/jenkins/${env.JOB_NAME}/detail/${env.JOB_NAME}/${env.BUILD_NUMBER}/pipeline" ) |
| 195 | Failed |
| 196 | } |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | } |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | } |