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 | 61657e4 | 2017-10-09 17:24:40 -0700 | [diff] [blame] | 51 | if( prop["manualRun"] == "false" ){ |
| 52 | def end = new Date() |
| 53 | TimeDuration duration = TimeCategory.minus( end, now ) |
| 54 | slackSend( color:"#5816EE", message: "USECASE tests ended at: " + end.toString() + "\nTime took : " + duration ) |
| 55 | } |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 56 | // The testName should be the key from the FUNC |
| 57 | def USECASETest( testName, toBeRun, prop ) { |
| 58 | return { |
Devin Lim | 61657e4 | 2017-10-09 17:24:40 -0700 | [diff] [blame] | 59 | try{ |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 60 | stage(testName) { |
| 61 | if ( toBeRun ){ |
| 62 | workSpace = "/var/jenkins/workspace/"+testName |
| 63 | def fileContents = "" |
| 64 | node("TestStation-BMs"){ |
| 65 | withEnv(['ONOSBranch='+prop["ONOSBranch"], |
| 66 | 'ONOSJVMHeap='+prop["ONOSJVMHeap"], |
| 67 | 'TestONBranch='+prop["TestONBranch"], |
| 68 | 'ONOSTag='+prop["ONOSTag"], |
| 69 | 'WikiPrefix='+prop["WikiPrefix"], |
| 70 | 'WORKSPACE='+workSpace]){ |
| 71 | sh '''#!/bin/bash -l |
| 72 | set -i # interactive |
| 73 | set +e |
| 74 | shopt -s expand_aliases # expand alias in non-interactive mode |
| 75 | export PYTHONUNBUFFERED=1 |
| 76 | |
| 77 | ifconfig |
| 78 | |
| 79 | echo "ONOS Branch is: $ONOSBranch" |
| 80 | echo "TestON Branch is: $TestONBranch" |
| 81 | echo "Test date: " |
| 82 | date |
| 83 | |
| 84 | cd ~ |
| 85 | export PATH=$PATH:onos/tools/test/bin |
| 86 | |
| 87 | . .bash_killcmd |
| 88 | killTestONall |
| 89 | onos-group uninstall |
| 90 | timeout 240 stc teardown | head -100 |
| 91 | |
| 92 | cd ~/OnosSystemTest/TestON/bin |
| 93 | git log |head |
| 94 | ./cleanup.sh -f |
| 95 | ''' + "./cli.py run " + testName + ''' |
| 96 | ./cleanup.sh -f |
| 97 | cd ~/onos/tools/package/config |
| 98 | git clean -df''' |
| 99 | |
| 100 | // For the Wiki page |
| 101 | sh '''#!/bin/bash -i |
Devin Lim | a0e52eb | 2017-09-13 18:35:12 -0700 | [diff] [blame] | 102 | set +e |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 103 | echo "ONOS Branch is: ${ONOSBranch}" |
| 104 | echo "TestON Branch is: ${TestONBranch}" |
| 105 | |
| 106 | echo "Job name is: "''' + testName + ''' |
| 107 | echo "Workspace is: ${WORKSPACE}/" |
| 108 | |
| 109 | echo "Wiki page to post is: ${WikiPrefix}-" |
| 110 | |
| 111 | # remove any leftover files from previous tests |
| 112 | sudo rm ${WORKSPACE}/*Wiki.txt |
| 113 | sudo rm ${WORKSPACE}/*Summary.txt |
| 114 | sudo rm ${WORKSPACE}/*Result.txt |
| 115 | sudo rm ${WORKSPACE}/*.csv |
| 116 | |
| 117 | #copy files to workspace |
| 118 | cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'` |
| 119 | sudo cp *.txt ${WORKSPACE}/ |
| 120 | sudo cp *.csv ${WORKSPACE}/ |
| 121 | cd ${WORKSPACE}/ |
| 122 | for i in *.csv |
| 123 | do mv "$i" "$WikiPrefix"-"$i" |
| 124 | done |
| 125 | ls -al |
| 126 | cd ''' |
| 127 | |
Devin Lim | 61657e4 | 2017-10-09 17:24:40 -0700 | [diff] [blame] | 128 | if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){ |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 129 | // Post Results |
| 130 | withCredentials([ |
| 131 | string(credentialsId: 'db_pass', variable: 'pass'), |
| 132 | string(credentialsId: 'db_user', variable: 'user'), |
| 133 | string(credentialsId: 'db_host', variable: 'host'), |
| 134 | string(credentialsId: 'db_port', variable: 'port')]) { |
| 135 | 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);\"" |
| 136 | |
| 137 | sh '''#!/bin/bash |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 138 | export DATE=\$(date +%F_%T) |
| 139 | cd ~ |
| 140 | pwd |
| 141 | sed 1d ''' + workSpace + "/" + prop["WikiPrefix"] + "-" + testName + '''.csv | while read line |
| 142 | do |
| 143 | echo \$line |
| 144 | echo ''' + database_command + ''' |
| 145 | |
| 146 | done |
| 147 | Rscript ''' + graph_generator_file + " " + host + " " + port + " " + user + " " + pass + " " + testName + " " + prop["ONOSBranch"] + " 20 " + graph_saved_directory |
| 148 | |
| 149 | } |
| 150 | } |
| 151 | // Fetch Logs |
| 152 | sh '''#!/bin/bash |
Devin Lim | a0e52eb | 2017-09-13 18:35:12 -0700 | [diff] [blame] | 153 | set +e |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 154 | cd ~/OnosSystemTest/TestON/logs |
| 155 | echo "Job Name is: " + ''' + testName + ''' |
| 156 | TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1) |
| 157 | echo "########################################################################################" |
| 158 | echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}" |
| 159 | echo "########################################################################################" |
| 160 | cd $TestONlogDir |
| 161 | if [ $? -eq 1 ] |
| 162 | then |
| 163 | echo "Job name does not match any test suite name to move log!" |
| 164 | else |
| 165 | pwd |
| 166 | for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done |
| 167 | fi |
| 168 | cd''' |
| 169 | fileContents = readFile workSpace+"/"+USECASE[testName]['wiki_file'] |
| 170 | |
| 171 | } |
| 172 | } |
Devin Lim | 61657e4 | 2017-10-09 17:24:40 -0700 | [diff] [blame] | 173 | if( prop["manualRun"] == "false" || prop["postResult"] == "true" ){ |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 174 | def post = build job: "Pipeline_postjob_BM", propagate: false, |
| 175 | parameters: [ |
| 176 | string(name: 'Wiki_Contents', value: fileContents), |
| 177 | string(name: 'Wiki_Link', value: USECASE[testName]['wiki_link']) |
| 178 | ] |
| 179 | } |
| 180 | node("TestStation-BMs"){ |
| 181 | sh '''#!/bin/bash |
| 182 | |
| 183 | if [ -e ''' + workSpace + "/" + testName + "Result.txt ] && grep -q \"1\" " + workSpace + "/" + testName + "Result.txt" + ''' |
| 184 | then |
| 185 | echo ''' + testName + " : All passed." + ''' |
| 186 | else |
| 187 | echo ''' + testName + " : not all passed." + ''' |
| 188 | DoingThisToSetTheResultFalse |
| 189 | fi''' |
| 190 | } |
| 191 | } |
| 192 | } |
Devin Lim | 61657e4 | 2017-10-09 17:24:40 -0700 | [diff] [blame] | 193 | }catch (all) { |
| 194 | catchError{ |
| 195 | if( prop["manualRun"] == "false" ) |
Devin Lim | 4d57f7e | 2017-10-16 14:01:09 -0700 | [diff] [blame] | 196 | slackSend(color:"FF0000", message: "[" + prop["ONOSBranch"] + "]" + testName + " : Failed!\n" |
| 197 | + "https://onos-jenkins.onlab.us/blue/organizations/jenkins/${env.JOB_NAME}/detail/${env.JOB_NAME}/${env.BUILD_NUMBER}/pipeline" ) |
Devin Lim | 61657e4 | 2017-10-09 17:24:40 -0700 | [diff] [blame] | 198 | Failed |
| 199 | } |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | } |