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 USECASETest tests |
| 3 | |
| 4 | // TODO: Exception handling around steps |
| 5 | |
| 6 | def prop = null |
| 7 | node("TestStation-BMs"){ |
| 8 | prop = readProperties(file:'/var/jenkins/TestONOS.property') |
| 9 | } |
| 10 | USECASE = [ |
| 11 | "FUNCvirNetNB" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCvirNetNB", wiki_file:"FUNCvirNetNBWiki.txt"], |
| 12 | "FUNCbgpls" : [wiki_link:prop["WikiPrefix"]+"-"+"FUNCbgpls", wiki_file:"FUNCbgplsWiki.txt"], |
| 13 | "VPLSBasic" : [wiki_link:prop["WikiPrefix"]+"-"+"VPLSBasic", wiki_file:"VPLSBasicWiki.txt"], |
| 14 | "VPLSfailsafe" : [wiki_link:prop["WikiPrefix"]+"-"+"VPLSfailsafe", wiki_file:"VPLSfailsafeWiki.txt"], |
| 15 | "PLATdockertest": [wiki_link:"Docker Images sanity test", wiki_file:"PLATdockertestTableWiki.txt"], |
| 16 | "SRSanity": [wiki_link:prop["WikiPrefix"]+"-"+"SR Sanity", wiki_file:"SRSanityWiki.txt"], |
| 17 | "SRSwitchFailure": [wiki_link:prop["WikiPrefix"]+"-"+"SR Switch Failure", wiki_file:"SRSwitchFailureWiki.txt"], |
| 18 | "SRLinkFailure": [wiki_link:prop["WikiPrefix"]+"-"+"SR Link Failure", wiki_file:"SRLinkFailureWiki.txt"], |
| 19 | "SROnosFailure": [wiki_link:prop["WikiPrefix"]+"-"+"SR Onos node Failure", wiki_file:"SROnosFailureWiki.txt"], |
| 20 | "SRClusterRestart": [wiki_link:prop["WikiPrefix"]+"-"+"SR Cluster Restart", wiki_file:"SRClusterRestartWiki.txt"], |
| 21 | "SRDynamic": [wiki_link:prop["WikiPrefix"]+"-"+"SR Dynamic Config", wiki_file:"SRDynamicWiki.txt"], |
| 22 | "SRHA": [wiki_link:prop["WikiPrefix"]+"-"+"SR High Availability", wiki_file:"SRHighAvailabilityWiki.txt"], |
| 23 | "USECASE_SdnipFunction": [wiki_link:prop["WikiPrefix"]+"-"+"SDNIP Function", wiki_file:"USECASE_SdnipFunctionWiki.txt"], |
| 24 | "USECASE_SdnipFunctionCluster": [wiki_link:prop["WikiPrefix"]+"-"+"SDNIP Function Cluster", wiki_file:"USECASE_SdnipFunctionClusterWiki.txt"] |
| 25 | ] |
| 26 | |
| 27 | table_name = "executed_test_tests" |
| 28 | result_name = "executed_test_results" |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 29 | graph_generator_file = "~/OnosSystemTest/TestON/JenkinsFile/scripts/testCaseGraphGenerator.R" |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 30 | graph_saved_directory = "/var/jenkins/workspace/Pipeline_postjob_BM/" |
| 31 | |
| 32 | echo("Testcases:") |
| 33 | testsToRun = prop["Tests"].tokenize("\n;, ") |
| 34 | for ( String test : testsToRun ) { |
| 35 | println test |
| 36 | } |
| 37 | |
| 38 | def tests = [:] |
| 39 | for( String test : USECASE.keySet() ){ |
| 40 | toBeRun = testsToRun.contains( test ) |
| 41 | def stepName = ( toBeRun ? "" : "Not " ) + "Running $test" |
| 42 | tests[stepName] = USECASETest(test, toBeRun, prop) |
| 43 | } |
| 44 | |
| 45 | // run the tests |
| 46 | for ( test in tests.keySet() ){ |
| 47 | tests[test].call() |
| 48 | } |
| 49 | |
| 50 | // The testName should be the key from the FUNC |
| 51 | def USECASETest( testName, toBeRun, prop ) { |
| 52 | return { |
| 53 | catchError{ |
| 54 | stage(testName) { |
| 55 | if ( toBeRun ){ |
| 56 | workSpace = "/var/jenkins/workspace/"+testName |
| 57 | def fileContents = "" |
| 58 | node("TestStation-BMs"){ |
| 59 | withEnv(['ONOSBranch='+prop["ONOSBranch"], |
| 60 | 'ONOSJVMHeap='+prop["ONOSJVMHeap"], |
| 61 | 'TestONBranch='+prop["TestONBranch"], |
| 62 | 'ONOSTag='+prop["ONOSTag"], |
| 63 | 'WikiPrefix='+prop["WikiPrefix"], |
| 64 | 'WORKSPACE='+workSpace]){ |
| 65 | sh '''#!/bin/bash -l |
| 66 | set -i # interactive |
| 67 | set +e |
| 68 | shopt -s expand_aliases # expand alias in non-interactive mode |
| 69 | export PYTHONUNBUFFERED=1 |
| 70 | |
| 71 | ifconfig |
| 72 | |
| 73 | echo "ONOS Branch is: $ONOSBranch" |
| 74 | echo "TestON Branch is: $TestONBranch" |
| 75 | echo "Test date: " |
| 76 | date |
| 77 | |
| 78 | cd ~ |
| 79 | export PATH=$PATH:onos/tools/test/bin |
| 80 | |
| 81 | . .bash_killcmd |
| 82 | killTestONall |
| 83 | onos-group uninstall |
| 84 | timeout 240 stc teardown | head -100 |
| 85 | |
| 86 | cd ~/OnosSystemTest/TestON/bin |
| 87 | git log |head |
| 88 | ./cleanup.sh -f |
| 89 | ''' + "./cli.py run " + testName + ''' |
| 90 | ./cleanup.sh -f |
| 91 | cd ~/onos/tools/package/config |
| 92 | git clean -df''' |
| 93 | |
| 94 | // For the Wiki page |
| 95 | sh '''#!/bin/bash -i |
Devin Lim | a0e52eb | 2017-09-13 18:35:12 -0700 | [diff] [blame] | 96 | set +e |
Devin Lim | 90803a8 | 2017-08-29 13:41:44 -0700 | [diff] [blame] | 97 | echo "ONOS Branch is: ${ONOSBranch}" |
| 98 | echo "TestON Branch is: ${TestONBranch}" |
| 99 | |
| 100 | echo "Job name is: "''' + testName + ''' |
| 101 | echo "Workspace is: ${WORKSPACE}/" |
| 102 | |
| 103 | echo "Wiki page to post is: ${WikiPrefix}-" |
| 104 | |
| 105 | # remove any leftover files from previous tests |
| 106 | sudo rm ${WORKSPACE}/*Wiki.txt |
| 107 | sudo rm ${WORKSPACE}/*Summary.txt |
| 108 | sudo rm ${WORKSPACE}/*Result.txt |
| 109 | sudo rm ${WORKSPACE}/*.csv |
| 110 | |
| 111 | #copy files to workspace |
| 112 | cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'` |
| 113 | sudo cp *.txt ${WORKSPACE}/ |
| 114 | sudo cp *.csv ${WORKSPACE}/ |
| 115 | cd ${WORKSPACE}/ |
| 116 | for i in *.csv |
| 117 | do mv "$i" "$WikiPrefix"-"$i" |
| 118 | done |
| 119 | ls -al |
| 120 | cd ''' |
| 121 | |
| 122 | if( prop["manualRun"] == "false" ){ |
| 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+"/"+USECASE[testName]['wiki_file'] |
| 164 | |
| 165 | } |
| 166 | } |
| 167 | if( prop["manualRun"] == "false" ){ |
| 168 | def post = build job: "Pipeline_postjob_BM", propagate: false, |
| 169 | parameters: [ |
| 170 | string(name: 'Wiki_Contents', value: fileContents), |
| 171 | string(name: 'Wiki_Link', value: USECASE[testName]['wiki_link']) |
| 172 | ] |
| 173 | } |
| 174 | node("TestStation-BMs"){ |
| 175 | sh '''#!/bin/bash |
| 176 | |
| 177 | if [ -e ''' + workSpace + "/" + testName + "Result.txt ] && grep -q \"1\" " + workSpace + "/" + testName + "Result.txt" + ''' |
| 178 | then |
| 179 | echo ''' + testName + " : All passed." + ''' |
| 180 | else |
| 181 | echo ''' + testName + " : not all passed." + ''' |
| 182 | DoingThisToSetTheResultFalse |
| 183 | fi''' |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | } |