blob: da81c04241d869b32724f41d8f8e56f3253116e8 [file] [log] [blame]
Devin Limf5175192018-05-14 19:13:22 -07001// 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 Lim64a2eca2018-05-10 18:44:52 -070022#!groovy
Devin Limf5175192018-05-14 19:13:22 -070023// Read the files that has the dependencies
Devin Limb734ea52018-05-14 14:13:05 -070024fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
Devin Lim64a2eca2018-05-10 18:44:52 -070025
Devin Limfe9a4cb2018-05-11 17:06:21 -070026fileRelated.init()
Devin Limf5175192018-05-14 19:13:22 -070027// The way reading the parameters from the Jenkins.
Devin Lim64a2eca2018-05-10 18:44:52 -070028branches = params.ONOSbranch
Devin Lime4e90ee2018-05-14 13:52:54 -070029hours = params.hours
Devin Limf5175192018-05-14 19:13:22 -070030
31// divide the branch list into the list that was separated by newline, semi-colon, comma or space
Devin Lim64a2eca2018-05-10 18:44:52 -070032branchList = branches.tokenize( "\n;, " )
Devin Limf5175192018-05-14 19:13:22 -070033
34// initialize the directory.
35
36// Script file is the R script path
Devin Limfe9a4cb2018-05-11 17:06:21 -070037script_file = fileRelated.trendCHO
Devin Limf5175192018-05-14 19:13:22 -070038// saving_directory is the directory that save the generate graphs.
Devin Limfe9a4cb2018-05-11 17:06:21 -070039saving_directory = fileRelated.jenkinsWorkspace + "postjob-Fabric5/"
40scriptDir = fileRelated.CHOScriptDir
Devin Lim64a2eca2018-05-10 18:44:52 -070041
Devin Limf5175192018-05-14 19:13:22 -070042// create a bash script that will generate the graph
Devin Lim64a2eca2018-05-10 18:44:52 -070043graphScript = generateGraphScript( branchList )
44
45stage( 'Generating-Graph' ){
Devin Limf5175192018-05-14 19:13:22 -070046 // This will run on TestStation-Fabric5s node.
Devin Lim64a2eca2018-05-10 18:44:52 -070047 node( "TestStation-Fabric5s" ){
Devin Limf5175192018-05-14 19:13:22 -070048 // run the bash script on this node.
Devin Lim64a2eca2018-05-10 18:44:52 -070049 runScript( graphScript )
50 }
51}
Devin Limf5175192018-05-14 19:13:22 -070052// stage that will trigger postjob.
53// Need to be executed outside the current node to avoid deadlock.
Devin Lim64a2eca2018-05-10 18:44:52 -070054stage( 'posting-result' ){
55 postJob()
56}
57
58def generateGraphScript( branchList ){
Devin Limf5175192018-05-14 19:13:22 -070059 // Generate the bash script that will run the Rscript to make graph.
Devin Lim64a2eca2018-05-10 18:44:52 -070060 graphScript = ''''''
Devin Limf5175192018-05-14 19:13:22 -070061
62 // In case there are multiple branches running.
Devin Lim64a2eca2018-05-10 18:44:52 -070063 for( branch in branchList ){
64 branchDir = scriptDir + branch + "/"
Devin Limd482df72018-05-11 13:52:34 -070065 graphScript += '''export BRANCH=''' + branchDir + '''
Devin Limf5175192018-05-14 19:13:22 -070066 # make branch dir if not existing.
Devin Limd482df72018-05-11 13:52:34 -070067 mkdir ''' + branchDir + ''';
Devin Limf5175192018-05-14 19:13:22 -070068 # inside the branchDir, check if there were existing graph
Devin Lim8f7b3bc2018-05-11 14:55:04 -070069 if [ ! -f ''' + branchDir + '''existing.txt ]; then
Devin Limf5175192018-05-14 19:13:22 -070070 # If it was first generated, it will copy .csv file.
Devin Lim8f7b3bc2018-05-11 14:55:04 -070071 cp *.csv ''' + branchDir + ''';
Devin Limf5175192018-05-14 19:13:22 -070072 # mark that this has created already.
Devin Lim9e2f3652018-05-11 16:03:41 -070073 echo "1" > ''' + branchDir + '''existing.txt;
Devin Lim8f7b3bc2018-05-11 14:55:04 -070074 fi;
Devin Limf5175192018-05-14 19:13:22 -070075 # run the log-summary that will export status
Devin Lim64a2eca2018-05-10 18:44:52 -070076 bash log-summary;''' + '''
Devin Limf5175192018-05-14 19:13:22 -070077 # run Rscript with it's parameters.
Devin Lim324806b2018-05-11 15:36:52 -070078 Rscript ''' + script_file + ' ' + branchDir + 'event.csv ' +
Devin Lim64a2eca2018-05-10 18:44:52 -070079 branchDir + 'failure.csv ' + branchDir + 'error.csv ' +
Devin Lime4e90ee2018-05-14 13:52:54 -070080 branch + ' 60 ' + hours + ' ' + saving_directory + ''';
Devin Lim64a2eca2018-05-10 18:44:52 -070081 '''
82 print( graphScript )
83 }
84 return graphScript
85}
86def runScript( graphScript ){
Devin Limf5175192018-05-14 19:13:22 -070087 // run bash script that will init the environment and run the graph generating part.
Devin Lim64a2eca2018-05-10 18:44:52 -070088 sh '''#!/bin/bash -l
89 set -i
90 set +e
91 export PYTHONPATH=/home/sdn/TestON:/home/sdn/sts
Devin Limd482df72018-05-11 13:52:34 -070092 cd ''' + scriptDir + ''';
93 ''' + graphScript
Devin Lim64a2eca2018-05-10 18:44:52 -070094}
95def postJob(){
Devin Limf5175192018-05-14 19:13:22 -070096 // Triggering jenkins job called `postjob-Fabric5`
97 jobToRun = "postjob-Fabric5"
98 build job: jobToRun, propagate: false
Devin Lim64a2eca2018-05-10 18:44:52 -070099}