Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 1 | // Copyright 2017 Open Networking Foundation (ONF) |
| 2 | // |
| 3 | // Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 4 | // the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 5 | // or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 6 | // |
| 7 | // TestON is free software: you can redistribute it and/or modify |
| 8 | // it under the terms of the GNU General Public License as published by |
| 9 | // the Free Software Foundation, either version 2 of the License, or |
| 10 | // (at your option) any later version. |
| 11 | // |
| 12 | // TestON is distributed in the hope that it will be useful, |
| 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | // GNU General Public License for more details. |
| 16 | // |
| 17 | // You should have received a copy of the GNU General Public License |
| 18 | // along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | // This is the Jenkins script for graph-generator-CHO jenkins job. |
| 21 | |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 22 | #!groovy |
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() |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 27 | // The way reading the parameters from the Jenkins. |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 28 | branches = params.ONOSbranch |
Devin Lim | e4e90ee | 2018-05-14 13:52:54 -0700 | [diff] [blame] | 29 | hours = params.hours |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 30 | |
| 31 | // 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] | 32 | branchList = branches.tokenize( "\n;, " ) |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 33 | |
| 34 | // initialize the directory. |
| 35 | |
| 36 | // Script file is the R script path |
Devin Lim | fe9a4cb | 2018-05-11 17:06:21 -0700 | [diff] [blame] | 37 | script_file = fileRelated.trendCHO |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 38 | // saving_directory is the directory that save the generate graphs. |
Devin Lim | fe9a4cb | 2018-05-11 17:06:21 -0700 | [diff] [blame] | 39 | saving_directory = fileRelated.jenkinsWorkspace + "postjob-Fabric5/" |
| 40 | scriptDir = fileRelated.CHOScriptDir |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 41 | |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 42 | // create a bash script that will generate the graph |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 43 | graphScript = generateGraphScript( branchList ) |
| 44 | |
| 45 | stage( 'Generating-Graph' ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 46 | // This will run on TestStation-Fabric5s node. |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 47 | node( "TestStation-Fabric5s" ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 48 | // run the bash script on this node. |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 49 | runScript( graphScript ) |
| 50 | } |
| 51 | } |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 52 | // stage that will trigger postjob. |
| 53 | // Need to be executed outside the current node to avoid deadlock. |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 54 | stage( 'posting-result' ){ |
| 55 | postJob() |
| 56 | } |
| 57 | |
| 58 | def generateGraphScript( branchList ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 59 | // Generate the bash script that will run the Rscript to make graph. |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 60 | graphScript = '''''' |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 61 | |
| 62 | // In case there are multiple branches running. |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 63 | for( branch in branchList ){ |
| 64 | branchDir = scriptDir + branch + "/" |
Devin Lim | d482df7 | 2018-05-11 13:52:34 -0700 | [diff] [blame] | 65 | graphScript += '''export BRANCH=''' + branchDir + ''' |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 66 | # make branch dir if not existing. |
Devin Lim | d482df7 | 2018-05-11 13:52:34 -0700 | [diff] [blame] | 67 | mkdir ''' + branchDir + '''; |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 68 | # inside the branchDir, check if there were existing graph |
Devin Lim | 8f7b3bc | 2018-05-11 14:55:04 -0700 | [diff] [blame] | 69 | if [ ! -f ''' + branchDir + '''existing.txt ]; then |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 70 | # If it was first generated, it will copy .csv file. |
Devin Lim | 8f7b3bc | 2018-05-11 14:55:04 -0700 | [diff] [blame] | 71 | cp *.csv ''' + branchDir + '''; |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 72 | # mark that this has created already. |
Devin Lim | 9e2f365 | 2018-05-11 16:03:41 -0700 | [diff] [blame] | 73 | echo "1" > ''' + branchDir + '''existing.txt; |
Devin Lim | 8f7b3bc | 2018-05-11 14:55:04 -0700 | [diff] [blame] | 74 | fi; |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 75 | # run the log-summary that will export status |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 76 | bash log-summary;''' + ''' |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 77 | # run Rscript with it's parameters. |
Devin Lim | 324806b | 2018-05-11 15:36:52 -0700 | [diff] [blame] | 78 | Rscript ''' + script_file + ' ' + branchDir + 'event.csv ' + |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 79 | branchDir + 'failure.csv ' + branchDir + 'error.csv ' + |
Devin Lim | e4e90ee | 2018-05-14 13:52:54 -0700 | [diff] [blame] | 80 | branch + ' 60 ' + hours + ' ' + saving_directory + '''; |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 81 | ''' |
| 82 | print( graphScript ) |
| 83 | } |
| 84 | return graphScript |
| 85 | } |
| 86 | def runScript( graphScript ){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 87 | // 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] | 88 | sh '''#!/bin/bash -l |
| 89 | set -i |
| 90 | set +e |
| 91 | export PYTHONPATH=/home/sdn/TestON:/home/sdn/sts |
Devin Lim | d482df7 | 2018-05-11 13:52:34 -0700 | [diff] [blame] | 92 | cd ''' + scriptDir + '''; |
| 93 | ''' + graphScript |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 94 | } |
| 95 | def postJob(){ |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame^] | 96 | // Triggering jenkins job called `postjob-Fabric5` |
| 97 | jobToRun = "postjob-Fabric5" |
| 98 | build job: jobToRun, propagate: false |
Devin Lim | 64a2eca | 2018-05-10 18:44:52 -0700 | [diff] [blame] | 99 | } |