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