blob: 3dff2e21cf147558ee4f80c4e247ddff9a50975f [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
2'''
James Leec9cacaf2014-04-08 09:17:39 -07003Created on 31-May-2013
adminbae64d82013-08-01 10:50:15 -07004
James Leec9cacaf2014-04-08 09:17:39 -07005@author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
adminbae64d82013-08-01 10:50:15 -07006
James Leec9cacaf2014-04-08 09:17:39 -07007TestON is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 2 of the License, or
10(at your option) any later version.
adminbae64d82013-08-01 10:50:15 -070011
James Leec9cacaf2014-04-08 09:17:39 -070012TestON is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
adminbae64d82013-08-01 10:50:15 -070016
James Leec9cacaf2014-04-08 09:17:39 -070017You should have received a copy of the GNU General Public License
18along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070019
20
James Leec9cacaf2014-04-08 09:17:39 -070021'''
adminbae64d82013-08-01 10:50:15 -070022import time
23import pexpect
24import struct, fcntl, os, sys, signal
adminbae64d82013-08-01 10:50:15 -070025import re
26import json
Jon Hallf89c8552014-04-02 13:14:06 -070027import traceback
adminbae64d82013-08-01 10:50:15 -070028sys.path.append("../")
29from drivers.common.clidriver import CLI
30
31class OnosCliDriver(CLI):
32
33 def __init__(self):
34 super(CLI, self).__init__()
35
36 def connect(self,**connectargs):
Jon Halld8dc5772014-04-08 16:26:29 -070037 '''
38 Creates ssh handle for ONOS.
39 '''
Jon Hallf89c8552014-04-02 13:14:06 -070040 try:
41 for key in connectargs:
admine0eeea22014-04-14 10:22:46 -070042 vars(self)[key] = connectargs[key]
Jon Hallf89c8552014-04-02 13:14:06 -070043 self.home = "~/ONOS"
44 for key in self.options:
admine0eeea22014-04-14 10:22:46 -070045 if key == "home":
46 self.home = self.options['home']
47 break
adminbae64d82013-08-01 10:50:15 -070048
Jon Hallf89c8552014-04-02 13:14:06 -070049
50 self.name = self.options['name']
51 self.handle = super(OnosCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd, home = self.home)
adminbae64d82013-08-01 10:50:15 -070052
Jon Hallf89c8552014-04-02 13:14:06 -070053 if self.handle:
Jon Hallf89c8552014-04-02 13:14:06 -070054 return self.handle
55 else :
56 main.log.info("NO ONOS HANDLE")
57 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -070058 except pexpect.EOF:
59 main.log.error(self.name + ": EOF exception found")
60 main.log.error(self.name + ": " + self.handle.before)
61 main.cleanup()
62 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -070063 except:
64 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
65 main.log.error( traceback.print_exc() )
66 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
67 main.cleanup()
68 main.exit()
adminbae64d82013-08-01 10:50:15 -070069
70 def start(self):
Jon Halld8dc5772014-04-08 16:26:29 -070071 '''
72 Starts ONOS on remote machine.
73 Returns false if any errors were encountered.
74 '''
James Leec9cacaf2014-04-08 09:17:39 -070075 try:
Jon Hallf89c8552014-04-02 13:14:06 -070076 self.handle.sendline("")
Jon Hallae05dc22014-04-16 10:56:28 -070077 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
adminf939f8b2014-04-03 17:22:56 -070078 self.handle.sendline(self.home + "/onos.sh core start")
Jon Hallae05dc22014-04-16 10:56:28 -070079 i=self.handle.expect(["STARTED","FAILED",pexpect.EOF,pexpect.TIMEOUT])
80 response = self.handle.before + str(self.handle.after)
Jon Hallf89c8552014-04-02 13:14:06 -070081 if i==0:
Jon Hallae05dc22014-04-16 10:56:28 -070082 j = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], timeout=60)
83 if re.search("Killed",response):
84 main.log.warn(self.name + ": Killed existing process")
85 if j==0:
Jon Hallf89c8552014-04-02 13:14:06 -070086 main.log.info(self.name + ": ONOS Started ")
Jon Hallae05dc22014-04-16 10:56:28 -070087 return main.TRUE
88 elif j==1:
89 main.log.error(self.name + ": EOF exception found")
90 main.log.error(self.name + ": " + self.handle.before)
91 main.cleanup()
92 main.exit()
93 elif j==2:
Jon Hallf89c8552014-04-02 13:14:06 -070094 main.log.info(self.name + ": ONOS NOT Started, stuck while waiting for it to start ")
95 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -070096 else:
97 main.log.warn(self.name +": Unexpected response in start")
98 return main.TRUE
Jon Hallf89c8552014-04-02 13:14:06 -070099 elif i==1:
Jon Hallae05dc22014-04-16 10:56:28 -0700100 main.log.error(self.name + ": ONOS Failed to start")
adminbae64d82013-08-01 10:50:15 -0700101 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700102 elif i==2:
103 main.log.error(self.name + ": EOF exception found")
104 main.log.error(self.name + ": " + self.handle.before)
105 main.cleanup()
106 main.exit()
107 elif i==3:
108 main.log.error(self.name + ": ONOS timedout while starting")
109 return main.FALSE
110 else:
111 main.log.error(self.name + ": ONOS start expect script missed something... ")
adminbae64d82013-08-01 10:50:15 -0700112 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700113 except pexpect.EOF:
114 main.log.error(self.name + ": EOF exception found")
115 main.log.error(self.name + ": " + self.handle.before)
116 main.cleanup()
117 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700118 except:
119 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
120 main.log.error( traceback.print_exc() )
121 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
122 main.cleanup()
123 main.exit()
admine0ae8202013-08-28 11:51:43 -0700124
adminbae64d82013-08-01 10:50:15 -0700125 def start_rest(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700126 '''
127 Starts the rest server on ONOS.
128 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700129 try:
130 response = self.execute(cmd= self.home + "/start-rest.sh start",prompt="\$",timeout=10)
131 if re.search("admin",response):
132 main.log.info(self.name + ": Rest Server Started Successfully")
133 time.sleep(5)
134 return main.TRUE
135 else :
James Leec9cacaf2014-04-08 09:17:39 -0700136 main.log.warn(self.name + ": Failed to start Rest Server")
137 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700138 except pexpect.EOF:
139 main.log.error(self.name + ": EOF exception found")
140 main.log.error(self.name + ": " + self.handle.before)
141 main.cleanup()
142 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700143 except:
144 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
145 main.log.error( traceback.print_exc() )
146 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
147 main.cleanup()
148 main.exit()
149
adminbae64d82013-08-01 10:50:15 -0700150 def status(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700151 '''
152 Called onos.sh core status and returns TRUE/FALSE accordingly
153 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700154 try:
155 self.execute(cmd="\n",prompt="\$",timeout=10)
adminf939f8b2014-04-03 17:22:56 -0700156 response = self.execute(cmd= self.home + "/onos.sh core status ",prompt="\d+\sinstance\sof\sonos\srunning",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700157 self.execute(cmd="\n",prompt="\$",timeout=10)
158 if re.search("1\sinstance\sof\sonos\srunning",response):
159 return main.TRUE
160 elif re.search("0\sinstance\sof\sonos\srunning",response):
161 return main.FALSE
162 else :
163 main.log.info( self.name + " WARNING: status recieved unknown response")
164 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700165 except pexpect.EOF:
166 main.log.error(self.name + ": EOF exception found")
167 main.log.error(self.name + ": " + self.handle.before)
168 main.cleanup()
169 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700170 except:
171 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
172 main.log.error( traceback.print_exc() )
173 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
174 main.cleanup()
175 main.exit()
176
adminbae64d82013-08-01 10:50:15 -0700177
178 def isup(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700179 '''
180 A more complete check to see if ONOS is up and running properly.
181 First, it checks if the process is up.
182 Second, it reads the logs for "Exception: Connection refused"
183 Third, it makes sure the logs are actually moving.
184 returns TRUE/FALSE accordingly.
185 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700186 try:
187 self.execute(cmd="\n",prompt="\$",timeout=10)
adminf939f8b2014-04-03 17:22:56 -0700188 response = self.execute(cmd= self.home + "/onos.sh core status ",prompt="running",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700189 self.execute(cmd="\n",prompt="\$",timeout=10)
190 tail1 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10)
191 time.sleep(30)
192 self.execute(cmd="\n",prompt="\$",timeout=10)
193 tail2 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10)
194 pattern = '(.*)1 instance(.*)'
195 pattern2 = '(.*)Exception: Connection refused(.*)'
196 # if utilities.assert_matches(expect=pattern,actual=response,onpass="ONOS process is running...",onfail="ONOS process not running..."):
197
198 if re.search(pattern, response):
199 main.log.info(self.name + ": ONOS process is running...")
200 if tail1 == tail2:
201 main.log.error(self.name + ": ONOS is frozen...")#logs aren't moving
202 return main.FALSE
203 elif re.search( pattern2,tail1 ):
James Leec9cacaf2014-04-08 09:17:39 -0700204 main.log.info(self.name + ": Connection Refused found in onos log")
Jon Hallf89c8552014-04-02 13:14:06 -0700205 return main.FALSE
206 elif re.search( pattern2,tail2 ):
James Leec9cacaf2014-04-08 09:17:39 -0700207 main.log.info(self.name + ": Connection Refused found in onos log")
Jon Hallf89c8552014-04-02 13:14:06 -0700208 return main.FALSE
209 else:
210 main.log.info(self.name + ": Onos log is moving! It's looking good!")
211 return main.TRUE
adminbae64d82013-08-01 10:50:15 -0700212 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700213 main.log.error(self.name + ": ONOS process not running...")
214 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700215 except pexpect.EOF:
216 main.log.error(self.name + ": EOF exception found")
217 main.log.error(self.name + ": " + self.handle.before)
218 main.cleanup()
219 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700220 except:
221 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
222 main.log.error( traceback.print_exc() )
223 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
224 main.cleanup()
225 main.exit()
adminbae64d82013-08-01 10:50:15 -0700226
Jon Hallf89c8552014-04-02 13:14:06 -0700227
228
James Leec9cacaf2014-04-08 09:17:39 -0700229 def rest_status(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700230 '''
231 Checks if the rest server is running.
232 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700233 try:
234 response = self.execute(cmd= self.home + "/start-rest.sh status ",prompt="running",timeout=10)
235 if re.search("rest\sserver\sis\srunning",response):
236 main.log.info(self.name + ": Rest Server is running")
Jon Hallae05dc22014-04-16 10:56:28 -0700237 return main.TRUE
Jon Hallf89c8552014-04-02 13:14:06 -0700238 elif re.search("rest\sserver\sis\snot\srunning",response):
239 main.log.warn(self.name + ": Rest Server is not Running")
Jon Hallae05dc22014-04-16 10:56:28 -0700240 return main.FALSE
Jon Hallf89c8552014-04-02 13:14:06 -0700241 else :
242 main.log.error(self.name + ": No response" +response)
Jon Hallae05dc22014-04-16 10:56:28 -0700243 return main.FALSE
244 except pexpect.EOF:
245 main.log.error(self.name + ": EOF exception found")
246 main.log.error(self.name + ": " + self.handle.before)
247 main.cleanup()
248 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700249 except:
250 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
251 main.log.error( traceback.print_exc() )
252 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
253 main.cleanup()
254 main.exit()
255
256
adminbae64d82013-08-01 10:50:15 -0700257 def stop(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700258 '''
259 Runs ./onos.sh core stop to stop ONOS
260 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700261 try:
262 self.handle.sendline("")
Jon Hallae05dc22014-04-16 10:56:28 -0700263 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
adminf939f8b2014-04-03 17:22:56 -0700264 self.handle.sendline(self.home + "/onos.sh core stop")
Jon Hallae05dc22014-04-16 10:56:28 -0700265 i=self.handle.expect(["Stop",pexpect.EOF,pexpect.TIMEOUT])
266 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], 60)
James Leec9cacaf2014-04-08 09:17:39 -0700267 result = self.handle.before
Jon Hallf89c8552014-04-02 13:14:06 -0700268 if re.search("Killed", result):
269 main.log.info(self.name + ": ONOS Killed Successfully")
270 return main.TRUE
271 else :
272 main.log.warn(self.name + ": ONOS wasn't running")
273 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700274 except pexpect.EOF:
275 main.log.error(self.name + ": EOF exception found")
276 main.log.error(self.name + ": " + self.handle.before)
277 main.cleanup()
278 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700279 except:
280 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
281 main.log.error( traceback.print_exc() )
282 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
283 main.cleanup()
284 main.exit()
285
adminbae64d82013-08-01 10:50:15 -0700286
287 def rest_stop(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700288 '''
289 Runs ./start-rest.sh stop to stop ONOS rest server
290 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700291 try:
292 response = self.execute(cmd= self.home + "/start-rest.sh stop ",prompt="killing",timeout=10)
293 self.execute(cmd="\n",prompt="\$",timeout=10)
294 if re.search("killing", response):
295 main.log.info(self.name + ": Rest Server Stopped")
296 return main.TRUE
297 else :
298 main.log.error(self.name + ": Failed to Stop, Rest Server is not Running")
299 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700300 except pexpect.EOF:
301 main.log.error(self.name + ": EOF exception found")
302 main.log.error(self.name + ": " + self.handle.before)
303 main.cleanup()
304 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700305 except:
306 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
307 main.log.error( traceback.print_exc() )
308 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
309 main.cleanup()
310 main.exit()
311
312
adminbae64d82013-08-01 10:50:15 -0700313 def disconnect(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700314 '''
315 Called when Test is complete to disconnect the ONOS handle.
316 '''
adminaeedddd2013-08-02 15:14:15 -0700317 response = ''
318 try:
adminbae64d82013-08-01 10:50:15 -0700319 self.handle.sendline("exit")
adminaeedddd2013-08-02 15:14:15 -0700320 self.handle.expect("closed")
Jon Hallae05dc22014-04-16 10:56:28 -0700321 except pexpect.EOF:
322 main.log.error(self.name + ": EOF exception found")
323 main.log.error(self.name + ": " + self.handle.before)
James Leec9cacaf2014-04-08 09:17:39 -0700324 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700325 main.log.error(self.name + ": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700326 response = main.FALSE
adminaeedddd2013-08-02 15:14:15 -0700327 return response
328
Jon Hall76f2c462014-04-17 11:37:15 -0700329 def print_version(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700330 '''
331 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
332 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700333 try:
334 self.handle.sendline("export TERM=xterm-256color")
335 self.handle.expect("xterm-256color")
James Leec9cacaf2014-04-08 09:17:39 -0700336 self.handle.expect("\$")
adminf939f8b2014-04-03 17:22:56 -0700337 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.")
Jon Hallf89c8552014-04-02 13:14:06 -0700338 self.handle.expect("cd ..")
339 self.handle.expect("\$")
admine0eeea22014-04-14 10:22:46 -0700340 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
341 main.log.report(response)
Jon Hall76f2c462014-04-17 11:37:15 -0700342 except pexpect.EOF:
343 main.log.error(self.name + ": EOF exception found")
344 main.log.error(self.name + ": " + self.handle.before)
345 main.cleanup()
346 main.exit()
347 except:
348 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
349 main.log.error( traceback.print_exc() )
350 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
351 main.cleanup()
352 def get_version(self):
353 '''
354 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
355 '''
356 try:
357 self.handle.sendline("export TERM=xterm-256color")
358 self.handle.expect("xterm-256color")
359 self.handle.expect("\$")
360 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.")
361 self.handle.expect("cd ..")
362 self.handle.expect("\$")
363 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
admine0eeea22014-04-14 10:22:46 -0700364 lines=response.splitlines()
365 for line in lines:
366 print line
367 return lines[2]
Jon Hallae05dc22014-04-16 10:56:28 -0700368 except pexpect.EOF:
369 main.log.error(self.name + ": EOF exception found")
370 main.log.error(self.name + ": " + self.handle.before)
371 main.cleanup()
372 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700373 except:
374 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
375 main.log.error( traceback.print_exc() )
376 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
377 main.cleanup()
378 main.exit()
adminbae64d82013-08-01 10:50:15 -0700379
Jon Hallf89c8552014-04-02 13:14:06 -0700380 def add_flow(self, testONip, user, password, flowDef):
Jon Halld8dc5772014-04-08 16:26:29 -0700381 '''
382 Copies the flowdef file from TestStation -> ONOS machine
383 Then runs ./add_flow.py to add the flows to ONOS
384 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700385 try:
386 main.log.info("Adding Flows...")
387 self.handle.sendline("scp %s@%s:%s /tmp/flowtmp" %(user,testONip,flowDef))
388 i=self.handle.expect(['[pP]assword:', '100%', pexpect.TIMEOUT],30)
389 if(i==0):
390 self.handle.sendline("%s" %(password))
391 self.handle.sendline("")
392 self.handle.expect("100%")
393 self.handle.expect("\$", 30)
394 self.handle.sendline(self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp")
395 self.handle.expect("\$", 1000)
396 main.log.info("Flows added")
397 return main.TRUE
398
399 elif(i==1):
400 self.handle.sendline("")
401 self.handle.expect("\$", 10)
402 self.handle.sendline( self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp")
403 self.handle.expect("\$", 1000)
404 main.log.info("Flows added")
405 return main.TRUE
406
407 elif(i==2):
408 main.log.error("Flow Def file SCP Timed out...")
409 return main.FALSE
410
411 else:
412 main.log.error("Failed to add flows...")
James Leec9cacaf2014-04-08 09:17:39 -0700413 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700414 except pexpect.EOF:
415 main.log.error(self.name + ": EOF exception found")
416 main.log.error(self.name + ": " + self.handle.before)
417 main.cleanup()
418 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700419 except:
420 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
421 main.log.error( traceback.print_exc() )
422 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
423 main.cleanup()
424 main.exit()
425
adminbae64d82013-08-01 10:50:15 -0700426
427 def delete_flow(self, *delParams):
Jon Halld8dc5772014-04-08 16:26:29 -0700428 '''
429 Deletes a specific flow, a range of flows, or all flows.
430 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700431 try:
432 if len(delParams)==1:
433 if str(delParams[0])=="all":
434 main.log.info(self.name + ": Deleting ALL flows...")
435 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh all",prompt="done",timeout=150)
436 self.handle.sendline(self.home + "/web/delete_flow.py all")
437 self.handle.expect("delete_flow")
438 self.handle.expect("\$",1000)
439 main.log.info(self.name + ": Flows deleted")
440 else:
441 main.log.info(self.name + ": Deleting flow "+str(delParams[0])+"...")
442 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0]),prompt="done",timeout=150)
443 #self.execute(cmd="\n",prompt="\$",timeout=60)
444 self.handle.sendline(self.home +"/web/delete_flow.py %d" % int(delParams[0]))
445 self.handle.expect("delete_flow")
446 self.handle.expect("\$",60)
447 main.log.info(self.name + ": Flow deleted")
448 elif len(delParams)==2:
449 main.log.info(self.name + ": Deleting flows "+str(delParams[0])+" through "+str(delParams[1])+"...")
450 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0])+" "+str(delParams[1]),prompt="done",timeout=150)
451 #self.execute(cmd="\n",prompt="\$",timeout=60)
452 self.handle.sendline(self.home + "/web/delete_flow.py %d %d" % (int(delParams[0]), int(delParams[1])))
453 self.handle.expect("delete_flow")
454 self.handle.expect("\$",600)
455 main.log.info(self.name + ": Flows deleted")
Jon Hallae05dc22014-04-16 10:56:28 -0700456 except pexpect.EOF:
457 main.log.error(self.name + ": EOF exception found")
458 main.log.error(self.name + ": " + self.handle.before)
459 main.cleanup()
460 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700461 except:
462 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
463 main.log.error( traceback.print_exc() )
464 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
465 main.cleanup()
466 main.exit()
adminbae64d82013-08-01 10:50:15 -0700467
468 def check_flow(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700469 '''
470 Calls the ./get_flow.py all and checks:
471 - If each FlowPath has at least one FlowEntry
472 - That there are no "NOT"s found
473 returns TRUE/FALSE
474 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700475 try:
476 flowEntryDetect = 1
477 count = 0
478 self.handle.sendline("clear")
479 time.sleep(1)
480 self.handle.sendline(self.home + "/web/get_flow.py all")
481 self.handle.expect("get_flow")
482 while 1:
483 i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180)
484 if i==0:
485 count = count + 1
486 if flowEntryDetect == 0:
487 main.log.info(self.name + ": FlowPath without FlowEntry")
488 return main.FALSE
489 else:
490 flowEntryDetect = 0
491 elif i==1:
492 flowEntryDetect = 1
493 elif i==2:
494 main.log.error(self.name + ": Found a NOT")
adminbae64d82013-08-01 10:50:15 -0700495 return main.FALSE
Jon Hallf89c8552014-04-02 13:14:06 -0700496 elif i==3:
497 if count == 0:
498 main.log.info(self.name + ": There don't seem to be any flows here...")
499 return main.FALSE
500 else:
501 main.log.info(self.name + ": All flows pass")
502 main.log.info(self.name + ": Number of FlowPaths: "+str(count))
503 return main.TRUE
504 elif i==4:
James Leec9cacaf2014-04-08 09:17:39 -0700505 main.log.error(self.name + ":Check_flow() - Command Timeout!")
Jon Hallf89c8552014-04-02 13:14:06 -0700506 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700507 except pexpect.EOF:
508 main.log.error(self.name + ": EOF exception found")
509 main.log.error(self.name + ": " + self.handle.before)
510 main.cleanup()
511 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700512 except:
513 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
514 main.log.error( traceback.print_exc() )
515 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
516 main.cleanup()
517 main.exit()
adminbae64d82013-08-01 10:50:15 -0700518
519 def get_flow(self, *flowParams):
Jon Halld8dc5772014-04-08 16:26:29 -0700520 '''
521 Returns verbose output of ./get_flow.py
522 '''
523 try:
524 if len(flowParams)==1:
525 if str(flowParams[0])=="all":
526 self.execute(cmd="\n",prompt="\$",timeout=60)
527 main.log.info(self.name + ": Getting all flow data...")
528 data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh all",prompt="done",timeout=150)
529 self.execute(cmd="\n",prompt="\$",timeout=60)
530 return data
531 else:
532 main.log.info(self.name + ": Retrieving flow "+str(flowParams[0])+" data...")
533 data = self.execute(cmd=self.home +"/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150)
534 self.execute(cmd="\n",prompt="\$",timeout=60)
535 return data
536 elif len(flowParams)==5:
537 main.log.info(self.name + ": Retrieving flow installer data...")
538 data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh "+str(flowParams[0])+" "+str(flowParams[1])+" "+str(flowParams[2])+" "+str(flowParams[3])+" "+str(flowParams[4]),prompt="done",timeout=150)
539 self.execute(cmd="\n",prompt="\$",timeout=60)
540 return data
541 elif len(flowParams)==4:
542 main.log.info(self.name + ": Retrieving flow endpoints...")
543 data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh "+str(flowParams[0])+" "+str(flowParams[1])+" "+str(flowParams[2])+" "+str(flowParams[3]),prompt="done",timeout=150)
544 self.execute(cmd="\n",prompt="\$",timeout=60)
545 return data
Jon Hallae05dc22014-04-16 10:56:28 -0700546 except pexpect.EOF:
547 main.log.error(self.name + ": EOF exception found")
548 main.log.error(self.name + ": " + self.handle.before)
549 main.cleanup()
550 main.exit()
Jon Halld8dc5772014-04-08 16:26:29 -0700551 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700552 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
553 main.log.error( traceback.print_exc() )
554 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
555 main.cleanup()
556 main.exit()
adminbae64d82013-08-01 10:50:15 -0700557
558
Jon Hall8060af02014-04-14 14:17:58 -0700559# http://localhost:8080/wm/onos/ng/switches/json
560# http://localhost:8080/wm/onos/ng/links/json
561# http://localhost:8080/wm/onos/registry/controllers/json
562# http://localhost:8080/wm/onos/registry/switches/json"
adminbae64d82013-08-01 10:50:15 -0700563
564 def get_json(self, url):
Jon Halld8dc5772014-04-08 16:26:29 -0700565 '''
566 Helper functions used to parse the json output of a rest call
567 '''
adminbae64d82013-08-01 10:50:15 -0700568 try:
Jon Hallf89c8552014-04-02 13:14:06 -0700569 try:
570 command = "curl -s %s" % (url)
571 result = os.popen(command).read()
572 parsedResult = json.loads(result)
573 except:
574 print "REST IF %s has issue" % command
575 parsedResult = ""
576
577 if type(parsedResult) == 'dict' and parsedResult.has_key('code'):
578 print "REST %s returned code %s" % (command, parsedResult['code'])
579 parsedResult = ""
James Leec9cacaf2014-04-08 09:17:39 -0700580 return parsedResult
Jon Hallae05dc22014-04-16 10:56:28 -0700581 except pexpect.EOF:
582 main.log.error(self.name + ": EOF exception found")
583 main.log.error(self.name + ": " + self.handle.before)
584 main.cleanup()
585 main.exit()
adminbae64d82013-08-01 10:50:15 -0700586 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700587 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
588 main.log.error( traceback.print_exc() )
589 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
590 main.cleanup()
591 main.exit()
adminbae64d82013-08-01 10:50:15 -0700592
Jon Hallf89c8552014-04-02 13:14:06 -0700593 def check_switch(self,RestIP,correct_nr_switch, RestPort ="8080" ):
Jon Halld8dc5772014-04-08 16:26:29 -0700594 '''
595 Used by check_status
596 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700597 try:
598 buf = ""
599 retcode = 0
admine0eeea22014-04-14 10:22:46 -0700600 url="http://%s:%s/wm/onos/ng/switches/json" % (RestIP, RestPort)
Jon Hallf89c8552014-04-02 13:14:06 -0700601 parsedResult = self.get_json(url)
602 if parsedResult == "":
603 retcode = 1
604 return (retcode, "Rest API has an issue")
605 url = "http://%s:%s/wm/onos/registry/switches/json" % (RestIP, RestPort)
606 registry = self.get_json(url)
607
608 if registry == "":
609 retcode = 1
610 return (retcode, "Rest API has an issue")
611
612 cnt = 0
613 active = 0
adminbae64d82013-08-01 10:50:15 -0700614
Jon Hallf89c8552014-04-02 13:14:06 -0700615 for s in parsedResult:
616 cnt += 1
James Leec9cacaf2014-04-08 09:17:39 -0700617 if s['state'] == "ACTIVE":
Jon Hallf89c8552014-04-02 13:14:06 -0700618 active += 1
adminbae64d82013-08-01 10:50:15 -0700619
Jon Hallf89c8552014-04-02 13:14:06 -0700620 buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active)
621 if correct_nr_switch != cnt:
622 buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt)
623 retcode = 1
adminbae64d82013-08-01 10:50:15 -0700624
Jon Hallf89c8552014-04-02 13:14:06 -0700625 if correct_nr_switch != active:
626 buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active)
627 retcode = 1
628
629 return (retcode, buf)
Jon Hallae05dc22014-04-16 10:56:28 -0700630 except pexpect.EOF:
631 main.log.error(self.name + ": EOF exception found")
632 main.log.error(self.name + ": " + self.handle.before)
633 main.cleanup()
634 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700635 except:
636 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
637 main.log.error( traceback.print_exc() )
638 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
639 main.cleanup()
640 main.exit()
adminbae64d82013-08-01 10:50:15 -0700641
Jon Hallf89c8552014-04-02 13:14:06 -0700642 def check_link(self,RestIP, nr_links, RestPort = "8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700643 '''
644 Used by check_status
645 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700646 try:
647 buf = ""
648 retcode = 0
649
admine0eeea22014-04-14 10:22:46 -0700650 url = "http://%s:%s/wm/onos/ng/links/json" % (RestIP, RestPort)
Jon Hallf89c8552014-04-02 13:14:06 -0700651 parsedResult = self.get_json(url)
652
653 if parsedResult == "":
654 retcode = 1
655 return (retcode, "Rest API has an issue")
656
657 buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links)
658 intra = 0
659 interlink=0
660
661 for s in parsedResult:
James Leec9cacaf2014-04-08 09:17:39 -0700662 intra = intra + 1
Jon Hallf89c8552014-04-02 13:14:06 -0700663
664 if intra != nr_links:
665 buf += "link fail\n"
666 retcode = 1
667
668 return (retcode, buf)
Jon Hallae05dc22014-04-16 10:56:28 -0700669 except pexpect.EOF:
670 main.log.error(self.name + ": EOF exception found")
671 main.log.error(self.name + ": " + self.handle.before)
672 main.cleanup()
673 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700674 except:
675 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
676 main.log.error( traceback.print_exc() )
677 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
678 main.cleanup()
679 main.exit()
adminbae64d82013-08-01 10:50:15 -0700680
Jon Hallf89c8552014-04-02 13:14:06 -0700681 def check_status_report(self, ip, numoswitch, numolink, port="8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700682 '''
683 Checks the number of swithes & links that ONOS sees against the supplied values.
684 Writes to the report log.
685 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700686 try:
James Leec9cacaf2014-04-08 09:17:39 -0700687 main.log.info(self.name + ": Making some rest calls...")
Jon Hallf89c8552014-04-02 13:14:06 -0700688 switch = self.check_switch(ip, int(numoswitch), port)
689 link = self.check_link(ip, int(numolink), port)
690 value = switch[0]
691 value += link[0]
692 main.log.report( self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
693 if value != 0:
694 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700695 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700696 # "PASS"
697 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700698 except pexpect.EOF:
699 main.log.error(self.name + ": EOF exception found")
700 main.log.error(self.name + ": " + self.handle.before)
701 main.cleanup()
702 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700703 except:
704 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
705 main.log.error( traceback.print_exc() )
706 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
707 main.cleanup()
708 main.exit()
adminbae64d82013-08-01 10:50:15 -0700709
Jon Hallf89c8552014-04-02 13:14:06 -0700710 def check_status(self, ip, numoswitch, numolink, port = "8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700711 '''
712 Checks the number of swithes & links that ONOS sees against the supplied values.
713 Writes to the main log.
714 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700715 try:
James Leec9cacaf2014-04-08 09:17:39 -0700716 main.log.info(self.name + ": Making some rest calls...")
Jon Hallf89c8552014-04-02 13:14:06 -0700717 switch = self.check_switch(ip, int(numoswitch), port)
718 link = self.check_link(ip, int(numolink), port)
719 value = switch[0]
720 value += link[0]
721 main.log.info(self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
722 if value != 0:
723 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700724 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700725 # "PASS"
726 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700727 except pexpect.EOF:
728 main.log.error(self.name + ": EOF exception found")
729 main.log.error(self.name + ": " + self.handle.before)
730 main.cleanup()
731 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700732 except:
733 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
734 main.log.error( traceback.print_exc() )
735 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
736 main.cleanup()
737 main.exit()
adminbae64d82013-08-01 10:50:15 -0700738
adminbae64d82013-08-01 10:50:15 -0700739 def check_for_no_exceptions(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700740 '''
741 TODO: Rewrite
742 Used by CassndraCheck.py to scan ONOS logs for Exceptions
743 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700744 try:
745 self.handle.sendline("dsh 'grep Exception ~/ONOS/onos-logs/onos.*.log'")
James Leec9cacaf2014-04-08 09:17:39 -0700746 self.handle.expect("\$ dsh")
Jon Hallf89c8552014-04-02 13:14:06 -0700747 self.handle.expect("\$")
748 output = self.handle.before
James Leec9cacaf2014-04-08 09:17:39 -0700749 main.log.info(self.name + ": " + output )
Jon Hallf89c8552014-04-02 13:14:06 -0700750 if re.search("Exception",output):
751 return main.FALSE
752 else :
753 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700754 except pexpect.EOF:
755 main.log.error(self.name + ": EOF exception found")
756 main.log.error(self.name + ": " + self.handle.before)
757 main.cleanup()
758 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700759 except:
760 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
761 main.log.error( traceback.print_exc() )
762 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
763 main.cleanup()
764 main.exit()
765
766
admine0eeea22014-04-14 10:22:46 -0700767 def git_pull(self, comp1=""):
Jon Halld8dc5772014-04-08 16:26:29 -0700768 '''
Jon Halld8dc5772014-04-08 16:26:29 -0700769 Assumes that "git pull" works without login
admine0eeea22014-04-14 10:22:46 -0700770
771 This function will perform a git pull on the ONOS instance.
772 If used as git_pull("NODE") it will do git pull + NODE. This is
773 for the purpose of pulling from other nodes if necessary.
774
775 Otherwise, this function will perform a git pull in the
776 ONOS repository. If it has any problems, it will return main.ERROR
777 If it successfully does a git_pull, it will return a 1.
778 If it has no updates, it will return a 0.
779
Jon Halld8dc5772014-04-08 16:26:29 -0700780 '''
Jon Hallae05dc22014-04-16 10:56:28 -0700781 try:
782 main.log.info(self.name + ": Stopping ONOS")
783 self.stop()
784 self.handle.sendline("cd " + self.home)
785 self.handle.expect("ONOS\$")
786 if comp1=="":
787 self.handle.sendline("git pull")
788 else:
789 self.handle.sendline("git pull " + comp1)
790
791 uptodate = 0
SeanCorcoran20bd6fc2014-04-16 17:10:30 -0700792 i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','Unpacking\sobjects',pexpect.TIMEOUT,'Already up-to-date','Aborting'],timeout=1800)
Jon Hallae05dc22014-04-16 10:56:28 -0700793 #debug
794 #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after))
795 if i==0:
796 main.log.error(self.name + ": Git pull had some issue...")
797 return main.ERROR
798 elif i==1:
799 main.log.error(self.name + ": Git Pull Asking for username!!! BADD!")
800 return main.ERROR
801 elif i==2:
802 main.log.info(self.name + ": Git Pull - pulling repository now")
803 self.handle.expect("ONOS\$", 120)
804 return 0
805 elif i==3:
806 main.log.error(self.name + ": Git Pull - TIMEOUT")
807 return main.ERROR
808 elif i==4:
809 main.log.info(self.name + ": Git Pull - Already up to date")
810 return 1
811 elif i==5:
812 main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?")
813 return main.ERROR
814 else:
815 main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors")
816 return main.ERROR
817 except pexpect.EOF:
818 main.log.error(self.name + ": EOF exception found")
819 main.log.error(self.name + ": " + self.handle.before)
820 main.cleanup()
821 main.exit()
822 except:
823 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
824 main.log.error( traceback.print_exc() )
825 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
826 main.cleanup()
827 main.exit()
admine0eeea22014-04-14 10:22:46 -0700828#********************************************************
829
830
admin7373a812014-04-16 09:49:02 -0700831 def git_compile(self):
Jon Hallae05dc22014-04-16 10:56:28 -0700832 '''
833 Compiles ONOS
834 First runs mvn clean then mvn compile
835 '''
836 try:
837 main.log.info(self.name + ": mvn clean")
admin8fc02822014-04-16 13:31:23 -0700838 self.handle.sendline("cd " + self.home)
Jon Hallae05dc22014-04-16 10:56:28 -0700839 self.handle.sendline("mvn clean")
840 while 1:
Jon Hall1636f942014-04-17 10:07:23 -0700841 i=self.handle.expect(['There\sis\sinsufficient\smemory\sfor\sthe\sJava\sRuntime\sEnvironment\sto\scontinue','BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=30)
Jon Hallae05dc22014-04-16 10:56:28 -0700842 if i == 0:
Jon Hall1636f942014-04-17 10:07:23 -0700843 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
Jon Hallae05dc22014-04-16 10:56:28 -0700844 return main.FALSE
845 elif i == 1:
Jon Hall1636f942014-04-17 10:07:23 -0700846 main.log.error(self.name + ": Clean failure!")
847 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700848 elif i == 2:
Jon Hall1636f942014-04-17 10:07:23 -0700849 main.log.info(self.name + ": Clean success!")
850 elif i == 3:
admin8fc02822014-04-16 13:31:23 -0700851 main.log.info(self.name + ": Clean complete")
Jon Hallae05dc22014-04-16 10:56:28 -0700852 break;
Jon Hall1636f942014-04-17 10:07:23 -0700853 elif i == 4:
Jon Hallae05dc22014-04-16 10:56:28 -0700854 main.log.error(self.name + ": mvn clean TIMEOUT!")
855 return main.FALSE
Jon Hall1636f942014-04-17 10:07:23 -0700856 else:
857 main.log.error(self.name + ": unexpected response from mvn clean")
858 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700859
860 main.log.info(self.name + ": mvn compile")
861 self.handle.sendline("mvn compile")
862 while 1:
Jon Hall1636f942014-04-17 10:07:23 -0700863 i=self.handle.expect(['There\sis\sinsufficient\smemory\sfor\sthe\sJava\sRuntime\sEnvironment\sto\scontinue','BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=60)
Jon Hallae05dc22014-04-16 10:56:28 -0700864 if i == 0:
Jon Hall1636f942014-04-17 10:07:23 -0700865 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
866 return main.FALSE
867 if i == 1:
Jon Hallae05dc22014-04-16 10:56:28 -0700868 main.log.error(self.name + ": Build failure!")
869 return main.FALSE
Jon Hall1636f942014-04-17 10:07:23 -0700870 elif i == 2:
Jon Hallae05dc22014-04-16 10:56:28 -0700871 main.log.info(self.name + ": Build success!")
872 return main.TRUE
Jon Hall1636f942014-04-17 10:07:23 -0700873 elif i == 3:
Jon Hallae05dc22014-04-16 10:56:28 -0700874 main.log.info(self.name + ": Build complete")
875 return main.TRUE
Jon Hall1636f942014-04-17 10:07:23 -0700876 elif i == 4:
Jon Hallae05dc22014-04-16 10:56:28 -0700877 main.log.error(self.name + ": mvn compile TIMEOUT!")
878 return main.FALSE
879 else:
Jon Hall1636f942014-04-17 10:07:23 -0700880 main.log.error(self.name + ": unexpected response from mvn compile")
881 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700882 except pexpect.EOF:
883 main.log.error(self.name + ": EOF exception found")
884 main.log.error(self.name + ": " + self.handle.before)
885 main.cleanup()
886 main.exit()
887 except:
888 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
889 main.log.error( traceback.print_exc() )
890 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
891 main.cleanup()
892 main.exit()
admin4a58db92013-09-30 12:04:54 -0700893
Jon Hallf89c8552014-04-02 13:14:06 -0700894 def tcpdump(self, intf = "eth0"):
Jon Hallae05dc22014-04-16 10:56:28 -0700895 '''
896 Runs tpdump on an intferface and saves in onos-logs under the ONOS home directory
897 intf can be specified, or the default eth0 is used
898 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700899 try:
900 self.handle.sendline("")
901 self.handle.expect("\$")
Jon Hall26f316b2014-04-11 11:21:25 -0700902 self.handle.sendline("sudo tcpdump -n -i "+ intf + " -s0 -w " + self.home +"/onos-logs/tcpdump &")
Jon Hallf89c8552014-04-02 13:14:06 -0700903 i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT],timeout=10)
904 if i == 0:
905 main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf)
906 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700907 elif i == 1:
Jon Hallf89c8552014-04-02 13:14:06 -0700908 main.log.info(self.name + ": tcpdump started on " + intf)
909 return main.TRUE
James Leec9cacaf2014-04-08 09:17:39 -0700910 elif i == 2:
Jon Hallf89c8552014-04-02 13:14:06 -0700911 main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf)
912 return main.FALSE
913 else:
914 main.log.error(self.name + ": tcpdump - unexpected response")
915 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700916 except pexpect.EOF:
917 main.log.error(self.name + ": EOF exception found")
918 main.log.error(self.name + ": " + self.handle.before)
919 main.cleanup()
920 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700921 except:
922 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
923 main.log.error( traceback.print_exc() )
924 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
925 main.cleanup()
926 main.exit()
927
admin4a58db92013-09-30 12:04:54 -0700928 def kill_tcpdump(self):
Jon Hallae05dc22014-04-16 10:56:28 -0700929 '''
930 Kills any tcpdump processes running
931 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700932 try:
933 self.handle.sendline("")
934 self.handle.expect("\$")
935 self.handle.sendline("sudo kill -9 `ps -ef | grep \"tcpdump -n\" | grep -v grep | awk '{print $2}'`")
Jon Hallae05dc22014-04-16 10:56:28 -0700936 except pexpect.EOF:
937 main.log.error(self.name + ": EOF exception found")
938 main.log.error(self.name + ": " + self.handle.before)
939 main.cleanup()
940 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700941 except:
942 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
943 main.log.error( traceback.print_exc() )
944 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
945 main.cleanup()
946 main.exit()
947
948 def find_host(self,RestIP,RestPort,RestAPI,hostIP):
949 retcode = 0
950 retswitch = []
951 retport = []
952 retmac = []
953 foundIP = []
954 try:
Jon Hall8060af02014-04-14 14:17:58 -0700955 ##### device rest API is: 'host:8080/wm/onos/ng/switches/json' ###
Jon Hallf89c8552014-04-02 13:14:06 -0700956 url ="http://%s:%s%s" %(RestIP,RestPort,RestAPI)
957
958 try:
959 command = "curl -s %s" % (url)
960 result = os.popen(command).read()
961 parsedResult = json.loads(result)
962 # print parsedResult
963 except:
964 print "REST IF %s has issue" % command
965 parsedResult = ""
966
967 if parsedResult == "":
Jon Hallae05dc22014-04-16 10:56:28 -0700968 return (retcode, "Rest API has an error", retport, retmac)
Jon Hallf89c8552014-04-02 13:14:06 -0700969 else:
970 for switch in enumerate(parsedResult):
971 for port in enumerate(switch[1]['ports']):
972 if ( port[1]['devices'] != [] ):
973 try:
James Leec9cacaf2014-04-08 09:17:39 -0700974 foundIP = port[1]['devices'][0]['ipv4addresses'][0]['ipv4']
Jon Hallf89c8552014-04-02 13:14:06 -0700975 except:
976 print "Error in detecting IP address."
977 if foundIP == hostIP:
978 retswitch.append(switch[1]['dpid'])
979 retport.append(port[1]['desc'])
980 retmac.append(port[1]['devices'][0]['mac'])
981 retcode = retcode +1
982 foundIP =''
983 return(retcode, retswitch, retport, retmac)
Jon Hallae05dc22014-04-16 10:56:28 -0700984 except pexpect.EOF:
985 main.log.error(self.name + ": EOF exception found")
986 main.log.error(self.name + ": " + self.handle.before)
987 main.cleanup()
988 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700989 except:
990 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
991 main.log.error( traceback.print_exc() )
992 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
993 main.cleanup()
994 main.exit()