blob: 8fccedef240d822c38eb170e3db1b16c57eafb86 [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 ){
42 case "Fabric-1.x":
43 return "Fabric2"
44 break
45 case "Fabric-2.x":
46 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
79def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
80 // 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
83 // testName : Jenkins name for the test
84 // pureTestName : TestON name for the test
85 // 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 ) +
96 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
97 sh script: '''#!/bin/bash
98 export DATE=\$(date +%F_%T)
99 cd ~
100 pwd ''' + ( graphOnly ? "" :
101 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
102 SCPFfunc.databasePart( testName, database_command ) ) ), label: "Database"
103 sh script: ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
104 graph_generator_file ) :
105 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) ), label: "Generate Test Graph"
106 }
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 )
162 sh script: ( '''#!/bin/bash''' +
163 basicGraphPart( trend_generator_file, host, port,
164 user, pass, testType,
165 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory ), label: "Generate Overall Graph"
166 }
167 }
168 postResult( prop, false, nodeLabel )
169 }
170}
171
172def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
173 // Rcommand for the pie graph
174
175 return basicGraphPart( file, host, port, user, pass, type, branch ) +
176 " \"" + testList + "\" latest " + yOrN + " " + path
177}
178
179def sqlCommand( testName ){
180 // get the inserting sqlCommand for non-SCPF tests.
181 table_name = "executed_test_tests"
182 result_name = "executed_test_results"
183
184 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
185 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
186}
187
188def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
189 // get the graphGenerating R command for non-SCPF tests
190
191 return basicGraphPart( graph_generator_file, host, port, user, pass, testName,
192 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
193}
194
195def databasePart( wikiPrefix, testName, database_command ){
196 // to read and insert the data from .csv to the database
197
198 return '''
199 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
200 do
201 echo \$line
202 echo ''' + database_command + '''
203 done '''
204}
205
206def generateStatGraph( testMachineOn, onos_branch, stat_graph_generator_file, pie_graph_generator_file,
207 graph_saved_directory, nodeLabel ){
208
209 table_name = "executed_test_tests"
210 result_name = "executed_test_results"
211
212 // Will generate the stats graph.
213 FUNCtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "FUNC" ) )
214 HAtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "HA" ) )
215 USECASEtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "USECASE" ) )
216
217 testListParam = "FUNC-" + FUNCtestsStr + ";" +
218 "HA-" + HAtestsStr + ";" +
219 "USECASE-" + USECASEtestsStr
220
221 pieTestListParam = FUNCtestsStr + "," +
222 HAtestsStr + "," +
223 USECASEtestsStr
224
225 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
226 "ALL", onos_branch, testListParam, graph_saved_directory, pieTestListParam, nodeLabel )
227}
228
229return this