blob: b39c2b466e6193409dd9b3c9bb4e482b4a5c58a0 [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 )
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.
182 table_name = "executed_test_tests"
183 result_name = "executed_test_results"
184
185 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
186 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
187}
188
189def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
190 // get the graphGenerating R command for non-SCPF tests
191
192 return basicGraphPart( graph_generator_file, host, port, user, pass, testName,
193 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
194}
195
196def databasePart( wikiPrefix, testName, database_command ){
197 // to read and insert the data from .csv to the database
198
199 return '''
200 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
201 do
202 echo \$line
203 echo ''' + database_command + '''
204 done '''
205}
206
207def generateStatGraph( testMachineOn, onos_branch, stat_graph_generator_file, pie_graph_generator_file,
208 graph_saved_directory, nodeLabel ){
209
210 table_name = "executed_test_tests"
211 result_name = "executed_test_results"
212
213 // Will generate the stats graph.
214 FUNCtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "FUNC" ) )
215 HAtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "HA" ) )
216 USECASEtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "USECASE" ) )
217
218 testListParam = "FUNC-" + FUNCtestsStr + ";" +
219 "HA-" + HAtestsStr + ";" +
220 "USECASE-" + USECASEtestsStr
221
222 pieTestListParam = FUNCtestsStr + "," +
223 HAtestsStr + "," +
224 USECASEtestsStr
225
226 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
227 "ALL", onos_branch, testListParam, graph_saved_directory, pieTestListParam, nodeLabel )
228}
229
230return this