blob: bd14c725a9233428a1fa44f70c43480a9828a919 [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' ])
Jon Hall4ba53f02015-07-29 13:07:41 -070038 cellName = main.params[ 'ENV' ][ 'cellName' ]
GlennRCf6826f12015-12-10 11:56:12 -080039 cellApps = main.params[ 'ENV' ][ 'cellApps' ]
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 #git
59 main.step( "Git checkout and pull " + checkoutBranch )
60 if gitPull == 'on':
61 checkoutResult = main.ONOSbench.gitCheckout( checkoutBranch )
62 pullResult = main.ONOSbench.gitPull()
63
64 else:
65 checkoutResult = main.TRUE
66 pullResult = main.TRUE
67 main.log.info( "Skipped git checkout and pull" )
Jon Hall4ba53f02015-07-29 13:07:41 -070068
jenkins24dde6b2015-06-19 13:40:44 -070069 # -- END OF INIT SECTION --#
Jon Hall4ba53f02015-07-29 13:07:41 -070070
jenkins24dde6b2015-06-19 13:40:44 -070071 clusterCount = int(scale[0])
Jon Hall4ba53f02015-07-29 13:07:41 -070072 scale.remove(scale[0])
73
74 #kill off all onos processes
Jon Hall6509dbf2016-06-21 17:01:17 -070075 main.step("Safety check, killing all ONOS processes")
76 main.step("before initiating environment setup")
jenkins24dde6b2015-06-19 13:40:44 -070077 for node in range(1, maxNodes + 1):
You Wangb98a9fa2017-02-15 17:27:42 -080078 main.ONOSbench.onosStop(ONOSIp[node])
79 main.ONOSbench.onosKill(ONOSIp[node])
Jon Hall4ba53f02015-07-29 13:07:41 -070080
jenkins24dde6b2015-06-19 13:40:44 -070081 #Uninstall everywhere
Jon Hall6509dbf2016-06-21 17:01:17 -070082 main.step( "Cleaning Enviornment..." )
jenkins24dde6b2015-06-19 13:40:44 -070083 for i in range(1, maxNodes + 1):
84 main.log.info(" Uninstalling ONOS " + str(i) )
85 main.ONOSbench.onosUninstall( ONOSIp[i] )
Jon Hall4ba53f02015-07-29 13:07:41 -070086
Jon Hallf57a5ef2015-07-07 17:56:16 -070087 time.sleep(10)
Jon Hallf57a5ef2015-07-07 17:56:16 -070088
89 print "Cellname is: "+ cellName + "ONOS IP is: " + str(ONOSIp)
Devin Lim461f0872017-06-05 16:49:33 -070090 main.ONOSbench.createCellFile(BENCHIp, cellName, MN1Ip,
91 cellApps, [ONOSIp[1]], main.ONOScli1.user_name)
Jon Hall4ba53f02015-07-29 13:07:41 -070092
jenkins24dde6b2015-06-19 13:40:44 -070093 main.step( "Set Cell" )
94 main.ONOSbench.setCell(cellName)
Jon Hallf57a5ef2015-07-07 17:56:16 -070095
jenkins24dde6b2015-06-19 13:40:44 -070096 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -070097 packageResult = main.ONOSbench.buckBuild()
jenkins24dde6b2015-06-19 13:40:44 -070098
99 main.step( "verify cells" )
100 verifyCellResult = main.ONOSbench.verifyCell()
Jon Hall4ba53f02015-07-29 13:07:41 -0700101
suibin zhang8a46f2e2015-07-13 21:56:07 -0700102 main.log.report( "Initializing " + str( clusterCount ) + " node cluster." )
jenkins24dde6b2015-06-19 13:40:44 -0700103 for node in range(1, clusterCount + 1):
104 main.log.info("Starting ONOS " + str(node) + " at IP: " + ONOSIp[node])
105 main.ONOSbench.onosInstall( ONOSIp[node])
You Wangb12fa3b2017-06-09 17:10:18 -0700106 main.ONOSbench.onosSecureSSH( node=ONOSIp[node] )
jenkins24dde6b2015-06-19 13:40:44 -0700107
108 for node in range(1, clusterCount + 1):
109 for i in range( 2 ):
110 isup = main.ONOSbench.isup( ONOSIp[node] )
111 if isup:
112 main.log.info("ONOS " + str(node) + " is up\n")
113 break
114 if not isup:
115 main.log.report( "ONOS " + str(node) + " didn't start!" )
116 main.log.info("Startup sequence complete")
117
Jon Hall4ba53f02015-07-29 13:07:41 -0700118 for i in range(5):
jenkins24dde6b2015-06-19 13:40:44 -0700119 main.ONOSbench.onosCfgSet(ONOSIp[1], "org.onosproject.fwd.ReactiveForwarding","packetOutOnly true")
120 time.sleep(5)
Jon Hall4ba53f02015-07-29 13:07:41 -0700121 main.ONOSbench.handle.sendline("onos $OC1 cfg get|grep packetOutOnly")
122 main.ONOSbench.handle.expect(":~")
jenkins24dde6b2015-06-19 13:40:44 -0700123 check = main.ONOSbench.handle.before
124 if "value=true" in check:
Jon Hall4ba53f02015-07-29 13:07:41 -0700125 main.log.info("cfg set successful")
suibin zhang8a46f2e2015-07-13 21:56:07 -0700126 stepResult = main.TRUE
Jon Hall4ba53f02015-07-29 13:07:41 -0700127 break
128 if i == 4:
suibin zhang8a46f2e2015-07-13 21:56:07 -0700129 main.log.info("Cfg set failed")
130 stepResult = main.FALSE
Jon Hall4ba53f02015-07-29 13:07:41 -0700131 else:
jenkins24dde6b2015-06-19 13:40:44 -0700132 time.sleep(5)
suibin zhang8a46f2e2015-07-13 21:56:07 -0700133
Jon Hall4ba53f02015-07-29 13:07:41 -0700134 utilities.assert_equals( expect=main.TRUE,
135 actual=stepResult,
136 onpass="Successfully configure onos for cbench test ",
suibin zhang8a46f2e2015-07-13 21:56:07 -0700137 onfail="Failed to configure onos for cbench test" )
jenkins24dde6b2015-06-19 13:40:44 -0700138
Jon Hall4ba53f02015-07-29 13:07:41 -0700139
jenkins24dde6b2015-06-19 13:40:44 -0700140 def CASE2( self, main ):
suibin zhang8a46f2e2015-07-13 21:56:07 -0700141 main.case("Running Cbench")
142 main.step("Issuing cbench commands and grab returned results")
143 validFlag = False
suibin zhangacdd8fe2015-08-31 17:01:39 -0700144 cbenchCMD = main.params[ 'TEST' ][ 'cbenchCMD' ]
jenkins24dde6b2015-06-19 13:40:44 -0700145 mode = main.params[ 'TEST' ][ 'mode' ]
146 if mode != "t":
Jon Hall4ba53f02015-07-29 13:07:41 -0700147 mode = " "
jenkins24dde6b2015-06-19 13:40:44 -0700148
suibin zhangacdd8fe2015-08-31 17:01:39 -0700149 runCbench = ( "ssh " + CBENCHuser + "@" + ONOSIp[1] + " " + cbenchCMD + mode )
jenkins24dde6b2015-06-19 13:40:44 -0700150 main.ONOSbench.handle.sendline(runCbench)
151 time.sleep(30)
Jon Hall4ba53f02015-07-29 13:07:41 -0700152 main.ONOSbench.handle.expect(":~")
jenkins24dde6b2015-06-19 13:40:44 -0700153 output = main.ONOSbench.handle.before
154 main.log.info(output)
155
156 output = output.splitlines()
Jon Hall4ba53f02015-07-29 13:07:41 -0700157 for line in output:
suibin zhang8a46f2e2015-07-13 21:56:07 -0700158 if "RESULT: " in line:
159 validFlag = True
jenkins24dde6b2015-06-19 13:40:44 -0700160 print line
Jon Hall4ba53f02015-07-29 13:07:41 -0700161 resultLine = line.split(" ")
suibin zhang8a46f2e2015-07-13 21:56:07 -0700162 for word in resultLine:
Jon Hall4ba53f02015-07-29 13:07:41 -0700163 if word == "min/max/avg/stdev":
suibin zhang8a46f2e2015-07-13 21:56:07 -0700164 resultsIndex = resultLine.index(word)
165 print resultsIndex
166 break
jenkins24dde6b2015-06-19 13:40:44 -0700167
suibin zhang8a46f2e2015-07-13 21:56:07 -0700168 finalDataString = resultLine[resultsIndex + 2]
169 print finalDataString
170 finalDataList = finalDataString.split("/")
171 avg = finalDataList[2]
172 stdev = finalDataList[3]
Jon Hall4ba53f02015-07-29 13:07:41 -0700173
174 main.log.info("Average: \t\t\t" + avg)
175 main.log.info("Standard Deviation: \t" + stdev)
176
jenkins24dde6b2015-06-19 13:40:44 -0700177
suibin zhang8a46f2e2015-07-13 21:56:07 -0700178 commit = main.ONOSbench.getVersion()
179 commit = (commit.split(" "))[1]
jenkins24dde6b2015-06-19 13:40:44 -0700180
suibin zhang8a46f2e2015-07-13 21:56:07 -0700181 try:
182 dbFileName="/tmp/CbenchDB"
Jon Hall4ba53f02015-07-29 13:07:41 -0700183 dbfile = open(dbFileName, "w+")
184 temp = "'" + commit + "',"
185 temp += "'" + mode + "',"
suibin zhang8a46f2e2015-07-13 21:56:07 -0700186 temp += "'" + avg + "',"
Jon Hall4ba53f02015-07-29 13:07:41 -0700187 temp += "'" + stdev + "'\n"
suibin zhang8a46f2e2015-07-13 21:56:07 -0700188 dbfile.write(temp)
189 dbfile.close()
Jon Hall4ba53f02015-07-29 13:07:41 -0700190 main.ONOSbench.logReport(ONOSIp[1], ["ERROR", "WARNING", "EXCEPT"], outputMode="d")
suibin zhang8a46f2e2015-07-13 21:56:07 -0700191 except IOError:
192 main.log.warn("Error opening " + dbFileName + " to write results.")
Jon Hall4ba53f02015-07-29 13:07:41 -0700193
suibin zhang8a46f2e2015-07-13 21:56:07 -0700194 stepResult = main.TRUE
195 break
196 if ( validFlag == False ):
197 main.log.warn("Cbench Test produced no valid results!!!!")
198 stepResult = main.FALSE
jenkins24dde6b2015-06-19 13:40:44 -0700199
suibin zhang8a46f2e2015-07-13 21:56:07 -0700200 utilities.assert_equals( expect=main.TRUE,
201 actual=stepResult,
202 onpass="Successfully tested onos for cbench. ",
203 onfail="Failed to obtain valid onos cbench result!" )
jenkins24dde6b2015-06-19 13:40:44 -0700204