blob: 382b16fd8bb7ab4be70b2afe6a1c91447ba8ac74 [file] [log] [blame]
jenkins24dde6b2015-06-19 13:40:44 -07001# ScaleOutTemplate --> CbenchBM
2#
3# CASE1 starts number of nodes specified in param file
4#
5# cameron@onlab.us
6
7import sys
Jon Hallf57a5ef2015-07-07 17:56:16 -07008import os
jenkins24dde6b2015-06-19 13:40:44 -07009import os.path
10
11
Jon Hallf57a5ef2015-07-07 17:56:16 -070012class SCPFcbench:
jenkins24dde6b2015-06-19 13:40:44 -070013
14 def __init__( self ):
15 self.default = ''
16
Jon Hall4ba53f02015-07-29 13:07:41 -070017 def CASE1( self, main ):
18
19 import time
20 import os
21 global init
suibin zhang8a46f2e2015-07-13 21:56:07 -070022 main.case("pre-condition for cbench test.")
23
Jon Hall4ba53f02015-07-29 13:07:41 -070024 try:
25 if type(init) is not bool:
26 init = False
27 except NameError:
28 init = False
29
jenkins24dde6b2015-06-19 13:40:44 -070030 #Load values from params file
31 checkoutBranch = main.params[ 'GIT' ][ 'checkout' ]
32 gitPull = main.params[ 'GIT' ][ 'autopull' ]
33 BENCHIp = main.params[ 'BENCH' ][ 'ip1' ]
34 BENCHUser = main.params[ 'BENCH' ][ 'user' ]
jenkinsf4ac82d2015-07-13 16:40:20 -070035 CBENCHuser = main.params[ 'CBENCH'][ 'user' ]
suibin zhangefae9032015-07-13 17:14:39 -070036 MN1Ip = os.environ[ main.params[ 'MN' ][ 'ip1' ] ]
jenkins24dde6b2015-06-19 13:40:44 -070037 maxNodes = int(main.params[ 'availableNodes' ])
38 skipMvn = main.params[ 'TEST' ][ 'skipCleanInstall' ]
Jon Hall4ba53f02015-07-29 13:07:41 -070039 cellName = main.params[ 'ENV' ][ 'cellName' ]
jenkins24dde6b2015-06-19 13:40:44 -070040
Jon Hall4ba53f02015-07-29 13:07:41 -070041 # -- INIT SECTION, ONLY RUNS ONCE -- #
42 if init == False:
jenkins24dde6b2015-06-19 13:40:44 -070043 init = True
44 global clusterCount #number of nodes running
45 global ONOSIp #list of ONOS IP addresses
Jon Hall4ba53f02015-07-29 13:07:41 -070046 global scale
47
jenkins24dde6b2015-06-19 13:40:44 -070048 clusterCount = 0
49 ONOSIp = [ 0 ]
Jon Hall4ba53f02015-07-29 13:07:41 -070050 scale = (main.params[ 'SCALE' ]).split(",")
jenkins24dde6b2015-06-19 13:40:44 -070051 clusterCount = int(scale[0])
52
Jon Hall4ba53f02015-07-29 13:07:41 -070053 #Populate ONOSIp with ips from params
54 for i in range(1, maxNodes + 1):
Jon Hallf57a5ef2015-07-07 17:56:16 -070055 ipString = os.environ[main.params['CTRL']['ip1']]
Jon Hall4ba53f02015-07-29 13:07:41 -070056 ONOSIp.append(ipString)
57
jenkins24dde6b2015-06-19 13:40:44 -070058 #mvn clean install, for debugging set param 'skipCleanInstall' to yes to speed up test
59 if skipMvn != "yes":
60 mvnResult = main.ONOSbench.cleanInstall()
61
62 #git
63 main.step( "Git checkout and pull " + checkoutBranch )
64 if gitPull == 'on':
65 checkoutResult = main.ONOSbench.gitCheckout( checkoutBranch )
66 pullResult = main.ONOSbench.gitPull()
67
68 else:
69 checkoutResult = main.TRUE
70 pullResult = main.TRUE
71 main.log.info( "Skipped git checkout and pull" )
Jon Hall4ba53f02015-07-29 13:07:41 -070072
jenkins24dde6b2015-06-19 13:40:44 -070073 # -- END OF INIT SECTION --#
Jon Hall4ba53f02015-07-29 13:07:41 -070074
jenkins24dde6b2015-06-19 13:40:44 -070075 clusterCount = int(scale[0])
Jon Hall4ba53f02015-07-29 13:07:41 -070076 scale.remove(scale[0])
77
78 #kill off all onos processes
jenkins24dde6b2015-06-19 13:40:44 -070079 main.log.step("Safety check, killing all ONOS processes")
Jon Hall70b2ff42015-11-17 15:49:44 -080080 main.log.step("before initiating environment setup")
jenkins24dde6b2015-06-19 13:40:44 -070081 for node in range(1, maxNodes + 1):
82 main.ONOSbench.onosDie(ONOSIp[node])
Jon Hall4ba53f02015-07-29 13:07:41 -070083
jenkins24dde6b2015-06-19 13:40:44 -070084 #Uninstall everywhere
85 main.log.step( "Cleaning Enviornment..." )
86 for i in range(1, maxNodes + 1):
87 main.log.info(" Uninstalling ONOS " + str(i) )
88 main.ONOSbench.onosUninstall( ONOSIp[i] )
Jon Hall4ba53f02015-07-29 13:07:41 -070089
Jon Hallf57a5ef2015-07-07 17:56:16 -070090 time.sleep(10)
91 main.ONOSbench.handle.sendline(" ")
92 main.ONOSbench.handle.expect(":~")
Jon Hall4ba53f02015-07-29 13:07:41 -070093 print "pexpect: \n" + main.ONOSbench.handle.before
Jon Hallf57a5ef2015-07-07 17:56:16 -070094
95
96 print "Cellname is: "+ cellName + "ONOS IP is: " + str(ONOSIp)
jenkinsf4ac82d2015-07-13 16:40:20 -070097 main.ONOSbench.createCellFile(BENCHIp,cellName,MN1Ip,"drivers,openflow,fwd",[ONOSIp[1]])
Jon Hall4ba53f02015-07-29 13:07:41 -070098
jenkins24dde6b2015-06-19 13:40:44 -070099 main.step( "Set Cell" )
100 main.ONOSbench.setCell(cellName)
Jon Hallf57a5ef2015-07-07 17:56:16 -0700101
Jon Hall4ba53f02015-07-29 13:07:41 -0700102 #main.ONOSbench.handle.sendline(" ")
103 #main.ONOSbench.handle.expect(":~")
104 #print "pexpect: \n" + main.ONOSbench.handle.before
Jon Hallf57a5ef2015-07-07 17:56:16 -0700105
jenkins24dde6b2015-06-19 13:40:44 -0700106 main.step( "Creating ONOS package" )
Jon Hall4ba53f02015-07-29 13:07:41 -0700107 packageResult = main.ONOSbench.onosPackage()
jenkins24dde6b2015-06-19 13:40:44 -0700108
109 main.step( "verify cells" )
110 verifyCellResult = main.ONOSbench.verifyCell()
Jon Hall4ba53f02015-07-29 13:07:41 -0700111
suibin zhang8a46f2e2015-07-13 21:56:07 -0700112 main.log.report( "Initializing " + str( clusterCount ) + " node cluster." )
jenkins24dde6b2015-06-19 13:40:44 -0700113 for node in range(1, clusterCount + 1):
114 main.log.info("Starting ONOS " + str(node) + " at IP: " + ONOSIp[node])
115 main.ONOSbench.onosInstall( ONOSIp[node])
116
117 for node in range(1, clusterCount + 1):
118 for i in range( 2 ):
119 isup = main.ONOSbench.isup( ONOSIp[node] )
120 if isup:
121 main.log.info("ONOS " + str(node) + " is up\n")
122 break
123 if not isup:
124 main.log.report( "ONOS " + str(node) + " didn't start!" )
125 main.log.info("Startup sequence complete")
126
Jon Hall4ba53f02015-07-29 13:07:41 -0700127 for i in range(5):
jenkins24dde6b2015-06-19 13:40:44 -0700128 main.ONOSbench.onosCfgSet(ONOSIp[1], "org.onosproject.fwd.ReactiveForwarding","packetOutOnly true")
129 time.sleep(5)
Jon Hall4ba53f02015-07-29 13:07:41 -0700130 main.ONOSbench.handle.sendline("onos $OC1 cfg get|grep packetOutOnly")
131 main.ONOSbench.handle.expect(":~")
jenkins24dde6b2015-06-19 13:40:44 -0700132 check = main.ONOSbench.handle.before
133 if "value=true" in check:
Jon Hall4ba53f02015-07-29 13:07:41 -0700134 main.log.info("cfg set successful")
suibin zhang8a46f2e2015-07-13 21:56:07 -0700135 stepResult = main.TRUE
Jon Hall4ba53f02015-07-29 13:07:41 -0700136 break
137 if i == 4:
suibin zhang8a46f2e2015-07-13 21:56:07 -0700138 main.log.info("Cfg set failed")
139 stepResult = main.FALSE
Jon Hall4ba53f02015-07-29 13:07:41 -0700140 else:
jenkins24dde6b2015-06-19 13:40:44 -0700141 time.sleep(5)
suibin zhang8a46f2e2015-07-13 21:56:07 -0700142
Jon Hall4ba53f02015-07-29 13:07:41 -0700143 utilities.assert_equals( expect=main.TRUE,
144 actual=stepResult,
145 onpass="Successfully configure onos for cbench test ",
suibin zhang8a46f2e2015-07-13 21:56:07 -0700146 onfail="Failed to configure onos for cbench test" )
jenkins24dde6b2015-06-19 13:40:44 -0700147
Jon Hall4ba53f02015-07-29 13:07:41 -0700148
149
150
jenkins24dde6b2015-06-19 13:40:44 -0700151 def CASE2( self, main ):
suibin zhang8a46f2e2015-07-13 21:56:07 -0700152 main.case("Running Cbench")
153 main.step("Issuing cbench commands and grab returned results")
154 validFlag = False
suibin zhangacdd8fe2015-08-31 17:01:39 -0700155 cbenchCMD = main.params[ 'TEST' ][ 'cbenchCMD' ]
jenkins24dde6b2015-06-19 13:40:44 -0700156 mode = main.params[ 'TEST' ][ 'mode' ]
157 if mode != "t":
Jon Hall4ba53f02015-07-29 13:07:41 -0700158 mode = " "
jenkins24dde6b2015-06-19 13:40:44 -0700159
suibin zhangacdd8fe2015-08-31 17:01:39 -0700160 runCbench = ( "ssh " + CBENCHuser + "@" + ONOSIp[1] + " " + cbenchCMD + mode )
jenkins24dde6b2015-06-19 13:40:44 -0700161 main.ONOSbench.handle.sendline(runCbench)
162 time.sleep(30)
Jon Hall4ba53f02015-07-29 13:07:41 -0700163 main.ONOSbench.handle.expect(":~")
jenkins24dde6b2015-06-19 13:40:44 -0700164 output = main.ONOSbench.handle.before
165 main.log.info(output)
166
167 output = output.splitlines()
Jon Hall4ba53f02015-07-29 13:07:41 -0700168 for line in output:
suibin zhang8a46f2e2015-07-13 21:56:07 -0700169 if "RESULT: " in line:
170 validFlag = True
jenkins24dde6b2015-06-19 13:40:44 -0700171 print line
Jon Hall4ba53f02015-07-29 13:07:41 -0700172 resultLine = line.split(" ")
suibin zhang8a46f2e2015-07-13 21:56:07 -0700173 for word in resultLine:
Jon Hall4ba53f02015-07-29 13:07:41 -0700174 if word == "min/max/avg/stdev":
suibin zhang8a46f2e2015-07-13 21:56:07 -0700175 resultsIndex = resultLine.index(word)
176 print resultsIndex
177 break
jenkins24dde6b2015-06-19 13:40:44 -0700178
suibin zhang8a46f2e2015-07-13 21:56:07 -0700179 finalDataString = resultLine[resultsIndex + 2]
180 print finalDataString
181 finalDataList = finalDataString.split("/")
182 avg = finalDataList[2]
183 stdev = finalDataList[3]
Jon Hall4ba53f02015-07-29 13:07:41 -0700184
185 main.log.info("Average: \t\t\t" + avg)
186 main.log.info("Standard Deviation: \t" + stdev)
187
jenkins24dde6b2015-06-19 13:40:44 -0700188
suibin zhang8a46f2e2015-07-13 21:56:07 -0700189 commit = main.ONOSbench.getVersion()
190 commit = (commit.split(" "))[1]
jenkins24dde6b2015-06-19 13:40:44 -0700191
suibin zhang8a46f2e2015-07-13 21:56:07 -0700192 try:
193 dbFileName="/tmp/CbenchDB"
Jon Hall4ba53f02015-07-29 13:07:41 -0700194 dbfile = open(dbFileName, "w+")
195 temp = "'" + commit + "',"
196 temp += "'" + mode + "',"
suibin zhang8a46f2e2015-07-13 21:56:07 -0700197 temp += "'" + avg + "',"
Jon Hall4ba53f02015-07-29 13:07:41 -0700198 temp += "'" + stdev + "'\n"
suibin zhang8a46f2e2015-07-13 21:56:07 -0700199 dbfile.write(temp)
200 dbfile.close()
Jon Hall4ba53f02015-07-29 13:07:41 -0700201 main.ONOSbench.logReport(ONOSIp[1], ["ERROR", "WARNING", "EXCEPT"], outputMode="d")
suibin zhang8a46f2e2015-07-13 21:56:07 -0700202 except IOError:
203 main.log.warn("Error opening " + dbFileName + " to write results.")
Jon Hall4ba53f02015-07-29 13:07:41 -0700204
suibin zhang8a46f2e2015-07-13 21:56:07 -0700205 stepResult = main.TRUE
206 break
207 if ( validFlag == False ):
208 main.log.warn("Cbench Test produced no valid results!!!!")
209 stepResult = main.FALSE
jenkins24dde6b2015-06-19 13:40:44 -0700210
suibin zhang8a46f2e2015-07-13 21:56:07 -0700211 utilities.assert_equals( expect=main.TRUE,
212 actual=stepResult,
213 onpass="Successfully tested onos for cbench. ",
214 onfail="Failed to obtain valid onos cbench result!" )
jenkins24dde6b2015-06-19 13:40:44 -0700215
216
217
218
219
220