blob: db65ce71e65c186b18266f3b803cebf099183c69 [file] [log] [blame]
Devin Lime1346f42018-05-15 15:41:36 -07001#!groovy
Devin Limf5175192018-05-14 19:13:22 -07002// 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 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()
Jeremy Ronquilloe1750cb2019-05-17 15:04:30 -070027
Devin Limf5175192018-05-14 19:13:22 -070028// The way reading the parameters from the Jenkins.
Devin Lim64a2eca2018-05-10 18:44:52 -070029branches = params.ONOSbranch
Devin Lime4e90ee2018-05-14 13:52:54 -070030hours = params.hours
Devin Limf5175192018-05-14 19:13:22 -070031
32// divide the branch list into the list that was separated by newline, semi-colon, comma or space
Devin Lim64a2eca2018-05-10 18:44:52 -070033branchList = branches.tokenize( "\n;, " )
Devin Limf5175192018-05-14 19:13:22 -070034
35// initialize the directory.
36
37// Script file is the R script path
Jeremy Ronquilloe1750cb2019-05-17 15:04:30 -070038script_file = fileRelated.rScriptPaths[ "scripts" ][ "trendCHO" ]
39
Devin Limf5175192018-05-14 19:13:22 -070040// saving_directory is the directory that save the generate graphs.
Jeremy Ronquilloe1750cb2019-05-17 15:04:30 -070041saving_directory = fileRelated.workspaces[ "Fabric5" ]
42scriptDir = fileRelated.rScriptPaths[ "directories" ][ "CHO" ]
Devin Lim64a2eca2018-05-10 18:44:52 -070043
Devin Limf5175192018-05-14 19:13:22 -070044// create a bash script that will generate the graph
Devin Lim64a2eca2018-05-10 18:44:52 -070045graphScript = generateGraphScript( branchList )
Jon Hall6af749d2018-05-29 12:59:47 -070046stage( 'Generating-Graph' ) {
Devin Limf5175192018-05-14 19:13:22 -070047 // This will run on TestStation-Fabric5s node.
Jon Hall6af749d2018-05-29 12:59:47 -070048 node( "TestStation-Fabric5s" ) {
Devin Limf5175192018-05-14 19:13:22 -070049 // run the bash script on this node.
Devin Lim64a2eca2018-05-10 18:44:52 -070050 runScript( graphScript )
51 }
52}
Devin Limf5175192018-05-14 19:13:22 -070053// stage that will trigger postjob.
54// Need to be executed outside the current node to avoid deadlock.
Jon Hall6af749d2018-05-29 12:59:47 -070055stage( 'posting-result' ) {
Devin Lim64a2eca2018-05-10 18:44:52 -070056 postJob()
57}
58
Jeremy Ronquilloe1750cb2019-05-17 15:04:30 -070059saving_directory = fileRelated.workspaces[ "Trellis" ]
You Wangea922a62019-02-07 14:03:32 -080060graphScript = generateGraphScript( branchList )
61stage( '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}
68stage( 'posting-result-POD' ) {
69 postJobPOD()
70}
71
Devin Lim64a2eca2018-05-10 18:44:52 -070072def generateGraphScript( branchList ){
Devin Limf5175192018-05-14 19:13:22 -070073 // Generate the bash script that will run the Rscript to make graph.
Devin Lim64a2eca2018-05-10 18:44:52 -070074 graphScript = ''''''
Devin Limf5175192018-05-14 19:13:22 -070075
76 // In case there are multiple branches running.
Jon Hall6af749d2018-05-29 12:59:47 -070077 for ( branch in branchList ){
Devin Lim64a2eca2018-05-10 18:44:52 -070078 branchDir = scriptDir + branch + "/"
Devin Limd482df72018-05-11 13:52:34 -070079 graphScript += '''export BRANCH=''' + branchDir + '''
Devin Limf5175192018-05-14 19:13:22 -070080 # make branch dir if not existing.
Devin Limd482df72018-05-11 13:52:34 -070081 mkdir ''' + branchDir + ''';
Devin Limf5175192018-05-14 19:13:22 -070082 # inside the branchDir, check if there were existing graph
Devin Lim8f7b3bc2018-05-11 14:55:04 -070083 if [ ! -f ''' + branchDir + '''existing.txt ]; then
Devin Limf5175192018-05-14 19:13:22 -070084 # If it was first generated, it will copy .csv file.
Devin Lim8f7b3bc2018-05-11 14:55:04 -070085 cp *.csv ''' + branchDir + ''';
Devin Limf5175192018-05-14 19:13:22 -070086 # mark that this has created already.
Devin Lim9e2f3652018-05-11 16:03:41 -070087 echo "1" > ''' + branchDir + '''existing.txt;
Devin Lim8f7b3bc2018-05-11 14:55:04 -070088 fi;
Devin Limf5175192018-05-14 19:13:22 -070089 # run the log-summary that will export status
Devin Lim64a2eca2018-05-10 18:44:52 -070090 bash log-summary;''' + '''
Devin Limf5175192018-05-14 19:13:22 -070091 # run Rscript with it's parameters.
Jon Hall6af749d2018-05-29 12:59:47 -070092 Rscript ''' + script_file + ' ' + branchDir + 'event.csv ' +
93 branchDir + 'failure.csv ' + branchDir + 'error.csv ' +
94 branch + ' 60 ' + hours + ' ' + saving_directory + ''';
Devin Lim64a2eca2018-05-10 18:44:52 -070095 '''
96 print( graphScript )
97 }
98 return graphScript
99}
Jon Hall6af749d2018-05-29 12:59:47 -0700100
Devin Lim64a2eca2018-05-10 18:44:52 -0700101def runScript( graphScript ){
Devin Limf5175192018-05-14 19:13:22 -0700102 // run bash script that will init the environment and run the graph generating part.
Devin Lim64a2eca2018-05-10 18:44:52 -0700103 sh '''#!/bin/bash -l
104 set -i
105 set +e
106 export PYTHONPATH=/home/sdn/TestON:/home/sdn/sts
Devin Limd482df72018-05-11 13:52:34 -0700107 cd ''' + scriptDir + ''';
108 ''' + graphScript
Devin Lim64a2eca2018-05-10 18:44:52 -0700109}
Jon Hall6af749d2018-05-29 12:59:47 -0700110
Devin Lim64a2eca2018-05-10 18:44:52 -0700111def postJob(){
Devin Limf5175192018-05-14 19:13:22 -0700112 // Triggering jenkins job called `postjob-Fabric5`
113 jobToRun = "postjob-Fabric5"
114 build job: jobToRun, propagate: false
Devin Lim64a2eca2018-05-10 18:44:52 -0700115}
You Wangea922a62019-02-07 14:03:32 -0800116
117def postJobPOD(){
118 // Triggering jenkins job called `postjob-Trellis-POD`
119 jobToRun = "postjob-Trellis-POD"
120 build job: jobToRun, propagate: false
121}