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 Jenkins script for graph-generator-CHO jenkins job. |
| 22 | |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 23 | // Read the files that has the dependencies |
Devin Lim | b734ea5 | 2018-05-14 14:13:05 -0700 | [diff] [blame] | 24 | fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' ) |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 25 | |
Devin Lim | fe9a4cb | 2018-05-11 17:06:21 -0700 | [diff] [blame] | 26 | fileRelated.init() |
Jeremy Ronquillo | e1750cb | 2019-05-17 15:04:30 -0700 | [diff] [blame] | 27 | |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 28 | // The way reading the parameters from the Jenkins. |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 29 | branches = params.ONOSbranch |
Devin Lim | e4e90ee | 2018-05-14 13:52:54 -0700 | [diff] [blame] | 30 | hours = params.hours |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 31 | |
| 32 | // divide the branch list into the list that was separated by newline, semi-colon, comma or space |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 33 | branchList = branches.tokenize( "\n;, " ) |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 34 | |
| 35 | // initialize the directory. |
| 36 | |
| 37 | // Script file is the R script path |
Jeremy Ronquillo | e1750cb | 2019-05-17 15:04:30 -0700 | [diff] [blame] | 38 | script_file = fileRelated.rScriptPaths[ "scripts" ][ "trendCHO" ] |
| 39 | |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 40 | // saving_directory is the directory that save the generate graphs. |
Jeremy Ronquillo | e1750cb | 2019-05-17 15:04:30 -0700 | [diff] [blame] | 41 | saving_directory = fileRelated.workspaces[ "Fabric5" ] |
| 42 | scriptDir = fileRelated.rScriptPaths[ "directories" ][ "CHO" ] |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 43 | |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 44 | // create a bash script that will generate the graph |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 45 | graphScript = generateGraphScript( branchList ) |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 46 | stage( 'Generating-Graph' ) { |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 47 | // This will run on TestStation-Fabric5s node. |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 48 | node( "TestStation-Fabric5s" ) { |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 49 | // run the bash script on this node. |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 50 | runScript( graphScript ) |
| 51 | } |
| 52 | } |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 53 | // stage that will trigger postjob. |
| 54 | // Need to be executed outside the current node to avoid deadlock. |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 55 | stage( 'posting-result' ) { |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 56 | postJob() |
| 57 | } |
| 58 | |
Jeremy Ronquillo | e1750cb | 2019-05-17 15:04:30 -0700 | [diff] [blame] | 59 | saving_directory = fileRelated.workspaces[ "Trellis" ] |
You Wang | ea922a6 | 2019-02-07 14:03:32 -0800 | [diff] [blame] | 60 | graphScript = generateGraphScript( branchList ) |
| 61 | stage( 'Generating-Graph-POD' ) { |
| 62 | // This will run on TestStation-Trellis-POD node. |
| 63 | node( "TestStation-Trellis-PODs" ) { |
| 64 | // run the bash script on this node. |
| 65 | runScript( graphScript ) |
| 66 | } |
| 67 | } |
| 68 | stage( 'posting-result-POD' ) { |
| 69 | postJobPOD() |
| 70 | } |
| 71 | |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 72 | def generateGraphScript( branchList ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 73 | // Generate the bash script that will run the Rscript to make graph. |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 74 | graphScript = '''''' |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 75 | |
| 76 | // In case there are multiple branches running. |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 77 | for ( branch in branchList ){ |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 78 | branchDir = scriptDir + branch + "/" |
Devin Lim | d482df7 | 2018-05-11 13:52:34 -0700 | [diff] [blame] | 79 | graphScript += '''export BRANCH=''' + branchDir + ''' |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 80 | # make branch dir if not existing. |
Devin Lim | d482df7 | 2018-05-11 13:52:34 -0700 | [diff] [blame] | 81 | mkdir ''' + branchDir + '''; |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 82 | # inside the branchDir, check if there were existing graph |
Devin Lim | 8f7b3bc | 2018-05-11 14:55:04 -0700 | [diff] [blame] | 83 | if [ ! -f ''' + branchDir + '''existing.txt ]; then |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 84 | # If it was first generated, it will copy .csv file. |
Devin Lim | 8f7b3bc | 2018-05-11 14:55:04 -0700 | [diff] [blame] | 85 | cp *.csv ''' + branchDir + '''; |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 86 | # mark that this has created already. |
Devin Lim | 9e2f365 | 2018-05-11 16:03:41 -0700 | [diff] [blame] | 87 | echo "1" > ''' + branchDir + '''existing.txt; |
Devin Lim | 8f7b3bc | 2018-05-11 14:55:04 -0700 | [diff] [blame] | 88 | fi; |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 89 | # run the log-summary that will export status |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 90 | bash log-summary;''' + ''' |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 91 | # run Rscript with it's parameters. |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 92 | Rscript ''' + script_file + ' ' + branchDir + 'event.csv ' + |
| 93 | branchDir + 'failure.csv ' + branchDir + 'error.csv ' + |
| 94 | branch + ' 60 ' + hours + ' ' + saving_directory + '''; |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 95 | ''' |
| 96 | print( graphScript ) |
| 97 | } |
| 98 | return graphScript |
| 99 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 100 | |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 101 | def runScript( graphScript ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 102 | // run bash script that will init the environment and run the graph generating part. |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 103 | sh '''#!/bin/bash -l |
| 104 | set -i |
| 105 | set +e |
| 106 | export PYTHONPATH=/home/sdn/TestON:/home/sdn/sts |
Devin Lim | d482df7 | 2018-05-11 13:52:34 -0700 | [diff] [blame] | 107 | cd ''' + scriptDir + '''; |
| 108 | ''' + graphScript |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 109 | } |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 110 | |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 111 | def postJob(){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 112 | // Triggering jenkins job called `postjob-Fabric5` |
| 113 | jobToRun = "postjob-Fabric5" |
| 114 | build job: jobToRun, propagate: false |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 115 | } |
You Wang | ea922a6 | 2019-02-07 14:03:32 -0800 | [diff] [blame] | 116 | |
| 117 | def postJobPOD(){ |
| 118 | // Triggering jenkins job called `postjob-Trellis-POD` |
| 119 | jobToRun = "postjob-Trellis-POD" |
| 120 | build job: jobToRun, propagate: false |
| 121 | } |