blob: 26e7ca24fc2138d6d9f41b27c19d8bc193e04357 [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()
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 )
Jon Hall6af749d2018-05-29 12:59:47 -070044stage( 'Generating-Graph' ) {
Devin Limf5175192018-05-14 19:13:22 -070045 // This will run on TestStation-Fabric5s node.
Jon Hall6af749d2018-05-29 12:59:47 -070046 node( "TestStation-Fabric5s" ) {
Devin Limf5175192018-05-14 19:13:22 -070047 // run the bash script on this node.
Devin Lim64a2eca2018-05-10 18:44:52 -070048 runScript( graphScript )
49 }
50}
Devin Limf5175192018-05-14 19:13:22 -070051// stage that will trigger postjob.
52// Need to be executed outside the current node to avoid deadlock.
Jon Hall6af749d2018-05-29 12:59:47 -070053stage( 'posting-result' ) {
Devin Lim64a2eca2018-05-10 18:44:52 -070054 postJob()
55}
56
You Wangea922a62019-02-07 14:03:32 -080057saving_directory = fileRelated.jenkinsWorkspace + "postjob-Trellis-POD/"
58graphScript = generateGraphScript( branchList )
59stage( 'Generating-Graph-POD' ) {
60 // This will run on TestStation-Trellis-POD node.
61 node( "TestStation-Trellis-PODs" ) {
62 // run the bash script on this node.
63 runScript( graphScript )
64 }
65}
66stage( 'posting-result-POD' ) {
67 postJobPOD()
68}
69
Devin Lim64a2eca2018-05-10 18:44:52 -070070def generateGraphScript( branchList ){
Devin Limf5175192018-05-14 19:13:22 -070071 // Generate the bash script that will run the Rscript to make graph.
Devin Lim64a2eca2018-05-10 18:44:52 -070072 graphScript = ''''''
Devin Limf5175192018-05-14 19:13:22 -070073
74 // In case there are multiple branches running.
Jon Hall6af749d2018-05-29 12:59:47 -070075 for ( branch in branchList ){
Devin Lim64a2eca2018-05-10 18:44:52 -070076 branchDir = scriptDir + branch + "/"
Devin Limd482df72018-05-11 13:52:34 -070077 graphScript += '''export BRANCH=''' + branchDir + '''
Devin Limf5175192018-05-14 19:13:22 -070078 # make branch dir if not existing.
Devin Limd482df72018-05-11 13:52:34 -070079 mkdir ''' + branchDir + ''';
Devin Limf5175192018-05-14 19:13:22 -070080 # inside the branchDir, check if there were existing graph
Devin Lim8f7b3bc2018-05-11 14:55:04 -070081 if [ ! -f ''' + branchDir + '''existing.txt ]; then
Devin Limf5175192018-05-14 19:13:22 -070082 # If it was first generated, it will copy .csv file.
Devin Lim8f7b3bc2018-05-11 14:55:04 -070083 cp *.csv ''' + branchDir + ''';
Devin Limf5175192018-05-14 19:13:22 -070084 # mark that this has created already.
Devin Lim9e2f3652018-05-11 16:03:41 -070085 echo "1" > ''' + branchDir + '''existing.txt;
Devin Lim8f7b3bc2018-05-11 14:55:04 -070086 fi;
Devin Limf5175192018-05-14 19:13:22 -070087 # run the log-summary that will export status
Devin Lim64a2eca2018-05-10 18:44:52 -070088 bash log-summary;''' + '''
Devin Limf5175192018-05-14 19:13:22 -070089 # run Rscript with it's parameters.
Jon Hall6af749d2018-05-29 12:59:47 -070090 Rscript ''' + script_file + ' ' + branchDir + 'event.csv ' +
91 branchDir + 'failure.csv ' + branchDir + 'error.csv ' +
92 branch + ' 60 ' + hours + ' ' + saving_directory + ''';
Devin Lim64a2eca2018-05-10 18:44:52 -070093 '''
94 print( graphScript )
95 }
96 return graphScript
97}
Jon Hall6af749d2018-05-29 12:59:47 -070098
Devin Lim64a2eca2018-05-10 18:44:52 -070099def runScript( graphScript ){
Devin Limf5175192018-05-14 19:13:22 -0700100 // run bash script that will init the environment and run the graph generating part.
Devin Lim64a2eca2018-05-10 18:44:52 -0700101 sh '''#!/bin/bash -l
102 set -i
103 set +e
104 export PYTHONPATH=/home/sdn/TestON:/home/sdn/sts
Devin Limd482df72018-05-11 13:52:34 -0700105 cd ''' + scriptDir + ''';
106 ''' + graphScript
Devin Lim64a2eca2018-05-10 18:44:52 -0700107}
Jon Hall6af749d2018-05-29 12:59:47 -0700108
Devin Lim64a2eca2018-05-10 18:44:52 -0700109def postJob(){
Devin Limf5175192018-05-14 19:13:22 -0700110 // Triggering jenkins job called `postjob-Fabric5`
111 jobToRun = "postjob-Fabric5"
112 build job: jobToRun, propagate: false
Devin Lim64a2eca2018-05-10 18:44:52 -0700113}
You Wangea922a62019-02-07 14:03:32 -0800114
115def postJobPOD(){
116 // Triggering jenkins job called `postjob-Trellis-POD`
117 jobToRun = "postjob-Trellis-POD"
118 build job: jobToRun, propagate: false
119}