1
2
3
4
5
6
7 import sys
8 import os
9 import os.path
10
11
13
16
18
19 import time
20 import os
21 global init
22 main.case("pre-condition for cbench test.")
23
24 try:
25 if type(init) is not bool:
26 init = False
27 except NameError:
28 init = False
29
30
31 checkoutBranch = main.params[ 'GIT' ][ 'checkout' ]
32 gitPull = main.params[ 'GIT' ][ 'autopull' ]
33 BENCHIp = main.params[ 'BENCH' ][ 'ip1' ]
34 BENCHUser = main.params[ 'BENCH' ][ 'user' ]
35 CBENCHuser = main.params[ 'CBENCH'][ 'user' ]
36 MN1Ip = os.environ[ main.params[ 'MN' ][ 'ip1' ] ]
37 maxNodes = int(main.params[ 'availableNodes' ])
38 skipMvn = main.params[ 'TEST' ][ 'skipCleanInstall' ]
39 cellName = main.params[ 'ENV' ][ 'cellName' ]
40
41
42 if init == False:
43 init = True
44 global clusterCount
45 global ONOSIp
46 global scale
47
48 clusterCount = 0
49 ONOSIp = [ 0 ]
50 scale = (main.params[ 'SCALE' ]).split(",")
51 clusterCount = int(scale[0])
52
53
54 for i in range(1, maxNodes + 1):
55 ipString = os.environ[main.params['CTRL']['ip1']]
56 ONOSIp.append(ipString)
57
58
59 if skipMvn != "yes":
60 mvnResult = main.ONOSbench.cleanInstall()
61
62
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" )
72
73
74
75 clusterCount = int(scale[0])
76 scale.remove(scale[0])
77
78
79 main.log.step("Safety check, killing all ONOS processes")
80 main.log.step("before initiating enviornment setup")
81 for node in range(1, maxNodes + 1):
82 main.ONOSbench.onosDie(ONOSIp[node])
83
84
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] )
89
90 time.sleep(10)
91 main.ONOSbench.handle.sendline(" ")
92 main.ONOSbench.handle.expect(":~")
93 print "pexpect: \n" + main.ONOSbench.handle.before
94
95
96 print "Cellname is: "+ cellName + "ONOS IP is: " + str(ONOSIp)
97 main.ONOSbench.createCellFile(BENCHIp,cellName,MN1Ip,"drivers,openflow,fwd",[ONOSIp[1]])
98
99 main.step( "Set Cell" )
100 main.ONOSbench.setCell(cellName)
101
102
103
104
105
106 main.step( "Creating ONOS package" )
107 packageResult = main.ONOSbench.onosPackage()
108
109 main.step( "verify cells" )
110 verifyCellResult = main.ONOSbench.verifyCell()
111
112 main.log.report( "Initializing " + str( clusterCount ) + " node cluster." )
113 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
127 for i in range(5):
128 main.ONOSbench.onosCfgSet(ONOSIp[1], "org.onosproject.fwd.ReactiveForwarding","packetOutOnly true")
129 time.sleep(5)
130 main.ONOSbench.handle.sendline("onos $OC1 cfg get|grep packetOutOnly")
131 main.ONOSbench.handle.expect(":~")
132 check = main.ONOSbench.handle.before
133 if "value=true" in check:
134 main.log.info("cfg set successful")
135 stepResult = main.TRUE
136 break
137 if i == 4:
138 main.log.info("Cfg set failed")
139 stepResult = main.FALSE
140 else:
141 time.sleep(5)
142
143 utilities.assert_equals( expect=main.TRUE,
144 actual=stepResult,
145 onpass="Successfully configure onos for cbench test ",
146 onfail="Failed to configure onos for cbench test" )
147
148
149
150
151 - def CASE2( self, main ):
152 main.case("Running Cbench")
153 main.step("Issuing cbench commands and grab returned results")
154 validFlag = False
155 mode = main.params[ 'TEST' ][ 'mode' ]
156 if mode != "t":
157 mode = " "
158
159 runCbench = ( "ssh " + CBENCHuser + "@" + ONOSIp[1] + " cbench -c localhost -p 6633 -m 1000 -l 25 -s 16 -M 100000 -w 15 -D 10000 -" + mode )
160 main.ONOSbench.handle.sendline(runCbench)
161 time.sleep(30)
162 main.ONOSbench.handle.expect(":~")
163 output = main.ONOSbench.handle.before
164 main.log.info(output)
165
166 output = output.splitlines()
167 for line in output:
168 if "RESULT: " in line:
169 validFlag = True
170 print line
171 resultLine = line.split(" ")
172 for word in resultLine:
173 if word == "min/max/avg/stdev":
174 resultsIndex = resultLine.index(word)
175 print resultsIndex
176 break
177
178 finalDataString = resultLine[resultsIndex + 2]
179 print finalDataString
180 finalDataList = finalDataString.split("/")
181 avg = finalDataList[2]
182 stdev = finalDataList[3]
183
184 main.log.info("Average: \t\t\t" + avg)
185 main.log.info("Standard Deviation: \t" + stdev)
186
187
188 commit = main.ONOSbench.getVersion()
189 commit = (commit.split(" "))[1]
190
191 try:
192 dbFileName="/tmp/CbenchDB"
193 dbfile = open(dbFileName, "w+")
194 temp = "'" + commit + "',"
195 temp += "'" + mode + "',"
196 temp += "'" + avg + "',"
197 temp += "'" + stdev + "'\n"
198 dbfile.write(temp)
199 dbfile.close()
200 main.ONOSbench.logReport(ONOSIp[1], ["ERROR", "WARNING", "EXCEPT"], outputMode="d")
201 except IOError:
202 main.log.warn("Error opening " + dbFileName + " to write results.")
203
204 stepResult = main.TRUE
205 break
206 if ( validFlag == False ):
207 main.log.warn("Cbench Test produced no valid results!!!!")
208 stepResult = main.FALSE
209
210 utilities.assert_equals( expect=main.TRUE,
211 actual=stepResult,
212 onpass="Successfully tested onos for cbench. ",
213 onfail="Failed to obtain valid onos cbench result!" )
214