Devin Lim | e1346f4 | 2018-05-15 15:41:36 -0700 | [diff] [blame] | 1 | #!groovy |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 2 | // Copyright 2017 Open Networking Foundation (ONF) |
| 3 | // |
| 4 | // Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | // the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | // or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | // |
| 8 | // TestON is free software: you can redistribute it and/or modify |
| 9 | // it under the terms of the GNU General Public License as published by |
| 10 | // the Free Software Foundation, either version 2 of the License, or |
| 11 | // (at your option) any later version. |
| 12 | // |
| 13 | // TestON is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | // GNU General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU General Public License |
| 19 | // along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | |
| 21 | // This is the dependency Jenkins script. |
| 22 | // it has some common functions that runs test and generate graph. |
| 23 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 24 | import groovy.time.TimeCategory |
| 25 | import groovy.time.TimeDuration |
| 26 | |
Devin Lim | b734ea5 | 2018-05-14 14:13:05 -0700 | [diff] [blame] | 27 | generalFuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/GeneralFuncs.groovy' ) |
| 28 | fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' ) |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 29 | test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' ) |
Devin Lim | fe9a4cb | 2018-05-11 17:06:21 -0700 | [diff] [blame] | 30 | |
| 31 | fileRelated.init() |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 32 | test_list.init() |
Jeremy Ronquillo | 14ecc17 | 2018-03-05 09:57:17 -0800 | [diff] [blame] | 33 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 34 | def initializeTrend( machine ){ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 35 | // For initializing any trend graph jobs |
| 36 | // machine : Either VM,BM, or Fabric# |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 37 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 38 | table_name = "executed_test_tests" |
| 39 | result_name = "executed_test_results" |
| 40 | testMachine = "TestStation-" + machine + "s" |
| 41 | this.machine = machine |
| 42 | isSCPF = false |
| 43 | isTrend = true |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 44 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 45 | |
Jeremy Ronquillo | 62199e7 | 2019-07-02 14:24:31 -0700 | [diff] [blame] | 46 | def initialize( type, SCPFfuncs=null ){ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 47 | // initializing for FUNC,HA,SR, and USECASE |
| 48 | // type : type of the test ( SR,FUNC,SCPF... ) |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 49 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 50 | init( type ) |
Jeremy Ronquillo | c6a862f | 2019-07-02 15:53:44 -0700 | [diff] [blame] | 51 | isSCPF = ( type == "SCPF" ) |
Jeremy Ronquillo | 62199e7 | 2019-07-02 14:24:31 -0700 | [diff] [blame] | 52 | SCPFfunc = SCPFfuncs |
| 53 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 54 | table_name = "executed_test_tests" |
| 55 | result_name = "executed_test_results" |
| 56 | trend_generator_file = fileRelated.trendMultiple |
| 57 | build_stats_generator_file = fileRelated.histogramMultiple |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 58 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 59 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 60 | def init( type ){ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 61 | // type : type of the test ( SR,FUNC,SCPF... ) |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 62 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 63 | machineType = [ "FUNC": "VM", |
| 64 | "HA": "VM", |
| 65 | "SR": "Fabric", |
| 66 | "SCPF": "BM", |
| 67 | "USECASE": "BM" ] |
| 68 | testType = type |
| 69 | testMachine = "TestStation-" + machineType[ type ] + "s" |
| 70 | isTrend = false |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 71 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 72 | |
Devin Lim | 86e4053 | 2018-04-06 12:44:06 -0700 | [diff] [blame] | 73 | def additionalInitForSR( branch ){ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 74 | // additional setup for SegmentRouting tests to determine the machine depends on the branch it is running. |
You Wang | f043d0a | 2019-04-22 16:30:40 -0700 | [diff] [blame] | 75 | // branch : branch of the onos. ( master, 2.1, 1.15... ) |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 76 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 77 | testMachine = ( ( new StringBuilder( testMachine ) ).insert( testMachine.size() - 1, fabricOn( branch ) ) ). |
| 78 | toString() |
| 79 | if ( isTrend ){ |
| 80 | machine += fabricOn( branch ) |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 81 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 82 | else { |
| 83 | machineType[ testType ] += fabricOn( branch ) |
| 84 | } |
| 85 | print testMachine |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 86 | } |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 87 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 88 | def fabricOn( branch ){ |
| 89 | // gets the fabric machines with the branch of onos. |
You Wang | f043d0a | 2019-04-22 16:30:40 -0700 | [diff] [blame] | 90 | // branch : master, 2.1, 1.15... |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 91 | // branch.reverse().take(4).reverse() will get last 4 characters of the string. |
You Wang | dba6c9f | 2018-12-21 11:58:55 -0800 | [diff] [blame] | 92 | switch ( branch.reverse().take( 3 ).reverse() ){ |
| 93 | case "ter": return "4" |
You Wang | f043d0a | 2019-04-22 16:30:40 -0700 | [diff] [blame] | 94 | case "2.1": return "3" |
You Wang | dba6c9f | 2018-12-21 11:58:55 -0800 | [diff] [blame] | 95 | case "2.0": return "3" |
| 96 | case ".15": return "2" |
| 97 | case ".14": return "3" |
| 98 | case ".13": return "2" |
| 99 | case ".12": return "3" |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 100 | default: return "4" |
| 101 | } |
| 102 | } |
| 103 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 104 | def getProperties( category, branchWithPrefix ){ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 105 | // get the properties of the test by reading the TestONOS.property |
| 106 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 107 | filePath = '''/var/jenkins/TestONOS-''' + category + '''-''' + branchWithPrefix + '''.property''' |
| 108 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 109 | node( testMachine ) { |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 110 | return readProperties( file: filePath ) |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | |
| 114 | def getTestsToRun( testList ){ |
| 115 | // get test to run by tokenizing the list. |
| 116 | |
| 117 | testList.tokenize( "\n;, " ) |
| 118 | } |
| 119 | |
| 120 | def getCurrentTime(){ |
| 121 | // get time of the PST zone. |
| 122 | |
| 123 | TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) ) |
| 124 | return new Date() |
| 125 | } |
| 126 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 127 | def sendResultToSlack( start, isManualRun, branch ){ |
| 128 | // send the result of the test to the slack when it is not manually running. |
| 129 | // start : start time of the test |
| 130 | // isManualRun : string that is whether "false" or "true" |
| 131 | // branch : branch of the onos. |
| 132 | |
| 133 | try { |
| 134 | if ( isManualRun == "false" ){ |
| 135 | end = getCurrentTime() |
| 136 | TimeDuration duration = TimeCategory.minus( end, start ) |
You Wang | 28cb855 | 2019-02-19 16:11:52 -0800 | [diff] [blame] | 137 | // FIXME: for now we disable notifications of normal test results |
| 138 | /* |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 139 | slackSend( color: "#5816EE", |
| 140 | message: testType + "-" + branch + " tests ended at: " + end.toString() + |
| 141 | "\nTime took : " + duration ) |
You Wang | 28cb855 | 2019-02-19 16:11:52 -0800 | [diff] [blame] | 142 | */ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | catch ( all ){ |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | def initAndRunTest( testName, testCategory ){ |
| 150 | // Bash script that will |
| 151 | // Initialize the environment to the machine and run the test. |
| 152 | // testName : name of the test |
| 153 | // testCategory : (SR,FUNC ... ) |
| 154 | |
| 155 | return '''#!/bin/bash -l |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 156 | set -i # interactive |
| 157 | set +e |
| 158 | shopt -s expand_aliases # expand alias in non-interactive mode |
| 159 | export PYTHONUNBUFFERED=1 |
| 160 | ifconfig |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 161 | echo "ONOS Branch is: $ONOSBranch" |
| 162 | echo "TestON Branch is: $TestONBranch" |
| 163 | echo "Test date: " |
| 164 | date |
| 165 | cd ~ |
| 166 | export PATH=$PATH:onos/tools/test/bin |
| 167 | timeout 240 stc shutdown | head -100 |
| 168 | timeout 240 stc teardown | head -100 |
| 169 | timeout 240 stc shutdown | head -100 |
| 170 | cd ~/OnosSystemTest/TestON/bin |
Jon Hall | 2ee92f8 | 2018-06-07 13:07:33 -0700 | [diff] [blame] | 171 | git log | head |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 172 | ./cleanup.sh -f |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 173 | ''' + "./cli.py run " + |
Jeremy Ronquillo | 62199e7 | 2019-07-02 14:24:31 -0700 | [diff] [blame] | 174 | testName + |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 175 | " --params GRAPH/nodeCluster=" + machineType[ testType ] + ''' |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 176 | ./cleanup.sh -f |
| 177 | # cleanup config changes |
| 178 | cd ~/onos/tools/package/config |
| 179 | git clean -df''' |
| 180 | } |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 181 | |
Jon Hall | 8b1e92c | 2018-06-13 14:07:22 -0700 | [diff] [blame] | 182 | def copyLogs(){ |
| 183 | // bash script to copy the logs and other necessary element for SR tests. |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 184 | |
| 185 | result = "" |
| 186 | if ( testType == "SR" ){ |
| 187 | result = ''' |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 188 | sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/* |
| 189 | sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
| 190 | sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
| 191 | sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
Devin Lim | a7b97a4 | 2018-04-09 14:26:38 -0700 | [diff] [blame] | 192 | sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
Devin Lim | 6faa3f9 | 2018-05-01 13:16:25 -0700 | [diff] [blame] | 193 | sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/ |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 194 | ''' |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 195 | } |
| 196 | return result |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 197 | } |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 198 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 199 | def cleanAndCopyFiles( testName ){ |
| 200 | // clean up some files that were in the folder and copy the new files from the log |
| 201 | // testName : name of the test |
| 202 | |
| 203 | return '''#!/bin/bash -i |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 204 | set +e |
| 205 | echo "ONOS Branch is: ${ONOSBranch}" |
| 206 | echo "TestON Branch is: ${TestONBranch}" |
| 207 | echo "Job name is: "''' + testName + ''' |
| 208 | echo "Workspace is: ${WORKSPACE}/" |
| 209 | echo "Wiki page to post is: ${WikiPrefix}-" |
| 210 | # remove any leftover files from previous tests |
| 211 | sudo rm ${WORKSPACE}/*Wiki.txt |
| 212 | sudo rm ${WORKSPACE}/*Summary.txt |
| 213 | sudo rm ${WORKSPACE}/*Result.txt |
You Wang | aa7bc72 | 2019-02-21 17:55:39 -0800 | [diff] [blame] | 214 | sudo rm ${WORKSPACE}/*Alarm.txt || true |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 215 | sudo rm ${WORKSPACE}/*.csv |
| 216 | #copy files to workspace |
| 217 | cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'` |
Jon Hall | 8b1e92c | 2018-06-13 14:07:22 -0700 | [diff] [blame] | 218 | ''' + copyLogs() + ''' |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 219 | sudo cp *.txt ${WORKSPACE}/ |
| 220 | sudo cp *.csv ${WORKSPACE}/ |
| 221 | cd ${WORKSPACE}/ |
| 222 | for i in *.csv |
| 223 | do mv "$i" "$WikiPrefix"-"$i" |
| 224 | done |
| 225 | ls -al |
| 226 | cd ''' |
| 227 | } |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 228 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 229 | def fetchLogs( testName ){ |
| 230 | // fetch the logs of onos from onos nodes to onos System Test logs |
| 231 | // testName: name of the test |
| 232 | |
| 233 | return '''#!/bin/bash |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 234 | set +e |
| 235 | cd ~/OnosSystemTest/TestON/logs |
Jon Hall | 8b1e92c | 2018-06-13 14:07:22 -0700 | [diff] [blame] | 236 | echo "TestON test name is: "''' + testName + ''' |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 237 | TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1) |
| 238 | echo "########################################################################################" |
| 239 | echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}" |
| 240 | echo "########################################################################################" |
| 241 | cd $TestONlogDir |
| 242 | if [ $? -eq 1 ] |
| 243 | then |
| 244 | echo "Job name does not match any test suite name to move log!" |
| 245 | else |
| 246 | pwd |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 247 | for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done |
| 248 | for i in $OC{1..7}; do atomix-fetch-logs $i || echo log does not exist for atomix $i; done |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 249 | fi |
| 250 | cd''' |
| 251 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 252 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 253 | def isPostingResult( manual, postresult ){ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 254 | // check if it is posting the result. |
| 255 | // posting when it is automatically running or has postResult condition from the manual run |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 256 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 257 | return manual == "false" || postresult == "true" |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 258 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 259 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 260 | def postResult( prop, graphOnly ){ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 261 | // post the result by triggering postjob. |
| 262 | // prop : property dictionary that was read from the machine. |
| 263 | // graphOnly : if it is graph generating job |
Jeremy Ronquillo | bd26bdb | 2019-07-08 16:15:45 -0700 | [diff] [blame^] | 264 | |
Jeremy Ronquillo | 593e500 | 2019-07-08 11:30:35 -0700 | [diff] [blame] | 265 | if ( graphOnly ){ |
Jeremy Ronquillo | bd26bdb | 2019-07-08 16:15:45 -0700 | [diff] [blame^] | 266 | if ( machine == null ){ |
| 267 | machine = machineType[ testType ] |
| 268 | } |
Jeremy Ronquillo | 593e500 | 2019-07-08 11:30:35 -0700 | [diff] [blame] | 269 | def post = build job: "postjob-" + machine, propagate: false |
| 270 | } else if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){ |
Jeremy Ronquillo | afca670 | 2019-07-02 16:05:36 -0700 | [diff] [blame] | 271 | def post = build job: "postjob-" + machineType[ testType ], propagate: false |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 272 | } |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 273 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 274 | |
| 275 | def postLogs( testName, prefix ){ |
| 276 | // posting logs of the onos jobs specifically SR tests |
| 277 | // testName : name of the test |
You Wang | f043d0a | 2019-04-22 16:30:40 -0700 | [diff] [blame] | 278 | // prefix : branch prefix ( master, 2.1, 1.15 ... ) |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 279 | |
| 280 | resultURL = "" |
| 281 | if ( testType == "SR" ){ |
| 282 | def post = build job: "SR-log-" + prefix, propagate: false |
| 283 | resultURL = post.getAbsoluteUrl() |
| 284 | } |
| 285 | return resultURL |
| 286 | } |
| 287 | |
| 288 | def getSlackChannel(){ |
| 289 | // get name of the slack channel. |
| 290 | // if the test is SR, it will return sr-failures |
| 291 | |
You Wang | 28cb855 | 2019-02-19 16:11:52 -0800 | [diff] [blame] | 292 | // FIXME: For now we move all notifications to #jenkins-related |
| 293 | // return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" ) |
| 294 | return "#jenkins-related" |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Jon Hall | 8b1e92c | 2018-06-13 14:07:22 -0700 | [diff] [blame] | 297 | def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){ |
You Wang | 28cb855 | 2019-02-19 16:11:52 -0800 | [diff] [blame] | 298 | // analyzing the result of the test and send to slack if any abnormal result is logged. |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 299 | // prop : property dictionary |
| 300 | // workSpace : workSpace where the result file is saved |
Jon Hall | 8b1e92c | 2018-06-13 14:07:22 -0700 | [diff] [blame] | 301 | // pureTestName : TestON name of the test |
| 302 | // testName : Jenkins name of the test. Example: SCPFflowTPFobj |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 303 | // resultURL : url for the logs for SR tests. Will not be posted if it is empty |
| 304 | // wikiLink : link of the wiki page where the result was posted |
| 305 | // isSCPF : Check if it is SCPF. If so, it won't post the wiki link. |
| 306 | |
| 307 | node( testMachine ) { |
You Wang | 28cb855 | 2019-02-19 16:11:52 -0800 | [diff] [blame] | 308 | def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt" |
| 309 | if ( fileExists( alarmFile ) ) { |
You Wang | 28cb855 | 2019-02-19 16:11:52 -0800 | [diff] [blame] | 310 | def alarmContents = readFile( alarmFile ) |
You Wang | 2dcde68 | 2019-02-21 12:18:15 -0800 | [diff] [blame] | 311 | slackSend( channel: getSlackChannel(), |
| 312 | color: "FF0000", |
| 313 | message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" + |
| 314 | alarmContents + "\n" + |
| 315 | "[TestON log] : \n" + |
| 316 | "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" + |
| 317 | ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" + |
| 318 | "https://wiki.onosproject.org/display/ONOS/" + |
| 319 | wikiLink.replaceAll( "\\s", "+" ) ) ) + |
| 320 | ( resultURL != "" ? ( "\n[Karaf log] : \n" + |
| 321 | resultURL + "artifact/" ) : "" ), |
| 322 | teamDomain: 'onosproject' ) |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 323 | throw new Exception( "Abnormal test result." ) |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 324 | } |
You Wang | 28cb855 | 2019-02-19 16:11:52 -0800 | [diff] [blame] | 325 | else { |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 326 | print "Test results are normal." |
You Wang | 28cb855 | 2019-02-19 16:11:52 -0800 | [diff] [blame] | 327 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
Devin Lim | e89761a | 2018-03-16 17:52:57 -0700 | [diff] [blame] | 331 | def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 332 | // publish HTML script to wiki confluence |
| 333 | // isManualRun : string "true" "false" |
| 334 | // isPostResult : string "true" "false" |
| 335 | // wikiLink : link of the wiki page to publish |
| 336 | // file : name of the file to be published |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 337 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 338 | if ( isPostingResult( isManualRun, isPostResult ) ){ |
| 339 | publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS', |
| 340 | attachArchivedArtifacts: true, buildIfUnstable: true, |
| 341 | editorList: [ confluenceWritePage( confluenceFile( file ) ) ] |
| 342 | } |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 343 | |
| 344 | } |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 345 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 346 | def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file, |
| 347 | graph_saved_directory ){ |
| 348 | // run the test on the machine that contains all the steps : init and run test, copy files, publish result ... |
Jon Hall | 8b1e92c | 2018-06-13 14:07:22 -0700 | [diff] [blame] | 349 | // testName : name of the test in Jenkins |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 350 | // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty |
| 351 | // result on pipeline view |
| 352 | // prop : dictionary property on the machine |
| 353 | // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp ) |
| 354 | // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part |
Jon Hall | 2ee92f8 | 2018-06-07 13:07:33 -0700 | [diff] [blame] | 355 | // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 356 | // graph_generator_file : Rscript file with the full path. |
| 357 | // graph_saved_directory : where the generated graph will be saved to. |
| 358 | |
| 359 | return { |
| 360 | catchError { |
| 361 | stage( testName ) { |
| 362 | if ( toBeRun ){ |
| 363 | def workSpace = "/var/jenkins/workspace/" + testName |
| 364 | def fileContents = "" |
| 365 | node( testMachine ) { |
| 366 | withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ], |
You Wang | 8e4f4c0 | 2019-01-03 10:49:46 -0800 | [diff] [blame] | 367 | 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ], |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 368 | 'TestONBranch=' + prop[ "TestONBranch" ], |
| 369 | 'ONOSTag=' + prop[ "ONOSTag" ], |
| 370 | 'WikiPrefix=' + prop[ "WikiPrefix" ], |
| 371 | 'WORKSPACE=' + workSpace ] ) { |
| 372 | if ( !graphOnly ){ |
You Wang | 6d17194 | 2018-10-17 11:45:05 -0700 | [diff] [blame] | 373 | if ( isSCPF ){ |
| 374 | // Remove the old database file |
| 375 | sh SCPFfunc.cleanupDatabaseFile( testName ) |
| 376 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 377 | sh initAndRunTest( testName, testCategory ) |
| 378 | // For the Wiki page |
| 379 | sh cleanAndCopyFiles( pureTestName ) |
| 380 | } |
Jon Hall | 8b1e92c | 2018-06-13 14:07:22 -0700 | [diff] [blame] | 381 | databaseAndGraph( prop, testName, pureTestName, graphOnly, |
| 382 | graph_generator_file, graph_saved_directory ) |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 383 | if ( !graphOnly ){ |
| 384 | sh fetchLogs( pureTestName ) |
| 385 | if ( !isSCPF ){ |
| 386 | publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ], |
Jeremy Ronquillo | 5b6279b | 2019-06-18 14:25:45 -0700 | [diff] [blame] | 387 | prop[ "WikiPrefix" ] + "-" + testCategory[ testName ][ 'wikiName' ], |
Jeremy Ronquillo | a833e96 | 2019-06-18 13:50:40 -0700 | [diff] [blame] | 388 | workSpace + "/" + testCategory[ testName ][ 'wikiFile' ] ) |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 389 | } |
| 390 | } |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 391 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 392 | } |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 393 | postResult( prop, graphOnly ) |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 394 | if ( !graphOnly ){ |
Jon Hall | 8b1e92c | 2018-06-13 14:07:22 -0700 | [diff] [blame] | 395 | def resultURL = postLogs( testName, prop[ "WikiPrefix" ] ) |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 396 | analyzeResult( prop, workSpace, pureTestName, testName, resultURL, |
Jeremy Ronquillo | a833e96 | 2019-06-18 13:50:40 -0700 | [diff] [blame] | 397 | isSCPF ? "" : testCategory[ testName ][ 'wikiName' ], |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 398 | isSCPF ) |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | } |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 404 | } |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 405 | |
Jon Hall | 8b1e92c | 2018-06-13 14:07:22 -0700 | [diff] [blame] | 406 | def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 407 | // part where it insert the data into the database. |
| 408 | // It will use the predefined encrypted variables from the Jenkins. |
| 409 | // prop : property dictionary that was read from the machine |
Jon Hall | 8b1e92c | 2018-06-13 14:07:22 -0700 | [diff] [blame] | 410 | // testName : Jenkins name for the test |
| 411 | // pureTestName : TestON name for the test |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 412 | // graphOnly : boolean whether it is graph only or not |
| 413 | // graph_generator_file : Rscript file with the full path. |
| 414 | // graph_saved_directory : where the generated graph will be saved to. |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 415 | if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){ |
| 416 | // Post Results |
| 417 | withCredentials( [ |
| 418 | string( credentialsId: 'db_pass', variable: 'pass' ), |
| 419 | string( credentialsId: 'db_user', variable: 'user' ), |
| 420 | string( credentialsId: 'db_host', variable: 'host' ), |
| 421 | string( credentialsId: 'db_port', variable: 'port' ) ] ) { |
| 422 | def database_command = generalFuncs.database_command_create( pass, host, port, user ) + |
| 423 | ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) ) |
| 424 | sh '''#!/bin/bash |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 425 | export DATE=\$(date +%F_%T) |
| 426 | cd ~ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 427 | pwd ''' + ( graphOnly ? "" : |
Jon Hall | 8b1e92c | 2018-06-13 14:07:22 -0700 | [diff] [blame] | 428 | ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) : |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 429 | SCPFfunc.databasePart( testName, database_command ) ) ) + ''' |
| 430 | ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, |
| 431 | graph_generator_file ) : |
| 432 | SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) ) |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 433 | } |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 434 | } |
| 435 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 436 | |
| 437 | def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart, |
| 438 | save_path, pieTestListPart ){ |
| 439 | // function that will generate the category stat graphs for the overall test. |
| 440 | // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases |
| 441 | // manualRun : string of "true" or "false" |
| 442 | // postresult : string of "true" or "false" |
| 443 | // stat_file : file name with full path for Rscript for the stat graph |
| 444 | // pie_file : file name with full path for Rscript for the pie graph |
| 445 | // type : type of the test ( USECASE, FUNC, HA ) |
You Wang | f043d0a | 2019-04-22 16:30:40 -0700 | [diff] [blame] | 446 | // branch : branch of the test ( master, onos-2.1, onos-1.15 ) |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 447 | // testListPart : list of the test to be included |
| 448 | // save_path : path that will save the graphs to |
| 449 | // pieTestListPart : list of the test for pie graph |
| 450 | |
| 451 | if ( isPostingResult( manualRun, postresult ) ){ |
| 452 | node( testMachineOn ) { |
| 453 | |
| 454 | withCredentials( [ |
| 455 | string( credentialsId: 'db_pass', variable: 'pass' ), |
| 456 | string( credentialsId: 'db_user', variable: 'user' ), |
| 457 | string( credentialsId: 'db_host', variable: 'host' ), |
| 458 | string( credentialsId: 'db_port', variable: 'port' ) ] ) { |
| 459 | sh '''#!/bin/bash |
| 460 | ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type, |
| 461 | branch ) + " \"" + testListPart + "\" latest " + save_path + ''' |
| 462 | ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y', |
| 463 | save_path ) + ''' |
| 464 | ''' + |
| 465 | getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path ) |
| 466 | } |
| 467 | } |
| 468 | postResult( [ ], true ) |
| 469 | } |
| 470 | } |
| 471 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 472 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 473 | def generateOverallGraph( prop, testCategory, graph_saved_directory ){ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 474 | // generate the overall graph for the test |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 475 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 476 | if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){ |
| 477 | node( testMachine ) { |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 478 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 479 | withCredentials( [ |
| 480 | string( credentialsId: 'db_pass', variable: 'pass' ), |
| 481 | string( credentialsId: 'db_user', variable: 'user' ), |
| 482 | string( credentialsId: 'db_host', variable: 'host' ), |
| 483 | string( credentialsId: 'db_port', variable: 'port' ) ] ) { |
| 484 | testList = generalFuncs.getTestList( testCategory ) |
| 485 | sh '''#!/bin/bash |
| 486 | ''' + |
| 487 | generalFuncs.basicGraphPart( trend_generator_file, host, port, |
| 488 | user, pass, testType, |
| 489 | prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory |
| 490 | } |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 491 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 492 | postResult( prop, false ) |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 493 | } |
| 494 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 495 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 496 | def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 497 | // Rcommand for the pie graph |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 498 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 499 | return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) + |
| 500 | " \"" + testList + "\" latest " + yOrN + " " + path |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 501 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 502 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 503 | def sqlCommand( testName ){ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 504 | // get the inserting sqlCommand for non-SCPF tests. |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 505 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 506 | return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" + |
| 507 | testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" " |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 508 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 509 | |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 510 | def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){ |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 511 | // get the graphGenerating R command for non-SCPF tests |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 512 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 513 | return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName, |
| 514 | prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 515 | } |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 516 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 517 | def databasePart( wikiPrefix, testName, database_command ){ |
| 518 | // to read and insert the data from .csv to the database |
| 519 | |
| 520 | return ''' |
Devin Lim | 6164376 | 2017-12-07 15:55:38 -0800 | [diff] [blame] | 521 | sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line |
| 522 | do |
| 523 | echo \$line |
| 524 | echo ''' + database_command + ''' |
| 525 | done ''' |
| 526 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 527 | |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 528 | def generateStatGraph( testMachineOn, onos_branch, stat_graph_generator_file, pie_graph_generator_file, |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 529 | graph_saved_directory ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 530 | |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 531 | // Will generate the stats graph. |
| 532 | FUNCtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "FUNC" ) ) |
| 533 | HAtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "HA" ) ) |
| 534 | USECASEtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "USECASE" ) ) |
| 535 | |
| 536 | testListParam = "FUNC-" + FUNCtestsStr + ";" + |
| 537 | "HA-" + HAtestsStr + ";" + |
| 538 | "USECASE-" + USECASEtestsStr |
| 539 | |
| 540 | pieTestListParam = FUNCtestsStr + "," + |
| 541 | HAtestsStr + "," + |
| 542 | USECASEtestsStr |
| 543 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 544 | generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file, |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 545 | "ALL", onos_branch, testListParam, graph_saved_directory, pieTestListParam ) |
Jeremy Ronquillo | 14ecc17 | 2018-03-05 09:57:17 -0800 | [diff] [blame] | 546 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 547 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 548 | return this |