blob: d0b4c523b4ed1a8f559089ba37706dfcb7e1354f [file] [log] [blame]
Jeremy Ronquillo336110a2019-07-11 14:20:40 -07001#!groovy
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 dependency Jenkins script.
22// it has some common functions that runs test and generate graph.
23
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070024fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
25test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
26
27fileRelated.init()
28test_list.init()
29
30testStation = null
31isSCPF = null
32
33def initialize( SCPFf=null ){
34 isSCPF = ( SCPFf != null )
35 SCPFfunc = SCPFf
36 trend_generator_file = fileRelated.rScriptPaths[ "scripts" ][ "trendMultiple" ]
37 build_stats_generator_file = fileRelated.rScriptPaths[ "scripts" ][ "histogramMultiple" ]
38}
39
Jeremy Ronquillo1bd814f2019-07-31 14:45:04 -070040def getPostjobType( nodeL ){
41 switch ( nodeL ){
Jeremy Ronquillof5482c92020-12-09 16:30:49 -080042 case "Fabric-LTS1":
Jeremy Ronquillo1bd814f2019-07-31 14:45:04 -070043 return "Fabric2"
44 break
Jeremy Ronquillof5482c92020-12-09 16:30:49 -080045 case "Fabric-LTS2":
Jeremy Ronquillo1bd814f2019-07-31 14:45:04 -070046 return "Fabric3"
47 break
48 case "Fabric-master":
49 return "Fabric4"
50 break
51 default:
52 return nodeL
53 break
54 }
55}
56
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070057def postResult( prop, graphOnly, nodeLabel ){
58 // post the result by triggering postjob.
59 // prop : property dictionary that was read from the machine.
60 // graphOnly : if it is graph generating job
61
62 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
Jeremy Ronquillo1bd814f2019-07-31 14:45:04 -070063 postjob_type = getPostjobType( nodeLabel )
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070064 def post = build job: "postjob-" + postjob_type, propagate: false
65 }
66}
67
68def isPostingResult( manual, postresult ){
69 // check if it is posting the result.
70 // posting when it is automatically running or has postResult condition from the manual run
71
72 return manual == "false" || postresult == "true"
73}
74
75def database_command_create( pass, host, port, user ){
76 return pass + "|psql --host=" + host + " --port=" + port + " --username=" + user + " --password --dbname onostest -c "
77}
78
Jon Halld4f33e12020-07-29 14:50:34 -070079def databaseAndGraph( prop, JenkinsLabel, TestONTest, graphOnly, graph_generator_file, graph_saved_directory ){
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070080 // part where it insert the data into the database.
81 // It will use the predefined encrypted variables from the Jenkins.
82 // prop : property dictionary that was read from the machine
Jon Halld4f33e12020-07-29 14:50:34 -070083 // JenkinsLabel : Jenkins name for the test
84 // TestONTest : TestON name for the test
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070085 // graphOnly : boolean whether it is graph only or not
86 // graph_generator_file : Rscript file with the full path.
87 // graph_saved_directory : where the generated graph will be saved to.
88 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
89 // Post Results
90 withCredentials( [
91 string( credentialsId: 'db_pass', variable: 'pass' ),
92 string( credentialsId: 'db_user', variable: 'user' ),
93 string( credentialsId: 'db_host', variable: 'host' ),
94 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
95 def database_command = database_command_create( pass, host, port, user ) +
Jon Halld4f33e12020-07-29 14:50:34 -070096 ( !isSCPF ? sqlCommand( JenkinsLabel ) : SCPFfunc.sqlCommand( JenkinsLabel ) )
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070097 sh script: '''#!/bin/bash
98 export DATE=\$(date +%F_%T)
99 cd ~
100 pwd ''' + ( graphOnly ? "" :
Jon Halld4f33e12020-07-29 14:50:34 -0700101 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], TestONTest, database_command ) :
102 SCPFfunc.databasePart( JenkinsLabel, database_command ) ) ), label: "Database"
103 sh script: ( !isSCPF ? graphGenerating( host, port, user, pass, JenkinsLabel, prop, graph_saved_directory,
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700104 graph_generator_file ) :
Jon Halld4f33e12020-07-29 14:50:34 -0700105 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, JenkinsLabel, prop ) ), label: "Generate Test Graph"
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700106 }
107 }
108}
109
110// make the basic graph part for the Rscript
111def basicGraphPart( rFileName, host, port, user, pass, subject, branchName ){
112 return " Rscript " + rFileName + " " + host + " " + port + " " + user + " " + pass + " " + subject + " " + branchName
113}
114
115def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
116 save_path, pieTestListPart, nodeLabel ){
117 // function that will generate the category stat graphs for the overall test.
118 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
119 // manualRun : string of "true" or "false"
120 // postresult : string of "true" or "false"
121 // stat_file : file name with full path for Rscript for the stat graph
122 // pie_file : file name with full path for Rscript for the pie graph
123 // type : type of the test ( USECASE, FUNC, HA )
124 // branch : branch of the test ( master, onos-2.1, onos-1.15 )
125 // testListPart : list of the test to be included
126 // save_path : path that will save the graphs to
127 // pieTestListPart : list of the test for pie graph
128
129 if ( isPostingResult( manualRun, postresult ) ){
130 node( testMachineOn ) {
131
132 withCredentials( [
133 string( credentialsId: 'db_pass', variable: 'pass' ),
134 string( credentialsId: 'db_user', variable: 'user' ),
135 string( credentialsId: 'db_host', variable: 'host' ),
136 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
137 sh script: ( '''#!/bin/bash
138 ''' + basicGraphPart( stat_file, host, port, user, pass, type,
139 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
140 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
141 save_path ) + '''
142 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path ) ), label: "Generate Stats Graphs"
143 }
144 }
145 postResult( [ ], true, nodeLabel )
146 }
147}
148
149
150def generateOverallGraph( prop, tests, graph_saved_directory, nodeLabel, testType ){
151 // generate the overall graph for the test
152
153 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
154 node( testStation ) {
155
156 withCredentials( [
157 string( credentialsId: 'db_pass', variable: 'pass' ),
158 string( credentialsId: 'db_user', variable: 'user' ),
159 string( credentialsId: 'db_host', variable: 'host' ),
160 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
161 testList = test_list.getTestListAsString( tests )
Jeremy Ronquillo31a3eb32019-08-02 13:30:37 -0700162 sh script: ( '''#!/bin/bash
163 ''' +
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700164 basicGraphPart( trend_generator_file, host, port,
165 user, pass, testType,
166 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory ), label: "Generate Overall Graph"
167 }
168 }
169 postResult( prop, false, nodeLabel )
170 }
171}
172
173def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
174 // Rcommand for the pie graph
175
176 return basicGraphPart( file, host, port, user, pass, type, branch ) +
177 " \"" + testList + "\" latest " + yOrN + " " + path
178}
179
180def sqlCommand( testName ){
181 // get the inserting sqlCommand for non-SCPF tests.
Jon Halld4f33e12020-07-29 14:50:34 -0700182 // testName : the name the the test results are stored under in the db.
183 // This is usually the same as the Jenkins Test name
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700184 table_name = "executed_test_tests"
185 result_name = "executed_test_results"
186
187 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
188 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
189}
190
191def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
192 // get the graphGenerating R command for non-SCPF tests
193
194 return basicGraphPart( graph_generator_file, host, port, user, pass, testName,
195 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
196}
197
Jon Halld4f33e12020-07-29 14:50:34 -0700198def databasePart( wikiPrefix, TestONTest, database_command ){
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700199 // to read and insert the data from .csv to the database
200
201 return '''
Jon Halld4f33e12020-07-29 14:50:34 -0700202 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + TestONTest + '''.csv | while read line
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700203 do
204 echo \$line
205 echo ''' + database_command + '''
206 done '''
207}
208
Jon Halld4f33e12020-07-29 14:50:34 -0700209def generateStatGraph( testMachineOn, onos_branch, stat_graph_generator_file,
210 pie_graph_generator_file, graph_saved_directory, nodeLabel ){
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700211
212 table_name = "executed_test_tests"
213 result_name = "executed_test_results"
214
215 // Will generate the stats graph.
216 FUNCtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "FUNC" ) )
217 HAtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "HA" ) )
218 USECASEtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "USECASE" ) )
219
220 testListParam = "FUNC-" + FUNCtestsStr + ";" +
221 "HA-" + HAtestsStr + ";" +
222 "USECASE-" + USECASEtestsStr
223
224 pieTestListParam = FUNCtestsStr + "," +
225 HAtestsStr + "," +
226 USECASEtestsStr
227
228 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
229 "ALL", onos_branch, testListParam, graph_saved_directory, pieTestListParam, nodeLabel )
230}
231
232return this