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