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