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