blob: ddadce230ff66bb27f9c26e2a9a9eaf2b9845ecb [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' ]
GlennRCf6826f12015-12-10 11:56:12 -080040 cellApps = main.params[ 'ENV' ][ 'cellApps' ]
jenkins24dde6b2015-06-19 13:40:44 -070041
Jon Hall4ba53f02015-07-29 13:07:41 -070042 # -- INIT SECTION, ONLY RUNS ONCE -- #
43 if init == False:
jenkins24dde6b2015-06-19 13:40:44 -070044 init = True
45 global clusterCount #number of nodes running
46 global ONOSIp #list of ONOS IP addresses
Jon Hall4ba53f02015-07-29 13:07:41 -070047 global scale
48
jenkins24dde6b2015-06-19 13:40:44 -070049 clusterCount = 0
50 ONOSIp = [ 0 ]
Jon Hall4ba53f02015-07-29 13:07:41 -070051 scale = (main.params[ 'SCALE' ]).split(",")
jenkins24dde6b2015-06-19 13:40:44 -070052 clusterCount = int(scale[0])
53
Jon Hall4ba53f02015-07-29 13:07:41 -070054 #Populate ONOSIp with ips from params
55 for i in range(1, maxNodes + 1):
Jon Hallf57a5ef2015-07-07 17:56:16 -070056 ipString = os.environ[main.params['CTRL']['ip1']]
Jon Hall4ba53f02015-07-29 13:07:41 -070057 ONOSIp.append(ipString)
58
jenkins24dde6b2015-06-19 13:40:44 -070059 #mvn clean install, for debugging set param 'skipCleanInstall' to yes to speed up test
60 if skipMvn != "yes":
61 mvnResult = main.ONOSbench.cleanInstall()
62
63 #git
64 main.step( "Git checkout and pull " + checkoutBranch )
65 if gitPull == 'on':
66 checkoutResult = main.ONOSbench.gitCheckout( checkoutBranch )
67 pullResult = main.ONOSbench.gitPull()
68
69 else:
70 checkoutResult = main.TRUE
71 pullResult = main.TRUE
72 main.log.info( "Skipped git checkout and pull" )
Jon Hall4ba53f02015-07-29 13:07:41 -070073
jenkins24dde6b2015-06-19 13:40:44 -070074 # -- END OF INIT SECTION --#
Jon Hall4ba53f02015-07-29 13:07:41 -070075
jenkins24dde6b2015-06-19 13:40:44 -070076 clusterCount = int(scale[0])
Jon Hall4ba53f02015-07-29 13:07:41 -070077 scale.remove(scale[0])
78
79 #kill off all onos processes
Jon Hall6509dbf2016-06-21 17:01:17 -070080 main.step("Safety check, killing all ONOS processes")
81 main.step("before initiating environment setup")
jenkins24dde6b2015-06-19 13:40:44 -070082 for node in range(1, maxNodes + 1):
You Wangb98a9fa2017-02-15 17:27:42 -080083 main.ONOSbench.onosStop(ONOSIp[node])
84 main.ONOSbench.onosKill(ONOSIp[node])
Jon Hall4ba53f02015-07-29 13:07:41 -070085
jenkins24dde6b2015-06-19 13:40:44 -070086 #Uninstall everywhere
Jon Hall6509dbf2016-06-21 17:01:17 -070087 main.step( "Cleaning Enviornment..." )
jenkins24dde6b2015-06-19 13:40:44 -070088 for i in range(1, maxNodes + 1):
89 main.log.info(" Uninstalling ONOS " + str(i) )
90 main.ONOSbench.onosUninstall( ONOSIp[i] )
Jon Hall4ba53f02015-07-29 13:07:41 -070091
Jon Hallf57a5ef2015-07-07 17:56:16 -070092 time.sleep(10)
93 main.ONOSbench.handle.sendline(" ")
94 main.ONOSbench.handle.expect(":~")
Jon Hall4ba53f02015-07-29 13:07:41 -070095 print "pexpect: \n" + main.ONOSbench.handle.before
Jon Hallf57a5ef2015-07-07 17:56:16 -070096
97
98 print "Cellname is: "+ cellName + "ONOS IP is: " + str(ONOSIp)
Devin Lim461f0872017-06-05 16:49:33 -070099 main.ONOSbench.createCellFile(BENCHIp, cellName, MN1Ip,
100 cellApps, [ONOSIp[1]], main.ONOScli1.user_name)
Jon Hall4ba53f02015-07-29 13:07:41 -0700101
jenkins24dde6b2015-06-19 13:40:44 -0700102 main.step( "Set Cell" )
103 main.ONOSbench.setCell(cellName)
Jon Hallf57a5ef2015-07-07 17:56:16 -0700104
Jon Hall4ba53f02015-07-29 13:07:41 -0700105 #main.ONOSbench.handle.sendline(" ")
106 #main.ONOSbench.handle.expect(":~")
107 #print "pexpect: \n" + main.ONOSbench.handle.before
Jon Hallf57a5ef2015-07-07 17:56:16 -0700108
jenkins24dde6b2015-06-19 13:40:44 -0700109 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700110 packageResult = main.ONOSbench.buckBuild()
jenkins24dde6b2015-06-19 13:40:44 -0700111
112 main.step( "verify cells" )
113 verifyCellResult = main.ONOSbench.verifyCell()
Jon Hall4ba53f02015-07-29 13:07:41 -0700114
suibin zhang8a46f2e2015-07-13 21:56:07 -0700115 main.log.report( "Initializing " + str( clusterCount ) + " node cluster." )
jenkins24dde6b2015-06-19 13:40:44 -0700116 for node in range(1, clusterCount + 1):
117 main.log.info("Starting ONOS " + str(node) + " at IP: " + ONOSIp[node])
118 main.ONOSbench.onosInstall( ONOSIp[node])
119
120 for node in range(1, clusterCount + 1):
121 for i in range( 2 ):
122 isup = main.ONOSbench.isup( ONOSIp[node] )
123 if isup:
124 main.log.info("ONOS " + str(node) + " is up\n")
125 break
126 if not isup:
127 main.log.report( "ONOS " + str(node) + " didn't start!" )
128 main.log.info("Startup sequence complete")
129
Jon Hall4ba53f02015-07-29 13:07:41 -0700130 for i in range(5):
jenkins24dde6b2015-06-19 13:40:44 -0700131 main.ONOSbench.onosCfgSet(ONOSIp[1], "org.onosproject.fwd.ReactiveForwarding","packetOutOnly true")
132 time.sleep(5)
Jon Hall4ba53f02015-07-29 13:07:41 -0700133 main.ONOSbench.handle.sendline("onos $OC1 cfg get|grep packetOutOnly")
134 main.ONOSbench.handle.expect(":~")
jenkins24dde6b2015-06-19 13:40:44 -0700135 check = main.ONOSbench.handle.before
136 if "value=true" in check:
Jon Hall4ba53f02015-07-29 13:07:41 -0700137 main.log.info("cfg set successful")
suibin zhang8a46f2e2015-07-13 21:56:07 -0700138 stepResult = main.TRUE
Jon Hall4ba53f02015-07-29 13:07:41 -0700139 break
140 if i == 4:
suibin zhang8a46f2e2015-07-13 21:56:07 -0700141 main.log.info("Cfg set failed")
142 stepResult = main.FALSE
Jon Hall4ba53f02015-07-29 13:07:41 -0700143 else:
jenkins24dde6b2015-06-19 13:40:44 -0700144 time.sleep(5)
suibin zhang8a46f2e2015-07-13 21:56:07 -0700145
Jon Hall4ba53f02015-07-29 13:07:41 -0700146 utilities.assert_equals( expect=main.TRUE,
147 actual=stepResult,
148 onpass="Successfully configure onos for cbench test ",
suibin zhang8a46f2e2015-07-13 21:56:07 -0700149 onfail="Failed to configure onos for cbench test" )
jenkins24dde6b2015-06-19 13:40:44 -0700150
Jon Hall4ba53f02015-07-29 13:07:41 -0700151
152
153
jenkins24dde6b2015-06-19 13:40:44 -0700154 def CASE2( self, main ):
suibin zhang8a46f2e2015-07-13 21:56:07 -0700155 main.case("Running Cbench")
156 main.step("Issuing cbench commands and grab returned results")
157 validFlag = False
suibin zhangacdd8fe2015-08-31 17:01:39 -0700158 cbenchCMD = main.params[ 'TEST' ][ 'cbenchCMD' ]
jenkins24dde6b2015-06-19 13:40:44 -0700159 mode = main.params[ 'TEST' ][ 'mode' ]
160 if mode != "t":
Jon Hall4ba53f02015-07-29 13:07:41 -0700161 mode = " "
jenkins24dde6b2015-06-19 13:40:44 -0700162
suibin zhangacdd8fe2015-08-31 17:01:39 -0700163 runCbench = ( "ssh " + CBENCHuser + "@" + ONOSIp[1] + " " + cbenchCMD + mode )
jenkins24dde6b2015-06-19 13:40:44 -0700164 main.ONOSbench.handle.sendline(runCbench)
165 time.sleep(30)
Jon Hall4ba53f02015-07-29 13:07:41 -0700166 main.ONOSbench.handle.expect(":~")
jenkins24dde6b2015-06-19 13:40:44 -0700167 output = main.ONOSbench.handle.before
168 main.log.info(output)
169
170 output = output.splitlines()
Jon Hall4ba53f02015-07-29 13:07:41 -0700171 for line in output:
suibin zhang8a46f2e2015-07-13 21:56:07 -0700172 if "RESULT: " in line:
173 validFlag = True
jenkins24dde6b2015-06-19 13:40:44 -0700174 print line
Jon Hall4ba53f02015-07-29 13:07:41 -0700175 resultLine = line.split(" ")
suibin zhang8a46f2e2015-07-13 21:56:07 -0700176 for word in resultLine:
Jon Hall4ba53f02015-07-29 13:07:41 -0700177 if word == "min/max/avg/stdev":
suibin zhang8a46f2e2015-07-13 21:56:07 -0700178 resultsIndex = resultLine.index(word)
179 print resultsIndex
180 break
jenkins24dde6b2015-06-19 13:40:44 -0700181
suibin zhang8a46f2e2015-07-13 21:56:07 -0700182 finalDataString = resultLine[resultsIndex + 2]
183 print finalDataString
184 finalDataList = finalDataString.split("/")
185 avg = finalDataList[2]
186 stdev = finalDataList[3]
Jon Hall4ba53f02015-07-29 13:07:41 -0700187
188 main.log.info("Average: \t\t\t" + avg)
189 main.log.info("Standard Deviation: \t" + stdev)
190
jenkins24dde6b2015-06-19 13:40:44 -0700191
suibin zhang8a46f2e2015-07-13 21:56:07 -0700192 commit = main.ONOSbench.getVersion()
193 commit = (commit.split(" "))[1]
jenkins24dde6b2015-06-19 13:40:44 -0700194
suibin zhang8a46f2e2015-07-13 21:56:07 -0700195 try:
196 dbFileName="/tmp/CbenchDB"
Jon Hall4ba53f02015-07-29 13:07:41 -0700197 dbfile = open(dbFileName, "w+")
198 temp = "'" + commit + "',"
199 temp += "'" + mode + "',"
suibin zhang8a46f2e2015-07-13 21:56:07 -0700200 temp += "'" + avg + "',"
Jon Hall4ba53f02015-07-29 13:07:41 -0700201 temp += "'" + stdev + "'\n"
suibin zhang8a46f2e2015-07-13 21:56:07 -0700202 dbfile.write(temp)
203 dbfile.close()
Jon Hall4ba53f02015-07-29 13:07:41 -0700204 main.ONOSbench.logReport(ONOSIp[1], ["ERROR", "WARNING", "EXCEPT"], outputMode="d")
suibin zhang8a46f2e2015-07-13 21:56:07 -0700205 except IOError:
206 main.log.warn("Error opening " + dbFileName + " to write results.")
Jon Hall4ba53f02015-07-29 13:07:41 -0700207
suibin zhang8a46f2e2015-07-13 21:56:07 -0700208 stepResult = main.TRUE
209 break
210 if ( validFlag == False ):
211 main.log.warn("Cbench Test produced no valid results!!!!")
212 stepResult = main.FALSE
jenkins24dde6b2015-06-19 13:40:44 -0700213
suibin zhang8a46f2e2015-07-13 21:56:07 -0700214 utilities.assert_equals( expect=main.TRUE,
215 actual=stepResult,
216 onpass="Successfully tested onos for cbench. ",
217 onfail="Failed to obtain valid onos cbench result!" )
jenkins24dde6b2015-06-19 13:40:44 -0700218
219
220
221
222
223