blob: 974ab5feaf514e5822aa7154ff482e7bda1537bf [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
40def postResult( prop, graphOnly, nodeLabel ){
41 // post the result by triggering postjob.
42 // prop : property dictionary that was read from the machine.
43 // graphOnly : if it is graph generating job
44
45 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
46 postjob_type = ""
47 switch ( nodeLabel ){
48 case "Fabric-1.x":
49 postjob_type = "Fabric2"
50 break
51 case "Fabric-2.x":
52 postjob_type = "Fabric3"
53 break
54 case "Fabric-master":
55 postjob_type = "Fabric4"
56 break
57 default:
58 postjob_type = nodeLabel
59 break
60 }
61
62 def post = build job: "postjob-" + postjob_type, propagate: false
63 }
64}
65
66def isPostingResult( manual, postresult ){
67 // check if it is posting the result.
68 // posting when it is automatically running or has postResult condition from the manual run
69
70 return manual == "false" || postresult == "true"
71}
72
73def database_command_create( pass, host, port, user ){
74 return pass + "|psql --host=" + host + " --port=" + port + " --username=" + user + " --password --dbname onostest -c "
75}
76
77def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
78 // part where it insert the data into the database.
79 // It will use the predefined encrypted variables from the Jenkins.
80 // prop : property dictionary that was read from the machine
81 // testName : Jenkins name for the test
82 // pureTestName : TestON name for the test
83 // graphOnly : boolean whether it is graph only or not
84 // graph_generator_file : Rscript file with the full path.
85 // graph_saved_directory : where the generated graph will be saved to.
86 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
87 // Post Results
88 withCredentials( [
89 string( credentialsId: 'db_pass', variable: 'pass' ),
90 string( credentialsId: 'db_user', variable: 'user' ),
91 string( credentialsId: 'db_host', variable: 'host' ),
92 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
93 def database_command = database_command_create( pass, host, port, user ) +
94 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
95 sh script: '''#!/bin/bash
96 export DATE=\$(date +%F_%T)
97 cd ~
98 pwd ''' + ( graphOnly ? "" :
99 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
100 SCPFfunc.databasePart( testName, database_command ) ) ), label: "Database"
101 sh script: ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
102 graph_generator_file ) :
103 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) ), label: "Generate Test Graph"
104 }
105 }
106}
107
108// make the basic graph part for the Rscript
109def basicGraphPart( rFileName, host, port, user, pass, subject, branchName ){
110 return " Rscript " + rFileName + " " + host + " " + port + " " + user + " " + pass + " " + subject + " " + branchName
111}
112
113def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
114 save_path, pieTestListPart, nodeLabel ){
115 // function that will generate the category stat graphs for the overall test.
116 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
117 // manualRun : string of "true" or "false"
118 // postresult : string of "true" or "false"
119 // stat_file : file name with full path for Rscript for the stat graph
120 // pie_file : file name with full path for Rscript for the pie graph
121 // type : type of the test ( USECASE, FUNC, HA )
122 // branch : branch of the test ( master, onos-2.1, onos-1.15 )
123 // testListPart : list of the test to be included
124 // save_path : path that will save the graphs to
125 // pieTestListPart : list of the test for pie graph
126
127 if ( isPostingResult( manualRun, postresult ) ){
128 node( testMachineOn ) {
129
130 withCredentials( [
131 string( credentialsId: 'db_pass', variable: 'pass' ),
132 string( credentialsId: 'db_user', variable: 'user' ),
133 string( credentialsId: 'db_host', variable: 'host' ),
134 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
135 sh script: ( '''#!/bin/bash
136 ''' + basicGraphPart( stat_file, host, port, user, pass, type,
137 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
138 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
139 save_path ) + '''
140 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path ) ), label: "Generate Stats Graphs"
141 }
142 }
143 postResult( [ ], true, nodeLabel )
144 }
145}
146
147
148def generateOverallGraph( prop, tests, graph_saved_directory, nodeLabel, testType ){
149 // generate the overall graph for the test
150
151 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
152 node( testStation ) {
153
154 withCredentials( [
155 string( credentialsId: 'db_pass', variable: 'pass' ),
156 string( credentialsId: 'db_user', variable: 'user' ),
157 string( credentialsId: 'db_host', variable: 'host' ),
158 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
159 testList = test_list.getTestListAsString( tests )
160 sh script: ( '''#!/bin/bash''' +
161 basicGraphPart( trend_generator_file, host, port,
162 user, pass, testType,
163 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory ), label: "Generate Overall Graph"
164 }
165 }
166 postResult( prop, false, nodeLabel )
167 }
168}
169
170def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
171 // Rcommand for the pie graph
172
173 return basicGraphPart( file, host, port, user, pass, type, branch ) +
174 " \"" + testList + "\" latest " + yOrN + " " + path
175}
176
177def sqlCommand( testName ){
178 // get the inserting sqlCommand for non-SCPF tests.
179 table_name = "executed_test_tests"
180 result_name = "executed_test_results"
181
182 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
183 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
184}
185
186def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
187 // get the graphGenerating R command for non-SCPF tests
188
189 return basicGraphPart( graph_generator_file, host, port, user, pass, testName,
190 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
191}
192
193def databasePart( wikiPrefix, testName, database_command ){
194 // to read and insert the data from .csv to the database
195
196 return '''
197 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
198 do
199 echo \$line
200 echo ''' + database_command + '''
201 done '''
202}
203
204def generateStatGraph( testMachineOn, onos_branch, stat_graph_generator_file, pie_graph_generator_file,
205 graph_saved_directory, nodeLabel ){
206
207 table_name = "executed_test_tests"
208 result_name = "executed_test_results"
209
210 // Will generate the stats graph.
211 FUNCtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "FUNC" ) )
212 HAtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "HA" ) )
213 USECASEtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "USECASE" ) )
214
215 testListParam = "FUNC-" + FUNCtestsStr + ";" +
216 "HA-" + HAtestsStr + ";" +
217 "USECASE-" + USECASEtestsStr
218
219 pieTestListParam = FUNCtestsStr + "," +
220 HAtestsStr + "," +
221 USECASEtestsStr
222
223 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
224 "ALL", onos_branch, testListParam, graph_saved_directory, pieTestListParam, nodeLabel )
225}
226
227return this